akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

signed main() {
	int n;
	cin >> n;
	vec<int> t(n);
	rep (i, n) {
		cin >> t[i];
	}

	int ans = 1e18;
	int sum = 0;
	int all = accumulate(all(t), 0ll);
	rep (i, n) {
		sum += t[i];
		all -= t[i];
		int t = abs(sum - all);
		chmin(ans, t);
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int a[3]; REP(i,3) cin>>a[i];
  sort(a,a+3);
  cout << a[0]+a[1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    long long int n,x,i,j,b[51]={0},p[51]={0},ans=0,num[51]={0};
	int flag=0;
	
	scanf("%lld %lld",&n,&x);
	for(i=0;i<=n;i++)
	{
		if(i==0)p[i]=1;
		else
		{
			b[i]=b[i-1]*2+2;
			p[i]=p[i-1]*2+1;
		}
		num[i]=b[i]+p[i];
	}
	for(j=n;j>=0;j--)//にぶたん
	{
		if(x<=num[j]/2) x--;
		else if(x==(num[j]/2)+1)
		{
			ans+=(p[j-1]+1);
			break;
		}
		else
		{
			ans+=(p[j-1]+1);
			x-=(num[j-1]+2);
		}
	}
	
	
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
 
long long dp[103][100005];

int main() 
{
    int n, k;
    std::cin >> n >> k;
        
    std::vector<int>w;
    std::vector<int>v;

    for(int i = 0;i<n;i++){
        int weight, value;
        std::cin >> weight >> value;
        w.push_back(weight);
        v.push_back(value);
    }
        
    for(int i = 0; i <= n; i++){

        for(int j = 0; j <= k; j++){

            if(i == 0 || j == 0)
            {
                dp[i][j] = 0;
                continue;
            }
            if (w[i-1] <= j)
            {
                dp[i][j] = std::max(v[i-1] + dp[i-1][j - w[i-1]] , dp[i-1][j]);
            }
            else
            {
             dp[i][j] = dp[i-1][j];
            }
        }
    }
        
    std::cout << dp[n][k];
    return 0;
}

Measured memory_bytes: 80128
#include<stdio.h>
//???????????????????????????????????????

int main(){

int N,i,j,k,l,m,v;
int A[100];
int count = 0;//???????????°

scanf("%d\n",&N);
for(i=0;i<=N-1;i++){
  scanf("%d",&A[i]);
}
j=N-1;
while(j>0){
  for(k=N-1;k>=1;k--){
  v=A[k];
  l=k-1;
  if(v<A[l]){
    A[k]=A[l];
    A[l]=v;
    count++;
  }
  }
j--;
}
for(m=0;m<=N-1;m++){
  if(m>0){
    printf(" ");
  }
  printf("%d",A[m]);
  if(m==N-1){
    printf("\n");
  }
}
printf("%d\n",count);
return 0;
}

Measured memory_bytes: 604
#include <stdio.h>

int main(){
  int n,f=0,a;
  scanf("%d",&n);
  for(n;n>0;n--){
    scanf("%d",&a);
    if((a%2==0)&(a%3!=0)&(a%5!=0)){
      f=1;
      break;
    }
  }
  if(f){
    printf("DENIED");
  }else{
    printf("APPROVED");
  }
  return(0);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
int main(void){
   int a,b,C;
   double h,S,L,d;
   scanf("%d %d %d\n",&a,&b,&C);
   S=(a*b*sin((M_PI/180)*C))/2.0;
   d=sqrt(a*a+b*b-2*a*b*cos((M_PI/180)*C));
   L=a+b+d;
   h=2*S/a;
   printf("%f\n",S);
   printf("%f\n",L);
   printf("%f\n",h);
   return 0; 
}



Measured memory_bytes: 2100
parseInt(x::SubString{String}) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function hpush(h::Array{Tuple{Int,Int},1},x::Tuple{Int,Int})
	push!(h,x)
	if length(h) > 1
		l = length(h)
		k = div(l,2)
		while h[k][2]>x[2]&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(div(k,2),1)
			l = div(l,2)
		end
	end
end

function hpop(h::Array{Tuple{Int,Int},1})
	x = h[1]
	z = pop!(h)
	if !isempty(h)
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>=l
				break
			elseif 2*k+1>=l
				if h[2*k][2]>=z[2]
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if h[2*k][2]>=z[2]&&h[2*k+1][2]>=z[2]
					break
				else
					t = h[2*k][2]<h[2*k+1][2]?2*k:2*k+1
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end


function main()
	n,m = readline() |> split |> parseMap
	e = [Int[] for i in 1:3*n]
	for i in 1:m
		u,v = readline() |> split |> parseMap
		push!(e[u],n+v)
		push!(e[n+u],2*n+v)
		push!(e[2*n+u],v)
	end
	s,t = readline() |> split |> parseMap
	dis = -ones(Int,3*n)
	h = Array{Tuple{Int,Int},1}()
	push!(h,(s,0))
	while !isempty(h)
		v,w = hpop(h)
		if v == t
			break
		end
		for i in 1:length(e[v])
			if dis[e[v][i]]<0　|| dis[e[v][i]]>w+1
				dis[e[v][i]] = w+1
				hpush(h,(e[v][i],w+1))
			end
		end
	end
	println(dis[t]>=0?div(dis[t],3):-1)

end

main()

Measured memory_bytes: 166464
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;

int main(){
	int a,b,c;
    cin >> a >> b >> c;

    if(a==b && a==c){
        cout << "No" << endl;
    }else if(a!=b && b!=c && c!=a){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3*100000 + 10;
int n,pre[maxn],sub[maxn],ans = 9999999;
char str[maxn];
int main() {
    scanf("%d%s",&n,str+1);
    for (int i = 1;i <= n;i++) pre[i] = pre[i-1]+(str[i] == 'W');
    for (int i = n;i >= 1;i--) sub[i] = sub[i+1]+(str[i] == 'E');
    for (int i = 1;i <= n;i++) ans = min(ans,pre[i-1]+sub[i+1]);
    printf("%d",ans);
    return 0;
}

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

int main() {
	string s,t;
	int a,b;
	string u;
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	if(s == u){
		cout << a - 1 << ' ' << b << '\n';
	}else{
		cout << a << ' ' << b - 1 << '\n';
	}
	return 0;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  cout << (H * W - (H * w + h * W - h * w)) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
 
#define MAXLEN 20000
 
int garea,gareas[(MAXLEN/2)+1],gcnt;
 
 
int getArea( char *inputs, int start, int end )
{
    int i;
    int ravine,water;
    
    gareas[gcnt]=ravine=water=0;
    for( i=start; i!=end; i++ ) {
        if( '\\'== *(inputs+i) ) {
           	water+=(ravine*2);
            ravine++;
            water++;
        } else if( 0 != ravine && '/' == *(inputs+i) ) {
        	ravine--;
        } else {
	     	water+=ravine;
        }       
    }
	gareas[gcnt]+=water;
    
    return gareas[gcnt];
}
  
int checkRavine( char *inputs, int start )
{
    int i;
    int ravine;
    
    ravine=0;
    for( i=start; '\0'!=*(inputs+i); i++ ) {
        if( '\\'== *(inputs+i) ) {
            ravine++;
        } else if( 0 != ravine && '/' == *(inputs+i) ) {   
            ravine--;
            if( 0 == ravine ) {
            	garea+=getArea( inputs, start, i+1 );
            	gcnt++;
                return i-start;
            }           
        }
    }
    return 0;
}
 
 
void getAreas( char *inputs )
{
    int i,next;
     
    next=0;
    for( i=0; '\0'!=inputs[i]; i++ ) {
        next=checkRavine( inputs, i );
        i+=next;
    }
 
    return;
}
 
int main( void ) 
{
    char inputs[MAXLEN+1];
    int i;
 
    scanf( "%s", inputs );
    garea=gcnt=0;
    getAreas( inputs );
     
    printf( "%d\n", garea );
    
    if( gcnt ) {
        printf( "%d ", gcnt );
        for( i=0; i<gcnt; i++ ) {
            printf( "%d", gareas[i] );
            if( i < gcnt-1 ) {
            	printf( " " );  
            }
        }
        printf( "\n" );
       
    } else {
        printf( "0\n" );
    }
     
    return 0;
}

Measured memory_bytes: 568
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const llong MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int main() {
	string str;
	cin >> str;
	REP(i, str.size()) {
		if (str[i] != str[str.size() - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	int f = (str.size() - 1) / 2;
	REP(i, f) {
		if (str[i] != str[f -1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	int l = (str.size() + 3) / 2 - 1;
	for (int i = l; i < str.size(); ++i) {
		if (str[i] != str[str.size() - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	int ans=0;
	for(int i=a;i<=b;++i){
		if(i%c==0){
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 3812
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;
const int MAX_PRIME = 1000000;


int prime[MAX_PRIME+1];
bool isPrime[MAX_PRIME+1];
int p;

void erats(){
	// primeツδ環スツトツづーツ渉可甘コツ可サ
	fill(isPrime,isPrime+MAX_PRIME,true);
	p = 0;
	isPrime[0] = isPrime[1] = false;

	for(int i = 2; i <= MAX_PRIME; i++){
		if(isPrime[i]){
			prime[p++] = i;
		}
		else
			continue;

		// ツづ督づゥツつ「ツづ可つゥツつッツづゥ
		for(int j = 2*i; j <= MAX_PRIME; j+=i){
			isPrime[j] = false;
		}
	}
}


int main(){

	erats();
	int n;
	while(cin>>n&&n!=0){
		int cnt=0;
		for(int i = n+1; i <= 2*n; i++){
			if(isPrime[i])
				cnt++;
		}
		cout<<cnt<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
n=int(input())
memo=[{} for i in range(n+1)]

def ok(last4):
    for i in range(4):
        t=list(last4)
        if i>=1:
            t[i-1],t[i]=t[i],t[i-1]
        if ''.join(t).count('AGC')>=1:
            return False
        #t[i-1],t[i]=t[i],t[i-1]
        
    return True

mod=10**9+7

def dfs(cur,last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur==n:
        return 1
    ret=0
    for i in 'ACGT':
        if ok(last3+i):
            ret=(ret+dfs(cur+1,last3[1:]+i))%mod
    memo[cur][last3]=ret
    return ret
print(dfs(0,'TTT'))


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

int main(){
  int h,w;
  cin >>h >>w;
  string board[50];
  rep(i,h) cin >>board[i];
  const int dx[8] = {1,0,-1,0,1,-1,-1,1};
  const int dy[8] = {0,1,0,-1,1,1,-1,-1};
  rep(i,h){
    rep(j,w){
      if(board[i][j] == '#') continue;
      int num = 0;
      rep(d,8){
        const int ni = i+dy[d];
        const int nj = j+dx[d];
        if(ni<0 or h<=ni) continue;
        if(nj<0 or w<=nj) continue;
        if(board[ni][nj]=='#') num++;
      }
      board[i][j] = char(num+'0');
    }
  }
  rep(i,h) cout << board[i] << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] w = new int[n];
        for (int i = 0; i < w.length; i++) {
            w[i] = sc.nextInt();
        }
        int ans = Integer.MAX_VALUE;
        for (int i = 1; i < w.length; i++) {
            int total1 = 0;
            for (int j = 0; j < i; j++) {
                total1 += w[j];
            }
            int total2 = 0;
            for (int j = i; j < w.length; j++) {
                total2 += w[j];
            }
            int tmp = Math.abs(total2 - total1);
            if(ans > tmp)ans = tmp;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35716
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main()
{
  int N;
  cin >> N;
  
  vector<pair<int, int>> v(N);
  
  for (int i = 0; i < N; ++i)
  {
    int time, deadline;
    cin >> time >> deadline;
    v.at(i) = make_pair(time, deadline);
  }
  
  // 締切の降順に並び替え
  sort(v.begin(), v.end(), [](pair<int, int> p1, pair<int, int> p2){ return p1.second < p2.second; });
  
  int sumTime = 0;
  for (auto p : v)
  {
    sumTime += p.first;
    if (sumTime > p.second)
    {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1792
import math
import collections
import heapq
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    maxv = n*(n-1)//2
    a = [list(map(lambda x:x-1, list(map(int, input().split()))))for i in range(n)]


    # 試合を頂点とする(ex 1-2,2-4 : i < j)
    v = 0  # 頂点数
    # 頂点にIDをふる
    Id = [[-1 for i in range(n)] for j in range(n)]
    for i in range(n):
        for j in range(n):
            if i < j:
                Id[i][j] = v
                Id[j][i] = v
                v += 1

    # 頂点間の辺を貼る
    e = [[] for i in range(maxv)]
    for i in range(n):
        # a[i][j]にIDを代入する Id[1][3]=1 => a[1][3] = a[3][1] = 1
        for j in range(n - 1):
            a[i][j] = Id[i][a[i][j]]

        # 辺をはる
        for j in range(n - 2):
            e[a[i][j]].append(a[i][j+1])


    calculated = [False for i in range(maxv)]
    dp = [-1 for i in range(maxv)]
    def dfs(v):
        if dp[v] != -1:
            if not calculated[v]:
                return -1
            return dp[v]
        dp[v] = 1
        for u in e[v]:
            ret = dfs(u)
            if ret == -1:
                return -1
            dp[v] = max(dp[v], ret + 1)
        calculated[v] = True #帰りがけ
        return dp[v]
    

    #トポロジカルソート
    ans = 0
    for i in range(v):
        ret = dfs(i)
        if ret == -1:  # サイクル検知
            print(-1)
            exit()
        ans = max(ans, ret)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 157320
lower, upper = [], []
n = int(input())
for _ in range(n):
    a, b = map(int, input().split())
    lower.append(a)
    upper.append(b)
lower.sort()
upper.sort(reverse=True)
if n % 2 == 1:
    mid = n // 2
    median_min = lower[mid]
    median_max = upper[mid]
else:
    mid = n // 2 - 1
    median_min = lower[mid] + lower[mid + 1]
    median_max = upper[mid] + upper[mid + 1]
print(median_max - median_min + 1)

Measured memory_bytes: 25428
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

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

    for(int i = 0; i < n; i++){
        int a; cin >> a;
        w.push_back(a);
    }

    int min = 10001;
    for(int i = 1;i < n-1; i++){
        int s1 = 0;
        int s2 = 0;
        for(int j = i;j >= 0; j--){
            s1 += w[j];
        }
        for(int j = i+1;j < n; j++){
            s2 += w[j];
        }
        if(min > abs(s1-s2)) min = abs(s1-s2);
    }

    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a+b>c+d) printf("Left\n");
	if(a+b==c+d) printf("Balanced\n");
	if(a+b<c+d) printf("Right\n");
}

Measured memory_bytes: 128
def main
  n = gets.chomp.to_i
  a,b = gets.chomp.split(' ').map(&:to_i)
  c,d = gets.chomp.split(' ').map(&:to_i)

  puts (1..n).map {|w|
    dist(*pos(w, a), *pos(w, b)) + dist(*pos(w, c), *pos(w, d))
  }.min
end

def dist x1, y1, x2, y2
  (x1 - x2).abs + (y1 - y2).abs
end

def pos width, order
  [(order - 1) / width, (order - 1) % width]
end

main

Measured memory_bytes: 6136
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
using namespace std;
signed main()
{
	ios::sync_with_stdio(false);
	int n, k;
	int a[100005];
	int b[100003];
	cin >> n >> k;
	int sizea=0, sizeb = 0;
	int tmp;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		if (tmp >= 0) {
			a[sizea++] = tmp;
		}
		else {
			b[sizeb++] = abs(tmp);
		}
	}
	sort(a, a + sizea);
	sort(b, b + sizeb);
	long long ans;
	ans =9999999999999999;
	if (sizea >= k) {
		if (a[k - 1] < ans)ans = a[k - 1];
	}
	if (sizeb >= k) {
		if (b[k - 1] < ans)ans = b[k - 1];
	}
	for (int i = 1; i < k; i++) {
		if (i <= sizeb && (k - i - 1 >= 0)&&(k-i-1<=sizea-1)) {
			long long mini;
				long long maxi;
			if (b[i - 1] < a[k - i - 1]) {
				mini = b[i - 1];
				maxi = a[k - i - 1];
			}
			else {
				mini = a[k - i - 1];
				maxi = b[i - 1];
			}
			if (mini * 2 + maxi < ans)ans = mini * 2 + maxi;
		}
	}
	cout << ans;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int h, w, n;
  cin >> h >> w >> n;
  vi32 a(n);
  cin >> a;
  int now = 0;
  int cnt = 0;
  vector<vi32> ans(h, vi32(w));
  rep(i, h) {
    if (i % 2 == 0) {
      rep(j, w) {
        ans[i][j] = now + 1;
        cnt += 1;
        if (cnt == a[now]) {
          now += 1;
          cnt = 0;
        }
      }
    } else {
      rrep(j, w) {
        ans[i][j] = now + 1;
        cnt += 1;
        if (cnt == a[now]) {
          now += 1;
          cnt = 0;
        }
      }
    }
  }
  rep(i, h) cout << ans[i] << endl;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        try {
 
            String str[] = br.readLine().split("\\s+");
            int array[] = new int[str.length];
 
            for(int i = 0; i < str.length; i++){
                array[i] = Integer.parseInt(str[i]);
            }
 
            Dice dice = new Dice();
            dice.setNumber(array[0], array[1], array[2], array[3], array[4], array[5]);
 
            int Q = Integer.parseInt(br.readLine());
 
            String tmp_str[] = new String[2];
            int top_num,front_num;
 
            for(int loop = 0; loop < Q; loop++){
 
                tmp_str = br.readLine().split("\\s+");
                top_num = Integer.parseInt(tmp_str[0]);
                front_num = Integer.parseInt(tmp_str[1]);
 
                System.out.println(dice.query(top_num, front_num));
            }
 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
class Dice{
 
    private int number[];
    private int work[];
    private final String order = "NNNNWNNNWNNNENNNENNNWNNN";
 
    Dice(){
        number = new int[6];
        work = new int[6];
    }
 
 
    public void roll(char dst){
        for(int i = 0; i < 6; i++) work[i] = number[i];
        switch(dst){
        case 'E':
            setNumber(work[3],work[1],work[0],work[5],work[4],work[2]);
            break;
        case 'N':
            setNumber(work[1],work[5],work[2],work[3],work[0],work[4]);
            break;
        case 'S':
            setNumber(work[4],work[0],work[2],work[3],work[5],work[1]);
            break;
        case 'W':
            setNumber(work[2],work[1],work[5],work[0],work[4],work[3]);
            break;
        }
    };
 
    public int query(int top_num,int front_num){
 
        int save_data[] = new int[6];
        for(int i = 0; i < number.length; i++){
            save_data[i] = number[i];
        }
 
        int ret = -1;
 
        for(int i = 0; i < order.length(); i++){
            roll(order.charAt(i));
            if(number[0] == top_num && number[1] == front_num){
                ret = number[2];
                break;
            }
        }
 
        for(int i = 0; i < save_data.length; i++){
            number[i] = save_data[i];
        }
 
        return ret;
    }
 
    public int getTop(){
        return number[0];
    }
 
    public void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
        number[0] = n0;
        number[1] = n1;
        number[2] = n2;
        number[3] = n3;
        number[4] = n4;
        number[5] = n5;
    }
};


Measured memory_bytes: 24432
#include <bits/stdc++.h>
std::string s, t, u;
int a, b;
int main() {
    std::cin >> s >> t;
    std::cin >> a >> b;
    std::cin >> u;

    if(s == u) a --;
    if(t == u) b --;

    std::cout << a << " " << b << std::endl; 
}


Measured memory_bytes: 256
import Data.Function
import Data.List

f :: Int -> [Int] -> Int
f x as = (min `on` length) ss ls
  where (ss,ls) = span (< x) as

main = do
  [_,_,x] <- (map read . words) <$> getLine
  as <- (map read . words) <$> getLine
  print $ f x as

Measured memory_bytes: 892
#include<stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a+b>c+d) printf("Left\n");
    else if(a+b<c+d)printf("Right\n");
    else printf("Balanced\n");
    return 0;

}


Measured memory_bytes: 1664
H, W = map(int, input().split())

if H == 1 or W == 1:
    print(1)
elif W % 2 == 0:
    W //= 2
    print(H * W)
else:
    W //= 2
    W += 1
    print((H + 1) // 2 * W + H // 2 * (W - 1))


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

using namespace std;

int main(){
	int k,s;
	int count = 0;
	cin >> k >> s;
	for(int x=0; x<=k; x++){
		for(int y=0; y<=k; y++){
			int z = s-y-x;
			if(z>=0 && z<=k) count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int coin[6]={500,100,50,10,5,1};
    int n,c=0;
    for(;;){
        cin >> n;
        if(n==0) break;
        n=1000-n;
        for(int i=0;i<6;i++){
            for(;;){
                if(n>=coin[i]){
                    n-=coin[i];
                    c++;
                }
                else break;
            }
        }
        cout << c << endl;
        c=0;
    }

    return 0;
}



Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define MAX 1000000007
typedef long long ll;
int main(){

	ll n;
	string s;
	cin >> n>>s;

	map<char, ll> m;

	rep(i,n) {
		if (m[s[i]]==0) {
			m[s[i]]=1;
		} else {
			m[s[i]]++;
		}
	}

	ll ans = 1;
	for (auto &item:m) {
		ans %= MAX;
		ans = ans * (item.second+1);
	}

	ans--;
	ans %= MAX;

	cout << ans << endl;
}

Measured memory_bytes: 512
a, b, k = map(int,input().split())
a_div = []
b_div = []
for i in range(1, a + 1, 1):
  if a % i == 0:
    a_div.append(i)
for i in range(1, b + 1, 1):
  if b % i == 0:
    b_div.append(i)
common_div = []
common_div = set(a_div) & set(b_div)
common_div_lst = list(common_div)
common_div_lst.sort(reverse = True)
print(common_div_lst[k - 1])


Measured memory_bytes: 3060
a=int(input())
b=int(input())
if a==1 and b==2:
    print(3)
elif a==2 and b==1:
    print(3)
elif a==1 and b==3:
    print(2)
elif a==3 and b==1:
    print(2)
elif a==2 and b==3:
    print(1)
else:
    print(1)
    

Measured memory_bytes: 2940
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	l := make([]int, 87)
	l[0] = 2
	l[1] = 1
	for i := 2; i < 87; i++ {
		l[i] = l[i-1] + l[i-2]
	}
	fmt.Println(l[n])
}


Measured memory_bytes: 512
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
const int maxn=1e5+10;
using namespace std;
typedef long long ll;
ll n,a[maxn],tree[maxn*2+5],pre[maxn*2+5],l,r;
void add(int x,ll v)
{
	for(int i=x;i<=2*maxn;i+=i&-i)
    tree[i]+=v;
}
ll ask(int x)
{
    ll ans=0;
    for(int i=x;i>0;i-=i&-i)
    ans+=tree[i];
    return ans;
}
bool check(int mid)//最后的中位数应该是从右数第n*(n+1)/4个,即顺序对恰为n*(n+1)/4即答案 大于说明mid找小了 小于说明mid找大了 
{
	memset(tree,0,sizeof(tree));
	pre[0]=0;
	ll ans=0;
	for(int i=1;i<=n;++i)
	pre[i]=pre[i-1]+(a[i]>=mid?1:-1);
	//任意大于0的区间均可 即若pre[1]>0 应加上1即pre[0] 故从0开始 
	for(int i=0;i<=n;++i)
	{
		ans+=ask(pre[i]+maxn);//求[1,pre[i]+maxn]的值即比当前值小的已插入值 顺序对 
		//考虑到pre[i]最小可为-n,故移位maxn使之不为负 
		add(pre[i]+maxn,1ll);
	}
	return ans>=n*(n+1)/4;//前缀和顺序对的个数 即比mid要大的中位数个数 
	//如果大于 说明大于mid的中位数超过n*(n+1)/4个 mid一定不是中位数 
	//mid在前一半里 只有n*(n+1)/2为奇数且ans取等才可能是中位数
	//如果小于 则mid在后一半里,比n*(n+1)/2+1要大 
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
	 scanf("%d",&a[i]);
	 r=max(r,a[i]);
    }
    while(l<=r)//二分最后的中位数 
    {
    	int mid=(l+r)>>1; 
    	if(check(mid))l=mid+1;//mid可能符合条件 但mid一旦符合条件 l即保持mid+1不变 答案只可能是l-1即r
		else r=mid-1; 
    }
    printf("%d\n",r);
	return 0;
} 

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <unordered_map>
#include <queue>
#include <set>

using namespace std;

#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

bool comparison(const pair<ll, ll> &a, const pair<ll, ll> &b){
    return a.second > b.second;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<pair<int, ll> > b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i].first >> b[i].second;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end(), comparison);

    ll count = 0;
    int b_num=0, b_index=0;
    rep(i, n){
        if (b_num < m && a[i] < b[b_num].second){
            count += b[b_num].second;
            b_index++;
            if (b_index == b[b_num].first){
                b_index = 0;
                b_num++;
            }
        }
        else {
            count += a[i];
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>


using namespace std;
#define INF 1000000005
int main()
{
int n,l;
std::cin >> n >> l;
std::vector<int> a;
std::vector<int> suma;
std::vector<int> ctie(n - 1, 0);
for(int i = 0; i < n; i++){
    int tempa;
    std::cin >> tempa;
    a.push_back(tempa);
}
int checksum = 0;
for(int i = 0; i < n - 1; i++){
    suma.push_back(a[i] + a[i + 1]);
    if(suma[i] >= l){
        checksum++;
        ctie[i]++;
    }
}
std::vector<int> output;
if(checksum == 0){
    std::cout << "Impossible" << std::endl;
} else {
    std::cout << "Possible" << std::endl;
    int flag = 0;
    for(int i = 0; i < n - 1; i++){
        if(ctie[i] == 1){
            flag = i;
            break;
        }
        output.push_back(i);
    }
    for(int i = n - 2; i >= flag; i--){
        output.push_back(i);
    }
    for(int i = 0; i < n - 1; i++){
        std::cout << output[i] + 1 << std::endl;
    }
}

return 0;
}

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

struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);}}init;

int main(){
    for(string s;cin>>s,s!="0";){
	int n=s.size();
	vector<int> num(n);
	for(int i=0;i<n;i++)
	    num[i]=s[i]-'0';
	vector<int> plus(11,0),minus(11,0);
	int res=0;
	for(auto &it:num){
	    auto np=plus;
	    auto nm=minus;
	    for(int i=0;i<11;i++){
		nm[(i-it+11)%11]=plus[i];
		np[(i+it)%11]=minus[i];
	    }
	    swap(minus,nm);
	    swap(plus,np);
	    if(it)plus[it]++;
	    res+=plus[0]+minus[0];
	}
	cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 3640
#!/usr/bin/env python3
import sys
import collections as cl


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    yama = LI()
    sum_ame = sum(yama)
    sum_kisuu = 0
    for i in range(1, N, 2):
        sum_kisuu += yama[i]

    ans = [0] * N
    ans[0] = sum_ame - 2 * sum_kisuu

    for i in range(1, N):
        ans[i] = 2 * yama[i - 1] - ans[i - 1]

    print(*ans, sep=" ")


main()


Measured memory_bytes: 95148
from heapq import heappop, heappush


class Medians:
    def __init__(self):
        self.left = []
        self.right = []
        self.size_l = 0
        self.size_r = 0
        self.sum_l = 0
        self.sum_r = 0

    def add(self, n):
        if self.size_l > self.size_r:
            t = -self.left[0]
            if n >= t:
                heappush(self.right, n)
                self.sum_r += n
            else:
                heappop(self.left)
                self.sum_l -= t
                heappush(self.left, -n)
                self.sum_l += n
                heappush(self.right, t)
                self.sum_r += t
            self.size_r += 1
        else:
            if not self.size_l:
                heappush(self.left, -n)
                self.sum_l += n
            else:
                t = self.right[0]
                if n <= t:
                    heappush(self.left, -n)
                    self.sum_l += n
                else:
                    heappop(self.right)
                    self.sum_r -= t
                    heappush(self.right, n)
                    self.sum_r += n
                    heappush(self.left, -t)
                    self.sum_l += t
            self.size_l += 1
    
    def get(self):
        return -self.left[0]


def solve():
    Q = int(input())
    s = 0
    med = Medians()
    for _ in range(Q):
        q, *l, = map(int, input().split())
        if q == 1:
            a, b = l
            s += b
            med.add(a)
        else:
            m = med.get()
            d1 = med.size_l - med.size_r
            d2 = med.sum_r - med.sum_l
            print(m, m*d1+d2+s)


if __name__ == "__main__":
    solve()

    # med = Medians()
    # for i in [4,3,5,1,2,7,9]:
    #     med.add(i)
    #     print(med.get())

Measured memory_bytes: 88108
import sys

s = int(input())
a = [s]
ans = 0
for i in range(1,10**6+10):
    if a[i-1] % 2 == 0:
        a.append(int(a[i-1]/2))
    else:
        a.append(3*a[i-1]+1)
    for j in range(len(a)):
        if a.count(a[i]) == 2:
            ans = i+1
            print(ans)
            sys.exit()



Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int to_i(char c)
{
	return c=='E'?0:c=='S'?1:c=='W'?2:3;
}
int N,T;
bool G[55][55][4];
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
main()
{
	int nx,ny;
	cin>>N>>nx>>ny>>T;
	for(int i=0;i<N;i++)
	{
		int xs,ys,xe,ye;
		cin>>xs>>ys>>xe>>ye;
		if(xs==xe)
		{
			if(ys<ye)
			{
				for(int y=ys;y<ye;y++)
				{
					G[xs][y][3]=true;
					G[xs][y+1][1]=true;
				}
			}
			else
			{
				for(int y=ye;y<ys;y++)
				{
					G[xs][y][3]=true;
					G[xs][y+1][1]=true;
				}
			}
		}
		else
		{
			if(xs<xe)
			{
				for(int x=xs;x<xe;x++)
				{
					G[x][ys][0]=true;
					G[x+1][ys][2]=true;
				}
			}
			else
			{
				for(int x=xe;x<xs;x++)
				{
					G[x][ys][0]=true;
					G[x+1][ys][2]=true;
				}
			}
		}
	}
	vector<pair<pair<int,int>,pair<int,bool> > >now;
	for(int r=0;r<4;r++)
	{
		now.push_back(make_pair(make_pair(nx,ny),make_pair(r,false)));
	}
	for(;T--;)
	{
		int d;char c;cin>>d>>c;
		for(int k=0;k<d;k++)
		{
			vector<pair<pair<int,int>,pair<int,bool> > >nxt;
			for(pair<pair<int,int>,pair<int,bool> >p:now)
			{
				int x=p.first.first,y=p.first.second;
				if(p.second.second)
				{
					int od=(p.second.first+2)%4;
					for(int nr=0;nr<4;nr++)
					{
						if(nr==od)continue;
						if(G[x][y][nr])
						{
							nxt.push_back(make_pair(make_pair(x+dx[nr],y+dy[nr]),make_pair(nr,true)));
						}
					}
				}
				else
				{
					int nr=p.second.first;
					if(G[x][y][nr])
					{
						nxt.push_back(make_pair(make_pair(x+dx[nr],y+dy[nr]),make_pair(nr,true)));
					}
				}
			}
			sort(nxt.begin(),nxt.end());
			now=vector<pair<pair<int,int>,pair<int,bool> > >(nxt.begin(),unique(nxt.begin(),nxt.end()));
		}
		vector<pair<pair<int,int>,pair<int,bool> > >tmp=now;
		now.clear();
		int cd=to_i(c);
		int od=(to_i(c)+2)%4;
		for(pair<pair<int,int>,pair<int,bool> >p:tmp)
		{
			if(p.second.first==cd)
			{
				now.push_back(make_pair(p.first,make_pair(cd,true)));
			}
			else if(p.second.first!=od&&G[p.first.first][p.first.second][cd])
			{
				now.push_back(make_pair(p.first,make_pair(cd,false)));
			}
		}
	}
	vector<pair<int,int> >ans;
	for(pair<pair<int,int>,pair<int,bool> >p:now)ans.push_back(p.first);
	sort(ans.begin(),ans.end());
	ans.erase(unique(ans.begin(),ans.end()),ans.end());
	for(pair<int,int>p:ans)cout<<p.first<<" "<<p.second<<endl;
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int a,b,e,f;
  cin>>a>>b;
  vector<int> d(b,0);
  for(int i=0;i<a;i++){
    cin>>e;
for(int j=0;j<e;j++){
  cin>>f;
  d.at(f-1)++;
}
  }
  int k=0;
  for(int i=0;i<b;i++){
    if(d.at(i)==a)
      k++;
  }
  cout<<k<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main(){
  ll n, k;
  std::cin >> n >> k;

  vector<int> h(n);
  for(int i=0; i<n; i++){
    std::cin >> h[i];
  }

  sort(h.begin(), h.end(), greater<int>());

  ll ans = 0;
  for(int i=0; i<n; i++){
    if( i >= k ){
      ans += h[i];
    }
  }

  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#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 fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " -> " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" -> ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, x, t;
    cin >> n >> x >> t;
    if (n % x == 0) n /= x;
    else n = n / x + 1;
    cout << n * t << endl;
}

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

Measured memory_bytes: 3640
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INF = 2147483647;
#define rep(i, n) rep3(i, 0, n)
#define rep2(i, n) rep3(i, 1, n+1)
#define rep3(i, x, n) for(ll i = x; i < (ll)(n); i++)

template<class T>
void printv(vector<T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}

int main(void){
    ll X,Y;
    cin>>X>>Y;
    for(int i=X*2; i<=X*4; i+=2) {
        if(i == Y) { cout << "Yes"; return 0; }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String ss = sc.next();

		String sss = ss.substring(0, ss.length() - 1);

		if (s.equals(sss)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}

}

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

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    int N;
    int A[210000];
    int temp[210000];

    cin >> N;

    rep(i,N) {
        int a;
        cin >> a;
        A[i] = a;
        temp[i] = a;
    }

    sort(A, A + N, greater<int>());

    rep(i,N){
        if(temp[i] == A[0]){
            cout << A[1] << endl;
        }else{
            cout << A[0] << endl;
        }
    }
}

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

using namespace std;

int const NMAX = 100;
int v[1 + NMAX + 1];

int main() {

  string n;
  cin >> n;
  bool N, E, W, S;
  N = E = W = S = false;
  for(int i = 0;i < n.size();i++){
    if(n[i] == 'N'){
      N = true;
    }else if(n[i] == 'E'){
      E = true;
    }else if(n[i] == 'W'){
      W = true;
    }else if(n[i] == 'S'){
      S = true;
    }
  }
  if((N == S) && (E == W)){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
    int c11, c12, c13; 
    int c21, c22, c23; 
    int c31, c32, c33; 

    cin >> c11 >> c12 >> c13;
    cin >> c21 >> c22 >> c23;
    cin >> c31 >> c32 >> c33;

    int a1, a2, a3;
    int b1, b2, b3;

    for (int i = 0; i <= 100; i++) {
        a1 = i;
        b1 = c11 - a1;
        a2 = c21 - b1;
        a3 = c31 - b1;
        b2 = c12 - a1;
        b3 = c13 - a1;

        if (a1 + b1 == c11
         && a1 + b2 == c12
         && a1 + b3 == c13
         && a2 + b1 == c21
         && a2 + b2 == c22
         && a2 + b3 == c23
         && a3 + b1 == c31
         && a3 + b2 == c32
         && a3 + b3 == c33
         ) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


def com(x, y):
    """ユークリッド互除法
    """
    if x == 0:
        return y
    if y == 0:
        return x
    a = max(x, y)
    b = min(x, y)
    c = a % b
    if c == 0:
        return b
    else:
        return com(b, c)


L = [0]
R = [0]

for i in range(N-1):
    L.append(com(L[i], A[i]))
    R.append(com(R[i], A[N-1-i]))

M = []
for i in range(N):
    M.append(com(L[i], R[N-1-i]))

print(max(M))


Measured memory_bytes: 14488
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  string s;
  cin >> s;
  cout << s[0]<<s[1]<<s[2];
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
ll N, f[64][3];
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> N;
  f[60][0] = 1;
  for (int i = 59; i >= 0; --i) {
    f[i][2] = (f[i + 1][2] * 3 + f[i + 1][1]) % MOD;
    f[i][0] = f[i + 1][0];
    f[i][1] = f[i + 1][1];
    if ((N >> i) & 1) {
      (f[i][2] += f[i + 1][1]) %= MOD;
      (f[i][1] += f[i + 1][0]) %= MOD;
    } else {
      (f[i][0] += f[i + 1][1]) %= MOD;
    }
  }
  cout << (f[0][0] + f[0][1] + f[0][2]) % MOD;
  return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    H = list(map(int,input().split()))
    ans = "Yes"

    for i in reversed(range(N-1)):
        if H[i]>H[i+1]:
            H[i] -= 1
            if H[i]>H[i+1]:
                ans = "No"
                break
    print(ans)

if __name__ =="__main__":
    main()

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


public class Test
{	
    public static void Main()
	{
	    string[] s = Console.ReadLine().Split(' ');
	    
	    if(s[0] == "H")
	    {
	        if(s[1]=="H") Console.WriteLine("H");
	        else Console.WriteLine("D");
	    } else if(s[0] == "D")
	    {
	        if(s[1]=="H") Console.WriteLine("D");
	        else Console.WriteLine("H");
	    }
	} 
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vii;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

	for (int i = n - 1; i >= 1; i--)
	{
		if (h[i - 1] > h[i])
		{
			if (h[i - 1] - 1 != h[i])
			{
				ANS("No");
				return 0;
			}
			else h[i - 1]--;
		}
	}
	ANS("Yes");
}

Measured memory_bytes: 640
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

ok = False
counts = dict(Counter(A))
keys = counts.keys()
if len(counts) <= 3:
    for k1, k2, k3 in itertools.product(keys, repeat=3):
        cnt = counts.copy()
        s = k1
        cnt[k1] -= 1
        cnt[k2] -= 1
        if k1 ^ k2 != k3:
            continue
        n = 2
        while n < N:
            cnt[k3] -= 1
            k1, k2, k3 = k2, k3, k2 ^ k3
            n += 1
        if s == k3 and not any(cnt.values()):
            ok = True
            break

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


Measured memory_bytes: 26584