akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,m;
    vll G[100010];
    bool b[100010]={};
    cin>>n>>m;
    ll s,t;
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        s=a,t=b;
        G[a].pb(b);
        G[b].pb(a);
    }
    deque<ll> deq;
    deq.push_front(s);
    deq.push_back(t);
    b[s]=true,b[t]=true;
    bool ok1=true,ok2=true;
    while(true){
        bool update=false;
        for(ll i:G[deq.front()]){
            if(b[i]==false){
                deq.push_front(i);
                b[i]=true;
                update=true;
                break;
            }
        }
        for(ll i:G[deq.back()]){
            if(b[i]==false){
                deq.push_back(i);
                b[i]=true;
                update=true;
                break;
            }
        }
        if(update) continue;
        break;
    }
    cout<<deq.size()<<endl;
    rep(i,deq.size()){
        cout<<deq.at(i);
        if(i!=deq.size()-1) cout<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 7168
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

ans = 0
rem = 10
for i in [0] * 5:
    N = input()
    if N % 10 != 0:
        ans += N / 10 * 10 + 10
        rem = min(rem, N % 10)
    else:
        ans += N

ans -= 10
ans += rem
print ans

Measured memory_bytes: 2812
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>

using namespace std;

int FindFurthest(vector<vector<int> > &adj_nodes, int start, int* p_furthest)
{
  int N = adj_nodes.size();
  vector<bool> visited(N, false);
  int remaining = N;

  queue<int> q;
  q.push(start);
  visited[start] = true;
  --remaining;
  queue<int> nq;

  int dist = 1;
  bool done = false;
  while (remaining > 0) {
    while (not q.empty()) {
      int x = q.front();
      q.pop();
      for (auto nx : adj_nodes[x]) {
	if (not visited[nx]) {
	  nq.push(nx);
	  visited[nx] = true;
	  --remaining;
	  if (remaining == 0) {
	    *p_furthest = nx;
	    done = true;
	    break;
	  }
	}
      }
      if (done) break;
    }
    if (done) break;
    swap(q, nq);
    ++dist;
  }

  return dist;
}

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

  if (N == 1) {
    cout << "First" << endl;
    return 0;
  }
  
  vector<vector<int> > adj_nodes(N);
  
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    adj_nodes[a].push_back(b);
    adj_nodes[b].push_back(a);
  }

  int dist;
  int furthest;
  dist = FindFurthest(adj_nodes, 0, &furthest);
  int furthest2;
  dist = FindFurthest(adj_nodes, furthest, &furthest2);
  
  if (dist % 3 == 1) cout << "Second" << endl;
  else cout << "First" << endl;
  
  return 0;
}


Measured memory_bytes: 12788
#include <bits/stdc++.h>
#define F(i, a, b) for (int i = (a); i < (b); ++i)
#define F2(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i > (b); --i)
#define dF2(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
int a[20];
typedef long long LL;
int main() {
//    freopen("in.txt", "r", stdin);
    LL n;
    scanf("%lld", &n);
    int cnt = 0, x;
    while (n) {
        a[cnt++] = n%10;
        n /= 10;
    }
    bool flag = false;
    F(i, 0, cnt-1) if (a[i]!=9) { flag=true; break; }
    if (!flag) printf("%d\n", a[cnt-1]+(cnt-1)*9);
    else printf("%d\n", a[cnt-1]-1+(cnt-1)*9);
    return 0;
}


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

import sys
sys.setrecursionlimit(300000)


def solve(N: int, P: "List[int]"):
    mn = float('inf')
    ret = 0
    for v in P:
        if v <= mn:
            ret += 1
        mn = min(mn, v)
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P)

if __name__ == '__main__':
    main()


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

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

const long long INF = 1LL << 60;

int main ()
{
    long long n,ans=0,k,d[15][15]={};    cin >> n;

    for(int i=1;i<=n;i++){
        for(k=i;k>=10;k/=10);
        d[k][i%10]++;
    }
    for(int i=1;i<=9;i++) {
        for(int j=1;j<=9;j++)
        { ans+=d[i][j]*d[j][i];}}

    cout << ans << endl;
}

     



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void){
    int n ;
    char t[101] , h[101] ;
    int i ;
    int tp = 0 , hp = 0 ;
    
    scanf("%d" , &n) ;
    
    for(i = 0 ; i < n ; i++){
        scanf("%s %s" , t , h) ;
        if(strcmp(t , h) == 0){
            tp++ ;
            hp++ ;
        }
        else if(strcmp(t , h) > 0){
            tp += 3 ;
        }
        else if(strcmp(t , h) < 0){
            hp += 3 ;
        }
    }
    printf("%d %d\n" , tp , hp) ;
    return 0 ;
}


Measured memory_bytes: 2052
import java.util.Scanner;

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

    int num [] = new int[3];

    for(int i=0; i<3; i++) num[i] = sc.nextInt();

    for(int i=0; i<2; i++){
      for(int j=0; j<2; j++){
        if(num[j]>num[j+1]){
          int change = 0;
          change = num[j];
          num[j] = num[j+1];
          num[j+1] = change;
        }
      }
    }
    System.out.printf("%d %d %d\n", num[0], num[1], num[2]);
  }
}



Measured memory_bytes: 26384
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;

int main() {
  double n, m, d;
  cin>>n>>m>>d;
  if (d > 0) {
    cout<<fixed<<setprecision(10)<<(2*(n-d))*(m-1)/(n*n)<<endl;
  } else {
    cout<<fixed<<setprecision(10)<<(n-d)*(m-1)/(n*n)<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d %d %d %d', $A, $B, $C, $D);

if ($A + $B > $C + $D) {
    echo 'Left';
} elseif ($A + $B < $C + $D) {
    echo 'Right';
} else {
    echo 'Balanced';
}


echo PHP_EOL;


Measured memory_bytes: 16148
import java.util.Scanner;
public class Main {
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String array[] = S.split("");
		boolean ch = true;

		for(int x = 0;x < array.length - 1;x++) {
			if(array[x].equals(array[x + 1])) {
				ch = false;
				break;
			}
		}

		if(ch == true) {
			System.out.println("Good");
		}else {
			System.out.println("Bad");
		}
	}
}


Measured memory_bytes: 23764
#include<iostream>
using namespace std;
int main(){
	int w,n,k,ans=0,x,y,xx,yy,sx,sy;
	cin>>w>>n>>k;
	cin>>x>>y;
	for(int i=0;i<k-1;i++){
		cin>>xx>>yy;
		sx=max(x,xx)-min(x,xx);
		sy=max(y,yy)-min(y,yy);
		if((x-xx>0 && y-yy>0)||(x-xx<0 && y-yy<0)){
			ans+=max(sx,sy);
		}
		else{
			ans+=sx+sy;
		}
		x=xx;
		y=yy;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1160
letters = {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4, 'g': 7, 'f': 6, 'i': 9, 'h': 8, 'k': 11, 'j': 10, 'm': 13, 'l': 12, 'o': 15, 'n': 14, 'q': 17, 'p': 16, 's': 19, 'r': 18, 'u': 21, 't': 20, 'w': 23, 'v': 22, 'y': 25, 'x': 24, 'z': 26}
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
n = int(input())
words = {}
total = 0
hashv = 1
for i in range(n):
    s = input()
    for l in s:
        hashv = hashv*primes[letters[l] - 1]
    if hashv not in words.keys():
        words[hashv] = 1
    else:
        words[hashv] += 1
    hashv = 1

for key in words:
    if words[key] != 1:
        total += int(words[key] * (words[key]-1)/2)
    
print(total)


Measured memory_bytes: 15812
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Q3
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = Int32.Parse(Console.ReadLine());
            string [] strAN = Console.ReadLine().Split(' ');
            var dictAN = new Dictionary<int, int>();
            for (int i = 0; i < N; i++)
            {
                dictAN.Add(i, Int32.Parse(strAN[i]));
            }
            var sorted = dictAN.OrderBy(pair => pair.Value);
            var output = new StringBuilder("");
            foreach(var student in sorted)
            {
                output.Append(student.Key + 1).Append(" ");
            }
            Console.WriteLine(output.ToString());

            //Console.ReadKey();
        }
    }
}


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1e9 + 7;
using m64 = modint<MOD>;

template<typename T>
struct combinatorics {
    vector<T> fac;

    combinatorics(i32 n): fac(2*n+1) {
        fac[0] = 1;
        for (i32 i = 1; i <= 2*n; i++) fac[i] = fac[i-1] * i;
    }

    T p(i32 n, i32 k) const {
        if (k < 0 || n < k) return 0;
        return fac[n] / fac[n-k];
    }

    T c(i32 n, i32 k) const {
        if (k < 0 || n < k) return 0;
        return fac[n] / (fac[k] * fac[n-k]);
    }

    T h(i32 n, i32 k) const {
        return c(n+k-1, k);
    }
};

using combi = combinatorics<m64>;

int main() {
    i32 n, k;
    cin >> n >> k;

    combi c(n);
    m64 ans = 0;
    for (i32 m = 0; m <= min(n, k); m++) {
        ans += c.c(n, m) * c.h(n-m, m);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll f[111][11];
ll p[111][12];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++)cin>>f[i][j];
  }
  ll ans=-llINF;
  for(int i=0;i<n;i++)
    for(int j=0;j<11;j++)cin>>p[i][j];
  for(int i=1;i<BITLE(10);i++){
    ll sum=0;
    for(int k=0;k<n;k++){
      ll cnt=0;
      for(int j=0;j<10;j++){
	if(i&BITLE(j)&&f[k][j]){
	  cnt++;
	}	
      }
      sum+=p[k][cnt];
    }
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}


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

a.sort()

ans = 0
tmp = 1

for i in range(n-1):
    if a[i] == a[i+1]:
        tmp += 1
        if i == n-2:
            ans += tmp % 2
            tmp = 0
    else:
        ans += tmp % 2
        tmp = 1

if tmp%2 == 1:
    ans += 1

print(ans)

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	int ans = 0;
	
	while(n > 0) {
		ans++;
		n /= k;
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 101

int main() {
  int M[MAX][MAX],i,j,n,m,p,r;

  scanf("%d",&n);
  for(i = 1; i <= n; i++) {
    for(j = 1; j <= n; j++) {
      M[i][j] = 0;
    }
  }
  for(i = 1; i <= n; i++) {
    scanf("%d%d",&m,&r);
    for(j = 1; j <= r; j++) {
      scanf("%d",&p);
      M[i][p] = 1;
    }
  }

  for(i = 1; i <= n; i++) {
    for(j = 1; j <= n; j++) {
      printf("%d",M[i][j]);
    if(j == n) break;
    printf(" ");
    }
    printf("\n");
  }
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	int sum=0;
	for(int i=1;i<=n;i++){
		int l,r;
		cin >> l >> r;
		sum+=(r-l+1);
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,u,v = LI()
Graph = [[] for i in range(N+1)]

for i in range(N-1):
    a,b = LI()
    Graph[a].append(b)
    Graph[b].append(a)

from collections import deque

q1 = deque([u])
distance1 = [-1]*(N+1)  # uから各頂点への最短距離
distance1[u] = 0

# bfs

while q1:
    n = q1.pop()
    for d in Graph[n]:
        if distance1[d] != -1:
            continue
        else:
            distance1[d] = distance1[n]+1
            q1.appendleft(d)

q2 = deque([v])
distance2 = [-1]*(N+1)  # vから各頂点への最短距離
distance2[v] = 0

# bfs

while q2:
    n = q2.pop()
    for d in Graph[n]:
        if distance2[d] != -1:
            continue
        else:
            distance2[d] = distance2[n]+1
            q2.appendleft(d)

q3 = deque([u])
distance3 = [-1]*(N+1)  # uから各頂点への最短距離、ただし青木君に追いつかれない
distance3[u] = 0

# bfs

while q3:
    n = q3.pop()
    for d in Graph[n]:
        if distance3[d] != -1 or distance1[d] >= distance2[d]:
            continue
        else:
            distance3[d] = distance3[n]+1
            q3.appendleft(d)

# 青木君に追いつかれずに行ける頂点まで行き、うろうろする

ans = 0
for i in range(1,N+1):
    if distance3[i] >= 0:
        ans = max(ans,distance2[i]-1)

print(ans)

Measured memory_bytes: 90472
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nmxy = scanner.nextLine().split(" ", 4);
        int n = Integer.parseInt(nmxy[0]);
        int m = Integer.parseInt(nmxy[1]);
        int x = Integer.parseInt(nmxy[2]);
        int y = Integer.parseInt(nmxy[3]);

        String[] xLine = scanner.nextLine().split(" ", n);
        int[] xNums = new int[n];
        for (int i = 0; i < n; i++) {
            xNums[i] = Integer.parseInt(xLine[i]);
        }
        Arrays.sort(xNums);

        String[] yLine = scanner.nextLine().split(" ", m);
        int[] yNums = new int[m];
        for (int i = 0; i < m; i++) {
            yNums[i] = Integer.parseInt(yLine[i]);
        }
        Arrays.sort(yNums);

        if (Math.max(x, xNums[n-1]) < Math.min(y, yNums[0])) {
            System.out.println("No War");
        } else {
            System.out.println("War");
        }
    }
}


Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#define _USE_MATH_DEFINES
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<string, map<string, int> > Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;


int board[5][5];
int score[] = {
	0, 0, 60, 70, 80
};
int to_num1(int *a){
	int res = 0;
	for(int i = 0; i < 5; i++){
		res = res * 5 + a[i];
	}
	return res;
}

int dp[5][5 * 5 * 5 * 5 * 5];

int main(){
	int n;
	cin >> n;
	for(int t = 0; t < n; t++){
		memset(dp, -1, sizeof(dp));
		for(int i = 0; i < 5; i++){
			for(int j = 0; j < 5; j++){
				cin >> board[i][j];
			}
		}
		dp[0][to_num1(board[0])] = 0;

		int a[5];
		int b[5];
		int c[5];
		int d[5];

		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 5 * 5 * 5 * 5 * 5; j++){
				if(dp[i][j] == -1) continue;

				a[4] = j % 5;
				a[3] = (j / 5) % 5;
				a[2] = (j / 5 / 5) % 5;
				a[1] = (j / 5 / 5 / 5) % 5;
				a[0] = (j / 5 / 5 / 5 / 5) % 5;

				for(int k = 0; k < 1 << (2 * 4); k++){

					c[0] = (k & 3);
					c[1] = (k & 3) + ((k >> 2) & 3);
					c[2] = ((k >> 2) & 3) + ((k >> 4) & 3);
					c[3] = ((k >> 4) & 3) + ((k >> 6) & 3);
					c[4] = ((k >> 6) & 3);

					//cout << c[0] << " " << c[1] << " " << c[2] << " " << c[3] << " " << c[4] << endl;
					int sum = 0;
					for(int l = 0; l < 5; l++){
						if(a[l] == 0){
						}else{
							sum += score[1 + (a[l] - 1 + c[l]) % 4];
						}

						if(i == 3){
							if(board[i+1][l] == 0){
								d[l] = 0;
							}else{
								d[l] = 1 + (board[i+1][l] - 1 + c[l]) % 4;
								sum += score[d[l]];
							}
						}

						if(board[i+1][l] == 0) b[l] = 0;
						else{
							b[l] = 1 + (board[i+1][l] - 1 + c[l]) % 4;
						}
					//	cout << b[l] << " ";
					}
			//		cout << endl;
				//	cout << sum << endl;
					dp[i+1][to_num1(b)] = max(dp[i+1][to_num1(b)], sum + dp[i][j]);
				//	cout << i << " " <<  dp[i+1][to_num1(b)] << endl;
				}
			}
		}
		int res = 0;
		for(int j = 0; j < 5; j++){
			for(int i = 0; i < 5 * 5 * 5 * 5 * 5; i++){
				res = max(res, dp[j][i]);
			}
			//cout << res << endl;
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 924
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define CLR(a) memset((a), 0 ,sizeof(a))

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

int main(void){
  int N, ans;
  cin >> N;
  int a[N];
  REP(i, N) cin >> a[i];

  for(int i=-100;i<=100;i++){
    int cost = 0;
    REP(j, N){
      cost += (a[j]-i)*(a[j]-i);
    }
    if(i == -100) ans = cost;
    else ans = min(ans, cost);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <queue>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(1e5 + 10);
std::deque<int> Q;
int K, f[N], vis[N];

int main()
{
	K = read(), Q.push_back(1);
	for (int i = 0; i < K; i++) f[i] = 1e9; f[1] = 1;
	while (!Q.empty())
	{
		int x = Q.front(), y; Q.pop_front();
		if (vis[x]) continue; vis[x] = 1;
		y = x * 10 % K, f[y] = std::min(f[y], f[x]), Q.push_front(y);
		y = (x + 1) % K, f[y] = std::min(f[y], f[x] + 1), Q.push_back(y);
	}
	printf("%d\n", f[0]);
	return 0;
}


Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define MOD 1000000007
#define MAXK 100002

int N, K;
LL ans = 0;
LL g[MAXK] = {0};

LL fastPow (LL a, LL k) {
	if (a == 0) return 0;

	LL res = 1;
	LL base = a % MOD;
	while (k) {
		if (k & 1) {
			res = res * base % MOD;
		}
		base = base * base % MOD;
		k >>= 1;
	}
	return res % MOD;
}

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

	for (int i = K; i >= 1; i --) {
		g[i] = fastPow (K / i, N);
		for (int j = i * 2; j <= K; j += i) {
			g[i] = (g[i] - g[j] + MOD) % MOD;
		}
		ans = (ans + (g[i] * i) % MOD) % MOD;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 4412
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ans = 0;
    if(k <= a){
        ans += k;
        cout << ans << endl;
        return 0;
    }
    ans += a;
    k -= a;
    if(k <= b){
        cout << ans << endl;
        return 0;
    }
    k -= b;
    if(k <= c){
        ans -= k;
        cout << ans << endl;
        return 0;
    }
    ans -= c;
    cout << ans << endl;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    if(b%a == 0) cout << a+b << endl;
    else cout << b-a << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        MyScanner in = new MyScanner(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, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            long[] A = in.nextLongArray(N);

            int l = 0;
            int r = N - 1;
            long diff = A[l++] - A[r--];
            while (l <= r) {
                if (diff <= 0) {
                    diff += A[l++];
                } else {
                    diff -= A[r--];
                }
            }
            out.println(Math.abs(diff));
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }

    }
}



Measured memory_bytes: 55124
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

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

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


int dx[5] = {1, 0, -1, 0};
int dy[5] = {0, 1, 0, -1};

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};
int main() {
    int N; cin >> N;

    vector<P> p(N);
    map<P,int> mp;

    rep(i,N){
        cin >> p[i].first >> p[i].second;
    }

    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(i==j) continue;

            ll a=p[i].first-p[j].first,
            b=p[i].second-p[j].second;

            mp[P(a,b)]++;
        }
    }

    int maximum=0;
    for(auto m: mp){
        maximum=max(maximum,m.second);
    }
    cout << N-maximum << endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(){
	int a, b, c, i, x;
	
    i = 0;
	scanf("%d %d %d",&a,&b,&c);
	for(x = a;x <= b; x++){
		if(c % x == 0){
		    i++;
		}
	}
	
	printf("%d\n", i);
	
	return 0;
}

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

int main(){
	int n;
	while(cin >> n , n){
		int hist[10] = {0} , a;
		rep(i,n)cin >> a , hist[a]++;
		rep(i,10){
			if(!hist[i])cout << "-";
			while(hist[i]--)cout << "*";
			cout << endl;
		}
	}
}

Measured memory_bytes: 0
def main():
    N = int(input())
    N = N % 100
    N = N % 10

    if N == 2 or N==4 or N==5 or N==7 or N==9:
        print("hon")
        return
    elif N == 0 or N==1 or N==6 or N==8:
        print("pon")
        return
    elif N==3:
        print("bon")
  

if __name__ == "__main__":
    main()


Measured memory_bytes: 9180
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fi   first
#define se   second
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)

const int N = 1e3 + 5;
const ll MOD = 1e9 + 7;
ll dp[N][N];
int n, m;
char grid[N][N];

void input() {
	cin >> n >> m;
	FOR(i, 1, n) {
		string s;
		cin >> s;
		REP(j, s.size()) grid[i][j + 1] = s[j];
	}
	memset(dp, 0, sizeof dp);
	dp[1][1] = 1;
}

void solve() {
	FOR(i, 1, n) FOR(j, 1, m) 
		if (grid[i][j] == '.' && !(i == 1 && j == 1)) dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
	cout << dp[n][m];
}

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0); cin.tie(0);

	input();
	solve();

	return 0;
}


Measured memory_bytes: 9088
N = int(input())
a = list(map(int, input().split()))
ans = [0] * N
for i in range(N):
    tmp = N - i
    kosuu = N // tmp
    if kosuu == 1:
        if a[tmp-1] == 1:
            ans[tmp-1] = 1
    else:
        sub_sum = 0
        for j in range(kosuu-1):
            sub_sum += ans[tmp * (j + 2) -1]
        if a[tmp-1] != sub_sum % 2:
            ans[tmp-1] = 1
            
true_ans = []
for i in range(N):
    if ans[i] == 1:
        true_ans.append(i + 1)
print(sum(ans))
print(*true_ans)

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    sort(All(p));
    int res = 0;
    rep(i, k) res += p[i];
    c(res);
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int h[5];
  while(cin>>h[0],h[0]){
    for(int i=1;i<5;i++) cin>>h[i];
    int x[4]={};
    for(int i=0;i<5;i++) x[h[i]]++;
    int a[5]={};
    if(x[1]&&x[2]&&x[3]){
      for(int i=0;i<5;i++) a[i]=3;
    }else if(!!x[1]+!!x[2]+!!x[3]==1){
      for(int i=0;i<5;i++) a[i]=3;
    }else{
      if(!x[1]){
	for(int i=0;i<5;i++){
	  if(h[i]==2) a[i]=1;
	  else a[i]=2;
	}
      }
      if(!x[2]){
	for(int i=0;i<5;i++){
	  if(h[i]==3) a[i]=1;
	  else a[i]=2;
	}
      }
      if(!x[3]){
	for(int i=0;i<5;i++){
	  if(h[i]==1) a[i]=1;
	  else a[i]=2;
	}
      }
    }
    for(int i=0;i<5;i++) cout<<a[i]<<endl;
  }
  return 0;
}

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

// cin.tie(0);
// ios::sync_with_stdio(false);
 
int main() {
  int N, K;
  int a, ans;
  cin >> N >> K;
  if (K == 1){ 
    ans = 0;
  } else {
    ans = N-K;
  }
  cout << ans << endl;
}

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

int main() {
    int n = 0 , d = 0 ,  ans = 0;
    long long a = 0 , b = 0;
    double x = 0.0;
    cin >> n >> d;
    while (n--){
        cin >> a >> b;
        x = sqrt(a*a + b*b);
        if (x < d || x == d)
            ans ++;
    }
    cout << ans;
	return 0;
}


Measured memory_bytes: 3648
from bisect import bisect_right
import itertools

N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
acum = list(itertools.accumulate(a))

answer = bisect_right(acum, x)
if answer == N:
    if acum[-1] < x:
        answer -= 1
print(answer)


Measured memory_bytes: 3188
import sys
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[sys.maxsize]*n
dp[0]=0
for i in range(1,n):
    for j in range(1,min(k+1,i+1)):
            dp[i]=min(abs(h[i-j]-h[i])+dp[i-j],dp[i])


print(dp[-1])


Measured memory_bytes: 84708
#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>;

const int INF = 1001001001;
int dp[1005][10005];

int main() {
    int h, n;
    cin >> h >> n;
    vector<int> A(n), B(n);
    rep(i, n) {
        cin >> A[i] >> B[i];
    }
    for (int i = 1; i <= h; ++i) dp[0][i] = INF;
    rep(i, n) rep(j, h+1) {
        if (j < A[i]) dp[i+1][j] = min(dp[i][j], B[i]);
        else dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]]+B[i]);
    }
    int ans = dp[n][h];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 39424
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int A = 0;
    int B = 0;
    int ans = 0;
    int[] dis = new int[N];
    int[] cnt = new int[N];
    for (int i = 0; i < N; i++) {
      dis[i] = sc.nextInt();
    }
    for (int j = 0; j < M; j++) {
      A = sc.nextInt();
      B = sc.nextInt();
      if (dis[A-1] < dis[B-1]) {
        cnt[A-1]++;
      } else if (dis[A-1] > dis[B-1]) {
        cnt[B-1]++;
      } else {
        cnt[A-1]++;
        cnt[B-1]++;
      }
    }
    for (int x = 0; x < N; x++) {
      if (cnt[x] == 0) {
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 60180
from itertools import product, combinations
from copy import deepcopy


def main():
    H, W, K = (int(x) for x in input().split(" "))
    sqr = [list(input()) for _ in range(H)]
    # mask_sqr = deepcopy(sqr)
    cnt_black = sum([len([y for y in x if y == "#"]) for x in sqr])
    cnt_way = 0
    for h in range(H+1):
        for w in range(W+1):
            for h_cs in combinations(range(H), h):
                for w_cs in combinations(range(W), w):
                    mask_sqr = deepcopy(sqr)
                    cnt_masked = 0
                    if len(h_cs) == 0:
                        for w_c in w_cs:
                            for i in range(len(sqr)):
                                if mask_sqr[i][w_c] == "#":
                                    mask_sqr[i][w_c] = "r"
                                    cnt_masked += 1
                    elif len(w_cs) == 0:
                        for h_c in h_cs:
                            for i in range(len(sqr[h_c])):
                                if mask_sqr[h_c][i] == "#":
                                    mask_sqr[h_c][i] = "r"
                                    cnt_masked += 1

                    else:
                        for h_c in h_cs:
                            for w_c in w_cs:
                                for i in range(len(sqr[h_c])):
                                    if mask_sqr[h_c][i] == "#":
                                        mask_sqr[h_c][i] = "r"
                                        cnt_masked += 1
                                for i in range(len(sqr)):
                                    if mask_sqr[i][w_c] == "#":
                                        mask_sqr[i][w_c] = "r"
                                        cnt_masked += 1

                    if cnt_black-cnt_masked == K:
                        cnt_way += 1
    print(cnt_way)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74084
#include <stdio.h>

int main(void){

  int n,count;
  long int d;

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

  long int x,y;

  count = 0;

  for(int i=1;i<n+1;i++){

    scanf("%ld %ld",&x,&y);

    if(x*x+y*y<=d*d){

      count++;

    }

  }

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

  return 0;

}


Measured memory_bytes: 1692
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int n;
    cin >> n;
    vector<int> L(n);
    rep(i, n) cin >> L.at(i);
    sort(L.begin(), L.end());

    int longest = L.back();
    int rest = 0;
    for (size_t i = 0; i < L.size() - 1; i++) {
        rest += L.at(i);
    }

    if (longest < rest)
        cout << "Yes";
    else
        cout << "No";
}

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

using namespace std;

int main() {

	int n, k;
	cin >> n >> k;

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

	// Stores whether the play moving will win when there are x stones remaining;
	bool willWin[k+1];
	willWin[0] = false;

	for (int i = 1; i < k+1; i++) {

		willWin[i] = false;
		for (int j = 0; j < n; j++) {
			if (i - vals[j] >= 0) {
				if (willWin[i - vals[j]] == false) {
					willWin[i] = true;
					break;
				}
			}
		}

	}

	if (willWin[k]) {
		cout << "First" << endl;
	}
	else {
		cout << "Second" << endl;
	}
	

}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

int gcd(int n, int m) {
    if (n < m) swap(n,m);
    while (m > 0) {
        n %= m;
        swap(n,m);
    }
    return n;
}

void solve() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    int ans = a[0];
    REP(i,1,n) ans = gcd(ans, a[i]);
    cout << ans << endl;
}

int main() {
    solve();
    
    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  int sum = 0;
  while(n > 0)
  {
    sum += n%10;
    n /= 10;
  }
  if(sum == 1)sum = 10;
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

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

  vi a(n), b(n);
  rep(i,n){
    cin >> a.at(i);
    b.at(i) = a.at(i);
  }
  sort(a.begin(), a.end());
  
  int ans, sub;
  ans = a.at(n-1);
  sub = a.at(n-2);
  rep(i,n){
    cout << (ans==b.at(i)? sub : ans) << endl;
  }
  return 0;
}


Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
template <class T>
using Grid = vector<vector<T>>;

int main() {
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    ll area = w * h;
    int count = 0;
    if (w % 2 == 0 && x == w / 2)
        count++;
    if (h % 2 == 0 && y == h / 2)
        count++;
    if (count == 1) {
        printf("%lld %d", area / 2, 0);
        return 0;
    }
    if (count == 2){
        printf("%lld %d", area / 2, 1);
        return 0;
    }
    printf("%.12f %d\n", area / 2.0, 0);
}

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

using namespace std;
using ll = long long;


int main(){
  string S;
  cin >> S;
  
  int N = S.size();
  int cnt = 0;
  for(int i=0; i<N/2; i++){
    if(S[i]!=S[N-1-i]){
      cnt += 1;
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

vector<int> v[200005];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    for (int i = 0; i < n; ++ i) {
        int a;
        cin >> a;
        v[a].emplace_back(i);        
    }
    int pos = -1, nxt = 1;
    int cnt = 0;
    while (true) {
        auto it = lower_bound(v[nxt].begin(), v[nxt].end(), pos);
        if (it == v[nxt].end()) break;
        pos = *it;
        nxt ++;
        cnt ++;
    }
    if (cnt == 0) cout << -1;
    else cout << n - cnt;
}

Measured memory_bytes: 11264
#include<iostream>
#include<set>
#include<string>
using namespace std;
int main() {
	set<long long>a;
	long long b, c,sum = 1;
	for (int i = 0; i <= 19; i++) {
		b = sum;
		for (int j = 0; j <= 12; j++) {
			c = sum;
			if (sum > 1000000)
				break;
			for (int z = 0; z <= 8; z++) {
				a.insert(sum);
				if (sum > 1000000)
					break;
				sum *= 5;
			}
			sum = c;
			sum *= 3;
		}
		sum = b;
		sum *= 2;
	}
	int m, n,o=0;
	string d, h = "";
	while (getline(cin, d)) {
		o = 0;
		if (d.length() == 1) break;
		d += " ";
		h = "";
		for (int i = 0; i < d.length(); i++) {
			if (d[i] == ' ') {
				if (o == 0){ m = atoi(h.c_str());}
				else {n = atoi(h.c_str());}
				o++;
				h = "";
			}
			else
				h += d[i];
		}
		set<long long>::iterator it = a.begin();
		int sum = 0;
		while ((*it) < m) {
			it++;
			if (it == a.end()){ break;}
		}
		while ((*it) >= m && (*it) <= n)
		{
			it++;
			sum++;
			if (it == a.end()) {break;}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3164
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;
import java.text.DecimalFormat;

class Main {
    public static void main (String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder("");

        int a, b, c, d, e, f;
        double denominator;
        double x, y;

        DecimalFormat df = new DecimalFormat("##0.000");

        while (sc.hasNextInt()) {
            a = sc.nextInt();
            b = sc.nextInt();
            c = sc.nextInt();
            d = sc.nextInt();
            e = sc.nextInt();
            f = sc.nextInt();

            denominator = b * d - a * e;

            x = (b * f - c * e) / denominator + 0.0;
            y = (c * d - a * f) / denominator + 0.0;

            sb.append(df.format(x)).append(' ').append(df.format(y)).append('\n');
        }
        System.out.print(sb);

    }
}

Measured memory_bytes: 26404
local mfl = math.floor
local TranFFT = {}

TranFFT.initialize = function(self)
  self.size = 20
  self.n = 1048576
  self.mod = 998244353
  self.w = 646
  self.ninv = 998243401
  self.winv = 208611436
  self.p2 = {1}
  for i = 2, self.size do
    self.p2[i] = self.p2[i - 1] * 2
  end
  self.binv = {}
  for i = 1, self.n do
    local y, z = 0, i - 1
    for j = 1, self.size do
      y = y + (z % 2) * self.p2[self.size + 1 - j]
      z = mfl(z / 2)
    end
    self.binv[i] = y + 1
  end
  self.wmul = {1}
  for i = 2, self.n do
    self.wmul[i] = self:mul(self.wmul[i - 1], self.w)
  end
  self.winvmul = {1}
  for i = 2, self.n do
    self.winvmul[i] = self:mul(self.winvmul[i - 1], self.winv)
  end
end

TranFFT.mul = function(self, x, y)
  local x0, y0 = x % 31596, y % 31596
  local x1, y1 = mfl(x / 31596), mfl(y / 31596)
  return (x1 * y1 * 62863 + (x1 * y0 + x0 * y1) * 31596 + x0 * y0) % self.mod
end

TranFFT.add = function(self, x, y) return (x + y) % self.mod end

TranFFT.fft_common = function(self, ary, wmul)
  local ret = {}
  for i = 1, self.n do
    ret[i] = ary[self.binv[i]]
  end
  for i = 1, self.size do
    local step_size = self.p2[i]
    local step_count = self.p2[self.size + 1 - i]
    for istep = 1, step_count do
      local ofst = (istep - 1) * step_size * 2
      for j = 1, step_size do
        local a1, a2 = ret[ofst + j], ret[ofst + step_size + j]
        ret[ofst + j] = self:add(a1, self:mul(a2, wmul[1 + (j - 1) * step_count]))
        ret[ofst + step_size + j] = self:add(a1, self:mul(a2, wmul[1 + (j + step_size - 1) * step_count]))
      end
    end
  end
  return ret
end

TranFFT.fft = function(self, ary)
  return self:fft_common(ary, self.wmul)
end
TranFFT.ifft = function(self, ary)
  local ret = self:fft_common(ary, self.winvmul)
  for i = 1, self.n do
    ret[i] = self:mul(ret[i], self.ninv)
  end
  return ret
end

-- sample (ATC001-C)
TranFFT:initialize()
local a, b = {}, {}
local n, m = io.read("*n", "*n")
for i = 1, TranFFT.n do
  a[i] = 0
  b[i] = 0
end
for i = 1, n do
  a[i] = io.read("*n")
end
for i = 1, m do
  b[i] = io.read("*n")
end

local at = TranFFT:fft(a)
local bt = TranFFT:fft(b)
for i = 1, TranFFT.n do
  at[i] = TranFFT:mul(at[i], bt[i])
end
local c = TranFFT:ifft(at)
for i = 1, n + m - 1 do
  io.write(c[i])
  io.write(i == n + m - 1 and "\n" or " ")
end


Measured memory_bytes: 121652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
    int N,T;
    cin>>N>>T;
    vector<int>C(N);
    vector<int>t(N);
    int ans=0;
    rep(i,N){
        cin>>C.at(i);
        cin>>t.at(i);
        if(t.at(i)<=T){
            if(ans==0){
                ans=C.at(i);
            }
            else if(C.at(i)<ans){
                ans=C.at(i);
            }
        }
    }
    if(ans==0){
        cout<<"TLE"<<endl;
    }
    else{
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3600