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

int main() {
    int ini, N, M;
    cin >> N >> M >> ini;
    vector<int> a(M);
    rep(i, M) cin >> a.at(i);
    vector<int> cost(N+1);
    rep(i, M) cost.at((a.at(i)))++;

    int left = 0;
    int right = 0;

    for(int i = ini; i < N+1; i++) {
        left += cost.at(i);
    }
    rep(i, ini) right += cost.at(i);

    cout << min(right, left) << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
/*{{{*/
#include <bits/stdc++.h>
#ifdef LOCAL
int c_ = 0;
#define cout (c_?cerr:cout)
#define debug(...) \
{if(!c_++)cerr<<"\033[96;1m"; \
__VA_ARGS__; \
if(!--c_)cerr<<"\033[0m";}
#else
#define debug(...) {}
#endif
#define assrt(...) debug(\
if (not (__VA_ARGS__)) \
    exit((cerr << __LINE__ << ": " << #__VA_ARGS__ << '\n', 0));\
)
#define st first
#define nd second
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
using namespace std; using ll = long long;
template < typename t > using V = vector< t >;
template < typename t, size_t s > using A = array< t, s >;
void print() {cout << '\n';}
template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":""); print(b...);}
template< typename t > void print_range(t a, const t& b)
{ while (a != b) cout << (*a++) << ' '; cout << '\n';}
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
#define dump_range(...) debug(cerr<<#__VA_ARGS__ << ": "; print_range(__VA_ARGS__))
/*}}}*/

constexpr int nax = 2e5;

int n; string s;

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> s;

    int cnt = 0;
    ll res = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        if (s[i] == 'B') ++cnt;
        else res += cnt;
    }

    print(res);
}


Measured memory_bytes: 720
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
//void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }


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

	int r[100];
	r[0] = 2;
	r[1] = 1;

	for (int i = 2; i <= N; i++)
	{
		r[i] = r[i - 2] + r[i - 1];
	}

	cout << r[N] << endl;
}




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

def main():
    [N, M] = list(map(int, input().split()))
    c_list = []
    for i in range(M):
        [p, y] = list(map(int, input().split()))
        c_list.append((i, p, y))

    c_list.sort(key = lambda t: t[2])

    ct = [0] * (N + 1)
    id_list = []
    for i in range(M):
        j, p, y = c_list[i]
        ct[p] += 1
        w = str(1000000 + p)[1:] + str(1000000 + ct[p])[1:]
        id_list.append((j, w))

    id_list.sort(key = lambda t: t[0])

    for i in range(M):
        print(id_list[i][1])



if __name__ == '__main__':
    main()



Measured memory_bytes: 36348
#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN = 100010;
pair<int,int> tree[mxN<<2];
long long L;
int sz;

long long getXOR(long long X) {
	if(!X) return 0;
	long long res = 1;
	while(!(X&1)) res <<= 1,X >>= 1;
	return res;
}

long long dfs(int v = 1,long long h = 0) {
	if(!tree[v].first && !tree[v].second) return 0;
	long long res = 0;
	if(tree[v].first) res ^= dfs(tree[v].first,h+1); else res ^= getXOR(L-h);
	if(tree[v].second) res ^= dfs(tree[v].second,h+1); else res ^= getXOR(L-h);
//	cerr<<v<<' '<<h<<' '<<res<<'\n';
	return res;
}

//void get(int x) {
//	vector<int> dp(x+2);
//	dp[1] = 1;
//	cerr<<"1 ";
//	for(int i = 2;i <= x;i++) {
//		set<int> to;
//		int cur = 0;
//		to.insert(cur);
//		for(int j = i-1;j >= 1;j--) {
//			cur ^= dp[j];
//			to.insert(cur);
//		}
//		while(to.count(dp[i])) dp[i]++;
//		cerr<<dp[i]<<' ';
//	}
//}

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

	//	get(100);
	//	return 0;

	cerr<<getXOR(2)<<'\n';
	
	int N;
	string s;
	cin>>N>>L;
	sz = 1;
	for(int i = 0;i < N;i++) {
		cin>>s;
		int cur = 0;
		for(int j = 0;j < (int)s.size();j++) {
			auto & to = (s[j]=='0'?tree[cur].first:tree[cur].second);
			if(!to) to = sz++;
			cur = to;
		}
	}
	assert(sz <= mxN);
	cout<<(dfs(0)?"Alice":"Bob")<<'\n';
	return 0;
}



Measured memory_bytes: 5968
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
long long  N;
long long a[300001];
long long R=0;
long long T=0;
int main(){
	cin>>N;
	for(int i = 0; i<N * 3; i++)cin>>a[ i ];

	sort(a,a + N * 3, greater<long long>() );


	int S = 0;
	for(int i = 1; S<N; i+=2){
		R += a[ i ];
		S += 1;
	}



	cout<<R<<endl;

	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  int c=0;
  if(a>b){
    c+=a;
    a--;
  }else{
    c+=b;
    b--;
  }
  if(a>b){
    c+=a;
    a--;
  }else{
    c+=b;
    b--;
  }
  printf("%d",c);
  return 0;
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Deque;
import java.util.ArrayDeque;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();
            String T = in.next();
            Deque<Character> q = new ArrayDeque<>();

            if (S.equals(T)) {
                out.println("Yes");
                return;
            }
            for (int i = 0; i < S.length(); i++) {
                q.offerLast(S.charAt(i));
            }

            for (int i = 0; i < S.length(); i++) {
                String s1 = q.toString().replaceAll("[, ]", "").substring(1, S.length() + 1);
//            out.println(s1);
                q.offerFirst(q.pollLast());
                if (s1.equals(T)) {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");

        }

    }
}



Measured memory_bytes: 24916
#include<bits/stdc++.h>
using namespace std;
int main()
{  
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	char  s;
 
	cin>>s;
	if(s>='A'&& s<'a')
	{
		cout << "A"<<"\n";
 
	}
	else
 
	{
		cout<< "a"<<"\n";
	}
 
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());
    sort(A.begin(), A.end());
    int prev = -1;
    for (const auto &a: A){
        if (prev == a){
            cout << "NO" << endl;
            return 0;
        }
        prev = a;
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll am = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        if(am > a[i]){
            ans += (am - a[i]);
        }
        else{
            am = a[i];
        }
    }
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> vec){ return (ll)vec.size(); }
ll sz(string s){ return (ll)s.size(); }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }


int main(){
    ll n;
    cin >> n;
    ll a[n],b[n];
    rep(i,0,n){
        cin >> a[i] >> b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    
    if(n % 2 == 0) cout << b[n/2]+b[n/2-1]-(a[n/2]+a[n/2-1]) + 1 << endl;
    else cout << b[n/2] - a[n/2] + 1 << endl;

    return 0;
}

Measured memory_bytes: 6752
import sys
input=sys.stdin.readline
import math
x=int(input())
i=x
while True:
  flag="ok"
  for j in range(2,int(math.sqrt(i)) + 1):
    if i % j == 0:
      flag="ng"
      break
  if flag=="ok":
    print(i)
    break
  i+=1

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  using ll = long long;
  int n;
  cin >> n;
  string s;
  cin >> s;
  ll ans = 0;
  for (int i = 0; i < 1000; i++) {
    string si = to_string(i);
    if (si.length() == 1)
      si = "00" + si;
    else if (si.length() == 2)
      si = "0" + si;
    auto ok = [&](string si) {
      bool ok1 = 0, ok2 = 0, ok3 = 0;
      int i1, i2;
      for (int i = 0; i < n; i++) {
        if (si[0] == s[i]) {
          ok1 = 1;
          i1 = i;
          break;
        }
      }
      if (ok1 == 0) return false;
      for (int i = n - 1; i > i1; i--) {
        if (si[2] == s[i]) {
          ok2 = 1;
          i2 = i;
          break;
        }
      }
      if (ok2 == 0) return false;
      for (int i = i1 + 1; i < i2; i++) {
        if (si[1] == s[i]) {
          ok3 = 1;
          break;
        }
      }
      if (ok3) {
        return true;
      } else {
        return false;
      }
    };
    if (ok(si)) ans++;
  }
  cout << ans << '\n';
  return 0;
}


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

public class Main {
	
	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		char[][]a=new char[H][W];
		for(int i=0;i<H;i++) {
			String s=sc.next();
			a[i]=s.toCharArray();
		}
		int[]alph=new int[26];
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				alph[a[i][j]-'a']++;
			}
		}
		int g1=(H%2)*(W%2);
		int g2=(H/2)*(W%2)+(W/2)*(H%2);
		int g3=(H/2)*(W/2);
		
		
		for(int i=0;i<26;i++) {
			g3-=alph[i]/4;
			alph[i]%=4;
			
			g2-=alph[i]/2;
			alph[i]%=2;
			
			g1-=alph[i]%2;
		}
		String ans="Yes";
		if(g3>0)ans="No";
		g2+=2*g3;
		if(g2>0)ans="No";
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    if(A + B + C >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }

    return 0;
}


Measured memory_bytes: 3660
n, a, b=gets.strip.split.map(&:to_i)
h = readlines.map {|line| line.strip.to_i }
c=a-b

ok=h.max
ng = 0

while ok-ng>1
#p ["#", ok, ng]
  mid = ((ok+ng)/2.to_f).ceil
  b_d = mid*b
  remains = h.map {|hh| hh-b_d }.select {|e| e>0 }
  if remains.count.zero?
    ok=mid
    next
  end
#p [mid, remains.map {|hh| (hh/c.to_f).ceil }.inject(:+)]
  if mid >= remains.map {|hh| (hh/c.to_f).ceil }.inject(:+)
    ok=mid
  else
    ng=mid
  end
end

p ok.to_i

Measured memory_bytes: 66380
//C - Be Together: 13Min;
//Assunto: Media;
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, media1, media2, ans1, ans2;
    double soma;

    cin >> n;
    vector<int> nums(n);
    soma = 0;
    loop(i, 0, n) {
        cin >> nums[i];
        soma += nums[i];
    }
    media1 = ceil(soma / n);
    media2 = soma / n; 
    ans1 = ans2 = 0;
    loop(i, 0, n) {
        ans1 += pow((nums[i] - media1), 2);
        ans2 += pow((nums[i] - media2), 2);
    }
    cout << min(ans1, ans2) << '\n';
}

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

l.sort()

ans = 0

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if l[i] + l[j] > l[k] and l[i] != l[j] and l[j] != l[k]:
                ans += 1

print(ans)


Measured memory_bytes: 9092
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int x1 = in.nextInt();
		int y1 = in.nextInt();
		int x2 = in.nextInt();
		int y2 = in.nextInt();
		
		int subx = x1 - x2;
		int suby = y1 - y2;
		
		if(subx<=0) {
			if(suby<=0) {
				System.out.println((x2+suby) + " " + (y2-subx) +" "+ (x1+suby) + " " + (y1-subx));		
			}else {
				System.out.println((x2+suby) + " " + (y2-subx) +" "+ (x1+suby) + " " + (y1-subx));
			}
		}else {
			if(suby<=0) {
				System.out.println((x2+suby) + " " + (y2-subx) +" "+ (x1+suby) + " " + (y1-subx));		
			}else {
				System.out.println((x2+suby) + " " + (y2-subx) +" "+ (x1+suby) + " " + (y1-subx));
			}
		}
	
		in.close();
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)


//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    ll N, P, Q; cin >> N >> P >> Q;
    vector<ll> d(N+1);
    for(int i=0; i<N; i++){
        ll c; cin >> c;
        d[i+1] = P * i + c;
    }
    sort(d.rbegin(), d.rend()-1);
    
    for(int i=1; i<=N; i++)
        d[i] += d[i-1];
    
    vector<ll> z(N+1);
    for(int i=1; i<=N; i++)
        z[i] += P*(Q+2*(i-1)) + z[i-1];
    
    ll ans = -1e15;
    for(int i=0; i<=N; i++)
        ans = max(ans, d[i] + z[N-i] - P*N*(N-1)/2);
  
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 8848
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	d, _ := strconv.Atoi(Scanner())
	g, _ := strconv.Atoi(Scanner())
	p := make([]int, d)
	c := make([]int, d)
	for i := 0; i < d; i++ {
		p[i], _ = strconv.Atoi(Scanner())
		c[i], _ = strconv.Atoi(Scanner())
	}
	all := make([][]bool, 0)
	list := make([]bool, 0)
	all = perm(d, list, all)
	ans := 100000000
	for _, i := range all {
		s := 0
		count := 0
		for j, b := range i {
			if b {
				s += p[j]*100*(j+1) + c[j]
				count += p[j]
			}
		}
		if s >= g {
			if count < ans {
				ans = count
			}
			continue
		}
		for j := d - 1; j >= 0; j-- {
			if !i[j] {
				point := (j + 1) * 100
				q := smaller(g-s, p[j]*point)
				m := q / point
				if q%point != 0 {
					m++
				}
				s += m * point
				count += m
				if m == p[j] {
					s += c[j]
				}
				if s >= g {
					if count < ans {
						ans = count
					}
					break
				}
			}
		}
	}
	fmt.Println(ans)
}
func perm(n int, list []bool, ret [][]bool) [][]bool {
	if len(list) == n {
		x := make([]bool, n)
		copy(x, list)
		ret = append(ret, x)
		return ret
	} else {
		ret = perm(n, append(list, true), ret)
		ret = perm(n, append(list, false), ret)
	}
	return ret
}
func smaller(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}


Measured memory_bytes: 768
alph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n = int(input())
moji = input()
ans = ''
for i in range(len(moji)):
    idx = alph.index(moji[i]) + n
    if idx >= len(alph):
        idx -= len(alph)
    ans += alph[idx]

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>

#define cal(i, n) for(int i = 0 ; i < n ; i++)
#define els(i, p) for(int i = int(p) - 1 ; i >= 0 ; i--)

using namespace std;

int main(){
    int H, W;
    vector<string> a(100);
    vector<int> ev;
    vector<int> eh;
    cin >> H >> W;
    cal(i, H) cin >> a[i];
    cal(i, H) {
        int total = 0;
        cal(j, W) total += a[i][j];
        if (total == 46 * W){
            ev.push_back(i);
        }
    }
    cal(i, W){
        int total = 0;
        cal(j, H) total += a[j][i];
        if (total == 46 * H){
            eh.push_back(i);
        }
    }
    els(i, ev.size()){
        a.erase(a.begin() + ev[i]);
    }
    els(i, eh.size()){
        cal(j, H - ev.size()){
            a[j].erase(eh[i],1);
        }
    }
    cal(i, a.size()){
        cout << a[i] << endl;
    }
    
    return 0;

}


Measured memory_bytes: 256
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    a_list = [int(input()) for _ in range(n)]

    a_sorted = sorted(a_list)
    a_max = a_sorted[-1]
    a_second = a_sorted[-2]
    for a in a_list:
        if a == a_max:
            print(a_second)
        else:
            print(a_max)


Measured memory_bytes: 70488
import java.util.*;
class Main {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		String[] SArray = S.split("");
		String[] TArray = T.split("");
		int x=0;
		if(SArray[0].equals(TArray[0])){x=x+1;};
		if(SArray[1].equals(TArray[1])){x=x+1;};
		if(SArray[2].equals(TArray[2])){x=x+1;};
		System.out.println(x);
	}
}

Measured memory_bytes: 21844
// https://atcoder.jp/contests/abc127/tasks/abc127_d

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, ans = 0;
    cin >> a >> b;

    if (a >= 13) {
        ans = b;
    } else if (a >= 6) {
        ans = b / 2;
    }

    cout << ans << '\n';

    return 0;
}

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

ans = sum(B)

for i in range(N-1):
    if A[i] + 1 == A[i+1]:
        ans += C[A[i]-1]

print(ans)

Measured memory_bytes: 9132
#!/usr/bin/python3

from itertools import permutations
from collections import Counter

def main():
  n = int(input())
  x = []
  y = []

  if n == 1:
    print(1)
    return

  for i in range(n):
    x_tmp, y_tmp = map(int, input().split(' '))
    x.append(x_tmp)
    y.append(y_tmp)

  cnt = Counter()

  for i, j in permutations(range(n), 2):
    dist = (x[i] - x[j], y[i]- y[j])
    cnt[dist] += 1

  dist, c = cnt.most_common(1)[0]
  print(n - c)

if __name__ == '__main__':
  main()

Measured memory_bytes: 3828
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if (a < b && b< c){
  cout<<"Yes"<<endl;
  } else if (a == b || b == c || a == c || a > b || b > c || a > c) {
  cout<<"No"<<endl;
  } return 0;
  }

Measured memory_bytes: 3068
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;

int q, h, s, d;
int n;

int main()
{
	scanf("%d %d %d %d", &q, &h, &s, &d);
	h = min(h, 2 * q);
	s = min(s, 2 * h);
	d = min(d, 2 * s);
	scanf("%d", &n);
	ll res = ll(n / 2) * d + ll(n % 2) * s;
	cout << res << endl;
	return 0;
}

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

namespace AtCoder
{
	class Programs
	{
		static void Main ()
		{
			var dg = Array.ConvertAll (Console.ReadLine ().Split (), int.Parse);
			var list = new List<Tuple<int,int>> ();
			for (int i = 0; i < dg [0]; i++) {
				var temp = Array.ConvertAll (Console.ReadLine ().Split (), int.Parse);
				list.Add (new Tuple<int,int> (temp [0], temp [1]));
			}
			int minSolve = int.MaxValue;
			for (int i = 0; i < Math.Pow (2, dg [0]); i++) {
				int score = 0;
				int solve = 0;
				var AllGreen = new int[dg [0]];
				for (int j = 0; j < dg [0]; j++) AllGreen [j] = 1;
				for (int slide = 0; slide < dg [0]; slide++) {
					if (((i >> slide) & 1) == 1) {
						score += (slide + 1) * 100 * list[slide].Item1 + list [slide].Item2;
						solve += list [slide].Item1;
						AllGreen [slide] = 0;
					}
				}
				if (score < dg [1]) {
					for (int j = dg [0] - 1; j >= 0; j--) {
						if (AllGreen [j] == 1) {
							int remain = list [j].Item1;
							while (remain >= 0) {
								score += (j + 1) * 100;
								solve++;
								remain--;
								if (score >= dg [1])
									break;
							}
							break;
						}
					}
				}
				if(score >= dg[1]) minSolve = Math.Min (minSolve, solve);
			}
			Console.WriteLine (minSolve);
		}
	}
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define pb push_back
#define pi pair<int, int>
#define l first
#define r second
#define all(x) x.begin(), x.end()
#define fori(a, b, step) for (int i = a; i < b; i += step)
#define forj(a, b, step) for (int j = a; j < b; j += step)
#define int long long

const int maxn = 1e6 + 1, mod = 1e9 + 7;

using namespace std;

int a[maxn];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int l = 0, r = 1e9 + 1;
    while (r - l > 1) {
        int md = (l + r) / 2;
        int ans = 0;
        for (int i = 0; i < n; i++)
            ans += (a[i] - 1) / md;
        if (ans <= k) r = md;
        else l = md;
    }
    cout << r;
    return 0;
}


Measured memory_bytes: 5080
import math


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    s1 = input()
    s2 = input()
    P = []
    modulo = 10**9+7
    H, V = 0, 1
    for i in range(N):
        if i > 0 and s2[i] == s2[i-1]:
            P[-1] = H
        else:
            P.append(V)
    dp = []
    if P[0] == H:
        dp.append(6)
    else:
        dp.append(3)
    """
    A B     |C
    B A|C    A

    dp[i] = 3*dp[i-1] if P[i]=H&P[i-1]=H
            2*dp[i-1]    P[i]=H&P[i-1]=V
            2*dp[i-1]    P[i]=V&P[i-1]=V
            1*dp[i-1]    P[i]=V&P[i-1]=V
    """
    for i in range(1, len(P)):
        if P[i] == H and P[i-1] == H:
            dp.append(3*dp[i-1])
        elif P[i] == H and P[i-1] == V:
            dp.append(2*dp[i-1])
        elif P[i] == V and P[i-1] == V:
            dp.append(2*dp[i-1])
        else:
            dp.append(dp[i-1])
        dp[-1] %= modulo
    return dp[-1]


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


Measured memory_bytes: 62196
N,Y=map(int,input().split())
ok = 0
for i in range(N+1):
  for j in range(N+1-i):
    k = N - i - j
    if i*10000+j*5000+k*1000 == Y:
      print(i,j,k)
      ok = 1
      break
  if ok == 1:
    break
if ok == 0:
  print("-1 -1 -1")


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

#define int long long

signed main() {
	int n, v;
	cin >> n;
	vector<int> h;
	for(int i = 0; i < n; i++) {
		cin >> v;
		h.push_back(v);
	}
	int i = n-1;
	while(i>0) {
		if(h[i]>=h[i-1]) {
			i--;
		}
		else {
			h[i-1] -= 1;
			if(h[i]>=h[i-1]) {
				i--;
			}
			else {
				break;
			}
		}
	}
	if(i==0){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1400
import sys
sys.setrecursionlimit(10**6)
n = int(input())
tree = [[] for i in range(n + 1)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    tree[u].append([v,w])
    tree[v].append([u,w])
finished = set()
ans = [-1 for i in range(n + 1)]
def dfs(node, weight):
    finished.add(node)
    if weight % 2 == 0:
        ans[node] = 0
    else:
        ans[node] = 1
    for i in tree[node]:
        next, w = i
        if next not in finished:
            dfs(next, w + weight)
dfs(1,0)
for i in range(1, len(ans)):
    print(ans[i])

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

using namespace std;

typedef long long ll;

const int MAX_N = 2e5 + 5;

vector<int> G[MAX_N];
int N, M;
int color[MAX_N];
int num[2];

void addEdge(int a, int b)
{
  G[a].push_back(b);
  G[b].push_back(a);
}

bool dfs(int v, int c)
{
  color[v] = c;
  if (c == 1) num[0]++;
  else num[1]++;
  for (int u : G[v]) {
    if (color[u] == c) return false;
    if (color[u] == 0 && !dfs(u, -c)) return false;
  }
  return true;
}

void solve()
{
  ll del = 0;
  if (dfs(0, 1)) {
    del += 1LL * num[0] * (num[0] - 1) / 2;
    del += 1LL * num[1] * (num[1] - 1) / 2;
  }
  ll tot = 1LL * N * (N - 1) / 2;
  tot -= del;
  ll ans = tot - M;
  cout << ans << endl;
}

int main()
{
#ifdef linjia
freopen("C:\\Users\\linjian\\Documents\\in.txt", "r", stdin);
#endif
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a; --b;
    addEdge(a, b);
  }
  solve();
  return 0;
}


Measured memory_bytes: 8832
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

struct Point {
    long x;
    long y;
    long h;
};

long height(long H, long x, long y, Point& p) {
    long h = H - abs(x - p.x) - abs(y - p.y);
    return max(h, 0L);
}

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

    int init_index;
    vector<Point> points(n);
    for (int i = 0; i < n; ++i) {
        cin >> points[i].x >> points[i].y >> points[i].h;
        if (points[i].h > 0)
            init_index = i;
    }

    const int xy_max = 100;
    for (int x = 0; x <= xy_max; ++x) {
        for (int y = 0; y <= xy_max; ++y) {
            long H = abs(x - points[init_index].x) +
                     abs(y - points[init_index].y) + points[init_index].h;
            H = max(H, 0L);

            bool flag = true;
            for (int i = 0; i < n; ++i) {
                if (height(H, x, y, points[i]) != points[i].h) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                cout << x << ' ' << y << ' ' << H << '\n';
                return 0;
            }
        }
    }
}


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



int main(){
    ll n,k;cin>>n>>k;
    ll a[200020];
    rep(i,0,n)cin>>a[i];
    rep(i,k,n){
        if(a[i]>a[i-k])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

    









Measured memory_bytes: 5184
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	int r,d,x,y;
	cin>>r>>d>>x;
	for(int i=0;i<10;i++)
	{
		y=x*r-d;
		x=y;
		cout<<y<<endl;
	}
    return 0;
}


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

int main(){
	int N;
	cin >> N;
	for (int i = 0;i <= 25;++i) {
		for (int j = 0;j <= 14;++j) {
			if (4 * i + 7 * j == N) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}

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

int main() {
  int n;
  double ans=0;
  cin>>n;
  vector<double>x(n);
  vector<string>u(n);
  for(int i=0;i<n;i++) cin>>x[i]>>u[i];
  for(int i=0;i<n;i++){
    if(u[i]=="JPY") ans+=x[i];
    else ans+=x[i]*380000.0;
  }
  cout<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, arr[100001][3];
ll dp[100001][3];

ll solve(int i = 0, int lst = 0) {
    if (i==n) {
        return 0;
    }
    if (i==0) {
        return max(arr[i][0] + solve(i+1, 0), max(arr[i][1] + solve(i+1, 1), arr[i][2] + solve(i+1, 2)));
    }
    ll& ret = dp[i][lst];
    if (~ret) {
        return ret;
    }
    if (lst == 0) {
        return ret = max(arr[i][1] + solve(i+1, 1), arr[i][2] + solve(i+1, 2));
    }
    if (lst == 1) {
        return ret = max(arr[i][0] + solve(i+1, 0), arr[i][2] + solve(i+1, 2));
    }
    return ret = max(arr[i][0] + solve(i+1, 0), arr[i][1] + solve(i+1, 1));
}
int main()
{
    IOS
    cin >> n;
    memset(dp, -1, sizeof dp);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> arr[i][j];
        }
    }
    cout << solve() << endl;



    return 0;
}


Measured memory_bytes: 8448
N, K = map(int, input().split())
 
mod = 10 ** 9 + 7

ans = 0

for i in range(K, N + 2):
  M = (2*N - i + 3) * i // 2
  m = i * (i+1) // 2
  ans += M - m + 1
  ans %= mod
  
print(ans)


Measured memory_bytes: 9180
using System;
using System.Collections.Generic;

namespace ConsoleApp_ITP1_4_C
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> inputList = new List<string>();

            while (true)
            {
                string input = Console.ReadLine();

                if (input.Contains(" ? "))
                {
                    break;
                }
                else
                {
                    inputList.Add(input);
                }
            }

            foreach (string input in inputList)
            {
                string[] literalAndoperand = input.Split(' ');
                var literal1 = Int32.Parse(literalAndoperand[0]);
                var operand = literalAndoperand[1];
                var literal2 = Int32.Parse(literalAndoperand[2]);

                switch (operand)
                {
                    case "+":
                        Console.WriteLine(literal1 + literal2);
                        break;
                    case "-":
                        Console.WriteLine(literal1 - literal2);
                        break;
                    case "*":
                        Console.WriteLine(literal1 * literal2);
                        break;
                    case "/":
                        Console.WriteLine(literal1 / literal2);
                        break;
                }
            }
        }
    }
}



Measured memory_bytes: 9776
/**

  @@@@@@@  @@@@  @@@@  @@@@  @@@@  @ 
  @  @  @  @  @  @  @  @  @  @  @  @
  @  @  @  @  @  @  @  @  @  @  @  @
  @  @  @  @  @  @  @  @  @  @  @  @
  @  @  @  @@@@  @@@@  @@@@  @  @  @

**/
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define str string
#define pi pair
#define tup tuple
#define vec vector
#define temp template
#define tn typename

#define ff first
#define ss second
#define SZ(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rsz resize
#define ins insert
#define fr front 
#define bc back
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mk make_pair

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++) 
#define ROF(i, a, b) for (ll i = (a); i >= (b); i--)
#define trav(a, x) for (auto &a : x)
#define popcount __builtin_popcount
#define ctz __builtin_ctz
#define clz __builtin_clz
#define gcd __gcd

// DEBUG
#define ts to_string
temp<tn A, tn B> str ts(pi<A, B> p);
temp<tn A, tn B, tn C> str ts(tup<A, B, C> p);
str ts(const str& s) { return '"' + s + '"'; }
str ts(const char* s) { return ts((str) s); }
str ts(bool b) { return (b ? "true" : "false"); }
str ts(vec<bool> v) { bool f = true; str res = "{";
FOR(i, 0, static_cast<ll>(v.size()) - 1) 
{ if (!f) res += ", "; res += ts(v[i]);
f = false; } res += "}"; return res; }
temp<size_t N> str ts(bitset<N> v) { str res = "";
trav(a, v) { res += (char) ('0' + a); } return res; }
temp<tn A> str ts(A v) { bool f = true; str res = "{";
trav(x, v) { if (!f) res += ", "; res += ts(x);
f = false; } res += "}"; return res; }
temp<tn A, tn B> str ts(pi<A, B> p) { 
  return "(" + ts(p.ff) + ", " + ts(p.ss) + ")"; }
temp<tn A, tn B, tn C> str ts(tup<A, B, C> t) {
  return "(" + ts(get<0>(t)) + ", " + ts(get<1>(t)) + ", " + ts(get<2>(t)) + ")"; }
void DBG() { cerr << endl; }
temp<tn H, tn... T> void DBG(H h, T... t) { cerr << " " << ts(h); DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", DBG(__VA_ARGS__);

// INPUT AND OUTPUT
temp<tn T> void re(T& x) { cin >> x; };
temp<tn H, tn... T> void re(H& h, T&... t) { re(h); re(t...); }
temp<tn T> void pr(T x) { cout << x; };
temp<tn H, tn... T> void pr(H h, T... t) { pr(h); pr(t...); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a;
  re(a);
  str s;
  re(s);
  ll b = 0;
  reverse(all(s));
  ll mul = 1;
  trav(c, s) {
    if (c == '.') continue;
    b += mul * (ll) (c - '0');
    mul *= 10;
  }
  ll res = a * b;
  res /= 100;
  pr(res, '\n');
  return 0;
}

Measured memory_bytes: 3580
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = sorted([int(i) for i in A.split()],reverse=True)[:K]
B = sorted([int(i) for i in B.split()],reverse=True)[:K]
C = sorted([int(i) for i in C.split()],reverse=True)[:K]

ABC = []
for i in range(X):
    if (i + 1) > K:
        break
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for l in range(Z):
            if (i + 1) * (j + 1) * (l + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[l])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Measured memory_bytes: 9544
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long int
#define pb push_back
using namespace std;

map<pair<char,char>,int> o; 

pair<char,int> decide(set<char> s, char c){
	for(auto e : s){
		if(o[{e,c}] == 1){
			return {e,1};
		}
	}
	return {'?',0};
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,k,r,s,p;
	ll ans = 0;
	string t;
	cin >> n >> k >> r >> s >> p >> t;
	map<char,int> mp;
	o[{'r', 's'}] = 1;
	o[{'s', 'p'}] = 1;
	o[{'p', 'r'}] = 1;
	mp['r'] = r;
	mp['s'] = s;
	mp['p'] = p; 
	vector<char> play(n);
	set<char> st;
	for(int i = 0; i < n; ++i){
		st.insert('r');
		st.insert('s');
		st.insert('p');
		if(i-k < 0){
			auto e = decide(st, t[i]);
			if(e.ss == 1){
				play[i] = e.ff;
				ans += mp[e.ff];
			}
		}else{
			st.erase(play[i-k]);
			auto e = decide(st, t[i]);
			if(e.ss == 1){
				play[i] = e.ff;
				ans += mp[e.ff];
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

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

int main() {
string s ; cin >> s;
int c = 0 ; 
int p =1; 

for( int i = 0 ;i <s.length() ; i++){//1
if ((i)%2==0 &&(s[i]== 'R' || s[i]== 'U' || s[i] == 'D'))
    c++ ; 

 if ((i)%2!=0 && ( s[i]== 'L' || s[i]== 'U' || s[i] =='D'))
 c++;
}
 if (c==s.length())
     cout<<"Yes" ;
     else cout<< "No" ; 
    return 0;
}

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


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

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

    int ans = A[0];
    for(int i=1;i<N;i++)
    {
        ans = gcd(ans,A[i]);
    }
    cout << ans << endl;

    return 0;
}


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

#define pb push_back

vector<int>g[100003];
vector<int>v(100003);
queue<int>q;

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

    set<string>st;
    while(n--)
    {
        string s;
        cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<endl;
}






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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int, int> pii;
const int mod = (int)1e9 + 7;


int main()
{

	ll x,y;
	cin >>x >>y;
	ll ans = 1e16;
	
	
	ll df= abs(abs(y) - abs(x));
	if(y>=x){
		if(x>=0) ans = df;
		else if(x<0 && y>=0) ans = min(df+1, y-x);
		else  ans =  y-x;
	}
	
	if(y<x){
		if(x>=0 && y<=0) ans = df +1;
		else ans = df+2;
	}
	cout << ans << endl;
	return 0;

}


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

using namespace std;

const int maxN = 2e5+10;
int N, M, F[maxN];

int main()
{
    ios_base :: sync_with_stdio(0);
    cin >> N >> M;
    for (int i=0,x,y; i < M; i++)
    {
        cin >> x >> y;
        if (x == 1 || x == N) F[y]++;
        if (y == 1 || y == N) F[x]++;
    }
    bool flag = 0;
    for (int i=2; i < N; i++)
        if (F[i] >= 2) flag = 1;
    puts(flag ? "POSSIBLE" : "IMPOSSIBLE");
}


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 1000000001
#define EPS 1.0e-6

using namespace std;

typedef long long ll;

int n;
int a[5];

int main()
{
	cin >> n;
	vector<int> cd;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);

	for (int i = 1; i*i <= a[0]; i++) {
		if (a[0] % i == 0) {
			if (a[1] % i == 0 && a[2] % i == 0) {
				cd.push_back(i);
			}
			if (i*i != a[0]) {
				int k = a[0] / i;
				if (a[1] % k == 0 && a[2] % k == 0)cd.push_back(k);
			}
		}
	}
	sort(cd.begin(), cd.end());

	for (int i = 0; i < cd.size(); i++) {
		cout << cd[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3104
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 100000
#define mod 1000000007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
struct Vec
{
	int s[3];
	Vec(){memset(s,0,sizeof(s));}
	Vec operator * (int y)
	{
		Vec c;
		for(int i=0;i<3;++i) c.s[i]=1LL*s[i]*y%mod;
		return c;
	}
	Vec operator + (const Vec&b)
	{
		Vec res;
		for(int i=0;i<3;++i) res.s[i]=(s[i]+b.s[i])%mod;
		return res;	
	}
}s,I;
struct Matrix
{
	int s[3][3];
	Matrix(){memset(s,0,sizeof(s));}
	Matrix operator * (const Matrix&b)
	{
		Matrix c;
		for(int i=0;i<3;++i)for(int k=0;k<3;++k)if(s[i][k])
			for(int j=0;j<3;++j) c.s[i][j]=(c.s[i][j]+1LL*s[i][k]*b.s[k][j])%mod;
		return c;
	}
	Vec operator * (const Vec&b)
	{
		Vec res;
		for(int i=0;i<3;++i) for(int j=0;j<3;++j)
			res.s[i]=(res.s[i]+1LL*s[i][j]*b.s[j])%mod;
		return res;	
	}
}A;
Matrix Pow(int x)
{
	Matrix B=A,C=A;
	for(--x;x;x>>=1,C=C*C) if(x&1) B=B*C;
	return B;
}
int n,m,x[MN+5],f[MN+5];
int main()
{
	A.s[1][0]=A.s[2][1]=1;
	A.s[0][0]=4;A.s[0][1]=mod-2;A.s[0][2]=1;
	I.s[0]=0;I.s[1]=1;I.s[2]=3;s=I*(mod-1);
	n=read();m=read();
	for(int i=1;i<=m;++i) x[i]=read();x[++m]=n;
	for(int i=1;i<=m;++i)
	{
		s=Pow(x[i]-x[i-1])*s;f[i]=(mod-s.s[0])%mod;
		s=s+I*f[i]; 
	}
	printf("%d\n",f[m]);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main() {
	int N;
	scanf("%d", &N);
	
	long long int A1[N];
	long long int A2 = 1;
	long long int max = 1000000000000000000;
	
	for(int i = 0; i < N; i++){
		scanf("%lld", &A1[i]);
	}
	
	for(int j = 0; j < N; j++){
		if(A1[j] == 0){
			printf("0\n");
			return 0;
		}
	}
	
	for(int k = 0; k < N; k++){
		if(A1[k] <= max/A2){
			A2 *= A1[k];
		} else{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", A2);
	
	return 0;
}

Measured memory_bytes: 2484
#include <iostream>
#include <algorithm>

using namespace std;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)

const int MAX = 1e5+10;

int N;
int A[MAX][3];
int dp[MAX][3];

int main () {
  cin >> N;
  REP (i, N) {
    REP (k, 3) {
      cin >> A[i][k];
      dp[i][k] = 0;
    }
  }
  REP (i, 3) dp[0][i] = A[0][i];
  FOR (i, 1, N) {
    REP (j, 3) {
      REP (k, 3) if (j != k)
        dp[i][j] = max(dp[i][j], dp[i-1][k]+A[i][j]);
    }
  }
  int ans = 0;
  REP (i, 3) ans = max(ans, dp[N-1][i]);
  cout << ans << endl;
}

Measured memory_bytes: 2560
package main

import (
	"fmt"
	"sort"
)

func nextInt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	n := nextInt()
	k := nextInt()

	dic := map[int]int{}

	for range make([]struct{}, n) {
		a := nextInt()
		b := nextInt()
		dic[a] += b
	}

	m := 0
	for _, v := range dic {
		m = max(m, v)
	}
	p := 1
	for p <= m {
		p *= 10
	}

	seq := []int{}
	for key, val := range dic {
		seq = append(seq, key*p+val)
	}
	sort.Ints(seq)

	var ans int
	for k > 0 {
		ans = seq[0] / p
		k -= seq[0] % p
		seq = seq[1:]
	}

	fmt.Println(ans)
}


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

int N;
long H[100001];

int main(int argc, char *argv[]) {
	int sr;
	int i;

	sr=scanf("%d", &N);

	for (i=1; i<=N; i++) {
		sr=scanf("%ld", &H[i]);
	}

	for (i=N; i>=2; i--) {
		if (H[i-1]>H[i]) {
			H[i-1]--;
			if (H[i-1]>H[i]) break;
		}
	}
	if (i==1 && H[1]>0) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	fflush(stdout);

	return 0;

}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
//出力関数
void print(std::vector<std::string>& array){
  bool first = true;;
 
  for(int i = 0; i < array.size(); ++i){
    if(!first){
      std::cout << " ";
    }else{
      first = false;
    }
 
    std::cout << array[i];
  }
 
  std::cout << std::endl;
}
 
int main(int argc,char* argv[]){
  int n;
  //入力
  std::cin >> n;
 
  std::vector<std::string> bubble(n), selection(n);
   
  for(int i = 0; i < n; i++){
    std::string tmp;
    std::cin >> tmp;
    bubble[i] = selection[i] = tmp;
  }
	//バブルソート
  for(int i = 0; i < n; i++){
    for(int j = n - 1; j > i; j--){
      if(bubble[j][1] < bubble[j-1][1]){
    swap(bubble[j], bubble[j-1]);
      }
    }
  }
	//選択ソート
  for(int i = 0; i < n; i++){
    int min = i;
 
    for(int j = i; j < n; j++){
      if(selection[j][1] < selection[min][1]){
    min = j;
      }
    }
 
    swap(selection[i], selection[min]);
  }
	//選択ソートの判定
  bool same = true;
  for(int i = 0; i < n; i++){
    if(bubble[i] != selection[i]){
      same = false;
      break;
    }
  }
	//出力
  print(bubble);
  std::cout << "Stable" << std::endl;
  print(selection);
  std::cout << (same ? "Stable" : "Not stable") << std::endl;
  return 0;
   
}

Measured memory_bytes: 1212
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)

n,m = ips()
mv = fractions.gcd(n,m)
l = []
for i in range(1,int(math.sqrt(mv))+1):
    if mv%i==0:
        l.append(i)
        l.append(mv//i)
#print(l)
l.sort()
p = set(l)
l = copy.copy(list(p))
s = []
for target in l:
    flag = 1
    for i in range(2,int(math.sqrt(target))+1):
        #print(target,i,target%i)
        if target%i==0:
            flag = 0
            break
    if flag:s.append(target)
print(len(s))

Measured memory_bytes: 5968
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (__typedef(c.begin()) it = c.begin(); it != c.end(); ++ it)

inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!(c >= 48); c = getchar()) if (c == 45) f ^= 1;
	for (; (c >= 48); c = getchar()) x = x * 10 + c - 48;
	return f ? x : -x;
}

const int N = 200005;
ll x[N], v[N];
ll sumv[N];
int n; ll C;
ll solve() {
	rep(i, n + n + 1) sumv[i + 1] = sumv[i] + v[i];
	ll ans = 0;
	set <ll> st;
	st.insert(0);
	for (int i = n + n; i >= n; -- i) {
		st.insert(sumv[n] - sumv[i - n] - (C - x[i - n]) * 2);
		ans = max(ans, sumv[i + 1] - sumv[n] - (x[i] - C) + *st.rbegin());
	}
	return ans;
}
int main() {
	n = read();
	scanf("%lld", &C);
	rep(i, n) {
		scanf("%lld", &x[i]);
		v[i] = read();
	}
	x[n] = C;
	v[n] = 0;
	rep(i, n) {
		x[i + 1 + n] = x[i] + C;
		v[i + 1 + n] = v[i];
	}
	ll ans = solve();
	rep(i, n + n + 1) {
		x[i] = C + C - x[i];
	}
	reverse(x, x + n + n + 1);
	reverse(v, v + n + n + 1);
	ans = max(ans, solve());
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 9600