akhauriyash/Code-Regression huggingface dataset:
N=int(input())
S=input()

level=[0]
for c in S:
	if c=='(':
		level.append(level[-1] + 1)
	else:
		level.append(level[-1] - 1)
numL = min(level)*(-1)
numR = numL + level[-1]
S    = "(" * numL + S + ")" * numR

#print(level)
#print(numL)
#print(numR)
print(S)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
   string s;
   cin>>s;
   set<int>st;
   for(int i=0;i<s.length();i++){
    st.insert(s[i]);
   }
   if(st.size()==s.length())
    cout<<"yes"<<endl;
   else
    cout<<"no"<<endl;

    return 0;
}


Measured memory_bytes: 3652
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{

	public static void main(String args[]){
		FastReader sc = new FastReader();
		StringBuilder sb=new StringBuilder();
		int t,i,n;
		t=1;
		while(t-->0){
			int ind=0;
			int a[]=new int[5];
			for(i=0;i<5;i++){
				a[i]=sc.nextInt();
				if(a[i]==0){
					ind=i+1;
				}
			}
			sb.append(ind).append('\n');
		}
		sb.deleteCharAt(sb.length()-1);
		out.println(sb);
	}

	static PrintWriter out;
	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br=new BufferedReader(new InputStreamReader(System.in));
			out=new PrintWriter(System.out,true);
		}
		String next(){
			while(st==null || !st.hasMoreElements()){
				try{
					st= new StringTokenizer(br.readLine());
				}
				catch (IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		String nextLine(){
			String str = "";
			try{
				str=br.readLine();
			}
			catch(IOException e){
				e.printStackTrace();
			}
			return str;
		}
	}

	public static boolean isPrime(int n) {
		if(n<2) return false;
		for(int i=2;i<=(int)Math.sqrt(n);i++) {
			if(n%i==0) return false;
		}
		return true;
	}

	public static void print(int a[],int l,int r){
		int i;
		for(i=l;i<=r;i++)
			out.print(a[i]+" ");
		out.println();
	}

	public static long fastexpo(long x, long y, long p){
		long res=1;
		while(y > 0){
			if((y & 1)==1)
				res= ((res%p)*(x%p))%p;
			y= y >> 1;			
			x = ((x%p)*(x%p))%p;
		}
		return res;
	}

	public static boolean[] sieve (int n) {
		boolean primes[]=new boolean[n+1];
		Arrays.fill(primes,true);
		primes[0]=primes[1]=false;
		for(int i=2;i*i<=n;i++){
			if(primes[i]){
				for(int j=i*i;j<=n;j+=i)
					primes[j]=false;
			}
		}
		return primes;
	}

	public static long gcd(long a,long b){
        return (BigInteger.valueOf(a).gcd(BigInteger.valueOf(b))).longValue();
    }

    public static void merge(long a[],int l,int m,int r){
        int n1,n2,i,j,k;
        n1=m-l+1;
        n2=r-m;

        long L[]=new long[n1];
        long R[]=new long[n2];

        for(i=0;i<n1;i++)
            L[i]=a[l+i];
        for(j=0;j<n2;j++)
            R[j]=a[m+1+j];

        i=0;j=0;

        k=l;
        while(i<n1&&j<n2){
            if(L[i]<=R[j]){
                a[k]=L[i];
                i++;
            }
            else{
                a[k]=R[j];
                j++;
            }
            k++;
        }

        while(i<n1){
            a[k]=L[i];
            i++;
            k++;
        }
        while(j<n2){
            a[k]=R[j];
            j++;
            k++;
        }
    }
    public static void sort(long a[],int l,int r){
        int m;
        if(l<r){
            m=(l+r)/2;
            sort(a,l,m);
            sort(a,m+1,r);
            merge(a,l,m,r);
        }
    }
}



Measured memory_bytes: 32808
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int MAX = 1000005;
const int mod = 1000000007;
/* global variables */
vector<int> cnt(MAX, 0);
vector<int> a;
int N;
/* function */
int gcd(int a, int b) {
    return (a % b) ? gcd(b, a % b) : b;
}
bool isPc1() {
    for (int i = 0; i < N; i++) {
        cnt[a[i]]++;
    }
    vector<bool> isPrime(MAX, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i < MAX; i++) {
        int num = cnt[i];
        if (isPrime[i]) {
            for (int j = i + i; j < MAX; j += i) {
                isPrime[j] = false;
                num += cnt[j];
            }
        }
        if (num >= 2) return false;
    }
    return true;
}
bool isSc() {
    int ret = 0;
    for (int i = 0; i < N; i++) { ret = gcd(ret, a[i]); }
    if (ret == 1) return true;
    else return false;
}
/* main */
int main(){
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    if (isPc1()) { cout << "pairwise coprime" << '\n'; }
    else if (isSc()) { cout << "setwise coprime" << '\n'; }
    else { cout << "not coprime" << '\n'; }
}

Measured memory_bytes: 11140
flag = [False]*100001
c = [0]*100002
n = int(input())

for i in range(2,100000):
    if(not(flag[i])):
        for j in range(i+i,100000,i):
            flag[j] = True
for i in range(3,100000,2):
    if(not(flag[i]) and not(flag[(i+1)//2])):
        c[i]+=1
for i in range(3,100000):
    c[i]+=c[i-1]

while(n):
    n-=1
    l,r = map(int,input().split())
    print(c[r]-c[l-1])

Measured memory_bytes: 12680
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

ll N;
ll A[100010];
ll sum = 0;
ll guuki = 0;

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		ll tmp;
		cin >> tmp;
		if (tmp < 0)
		{
			tmp = -tmp; 
			guuki++;
		}

		A[i] = tmp;
	}

	//いっこにまでへらせる
	sort(A, A + N);
	int i;
	if (guuki % 2 == 0)
	{
		i = 0;
	}
	else
	{
		i = 1;
		sum -= A[0];

	}
	for (; i < N; i++)
	{
		if (A[i] < 0) A[i] = -A[i];
		sum += A[i];
	}

	cout << sum << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int max(int, int);
int mid(int, int, int);
int min(int, int);
int intcat(int, int);

int main(){
  int A, B, C;
  int a[3];
  int i, result;

  scanf("%d %d %d", &a[0], &a[1], &a[2]);

  A=max(a[0],max(a[1],a[2]));
  B=mid(a[0],a[1],a[2]);
  C=min(a[0],min(a[1],a[2]));

  result=intcat(A,B)+C;
  printf("%d\n", result);
  
  return(0);
}

int max(int x, int y){
  if(x<=y)
    return(y);
  else
    return(x);
}

int mid(int x, int y, int z){
  if(y<x)
    return(x<=z?x:z<y?y:z);
  else
    return(y<=z?y:z<x?x:z);
}

int min(int x, int y){
  if(x<y)
    return(x);
  else
    return(y);
}

int intcat(int a, int b){
  int connect;
  char buf[256];

  sprintf(buf, "%d%d", a, b);
  sscanf(buf, "%d", &connect);
  return(connect);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  ll n;
  cin >> n;
  for(ll a = -150; a < 151; a++)for(ll b = -150; b < 151; b++){
    if(pow(a,5) - pow(b,5) == n){
      cout << a << " " << b;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

int main(){FIN;

    int d1,m1,d2,m2;
    cin>>d1>>m1>>d2>>m2;
    if(d1!=d2){
        cout<<1;
    }else{
        cout<<0;
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define MAX 128
#define fst first
#define sec second
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
#define int long long
const double PI = 3.141593;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double EPS = 1e-9;
template <class T>
bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }     //最小公倍数
ll combination(ll n, ll r){if (r * 2 > n)r = n - r;ll dividend = 1;ll divisor = 1;for (ll i = 1; i <= r; ++i){dividend *= (n - i + 1);divisor *= i;}return dividend / divisor;}


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

    string s;
    cin >> s;
    rep(i,s.length()){
        if(s[i]=='9'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
function count(y,x){
   var dy=[0,1,1,1];
   var dx=[1,-1,0,1];
   var max=0;
   for(var i=0;i<4;i++){
      var cnt=0;
      for(var j=0;j<=n;j++){
         var yy=y+(dy[i]*j);
         var xx=x+(dx[i]*j);
         if(yy<0 || xx<0 || yy>=n || xx>=n)break;
         if(yx[yy][xx]!=1)break;
         cnt++;
      }
      max=Math.max(max,cnt);
      cnt=0;
   }
   return max;
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var yx=[];
   for(var i=0;i<n;i++){
      yx[i]=(Arr.shift()).split("").map(Number);
   }
   var max=0;
   for(var i=0;i<n;i++){
      for(var j=0;j<n;j++){
         if(yx[i][j]==1)max=Math.max(max,count(i,j));
      }
   }
   console.log(max);
}

Measured memory_bytes: 18428
import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    m = 1
    pre = s
    st = {s}
    while True:
        m += 1
        if pre%2==0:
            tmp = pre/2
        else:
            tmp = 3*pre+1
        if tmp in st:
            print(m)
            return
        pre = tmp
        st.add(tmp)
    return

if __name__=='__main__':
    s = I()
    solve()

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

#define int long long
#define double long double

using namespace std;

#define REP(i, a, b) for (int(i) = (a); i < (b); (i)++)
#define rep(i, n) REP(i, 0, n)
#define PER(i, a, b) for (int(i) = (a - 1); i >= (b); (i)--)
#define per(i, n) PER(i, n, 0)
#define each(i, n) for (auto &i : n)
#define clr(a) memset((a), 0, sizeof(a))
#define mclr(a) memset((a), -1, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define dum(val) cerr << #val " = " << val;
#define dump(val) cerr << #val " = " << val << endl;
#define FILL(a, v) fill(a, a + sizeof(a) / sizeof(*a), v)

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const int dx[8] = {+1, +0, -1, +0, +1, +1, -1, -1};
const int dy[8] = {+0, -1, +0, +1, -1, +1, -1, +1};
const int mod = 1e9 + 7;
const int INF = 1e9;

template <typename T>
class CircleVector
    : private std::vector<T, std::allocator<T>> {
   public:
	using std::vector<T>::vector;
	T &operator[](int i) {
		int sz = this->size();
		i = (i % sz + sz) % sz;
		return vector<T, std::allocator<T>>::operator[](i);
	}
};

signed main() {
	int n, m;
	cin >> n >> m;

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

	int s = a[0];

	CircleVector<vector<P>> t(m);

	auto dist = [&](int s, int t) {
		if (s <= t)
			return t - s;
		else
			return m - s + t;
	};

	REP(i, 1, n) {
		if (dist(a[i - 1], a[i]) >= 2) {
			t[a[i - 1] + 2].push_back(P(i, -1));
			t[a[i] + 1].push_back(P(i, dist(a[i - 1], a[i]) - 1));
		}
	}

	vector<int> v(m, 0);
	vector<int> mp(n, 0);
	int ad = 0;
	int sz = 0;
	rep(i, m * 3) {
		int j = i % m;
		each(k, t[j]) {
			if (mp[k.first] == 0 && k.second == -1) {
				sz++;
				mp[k.first] = 1;
			} else if (mp[k.first] == 1 && k.second != -1) {
				sz--;
				ad -= k.second;
				mp[k.first] = -1;
			}
		}
		ad += sz;
		v[j] += ad;
	}

	int best = -1;
	int ma = 0;
	rep(i, m) {
		if (ma < v[i]) {
			ma = v[i];
			best = i;
		}
	}

	int ans = 0;
	REP(i, 1, n) {
		//s -> a[i]
		ans += min(dist(a[i - 1], a[i]), dist(best, a[i]) + 1);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 10368
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    ResultCount count = new ResultCount();
    for (int i = 0; i < m; i++) {
      int p = Integer.parseInt(sc.next());
      Result s = Result.ofString(sc.next());
      count.add(p, s);
    }
    pw.print(count.acCount());
    pw.print(" ");
    pw.println(count.waCount());
  }

  static class ResultCount {

    Map<Integer, Result> resultMap = new HashMap<>();
    Map<Integer, AtomicInteger> waCount = new HashMap<>();

    void add(int p, Result result) {
      if (isAC(p)) {
        return;
      }
      if (result == Result.AC) {
        resultMap.put(p, result);
        return;
      }
      waCount.computeIfAbsent(p, i -> new AtomicInteger(0)).incrementAndGet();
    }

    boolean isAC(int p) {
      return resultMap.get(p) == Result.AC;
    }

    int acCount() {
      return (int) resultMap.values().stream().filter(r -> r == Result.AC).count();
    }

    int waCount() {
      return waCount.entrySet()
        .stream()
        .filter(e -> isAC(e.getKey()))
        .map(Entry::getValue)
        .mapToInt(AtomicInteger::get)
        .sum();
    }
  }

  enum Result {
    AC() {
      @Override
      Result add(Result a) {
        return AC;
      }
    },
    WA() {
      @Override
      Result add(Result a) {
        if (a == AC) {
          return AC;
        }
        return WA;
      }
    };

    static Result ofString(String s) {
      if (s.equals("AC")) {
        return AC;
      }
      return WA;
    }

    abstract Result add(Result a);
  }
}


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

const int MAXW = 1000;
const int MAXN = 1000;
int DPV[MAXN + 4][MAXW + 4];
int DPW[MAXN + 4][MAXW + 4];
int W[MAXN + 4], V[MAXN + 4];

void init() {
  for (int i = 0; i < MAXN + 4; i++)
    W[i] = V[i] = 0;

  for (int i = 0; i < MAXN + 4; i++)
    for (int j = 0; j < MAXN + 4; j++)
      DPV[i][j] = DPW[i][j] = 0;
}

void solveV(int n, int w) {
  for (int i = n; i > 0; i--) {
    for (int j = 0; j <= w; j++) {
      if (j < W[i]) {
        DPV[i][j] = DPV[i + 1][j];
        DPW[i][j] = DPW[i + 1][j];
      } else {
        if (DPV[i + 1][j] > DPV[i + 1][j - W[i]]  + V[i]) {
          DPV[i][j] = DPV[i + 1][j];
          DPW[i][j] = DPW[i + 1][j];
        } else if (DPV[i + 1][j] == DPV[i + 1][j - W[i]] + V[i]) {
          DPV[i][j] = DPV[i + 1][j];
          DPW[i][j] = min(DPW[i + 1][j], DPW[i + 1][j - W[i]] + W[i]);
        } else {
          DPV[i][j] = DPV[i + 1][j - W[i]] + V[i];
          DPW[i][j] = DPW[i + 1][j - W[i]] + W[i];
        }
      }
    }
  }
}

int main() {
  int w, Case = 1;
  while (cin >> w and w != 0) {
    init();

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
      scanf("%d,%d", &V[i], &W[i]);

    solveV(n, w);

    cout << "Case " << Case << ":" << endl;
    cout << DPV[1][w] << endl << DPW[1][w] << endl;

    Case++;
  }
}

Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define moca(a, s, b) a=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


//for(i=0; i<N; i++) cin >> a[i];

ll D;
ll c[26];
ll s[366][26];

ll calcScore(vector<ll> sche) {
  ll score=0;
  ll i, j, k;
  ll p[26];
  for(i=0; i<26; i++) p[i]=-1;
  
  for(ll d=0; d<sche.size(); d++) {
    score+=s[d][sche[d]];
    
    p[sche[d]]=d;
    for(i=0; i<26; i++) score-=c[i]*(d-p[i]);
    
  }
  
  return score;
}

int main(void) {
  ll i, j, k;
  
  cin >> D;
  for(i=0; i<26; i++) cin >> c[i];
  for(i=0; i<D; i++) {
    for(j=0; j<26; j++) {
      cin >> s[i][j];
    }
  }
  
  vector<set<ll>> vs(26);
  vector<ll> t(D);
  for(i=0; i<D; i++) {
    cin >> t[i];
    t[i]--;
    vs[t[i]].insert(i);
  }
  
  for(i=0; i<26; i++) {
    vs[i].insert(-1);
    vs[i].insert(D);
  }
  
  ll res=calcScore(t);
  
  ll M;
  cin >> M;
  for(i=0; i<M; i++) {
    ll d, q;
    cin >> d >> q;
    d--; q--;
    
    ll oldnum=t[d];
    ll newnum=q;
    t[d]=q;
    
    set<ll>::iterator ptr, ltr, rtr;
    
    ptr=vs[oldnum].find(d);
    ltr=--ptr; ptr++;
    rtr=++ptr; ptr--;
    res-=c[oldnum]*(d-*ltr)*(*rtr-d);
    res-=s[d][oldnum];
    vs[oldnum].erase(d);
    
    
    vs[newnum].insert(d);
    ptr=vs[newnum].find(d);
    ltr=--ptr; ptr++;
    rtr=++ptr; ptr--;
    res+=c[newnum]*(d-*ltr)*(*rtr-d);
    res+=s[d][newnum];
    
    pt(res);
  }
  
  
  
}



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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int first = 0;
  int second = 0;
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  for (int i = 0; i < N; i++){
    if (A[i] >= first){
      second = first;
      first = A[i];
    }
    else if (A[i] >= second){
      second = A[i];
    }
  }
  for (int i = 0; i < N; i++){
    if (A[i] == first){
      cout << second << endl;
    }
    else {
      cout << first << endl;
    }
  }
}


Measured memory_bytes: 2432
from collections import deque

H, W = map(int, input().split())
S = [input() for i in range(H)]
l = []
directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            l.append((i, j))

m = -1
N = len(l)
for i in range(N-1):
    for j in range(i+1, N):
        start = l[i]
        goal = l[j]
        visited = [[-1]*W for i in range(H)]
        d = deque()
        d.appendleft(start)
        visited[start[0]][start[1]] = 0
        while d:
            now = d.pop()
            for direction in directions:
                next = (now[0]+direction[0], now[1]+direction[1])
                if not (next[0] in range(H) and next[1] in range(W)):
                    continue
                if visited[next[0]][next[1]] != -1:
                    continue
                if S[next[0]][next[1]] == '.':
                    visited[next[0]][next[1]] = visited[now[0]][now[1]] + 1
                    d.appendleft(next)
                if next == goal:
                    m = max(visited[goal[0]][goal[1]], m)
                    d = deque()

print(m)

Measured memory_bytes: 51932
n=int(input())
ans=0
x=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    a,b=x[n-1-i][0],x[n-1-i][1]
    a+=ans
    if a%b!=0:
        p=(a//b+1)*b-a
        ans+=p
print(ans)


Measured memory_bytes: 27380
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
int main() {
    string s ;
    cin >> s ;
    ll n = s.length() ;
    ll sum = 0 ;
    for(ll i = 0; i < n ; i++){
        sum += s[i] - '0' ;
        sum = sum % 9 ;
    }
    //cout << sum << endl;
    if(sum % 9 == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3728
#include <stdio.h>
#include<math.h>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
	int n;
	char buf[1100];

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

	for(int i=0; i < n; i++){
		fgets(buf,1100,stdin);

		for(int k=0; buf[k] != '\n' && buf[k] != '\n'; k++){
			if(k >= 6 && buf[k] == 'o' && buf[k-1] == 'n' && buf[k-2] == 'i'&&
					buf[k-3] == 'h' && buf[k-4] == 's' && buf[k-5] == 'o' && buf[k-6] == 'H'){
				buf[k] = 'a';
			}
		}

		printf("%s",buf);
		buf[0] = '\0';
	}


    return 0;
}

Measured memory_bytes: 2588
#include <bits/stdc++.h>
using namespace std;
#define Sz(a) ((int)(a).size())
const int maxn = 2000009;
const int MOD = 1e9 + 7;
int64_t fac[maxn],invfac[maxn];
int64_t pw(int64_t a,int64_t b){
  int64_t c=1;
  while(b){
    if(b&1ll)c=c*a%MOD;
    b>>=1;
    a=a*a%MOD;
  }
  return c;
}
int64_t C(int a,int b){
  return fac[a]*invfac[b]%MOD*invfac[a-b]%MOD;
}
int main(){
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  fac[0]=1;
  for(int i=1;i<maxn;++i)fac[i]=fac[i-1]*i%MOD;
  invfac[maxn-1]=pw(fac[maxn-1],MOD-2);
  for(int i=maxn-2;i>=0;--i)invfac[i]=invfac[i+1]*(i+1)%MOD;
  int K,n;
  string s;cin>>K>>s;
  n=Sz(s);
  int64_t ans=1,deg=1;
  for(int i=0;i<K;++i){
    deg=deg*25%MOD;
    ans=(ans*26+C(n+i,n-1)*deg)%MOD;
  }
  cout<<ans<<"\n";
  
  return 0;
}
//2020.06.23 19:49:09


Measured memory_bytes: 35476
#include<cstdio>
using namespace std;
int n;
int a[20010],b[20010],p[20010];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	for (int i=1;i<=n;i++)
	{
		a[i]=i*(n+1);
		b[i]=(n-i+1)*(n+1);
	}
	for (int i=1;i<=n;i++)
			b[p[i]]-=(n-i+1);
	for (int i=1;i<=n;i++)
		printf("%d%c",a[i]," \n"[i==n]);
	for (int i=1;i<=n;i++)
		printf("%d%c",b[i]," \n"[i==n]);
	return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input_str = Console.ReadLine().Split(' ');
            long A = long.Parse(input_str[0]);
            long B = long.Parse(input_str[1]);

            if ((A + B) % 2 == 0)
            {
                Console.WriteLine(((A + B) / 2).ToString());
            }
            else
            {
                Console.WriteLine("IMPOSSIBLE");
            }
//            Console.Read();
        }
    }
}

Measured memory_bytes: 11220
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int n,cpy,cnt,max,x,i;
	cin>>n;
	max=-1;
	for(i=n;i>=0;i--){
		cnt=0; cpy=i;
		if(max<cpy){
			while(1){
				if(cpy%2==0){
					cpy=cpy/2;
					cnt++;
				}
				else break;
			}
			if(max<cnt){
				max=cnt;
				x=i;
			}
		}
	}
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    n,a,b = map(int,input().split())
    MOD = 10**9 +7
    s = pow(2,n,MOD)-1
    P_ni = 1
    F_i = 1

    s = s - comb_mod(n,a,MOD)
    s = s - comb_mod(n,b,MOD)

    print(s%MOD)

def comb_mod(n, k, mod):
    numerator = 1
    denominator = 1
    for i in range(k):
        numerator = (numerator * (n - i)) % mod
        denominator = (denominator * (i + 1)) % mod

    return (numerator * pow(denominator, mod - 2, mod)) % mod


if __name__=='__main__':
    main()


Measured memory_bytes: 3064
#include<stdio.h>
#define INF 10000000
void warshall_floyd(void);
int min(int,int);
long long graph[101][101];
int n,c,d;

int main(void){
  int k,i,j,x,e,a,b;

  while(1){

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

    for(i=0;i<=n;i++)
      for(j=0;j<=n;j++)
	graph[i][j] = (i==j?0:INF);

    if(n==0 && k==0)break;
    
    for(i=0;i<k;i++){
      scanf("%d",&x);
      
      if(x){

	scanf("%d %d %d",&c,&d,&e);
	if(graph[c][d]>e){
	graph[c][d]=graph[d][c]=e;
	warshall_floyd();
	}
      }
      else{
	scanf("%d %d",&a,&b);
	if(graph[a][b]<INF)printf("%d\n",graph[a][b]);
	else printf("-1\n");
      }

    }

  }
  
  return 0;
}

void warshall_floyd(void){
  int i,j;

    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
	graph[i][j]=graph[j][i]=min(graph[i][j],graph[i][c]+graph[c][d]+graph[d][j]);
	//graph[i][j]=graph[j][i]=min(graph[i][j],graph[i][d]+graph[d][c]+graph[c][j]);
      }
    }
}

int min(int x,int y){
  return (x<y)?x:y;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
using namespace std;
#define inf 1<<29
#define nu 1000005
#define maxnum 100005
#define num 30
int n;
struct Md
{
    int v,u,flag;

}M[maxnum],C[maxnum];
struct Node
{
    int x,y,z;

}dis[nu];
bool cmp(Md a,Md b){
   return a.v<b.v;
}
bool cmp0(Md a,Md b){
   return a.u<b.u;
}
bool cmp1(Node a,Node b){
   return a.z<b.z;
}
int book[maxnum];
void init()
{
    for(int i=1;i<=n;i++)
        book[i]=i;

}
int getx(int x)
{
    if(book[x]!=x)
        book[x]=getx(book[x]);
    return book[x];
}
void mergexy(int x,int y)
{
     book[y]=x;
}
void change(){
    for(int i=1;i<=n;i++)
        {
            C[i].v=M[i].v;
            C[i].u=M[i].u;
            C[i].flag=M[i].flag;
        }
}
int main()
{
    scanf("%d",&n);

    for(int i=1;i<=n;i++){
         scanf("%d%d",&M[i].v,&M[i].u);
         M[i].flag=i;
    }
  /*  int t=unique(M+1,M+n)-M;

      n=t;*/
      change();
      int fl=0;
      sort(C+1,C+n+1,cmp);
      for(int i=1;i<n;i++)
      {
          dis[++fl].x=C[i].flag,dis[fl].y=C[i+1].flag,dis[fl].z=(min(fabs(C[i].v-C[i+1].v),fabs(C[i].u-C[i+1].u)));
      }
      change();
      sort(C+1,C+n+1,cmp0);
      for(int i=1;i<n;i++)
      {
          dis[++fl].x=C[i].flag,dis[fl].y=C[i+1].flag,dis[fl].z=(min(fabs(C[i].v-C[i+1].v),fabs(C[i].u-C[i+1].u)));
      }
    sort(dis+1,dis+fl+1,cmp1);
   /*  cout<<flag<<endl;
    for(int i=1;i<=flag;i++)
        cout<<dis[i].z<<endl;*/
        init();
         int number=0;
        int sum=0;
       for(int i=1;i<=fl;i++)
        {
            int p=getx(dis[i].x),q=getx(dis[i].y);
            if(p!=q){
                mergexy(p,q);
                number++;
                sum+=dis[i].z;
        }
        if(number==n)  break;
    }
   cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 8576
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
import collections
import itertools
import operator

class UnionFind:
  def __init__(self, elems=None):
    class KeyDict(dict):
      def __missing__(self, key):
        self[key] = key
        return key

    self.parent = KeyDict()
    self.rank = collections.defaultdict(int)
    self.size_ = collections.defaultdict(lambda: 1)

    if elems is not None:
      for elem in elems:
        _, _, _ = self.parent[elem], self.rank[elem], self.size_[elem]

  def find(self, x):
    if self.parent[x] == x:
      return x
    else:
      self.parent[x] = self.find(self.parent[x])
      return self.parent[x]

  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.rank[x] < self.rank[y]:
      self.parent[x] = y
      self.size_[y] += self.size_[x]
    else:
      self.parent[y] = x
      self.size_[x] += self.size_[y]
    if self.rank[x] == self.rank[y]:
      self.rank[x] += 1

  def are_same(self, x, y):
    return self.find(x) == self.find(y)

  def grouper(self):
    roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
    root = operator.itemgetter(1)
    for _, group in itertools.groupby(sorted(roots, key=root), root):
      yield [x for x, _ in group]

  def size(self,x):
    return self.size_[self.find(x)]

g = UnionFind()
n,m = na()

for i in range(m):
    x,y,z = na()
    g.unite(x,y)

f = list(g.grouper())

a = 0
b = 0
for i in f:
    a+=len(i)
    b+=1

print(b+n-a)

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

int main(){
    long long n,a[105],m=0;
    cin>>n;
    for(int i=0; i<n; i++)cin>>a[i];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(j==i)continue;
            m = max(m, abs(a[i]-a[j]));
        }
    }
    cout<<m<<endl;


return 0;
}


Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, k;
vector<ll> a;
ll score(int l,int r){
    priority_queue<ll,vector<ll>,greater<ll>> que;
    ll count=0,res=0;
    for(int i=0;i<l;i++){
        que.push(a[i]);
        res+=a[i];
        count++;
    }
    for(int j=n-1;j>=r;j--){
        que.push(a[j]);
        res+=a[j];
        count++;
    }
    ll count1=count;
    if(que.empty())return 0;
    for(int i=0;i<k-count1;i++){
        if(que.empty())break;
        if(que.top()>=0)break;
        count++;
        res-=que.top();
        que.pop();
    }
    if(count>k)return 0;
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>k;
    rep(i,n){
        ll temp;
        cin>>temp;
        a.push_back(temp);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        for(int j=n;j>=i;j--){
            chmax(ans,score(i,j));
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

using namespace std;

int main()
{
	int n; cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) { cin >> d[i]; }
	sort(d.begin(), d.end());
	
	cout << d[n/2] - d[n/2-1] << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;

int main(){
long N;
cin >> N;
vector<long> h(N+1);
erep(i, N) cin >> h[i];
long maxh = h[1];
long cnt = 0;
erep(i, N){
    if(h[i] >= maxh){
        cnt++;
        maxh = h[i];
    } 
// show(maxh);
}
show(cnt);

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define rp(i,n) for(long long i=0;i<n;i++)

using namespace std;
using ll = long long;

int main(void)
{
    double a,L;
    cin>>L;
    a=(L/3)*(L/3)*(L/3);
    printf("%.6lf\n",a);
    

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))

d = [0] * (m - 1)
for i in range( m - 1):
    d[i] = x[i + 1] - x[i]
d_s = sorted(d, reverse=True)

ans = d_s[n-1:]
print(sum(ans))

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

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

int main() {
  long long S,K;
  cin>>K;
  S=0;
  rep(i,K){
    rep(j,K){
      rep(l,K){
        int z;
        z=gcd(i+1,j+1);
        S+=gcd(z,l+1);
      }
    }
  }
  cout<<S<<endl;
}


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

using namespace std;

using LL = long long;

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

    int n, k, s;

    cin >> n >> k >> s;

    for (int i = 0; i < k; i++) {
        cout << s << ' ';
    }

    const int mx = 1e9;

    for (int i = 0; i < n - k; i++) {
        if (s == mx) {
            cout << 1 << ' ';
        }
        else cout << s + 1 << ' '; 
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 1280
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1000][1000];
vector<ll> va,vb,vc;

void wi107(ll &nq){
    nq=nq%1000000007;
}


int main(){
    cin>>n;
    a=1;
    for(int i=1;i<=n;i++){
        a*=i;
        wi107(a);
    }
    C a E;
}

Measured memory_bytes: 256
from bisect import bisect_left

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

# https://docs.python.org/ja/3/library/bisect.html
def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return 1
    return 0

n = ii()
s = li()

q = ii()
t = li()

cnt = 0

for i in t:
    cnt += index(s,i)

print(cnt)



Measured memory_bytes: 16744
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <vector>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e8, cnt;


int main(){
	ll a[5];
	for(ll i=0; i<5; i++) cin>>a[i];
	for(ll i=0; i<5; i++){
		if(a[i]==0) cout<<i+1;
	} 
}


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

int main(void){
    double a,b,x,cache;
    cin >> a >> b >> x;
    if (a*a*b/2>x){
        cache = atan(x*2/a/b/b);
        printf("%.10f",90-cache*180/3.14159265359);
    }
    else{
        x = a*a*b-x;
        cache = atan(x*2/a/a/a);
        printf("%.10f",cache*180/3.14159265359);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(b < a && c < a) cout << "A" << endl;
  if(a < b && c < b) cout << "B" << endl;
  if(b < c && a < c) cout << "C" << endl;
  return 0;
}


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

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

    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n-1;i++)
    {
        if(a[i]==a[i+1])
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <complex>
#include <cstdio>
using namespace std;
typedef complex<double> P;
#define X real()
#define Y imag()
#define EPS (1e-10)

double dot(P a, P b){
  return a.X * b.X + a.Y * b.Y;
}
double cross(P a, P b){
  return a.X * b.Y - a.Y * b.X;
}
  
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if( cross(b,c) > EPS ) return +1;
  if( cross(b,c) < -EPS ) return -1;
  if( dot(b,c) < 0 ) return +2;
  if( abs(b-a) + EPS < abs(c-a) ) return -2;
  return 0;
}

int main(){
  P p1, p2;
  double x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  p1 = P(x1,y1);
  p2 = P(x2,y2);
  int q;
  cin >> q;
  for(int i = 0; i < q; ++i){
    P p;
    cin >> x1 >> y1;
    p = P(x1,y1);
    int t = ccw(p1,p2,p);
    if (t == 1) cout << "COUNTER_CLOCKWISE" << endl;
    else if (t == -1) cout << "CLOCKWISE" << endl;
    else if (t == 2) cout << "ONLINE_BACK" << endl;
    else if (t == -2) cout << "ONLINE_FRONT" << endl;
    else cout << "ON_SEGMENT" << endl;
  }
  return 0;
}

Measured memory_bytes: 3260
import sys
readline = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    As = list(map(int, input().split()))

    edges = (map(int, readline().strip().split()) for _ in range(N-1))

    tree = [[] for _ in range(N)]
    for u, v in edges:
        tree[u-1].append(v-1)
        tree[v-1].append(u-1)

    inf = 10 ** 18
    dp = [inf] * (N+1)
    ans = [0] * N

    def dfs(node, parent):
        v = As[node]
        lb = binary_search(dp, v)
        old = dp[lb]
        dp[lb] = v
        ans[node] = binary_search(dp, inf)
        for child in tree[node]:
            if child == parent:
                continue
            dfs(child, node)
        dp[lb] = old

    dfs(0, 0)

    for k in range(N):
        print(ans[k])


def binary_search(seq, v):
    left = 0
    right = len(seq) - 1
    center = right // 2

    while left != right:
        if v <= seq[center]:
            right = center
        else:
            left = center+1
        center = (right + left) // 2

    return center


if __name__ == "__main__":
    main()


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  multiset<int> s(all(a));
  for (int i = 0; i < n; i++) {
    s.erase(s.find(a[i]));
    cout << *prev(s.end()) << '\n';
    s.insert(a[i]);
  }
}


Measured memory_bytes: 14272
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline void reverse(Type& arr) { reverse(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1e9 + 7;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    string N;
    cin >> N;
    ll total = 0;
    for (char ch :N)
    {
        total += (ch - '0');
    }
    yes(total % 3 == 0);
    return 0;
}

Measured memory_bytes: 3364
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define INF 200000000

using namespace std;

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

struct OwnVector2
{
	double x, y;
	OwnVector2(double x, double y) :x(x), y(y) {}
	OwnVector2() :OwnVector2(0, 0) {}
	OwnVector2 operator+(const OwnVector2& v)const
	{
		return OwnVector2(x + v.x, y + v.y);
	}
	OwnVector2 operator-(const OwnVector2& v)const
	{
		return OwnVector2(x - v.x, y - v.y);
	}
	OwnVector2 operator*(const double v)const
	{
		return OwnVector2(x*v, y*v);
	}
	bool operator==(const OwnVector2& v)const
	{
		return abs(x - v.x) <= 0.0000000000001&&abs(y - v.y) <= 0.00000000000001;
	}
	bool operator!=(const OwnVector2& v)const
	{
		return abs(x - v.x) > 0.0000000000001 || abs(y - v.y) > 0.00000000000001;
	}

	double dot(const OwnVector2& v)const
	{
		return x*v.x + y*v.y;
	}
	double cross(const OwnVector2& v)const
	{
		return x*v.y - y*v.x;
	}
	double length()const
	{
		return sqrt(x*x + y*y);
	}
	double length2()const
	{
		return x*x + y*y;
	}
};

OwnVector2 vertices[100];

int JudgeType(OwnVector2 p, int n)
{
	int count = 0;
	OwnVector2 p0 = vertices[0];
	bool bFlag0x = (p.x <= p0.x);
	bool bFlag0y = (p.y <= p0.y);

	if ((p0 - p).length2() <= 0.000000000001)
	{
		return 1;
	}

	for (int i = 1; i < n + 1; i++)
	{
		OwnVector2 p1 = vertices[(i) % n];
		if ((p1 - p).length2() <= 0.00000000001 || (abs((p0 - p).cross(p1 - p)) <= 0.00000000000001 && (p0 - p).dot(p1 - p) <= 0.0))
		{
			return 1;
		}
		bool bFlag1x = (p.x <= p1.x);
		bool bFlag1y = (p.y <= p1.y);
		if (bFlag0y != bFlag1y)
		{
			if (bFlag0x == bFlag1x)
			{
				if (bFlag0x)
				{
					count++;
				}
			}
			else
			{
				if (p.x <= (p0.x + (p1.x - p0.x)*(p.y - p0.y) / (p1.y - p0.y)))
				{
					count++;
				}
			}
		}
		p0 = p1;
		bFlag0x = bFlag1x;
		bFlag0y = bFlag1y;
	}

	return count % 2 == 0 ? 0 : 2;
}

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

	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		double x, y;
		cin >> x >> y;
		vertices[i] = OwnVector2(x, y);
	}

	int q;
	cin >> q;

	for (int i = 0; i < q; i++)
	{
		double px, py;
		cin >> px >> py;
		OwnVector2 p(px, py);

		printf("%d\n", JudgeType(p,n));
	}
	
	return 0;
}


Measured memory_bytes: 3300
def gcd(a, b):
    while a > 0:
        a, b = b, a
        a = a % b
    return b

n, x = map(int, input().split())
town = list(map(int, input().split()))

res = abs(town[0] - x)
for t in town[1:]:
    d = abs(t - x)
    res = gcd(res, d)

print(res)

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

string S[2];

int main()
{
    int N;
    cin >> N;
    REP(i, 2)
    {
        cin >> S[i];
    }

    ll a = 3;
    bool c = true; //! 前回が縦
    if (S[0][0] != S[1][0])
    {
        a = 6;
        c = false;
    }
    FOR(i, N, 1)
    {
        if (S[0][i] == S[0][i - 1])
            continue;

        if (S[0][i] == S[1][i])
        {
            //! 縦
            if (c)
                a *= 2;
            c = true;
        }
        else
        {
            if (c)
                a *= 2;
            else
                a *= 3;
            c = false;
        }
        a %= MOD;
    }
    cout << a << endl;
    return 0;
}

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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define fWrite          freopen ("out.txt","w",stdout);
#define TC              int t;cin >> t;FOR(tc,1,t)
#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define all(a)          a.begin(),a.end()
#define MEM(a,x)        memset(a,x,sizeof(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

#define Make(x,p)       (x  (1<<p))
#define DeMake(x,p)     (x & ~(1<<p))
#define Check(x,p)      (x & (1<<p))
#define popcount(x)     __builtin_popcount(x)

int main()
{
    string a,b;
    cin >> a >> b;
    int n=a.size(),m=b.size();
    int dp[n+1][m+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i==0 or j==0) dp[i][j]=0;
            else if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string str;
    int i=n,j=m;
    while(i>0 and j>0){
        if(a[i-1]==b[j-1]) {
            str+=a[i-1];
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1]) i--;
        else j--;
    }
    reverse(all(str));
    cout << str;
}


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

int main(void){
  vector<int> x(5);
  rep(i,5) cin >> x[i];

  for(int i=0;i<5;i++){
    if(x[i]==0){
      cout << i+1 << endl;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
using ll = long long;

int main() {
  bool flag{false};
  int K, A, B;
  std::cin >> K >> A >> B;
  for (int i = A; i <= B; i++) {
    if (i % K == 0) flag = true;
  }
  std::cout << (flag ? "OK" : "NG") << std::endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a = N%10;
  int b = (N/10)%10;
  int c = (N/100)%10;
  int d = (N/1000)%10;
  if ((b==c)&&(c==d)) cout << "Yes" << endl;
  else if ((a==b)&&(b==c)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n, r;
    cin >> n >> r;

    if(n >= 10){
        cout << r << endl;
    }else{
        cout << r + 100 * (10 - n) << endl;
    }

    return 0;
}


Measured memory_bytes: 256