akhauriyash/Code-Regression huggingface dataset:
if __name__ == '__main__':
	N = int(input())
	S = input()
	w = [0 for _ in range(N)]
	e = [0 for _ in range(N)]

#	if S[0] == 'W':
#		w[0] = 1

	for i in range(1,N):
		w[i] = w[i-1] + 1 if S[i-1] == 'W' else w[i-1]
		e[-i-1] = e[-i] + 1 if S[-i] == 'E' else e[-i]


	res = [0 for _ in range(N)]
	for i in range(N):
		res[i] = w[i] + e[i]

	print(min(res))

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

int main() {
	int N; cin >> N;
	vector<string>A(3);
	for (int i = 0; i < 3; i++) cin >> A.at(i);
	int ans = 0, ch = 0;
	for (int i = 0; i < N; i++) {
		if (A[0].at(i) != A[1].at(i))ch++;
		if (A[1].at(i) != A[2].at(i)) ch++;
		if (A[0].at(i) != A[2].at(i)) ch++;
		if (ch == 3) ans += 2;
		else ans += min(ch, 3 - ch);
		ch = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r = sc.nextInt();
		if(500*n>=r) {
			System.out.println( "Yes");
					
		}
		else {
			System.out.println("No");
		}
		

	}

}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;

void putstr(string s, int n)
{
    for (int i = 0; i < n; i++)
        cout << s;
}

void solve()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    putstr("R", tx - sx);
    putstr("U", ty - sy);
    putstr("L", tx - sx);
    putstr("D", ty - sy);

    putstr("D", 1);
    putstr("R", tx - sx + 1);
    putstr("U", ty - sy + 1);
    putstr("L", 1);

    putstr("U", 1);
    putstr("L", tx - sx + 1);
    putstr("D", ty - sy + 1);
    putstr("R", 1);

    cout << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <algorithm>

using namespace std;

const int maxn = 2e5 + 10;

int p[maxn], q[maxn];

int findset(int *o, int u)
{
	return u == o[u] ? u : o[u] = findset(o, o[u]);
}

void unionset(int *o, int u, int v)
{
	o[findset(o, u)] = findset(o, v);
}

int main()
{
	int n, K, L;
	scanf("%d %d %d", &n, &K, &L);
	for (int i = 1; i <= n; ++i)
		p[i] = q[i] = i;
	while (K--)
	{
		int u, v;
		scanf("%d %d", &u, &v);
		unionset(p, u, v);
	}
	while (L--)
	{
		int u, v;
		scanf("%d %d", &u, &v);
		unionset(q, u, v);
	}
	map<pair<int, int>, int> cnt;
	for (int i = 1; i <= n; ++i)
		++cnt[{findset(p, i), findset(q, i)}];
	for (int i = 1; i <= n; ++i)
		printf("%d ", cnt[{findset(p, i), findset(q, i)}]);
	puts("");
	return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, l;
    cin >> n >> l;
    int sweet[100];

    rep(i, n) {
        sweet[i] = l + i;
    }
    int Min = INF;
    int ans = INF;

    rep(i, n) {
        int pie = 0;

        rep(j, n) {
            if (j == i) continue;
            pie += sweet[j];
        }
        if (Min > abs((pie + sweet[i]) - pie)) {
            Min = abs((pie + sweet[i]) - pie);
            ans = pie;
        }
    }
    cout << ans << endl;
    return 0;
}



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

char s[100001];
int c[26];

int main() {
    scanf("%s", s);
    memset(c, -1, sizeof c);
    int i;
    for (i = 0; s[i]; i++) {
        int j = s[i] - 'a';
        if (c[j] != -1 && i - c[j] <= 2)
            break;
        c[j] = i;
    }
    if (s[i]) 
        printf("%d %d\n", c[s[i]-'a']+1, i+1);
    else 
        printf("-1 -1\n");
    return 0;
}


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

char S[27];
int N,t[27];

int main()
{
	scanf("%s",S);
	N=strlen(S);
		for(int i=0;i<N;i++)t[S[i]-'a']++;
	if(N==26){
		for(int i=N-2;~i;i--){
			if(S[i]<S[i+1]){
				char c=S[i+1];
				for(int j=0;j<i;j++)putchar(S[j]);
				for(int j=i+1;j<N;j++)if(S[j]>S[i])c=S[j];
				putchar(c);
				return 0;
			}
		}
		puts("-1");
		return 0;
	}
		for(int i=0;i<26;i++)
			if(!t[i])
				return printf("%s",S),putchar('a'+i),0;
	puts("-1");
	return 0;
}
//abcdefghijklmnopqrstuvwzyx
//abcdefghijklmnopqrstuvx

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

long gcd(long a, long b) {

  if (b == 0) {
    return a;
  }

  return gcd(b, a % b);

}

int main() {

  int N;
  cin >> N;

  vector<long> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }

  long g = T[0];
  for (int i = 1; i < N; i++) {
    long g_ = gcd(g, T[i]);
    g = g / g_ * T[i];
  }
  
  cout << g << endl;

}

Measured memory_bytes: 256
def solve(n, aaa):
    NINF = -(10 ** 12)
    dp = [[NINF] * n for _ in range(n)]
    dp_max = [NINF] * n
    ans = 0

    a0, a1 = sorted(aaa[:2])
    dp[a0][a1] = 0
    dp_max[a0] = 0
    dp_max[a1] = 0

    for k in range(n - 1):
        a0, a1, a2 = sorted(aaa[2 + 3 * k:5 + 3 * k])
        if a0 == a1 and a1 == a2:
            ans += 1
            continue

        dp_max_max = max(dp_max)
        update_tasks = []

        if a0 == a1 or a1 == a2:
            rev = a1 == a2
            if rev:
                a0, a2 = a2, a0

            for b in range(n):
                c, d = min(a0, b), max(a0, b)
                e, f = min(a2, b), max(a2, b)
                update_tasks.append((e, f, dp_max[b]))
                update_tasks.append((e, f, dp[c][d] + 1))

            update_tasks.append((a0, a0, dp_max_max))
            update_tasks.append((a0, a0, dp[a2][a2] + 1))

            if rev:
                update_tasks.append((a2, a0, dp_max_max))
            else:
                update_tasks.append((a0, a2, dp_max_max))

        else:
            update_tasks.append((a0, a1, dp_max_max))
            update_tasks.append((a0, a2, dp_max_max))
            update_tasks.append((a1, a2, dp_max_max))
            update_tasks.append((a1, a2, dp[a0][a0] + 1))
            update_tasks.append((a0, a2, dp[a1][a1] + 1))
            update_tasks.append((a0, a1, dp[a2][a2] + 1))

            for b in range(n):
                b_max = dp_max[b]
                for a in (a0, a1, a2):
                    c, d = min(a, b), max(a, b)
                    update_tasks.append((c, d, b_max))

        for a, b, c in update_tasks:
            dp[a][b] = max(dp[a][b], c)
            dp_max[a] = max(dp_max[a], c)
            dp_max[b] = max(dp_max[b], c)

    a = aaa[-1]
    dp[a][a] += 1

    return max(map(max, dp)) + ans


n = int(input())
aaa = [a - 1 for a in map(int, input().split())]
ans = solve(n, aaa)
print(ans)


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

w = set()
for i in range(F // (100 * A) + 1):
    for j in range((F - 100 * A * i) // (100 * B) + 1):
        w.add((A * i + B * j) * 100)
w.remove(0)

s = set()
t = E * F // 100
for i in range(t // C + 1):
    for j in range((t - C * i) // D + 1):
        s.add(C * i + D * j)

best_concentration = -1
best_a = -1
best_b = -1
for a in w:
    for b in sorted(s):
        if a + b > F:
            break
        if b > E * a // 100:
            break
        concentration = 100 * b / (a + b)
        if concentration > best_concentration:
            best_concentration = concentration
            best_a = a
            best_b = b
print(best_a + best_b, best_b)


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;


int main() {

	long N;
	cin >> N;

	vector<long> L(N, 0);
	for (long i = 0; i < N; i++) {
		cin >> L[i];
	}

	long v_max = *max_element(L.begin(), L.end());
	long sum = accumulate(L.begin(), L.end(), 0) - v_max;

	if (v_max < sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int h,w;
  while(1){
    cin>>w>>h;
    if(w+h==0)break;
    cin.ignore();
    vector<string> s(h);
    rep(i,h)cin>>s[i];
    queue<pii> q;
    vector<vi> used(h,vi(w,0));
    rep(i,h)rep(j,w)if(s[i][j]=='@'){
      q.push(pii(i,j));
      used[i][j]++;
    }
    int d[5]={0,1,0,-1,0};
    while(q.size()){
      rep(i,4){
	int x=q.front().first+d[i];
	int y=q.front().second+d[i+1];
	if(x>=0 && x<h && y>=0 && y<w && 
	   s[x][y]=='.' && used[x][y]==0){
	     used[x][y]++;
	     q.push(pii(x,y));
	}
      }
      q.pop();
    }
    int ans=0;
    rep(i,h)rep(j,w)if(used[i][j])ans++;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3056
fun main(arg: Array<String>) {
    val INF = 1L.shl(40)
    val N = nextInt()
    val G = Array(N) { mutableListOf<Pair<Int, Long>>() }
    repeat(N - 1) {
        val (a, b, c) = listOfInt(-1, -1, 0)
        val C = c.toLong()
        G[a].add(b to C); G[b].add(a to C)
    }
    val R = LongArray(N)
    fun dfs(v: Int, p: Int) {
        for ((u, c) in G[v]) {
            if (u == p) continue
            R[u] += R[v] + c
            dfs(u, v)
        }
    }
    val (Q, K) = listOfInt(0, -1)
    dfs(K, -1)
    val ans = LongArray(Q)
    repeat(Q) { q ->
        val (x, y) = listOfInt(-1, -1)
        ans[q] = R[x] + R[y]
    }
    println(ans.joinToString("\n"))
}
fun gcd(a: Long, b: Long): Long = if (b > 0) gcd(b, a % b) else a
fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")

fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }



Measured memory_bytes: 140756
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MAX 10000
#define G 819210
#define N 100000
#define INF 777333555
 
typedef struct{
  int a,b,c;
}data;
 
int n,A[N];
data I[G];
 
void cl(int u)
{
  int i,z=1;
 
  for(i=0; i<n; i++)A[i]=INF;
  
  A[0]=0;
 
  while(z!=0){
    
    z=0;
    
    for(i=0; i<u; i++){
      
      if(I[i].c+A[I[i].b]<A[I[i].a]){
	
    A[I[i].a]=I[i].c+A[I[i].b];
    
    z=1;
    
      }
    }
  }
}
 
int main()
{
  int i,j,x,y,dt=0;

  
  scanf("%d",&n);
  
  for(i=0; i<n; i++){
    
    scanf("%d%d",&y,&x);
    
    for(j=0; j<x; j++){
      
      I[dt].b=y;
      
      scanf("%d%d",&I[dt].a,&I[dt].c);
      
      dt++;
    }
  }
  
  cl(dt);
  
  for(i=0; i<n; i++)printf("%d %d\n",i,A[i]);
  
  return 0;
}



Measured memory_bytes: 7556
#include<stdio.h>
#define MAX 26

struct Node { int v, a, b; };
struct Node G[MAX];
int N,i,l,r,p;
char S[4][100]={"Preorder","Inorder","Postorder"};
void pre(int n)
{
    if(n==-1)return;
    printf(" %d",n);
    pre(G[n].a);
    pre(G[n].b);
    return;
}
 
void ino(int n)
{
    if(n==-1)return;
    ino(G[n].a);
    printf(" %d",n);
    ino(G[n].b);
    return;
}
 
void pos(int n)
{
    if(n==-1)return;
    pos(G[n].a);
    pos(G[n].b);
    printf(" %d",n);
    return;
}
 
 
 
int main()
{
    void (*funcs[])(int)={pre,ino,pos};
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d%d%d",&p,&l,&r);
        G[l].v=G[r].v=1;
        G[p].a=l;
        G[p].b=r;
    }
    for(i=0;i<N;i++)if(!G[i].v)p=i;
    for(i=0;i<3;i++)
    {
        puts(S[i]);
        (*(funcs[i]))(p);
        puts("");
    }
    return 0;
}



Measured memory_bytes: 2044
#include<stdio.h>
#include<string.h>
#define l 100005


typedef struct pp{
  char name[100];
  int t;
}P;

P Q[l];
int head,tail,n;

void enqueue(P x){
  Q[tail] = x;
  tail =(tail +1)%l;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) %l;
  return x;
}

int min(int a, int b){
  return a<b ? a : b ;
}

int main(){

  int el = 0;
  int c,i,q;
  P u;

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

  for(i= 1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }

  head = 1;
  tail = n + 1;

  while(head != tail){
    u = dequeue();
    c = min(q,u.t);
    u.t -=c;
    el += c;

    if(u.t>0){
      enqueue(u);
    }
    else{
   printf("%s %d\n",u.name,el);
    }
  }

  return 0;

}



Measured memory_bytes: 11916
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
int main()
{
	int n;
	int a[200002];
	cin >> n;
	set<int> s;
	int mm = 0;
	int kk = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] > mm)
		{
			kk = mm;
			mm = a[i];
			
		}
		else if (kk < a[i])
		{
			kk = a[i];
		}
	}
	for (int i = 0; i <n; i++)
	{
		if (a[i] == mm)
		{
			cout << kk << endl;
		}
		else
		{
			cout << mm << endl;
		}
	}
	


}

Measured memory_bytes: 2432
#include <stdio.h>
void spin1(int a[]);
void spin2(int a[]);
void spin3(int a[]);
int judge(int a[],int b[]);
 
int main(void){
  int d[100][6],n,f=0,i,j,k,l,m;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<6;j++)
      scanf("%d",&d[i][j]);
  }
  for(l=0;l<n;l++){
    for(m=0;m<n;m++){
      for(i=0;i<10;i++){
	spin1(d[l]);
	for(j=0;j<10;j++){
	  spin2(d[l]);
	  for(k=0;k<4;k++){
	    spin3(d[l]);
	    if(l!=m&&judge(d[l],d[m])){
	      f=1;
	      break;
	    }
	  }
	  if(f)
	    break;
	}
	if(f)
	  break;
      }
      if(f)
	break;
    }
    if(f)
      break;
  }
  if(f)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}
 
void spin1(int a[]){
    int t=a[0];
    a[0]=a[4];
    a[4]=a[5];
    a[5]=a[1];
    a[1]=t;
}
void spin2(int a[]){
    int t=a[1];
    a[1]=a[2];
    a[2]=a[4];
    a[4]=a[3];
    a[3]=t;
}
void spin3(int a[]){
    int t=a[0];
    a[0]=a[2];
    a[2]=a[5];
    a[5]=a[3];
    a[3]=t;
}
int judge(int a[],int b[]){
  int i;
  for(i=0;i<6;i++){
    if(a[i]!=b[i])
      return 0;
  }
  return 1;
}

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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, k; cin >> n >> k;
	vector<ll> st(n);
	rep(i, n){
		cin >> st.at(i);
	}
	sort(st.begin(), st.end(), greater<ll>());
	if(n <= k) cout << 0 << endl;
	else{
		ll sum = 0;
		for(int i = k; i < n; i++){
			sum += st.at(i);
		}
	cout << sum << endl;
	}
} 

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

const int N = 1000010;

int cnt[N];
int a[N];

int main(){
    int n;
    scanf("%d", &n);
    int gcd = 0;
    for (int i = 0; i < n; ++ i){
        scanf("%d", &a[i]);
        gcd = std::__gcd(gcd, a[i]);
        ++ cnt[a[i]];
    }
    if (gcd > 1){
        puts("not coprime");
        return 0;
    }
    for (int i = 2; i < N; ++ i){
        int num = 0;
        for (int j = i; j < N; j += i){
            num += cnt[j];
        }
        if (num > 1){
            puts("setwise coprime");
            return 0;
        }
    }
    puts("pairwise coprime");
    return 0;
}

Measured memory_bytes: 11464
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 3e5 + 10;
ll q, A[N], B[N];
long long S[N], T[N];
vector < ll > U;
inline void Add(ll i, long long val, long long * F)
{
    for (i += 5; i < N; i += i & -i)
        F[i] += val;
}
inline long long Get(ll i, long long * F)
{
    long long rt = 0;
    for (i += 5; i; i -= i & -i)
        rt += F[i];
    return rt;
}
int main()
{
    scanf("%lld", &q);
    for (ll i = 0; i < q; i++)
    {
        ll tp;
        scanf("%lld", &tp);
        if (tp == 1)
            scanf("%lld%lld", &A[i], &B[i]), U.push_back(A[i]);
        else
            A[i] = LLONG_MAX;
    }
    sort(U.begin(), U.end());
    U.resize(unique(U.begin(), U.end()) - U.begin());
    ll n = 0;
    long long sum = 0, suma = 0;
    for (ll i = 0; i < q; i++)
    {
        if (A[i] != LLONG_MAX)
        {
            sum += B[i];
            suma += A[i];
            ll a = lower_bound(U.begin(), U.end(), A[i]) - U.begin();
            Add(a, 1, S);
            Add(a + 1, A[i], T);
            n ++;
        }
        else
        {
            ll le = -1, ri = (ll)U.size(), md;
            while (ri - le > 1)
            {
                md = (le + ri) >> 1;
                if (Get(md, S) >= ((n + 1) >> 1))
                    ri = md;
                else
                    le = md;
            }
            /*long long res = sum + suma - Get(ri, T) - Get(ri + 1, T);
            if (n % 2 == 0)
                res -= U[ri];*/
            ll cl = ((n + 1) >> 1) - Get(ri - 1, S);
            ll cr = Get(ri, S) - Get(ri - 1, S) - cl;
            long long res = sum + suma - Get(ri + 1, T) - Get(ri, T) + cr * U[ri] - cl * U[ri] + ((n + 1) >> 1) * U[ri] - (n - ((n + 1) >> 1)) * U[ri];
            printf("%lld %lld\n", U[ri], res);
        }
    }
    return 0;
}

Measured memory_bytes: 10868
use proconio::input;

fn main() {
    input! {
        k: usize
    }

    if k % 2 == 0 || k % 5 == 0 {
        println!("-1")
    } else {
        let mut flag = false;
        let mut a = 0;
        let mut count = 1;
        for i in 0..k {
            a = (10*a + 7) % k;
            if a == 0 {
                flag = true;
                break;
            }
            count += 1;
        }
        if flag {
            println!("{}",count)
        } else {
            println!("-1")
        }
    }
}

Measured memory_bytes: 2136
N = int(input())
SP = []
for i in range(1,N+1):
    Si,Pi = input().split()
    SP.append([Si,-int(Pi),i])
SP.sort(key=lambda x:x[1])
SP.sort(key=lambda x:x[0])

for i in range(N):
    print(SP[i][2])


Measured memory_bytes: 3060
n = int(input())
wlist = list(map(int,input().split()))
wdic = {j:i for i,j in enumerate(wlist)}
wlist.sort()
cost = 0
used = [0]*n
res = []
for i in range(n):
    storage = []
    if used[i]:
        continue # next loop
    w = wlist[i]
    minimum = w
    used[i] = 1
    a = wdic[w]
    b = wlist[a]
    storage.append(w)
    while b not in storage:
        w = b
        used[a] = 1
        a = wdic[w]
        b = wlist[a]
        storage.append(w)
        #print(w,a,b,storage)
    ls = len(storage)
    cost += (sum(storage) - minimum)
    res.append((minimum,ls))
m,l = res[0]
if l>=2:
    cost += m*(l-1)
for minimum,ls in res[1:]:
    if ls>=2:
        cost += min(2*(m+minimum)+m*(ls-1), minimum*(ls-1))
    
print(cost)


Measured memory_bytes: 5724
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define ll long long
#define ld long double
#define int ll
#define pb push_back
#define ii pair<int,int>
#define llll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<ii>
#define vllll vector<llll>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<'='<<x<<endl
#define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o])
#define IO freopen("input.txt", "r", stdin); freopen("output.txt", "w+", stdout)
const double pi = 3.14159265358979323846;

ll power(ll a, ll b){//a^b
    ll res=1;
    //a=a%MOD;
    while(b>0){
        if(b&1)
		{res=(res*a);
		//res%=MOD;
		b--;}
        a=(a*a);
        //a%=MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int C(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}
int tab[1000003];
void solve()
{

	int i=0,j=0,k=0,m,n,p,sum=0,cnt=0;
	cin>>n;
	arrin(arr,n);
	for(int i:arr)
	{
	    tab[i]++;
	    k=__gcd(k,i);
	}
	bool pc =true;
	
	for(i=2;i<1000003;i++)
	{
	    cnt=0;
	    for(j=i;j<1000003;j+=i)
	    {
	        cnt+=tab[j];
	    }
	    if(cnt>1)
	    {
	        pc=false;
	        break;
	    }
	}
	if(pc==true)
	{
	    cout<<"pairwise coprime";
	    return;
	}
	 if(k==1)
	 {
	     cout<<"setwise coprime";
	     return;
	 }
	cout<<"not coprime";
	
	 
}
int32_t main() {
    fast
    //IO;
	//cout<<fixed<<setprecision(6);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

Measured memory_bytes: 19232
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#define	MOD  1000000007;
#define PI = 3.14159265358979323846;
using namespace std;

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

	int t[200000];
	long long X = 0;
	for (int i = 1; i <= N; i++)
	{
		cin >> t[i];

		if (i == 1) {
			continue;
		}

		if (t[i] - t[i - 1] >= T)
		{
			X += T;
		}
		else {
			X += t[i] - t[i - 1];
		}
	}

	cout << X + T << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int n;
  cin >> n;
  const int NMAX = 100005;
  vector<int> sum(NMAX) ;
  REP(i,n){
    int a;
    cin >> a;
    sum[a]++;
  }
  int cmax = 0;
  REP2(i,1,NMAX-1){
    int tmp = sum[i-1]+sum[i]+sum[i+1];
    cmax = max(tmp,cmax);
  }

  cout << cmax << endl;
  return 0;
}


Measured memory_bytes: 3780
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}

int main() {
	int n,m;
	cin >> n >> m;
	vector<pair<int, int>>ab(n);
	rep(i, n) {
		cin >> ab[i].F >> ab[i].second;
	}
	sort(all(ab), ps1);
	int count = 0;
	int i = 0;
	ll money = 0;
	while (count < m) {
		int	tmpc = count;
		count += ab[i].S;
		money += (ll)ab[i].F * ab[i].second;
		if (count > m) {
			money -= (ll)(count - m) * ab[i].first;
			break;
		}
		i++;
	}
	cout << money << endl;
}


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

int main(){
    int r,c;
    cin >> r >> c;
    int T[101][101]={0};
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){

            cin >> T[i][j];
            T[i][c] += T[i][j];
            T[r][j] += T[i][j];
            T[r][c] += T[i][j];
        }
    }
    
    for(int i=0;i<=r;i++){
        for(int j=0;j<=c;j++){
            if(j) cout << " ";
            cout << T[i][j];
        }
        cout << endl;
    }
    return 0;
}


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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int N, K;
	
	cin >> N >> K;
	
	ll ans = pow(N / K, 3);
	
	if(K % 2 == 0){
		N += K / 2;
		ans += pow(N / K, 3);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    int r; cin >> r;
    cout << 3*r*r << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
  long long x, k, d, ans;
  cin >> x >> k >> d;
  x = abs(x);
  if(x/d > k){
      ans = x-d*k;
  }else{
      long long e = x/d;
      k -= e;
      x -= e*d;
      if(k%2==1){
          x=abs(x-d);
      }
      ans = x;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
long long n,h[100005];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>h[i];
	for(int i=2;i<=n;i++)
	{
		if(h[i-1]-h[i]>1) {cout<<"No";return 0;}
		else if(h[i-1]-h[i]==1) h[i]++;
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N, ans;
	static int[] L, times;

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			times = new int[N];
			L = new int[N];
			for (int i = 0; i < N; ++i) {
				int M = sc.nextInt();
				L[i] = sc.nextInt();
				for (int j = 0; j < M; ++j) {
					int S = sc.nextInt();
					int E = sc.nextInt();
					for (int k = S; k < E; ++k) {
						times[i] |= (1 << k);
					}
				}
			}
			ans = 0;
			dfs(0, 0, 0);
			System.out.println(ans);
		}
	}

	static void dfs(int cur, int st, int sum) {
		if (cur == N) {
			ans = Math.max(ans, sum);
			return;
		}
		if ((st & times[cur]) == 0) {
			dfs(cur + 1, st | times[cur], sum + L[cur]);
		}
		dfs(cur + 1, st, sum);
	}

}

Measured memory_bytes: 58500
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
    public:
    static const int MAXN=2e3+10;
    static const int INF=0x3f3f3f3f;
    int H,W;
    char S[MAXN][MAXN];
    int l[MAXN][MAXN];
    int r[MAXN][MAXN];
    int u[MAXN][MAXN];
    int d[MAXN][MAXN];
    void solve(){
        ios::sync_with_stdio(false);
        cin>>H>>W;
        for(int u=1;u<=H;u++)
        cin>>S[u]+1;
        memset(l,0x3f,sizeof(l));
        memset(r,0xff,sizeof(r));
        memset(u,0x3f,sizeof(u));
        memset(d,0xff,sizeof(d));
        for(int s=1;s<=H;s++){
            for(int t=1;t<=W;t++){
                if(S[s][t]=='.')l[s][t]=min(t,l[s][t-1]);
            }
            for(int t=W;t>=1;t--){
                if(S[s][t]=='.')r[s][t]=max(t,r[s][t+1]);
            }
        }
        for(int s=1;s<=W;s++){
            for(int t=1;t<=H;t++){
                if(S[t][s]=='.')u[t][s]=min(t,u[t-1][s]);
            }
            for(int t=H;t>=1;t--){
                if(S[t][s]=='.')d[t][s]=max(t,d[t+1][s]);
            }
        }
        int ans=0;
        for(int s=1;s<=H;s++){
            for(int t=1;t<=W;t++){
                if(S[s][t]=='.'){
                    int sum=r[s][t]-l[s][t]+1+d[s][t]-u[s][t]+1-1;
                    ans=max(ans,sum);
                }
            }
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

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

int main() {
    int a,b;
    cin >> a >> b;
    vector<int> data(3);
    data.at(0) = a + b;
    data.at(1) = a - b;
    data.at(2) = a * b;
    sort(data.begin(), data.end());//小さい順に並べる
    cout << data.at(2) << endl;
}

Measured memory_bytes: 256
N,X = map(int,input().split(" "))
x = list(map(int,input().split(" ")))
x = list(map(lambda y: abs(y - X),x))


# gcd
def gcd (a,b):
    if a < b:
        a,b = b,a
    return a if b == 0 else gcd(b,a%b)

if N == 1:
    print(x[0])
    exit(0)
ans = gcd(x[0],x[1])
if N == 2:
    print(ans)
    exit(0)
for i in range(2,N):
    ans = gcd(ans,x[i])

print(ans)

Measured memory_bytes: 63444
fn main() {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let a: i32 = s.next().unwrap().parse().unwrap();
	let b: i32 = s.next().unwrap().parse().unwrap();
	for n in 1..2000 {
		let aa = n * 8 / 100;
		let bb = n * 10 / 100;
		if aa == a && bb == b {
			println!("{}", n);
			return;
		}
	}
	println!("-1");
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int const m = 1e5 + 1;
int const INF = 1e9;

vector<int> dp(m, INF);

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

    int a[n];
    rep(i, n) cin >> a[i];

    rep(i, n) * lower_bound(ALL(dp), a[i]) = a[i];

    OP(lower_bound(ALL(dp), INF) - dp.begin());

    return 0;
}

/*
オーダーn^2
const int m = 1e5 + 1;
int dp[m] = {};

int main()
{
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    int ans = 0;

    rep(i, n)
    {
        dp[i] = 1;
        for (int j = 0; j < i; j++)
        {
            if (a[j] < a[i])
                dp[i] = max(dp[i], dp[j] + 1);
        }
        ans = max(ans, dp[i]);
    }

    OP(ans);

    return 0;
}*/


Measured memory_bytes: 3616
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP (i,m,n) for(int i=( int)m ; i < (int ) n ; ++i )
#define rep (i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }



int main() {
	double r;
	cin >> r;
	cout << r * 2 * 3.14 << endl;
	return 0;
}


Measured memory_bytes: 3768
import java.util.*;
import java.io.*;

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

		boolean allnegs = true;
		boolean allposs = true;

		int min = 0;
		int max = 0;
		for(int i = 0; i < n; ++i) {
			arr[i] = in.nextInt();

			if(arr[i] < 0)
				allposs = false;
			else if(arr[i] >= 0)
				allnegs = false;

			if(arr[min] > arr[i])
				min = i;
			if(arr[max] < arr[i])
				max = i;
		}



		ArrayList<Pair> li = new ArrayList();
		if(allnegs) {
			for(int i = n - 1; i > 0; --i) {
				li.add(new Pair(i , i - 1));
			}
		} else if(allposs) {
			for(int i = 1; i < n; ++i) {
				li.add(new Pair(i -1, i));
			}
		} else {
			if(Math.abs(arr[min]) <= arr[max]) {
				for(int i = 0; i < n; ++i) 
					if(i != max)
						li.add(new Pair(max, i));
				for(int i = 1; i < n; ++i) {
					li.add(new Pair(i - 1 , i));
				}
			} else {
				for(int i = 0; i < n; ++i) 
					if(i != min)
						li.add(new Pair(min, i));

				for(int i = n - 1; i > 0; --i) {
					li.add(new Pair(i , i - 1));
				}
			}
		}

		System.out.println(li.size());
		for(Pair p : li) {
			System.out.println(p);
		}
	}

	private static class Pair {
		int f, s;

		public Pair(int f, int s) {
			this.f = f;
			this.s = s;
		}

		@Override
		public String toString() {
			return (f+1)+" "+(s+1);
		}
	}

}


Measured memory_bytes: 22740
#include <stdio.h>
int main(void) {
    int l,r;
    int tmp,tmp2,tmp3;
    scanf("%d%d",&l, &r);
    int i,j;
    int min = -1;
    for(i=l;i<=r;i++){
        for(j=i+1;j<=r;j++){

            tmp = i%2019;
            tmp2 = j%2019;
            while(tmp>2019){
                tmp = tmp%2019;
                tmp2 = tmp2%2019;
            }
            tmp3 = (tmp*tmp2)%2019;
            if(min == -1)
                min = tmp3;
            else if(min == 0)
                break;
            else if(min>tmp3)
                min = tmp3;
        }
        if(min == 0)
            break;
    }
    printf("%d\n",min);
}

Measured memory_bytes: 128
s = input()

x = 0
count0 = 0
count1 = 0

for i in s:
    if i == str(x):
        count0 += 1
    x = int(not(x))

x = 1
for i in s:
    if i == str(x):
        count1 += 1
    x = int(not(x))

print(min(count0, count1))

Measured memory_bytes: 3188
#include <stdio.h>
int main()
{
    int a,b,x;
    char c[61]={};
    scanf("%d%d ",&a,&b);
    for(x=1; x<=a; ++x)
    {
        scanf("%c",&c[x]);
    }
    c[b]+='a'-'A';
    for(x=1; x<=a; ++x)
    {
        printf("%c",c[x]);
    }
}


Measured memory_bytes: 128
input_list = list(map(int, input().split()))
#input_list = [1, 2]
a = input_list[0]
b = input_list[1]

flag = False
for c in range(1, 4):
    if (a * b * c) % 2 == 1:
        flag = True

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

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

int main(int argc, char const *argv[]) {
  int n;
  long t;
  std::cin >> n >> t;

  std::vector<long> ts;
  for (size_t i = 0; i < n; i++) {
    long tmp;
    std::cin >> tmp;
    ts.push_back(tmp);
  }

  int sum = 0;
  for (size_t i = 0; i < n-1; i++) {
    long delta = ts.at(i+1) - ts.at(i);
    if (delta > t) {
      sum += t;
    } else {
      sum += delta;
    }
  }

  sum += t;
  
  std::cout << sum << '\n';
}


Measured memory_bytes: 2420
loop{
  n,m = gets.split.map(&:to_i)
  break if (n|m)==0
  c = (1..n).to_a
  pos = c.length-1
  tmp = 0 if false
  loop{
    pos=(pos+m)%c.length
    tmp = c.delete_at(pos)
    pos-=1
    break if c.empty?
  }
  puts tmp
}

Measured memory_bytes: 2356
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
x, y = map(int, input().split())
if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

using namespace std;

typedef long long ll;

const int MAX_N = 1e2+10, MAX_V = 1e2+10;
const ll MAX_W = 1e9+10;
const int INF = std::numeric_limits<int>::max();

struct Item
{
	int v;
	ll w;
};

ll dp[MAX_N][MAX_N * MAX_V];
int N;
ll W;
Item items[MAX_N];

void solve() {
	fill(dp[0], dp[0] + MAX_N * MAX_V, INF);
	dp[0][0] = 0;
	for (int i = 0; i < N; ++i) {
		Item item = items[i];
		for (int j = 0; j < MAX_N * MAX_V; ++j) {
			if (j < item.v) {
				dp[i+1][j] = dp[i][j];
			} else {
				dp[i+1][j] = min(dp[i][j], dp[i][j-item.v]+item.w);
			}
		}
	}
}

int main(int argc, char const *argv[])
{
	cin >> N >> W;
	for (int i = 0; i < N; ++i) {
		cin >> items[i].v >> items[i].w;
	}

	solve();

	int ans = 0;
	for (int i = 0; i < MAX_N * MAX_V; ++i) {
		if (dp[N][i] <= W) ans = i;
	}

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


Measured memory_bytes: 12656
#include <iostream>

using namespace std;

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

    int a = N / 10;
    int b = N - 10*a;

    if (a == 9 || b == 9) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }

    return 0;
}

Measured memory_bytes: 256
import sys
# print(sys.version)
N = int(input())

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

P = 1000
K = 0
for i in range(N-1):
    if A[i] < A[i+1]:
        K += P // A[i]
        P %= A[i]
    elif A[i] > A[i+1]:
        P += K*A[i]
        K = 0
P += K * A[-1]
print(P)


Measured memory_bytes: 9208
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	map<int, int> mp;
	vector<int> D(N); rep(i, 0, N) {
		cin >> D[i];
		mp[D[i]]++;
	}
	int M; cin >> M;
	rep(i, 0, M) {
		int t; cin >> t;
		if (mp[t] > 0) {
			mp[t]--;
		}
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
#define MN 100005
int n,a[MN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	std::sort(a+1,a+1+n);
	for(int i=n,j=1;i;i--)
	{
		if(j+1>a[i-1])
		{
			int k=i;
			for(;a[k]>=j;k--);
			puts((((a[i]-j)&1)|((i-k-1)&1))?"First":"Second");
			break;
		}
		j++;
	}
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
 
int second(int one, int two, int three){
	if((two > one || two > three) && (two < one || two < three)){
		return 0;
	}
	else{
		return 1;
	}
}


int main(){
	int n;
	cin>>n;
	int arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	int count=0;
	for(int i=0; i<n; i++){
		if(i <= n-3){
			int ans;
			ans = second(arr[i], arr[i+1], arr[i+2]);
			if (ans == 0){
				count++;
			}
		}
	}	
	cout<<count;
	return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define fi first
#define se second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define pi pair<ll,ll>
#define mp make_pair
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
//freopen("explicit.in", "r", stdin);
//freopen("explicit.out", "w", stdout);
 
void SieveOfEratosthenes() 
{ 
    bool prime[10000001];
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000000; p++) 
    { 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false; 
            }
        } 
    }  
} 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll power(ll x,ll y,ll p) 
{ 
    ll r = 1;
  
    x = x % p;
    while (y > 0) {
        if (y & 1) 
            r = (r * x) % p;
        y = y >> 1; 
        x = (x * x) % p; 
    } 
    return r; 
}  
ll modInverse(ll n, ll p) 
{ 
    return power(n, p - 2, p); 
} 
 
ll nCrModP(ll n,ll r, ll p) 
{ 
    ll fac[100005];
    if (r == 0) 
        return 1; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
}
int32_t main() 
{
    fio
	ll j,i,n,t,l,r,c,h,k,m,maxi,d,x;
    string s,w;
	cin>>s;
	if(s[s.length()-1]=='s')
		cout<<s<<"es";
	else
		cout<<s<<"s";
}



	

		

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

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

  ll N; cin >> N;
  ll C; cin >> C;

  vector<ll> x(N), v(N), dp1(N), dp2(N);
  rep(i, N) cin >> x[i] >> v[i];

  dp1[0] = v[0] - x[0];
  rep(i, N - 1) {
    dp1[i + 1] = dp1[i] + v[i + 1] - (x[i + 1] - x[i]);
  }
  rep(i, N - 1) {
    dp1[i + 1] = max(dp1[i + 1], dp1[i]);
  }

  dp2[N - 1] = v[N - 1] - (C - x[N - 1]);
  for(int i = N - 2; i >= 0; i--) {
    dp2[i] = dp2[i + 1] + v[i] - (x[i + 1] - x[i]);
  }
  for(int i = N - 2; i >= 0; i--) {
    dp2[i] = max(dp2[i], dp2[i + 1]);
  }

  ll ans = 0;
  rep(i, N) {
    ll tmp = dp1[i];
    if(i + 1 < N && dp2[i + 1] - x[i] > 0) {
      tmp += dp2[i + 1] - x[i];
    }
    ans = max(ans, tmp);
  }

  for(int i = N - 1; i >= 0; i--) {
    ll tmp = dp2[i];
    if(i >= 1 && dp1[i - 1] - (C - x[i]) > 0) {
      tmp += dp1[i - 1] - (C - x[i]);
    }
    ans = max(ans, tmp);
  }

  cout << ans << endl;
}


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

using namespace std;
#define deb(x) cout << #x << ": " << x << endl
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fkn(i, k, n) for (i = k; i < n; i++)
#define ll long long
#define F first;
#define S second;
#define PB push_back;
#define MP(x,y) make_pair(x,y);
typedef vector<ll> vll;

bool powerOfTwo(ll x)
{
    return !(x & (x - 1));
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    ll ans=1;
  ll max =1e+18;
    cin>>n;
    vector<ll> v(n);
    ll q=0;
    fo(i,n) 
    {
        cin>>v[i];
        if(v[i] == 0)
        {
            q=1;
        }
    }
    if(q)
    {
        cout<<0;
    }
    else{
    fo(j,n)
    {
       
      ll x = max/v[j];
        if (ans  > x)
        {
            ans =-1;
            break;
        }
        else{
        ans *=v[j];
        }
    }
  
    cout<<ans;
    }


    


}



Measured memory_bytes: 3932
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,x;
  cin >> n >> x;
  ll a[n];
  rep(i,n) R a[i];
  ll sum=0,ans=1;
  rep(i,n) {
    sum+=a[i];
    if(sum<=x) ans++;
  }
  pr(ans);
}

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
using namespace std;

int main() {

	for (int dd = 0; dd < 5; dd++) {
		int m;
		cin >> m;
		if (m == 0)break;
		else {
			int n, x, y, tar[210][2], sar[1010][2];//x,y
			bool cona = false, cons = false;

			for (int i = 0; i < m; i++) {
				int x1, y1;
				cin >> x1 >> y1;
				tar[i][0] = x1;
				tar[i][1] = y1;
			}
			cin >> n;
			for (int i = 0; i < n; i++) {
				int x2, y2;
				cin >> x2 >> y2;
				sar[i][0] = x2;
				sar[i][1] = y2;
			}

			for (int i = 0; i < n; i++) {//sarching star
				x = sar[i][0] - tar[0][0];//diside distance
				y = sar[i][1] - tar[0][1];
				for (int j = 1; j < m; j++) {//target star
					for (int k = 0; k < n; k++) {//sas[any]>(+x +y)>tas[j]?
						if (tar[j][0] + x == sar[k][0] && tar[j][1] + y == sar[k][1]) {
							cons = true;
							break;
						}
						else cons = false;
					}
					if (!cons)break;
					else if (j == m - 1) cona = true;
				}
				if (cona)break;
			}

			cout << x << " " << y << endl;
		}
	}
	return 0;
}



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

const int MAX = 1000000;
int primes[80000];
int pNum;

void calcPrimes() {
    primes[0] = 2;
    pNum = 1;
    for (int i = 3; i <= MAX; i += 2) {
        bool add = true;
        for (int j = 0; j < pNum; j++) {
            if (primes[j] * primes[j] > i) {
                break;
            }
            if (i % primes[j] == 0) {
                add = false;
                break;
            }
        }
        if (add) {
            primes[pNum++] = i;
        }
    }
}

int main() {
    calcPrimes();
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int pi = 0, qi = pNum - 1, ans = 0;
        while (pi <= qi) {
            int sum = primes[pi] + primes[qi];
            if (sum <= n) {
                if (sum == n) {
                    ans++;
                }
                pi++;
            } else {
                qi--;
            }
        }
        cout << ans << endl;
    }
}

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

#define F first
#define S second

using ll = long long;
using pii = pair <int, int>;

const int oo = 1e9 + 4;
const int SZ = 2e5 + 4;
const ll M = 1e9 + 7;

int n, k;

void read() {
    cin >> n >> k;
}

void solve() {
    ll ans = 0;
    ll l = 0, r = 0;
    for (int i = 0; i <= n + 1; i++) {
        if (i >= k) ans = 1ll * (ans + r - l + 1) % M;
        l += i;
        r += n - i;
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    read();
    solve();
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,(e))
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define irpz(i,s) irp(i,(s),-1)
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;}
template<class T> T in(){T x;cin>>x;return x;}
// long long a = in<long long>();
template<class T> vector<T> inarr(int s,int e, T init){
	vector<T> v;T x;
	for(int i=0;i<s;++i)v.push_back(init);
	for(int i=s;i<e;++i){cin>>x;v.push_back(x);}
	return v;
}

int N;
vi X;

ll solve(){
	ll ans = LLONG_MAX;
	sort(all(X));
	rp(p,X[0],X[N-1]+1){
		ll wa = 0;
		for(auto x:X){
			wa += (x-p)*(x-p);
		}
		chmin(ans, wa);
	}
	return ans;
}

int main(){
	cin>>N;
	X = inarr<int>(0,N,0);
	cout<< solve() <<endl;
}


Measured memory_bytes: 256