akhauriyash/Code-Regression huggingface dataset:
def merge(A, l, m, r):
  L = A[l:m] + [SENTINEL]
  R = A[m:r] + [SENTINEL]

  i = 0
  j = 0
  for k in range(l, r):
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
  global count
  count += r - l

def merge_sort(A, l, r):
  if l + 1 < r:
    m = (l + r) // 2
    merge_sort(A, l, m)
    merge_sort(A, m, r)
    merge(A, l, m, r)

SENTINEL = float('inf')
n = int(input())
A = list(map(int, input().split()))
count = 0
merge_sort(A, 0, len(A))
print(" ".join(map(str, A)))
print(count)

Measured memory_bytes: 68772
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(void){
    int n;
    cin >> n;
    int a[n],ans=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int x=0,y=0;
    for(int i=0;i<n-2;i++){
        x=a[i];
        for(int j=i+1;j<n-1;j++){
            if(x!=a[j]){
                y=a[j];
            }else{
                y=0;
            }
            if(y!=0){
                for(int k=j+1;k<n;k++){
                    if(x!=a[k]&&y!=a[k]){
                        if(x+y>a[k]&&y+a[k]>x&&a[k]+x>y){
                            ans++;
                            //cout << x << " " << y << " " << a[k] << endl;
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
// Hopcroft-Karp Algorithm
// O(|E| * |V|^(1/2))
// http://en.wikipedia.org/wiki/Hopcroft%E2%80%93Karp_algorithm
// aoj 1163

#include <vector>
#include <queue>
#include <iostream>
using namespace std;

int NIL;
const int inf = 1<<29;

typedef vector<int> vi;
typedef vector<vector<int> > Graph;

bool bfs(const Graph &g,vi &dist,const vi &pair,int m) {
    queue<int> q;

    for(int i=0; i<m; ++i)
        if(pair[i] == NIL) {
            dist[i] = 0;
            q.push(i);
        }else
            dist[i] = inf;
    dist[NIL] = inf;

    while(!q.empty()) {
        int v = q.front(); q.pop();
        if(v == NIL) continue;
        for(int i=0; i<g[v].size(); ++i) {
            int u = g[v][i];
            if(dist[pair[u]] == inf) {
                dist[pair[u]] = dist[v]+1;
                q.push(pair[u]);
            }
        }
    }
    return dist[NIL] != inf;
}

bool dfs(int v,const Graph &g,vi &dist,vi &pair) {
    for(int i=0; i<g[v].size(); ++i) {
        int u = g[v][i];
        if(dist[pair[u]] == dist[v]+1) {
            if(pair[u] == NIL || dfs(pair[u],g,dist,pair)) {
                pair[u] = v, pair[v] = u;
                return true;
            }
        }
    }
    dist[v] = inf;
    return false;
}

// 0ツつゥツづァm-1ツづ慊づづ個静淞点ツづツつゥツづァn-1ツづ慊づづ個静淞点ツづづ個催妥・ツマツッツチツδ督グツづーツ仰づ淞づゥ
int hopcroft_karp(Graph &graph,int m) {
    const int n = graph.size();
    NIL = n;
    vi pair(n+1, NIL), dist(n+1, 0);
    int ret = 0;
    while(bfs(graph,dist,pair,m)) {
        for(int i=0; i<m; ++i)
            if(pair[i] == NIL)
                if(i == NIL || dfs(i,graph,dist,pair)) ret++;
    }
    return ret;
}

int gcd(int x,int y) {
    if(y == 0) return x;
    return gcd(y,x%y);
}

int main() {
    ios::sync_with_stdio(false);
    int m,n;
    while(cin>>m>>n, m|n) {
        Graph g(m+n);
        vector<int> b(m), r(n);
        for(int i=0; i<m; ++i) cin>>b[i];
        for(int i=0; i<n; ++i) cin>>r[i];

        for(int i=0; i<m; ++i)
            for(int j=0; j<n; ++j)
                if(gcd(b[i],r[j]) > 1)
                    g[i].push_back(j+m);
        cout<<hopcroft_karp(g,m)<<endl;
    }
}

Measured memory_bytes: 1616
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	int d,n;
	cin>>d>>n;
	int sum = 0;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		sum+=a;
	}
	if(d-sum >= 0){
		cout<<d-sum;
	}else{
		cout<<-1;
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
#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 INF 2e9
#define MOD 1e9+7
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define bit(n) (1LL<<(n))

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

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

template<class InputIterator>
InputIterator adv(InputIterator x, typename std::iterator_traits<InputIterator>::difference_type n) {
    advance(x, n);
    return x;
}

int ni() {
    int i;
    cin >> i;
    return i;
}

ll nl() {
    ll l;
    cin >> l;
    return l;
}

int main() {
    int N = nl();

    ll ans = nl();
    REP(i, N-1) {
        ll a = nl();
        a /= __gcd(ans, a);
        ans *= a;
    }

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

Measured memory_bytes: 256
#include<stdio.h>
#define SIZE 100000
typedef struct{
  int x;
  int y;
}Zahyo;
Zahyo  z[SIZE];
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
main(){
  int h,w;
  char maps[30][30];
  int i,j;
  while(1){
    scanf("%d %d",&w,&h);
    if(w == 0 && h == 0) break;
    int cnt=0;
    int head=0;
    int tail=0;
    for(i=0;i<h;i++){
      scanf("%s",maps[i]);
      for(j=0;j<w;j++){
	if(maps[i][j]=='@'){
	  z[0]=(Zahyo){j,i};
	  tail=(tail+1)%SIZE;
	}
      }
    }
    while(head != tail){
      int x = z[head].x; int y = z[head].y; head = (head+1) % SIZE;
      if(0 <= x && 0 <= y && x < w && y < h && maps[y][x] != '#'){
	maps[y][x] = '#';
	cnt++;
	for(i=0;i<4;i++){
	  int nx = x + dx[i]; int ny = y + dy[i];
	  z[(tail+i) % SIZE] = (Zahyo){ nx,ny };
	}
	tail = (tail+4) % SIZE;
      }
    }
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 612
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>

#define DAYS 31
#define MAX 50

using namespace std;

typedef vector< int > pep;
typedef vector< pep > days;

struct Node{
	bitset< MAX > maps;
};

int main(){
	while(true){
		int n;
		Node G[MAX];
		int ans = 1;
		days d;

		scanf("%d", &n);
		if( n == 0 ) break;

		d.resize( DAYS );
		for(int i=0;i<n;++i){
			int m;
			scanf("%d", &m);
			for(int j=0;j<m;++j){
				int t;
				scanf("%d", &t);
				d[t].push_back( i );
			}
		}

		for(int i = 0; i < n; ++i){
			G[i].maps.set(i);
		}

		/* solve */
		for(ans = 1; ans < DAYS; ++ans){
			bool bCont = true;
			
			for(unsigned int i = 0; i < d[ans].size(); ++i){
				for(unsigned int j = 0; j < d[ans].size(); ++j){
					G[ d[ans][i] ].maps |= G[ d[ans][j] ].maps;
				}
			}

			for(int i = 0; i < n; ++i){
				if( G[ i ].maps.count() == n ){
					bCont = false;
					break;
				}
			}

			if( !bCont ){
				break;
			}
		}

		printf("%d\n", ans >= DAYS ? -1 : ans );
	}
	return 0;
}

Measured memory_bytes: 940
#include<bits/stdc++.h>
using namespace std;
int n,a,b,ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a>>b;
        ans+=(b-a+1);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {

    int a,b ;
    cin >> a >> b ;
  
   if(a*b%2==0)
    cout << "Even" << endl ;
   else
    cout << "Odd" << endl ;    
    


	return 0;
}



Measured memory_bytes: 256
program probC
    implicit none
    integer::n, i, maxv, smax
    integer, allocatable::a(:), c(:)
    read(*,*) n
    allocate(a(n),c(n))
    do i = 1, n
        read(*,*) a(i)
    end do
    c = a
    call hsort(n,1,1,c)
    do i = 1, n
        if(a(i) == c(n)) then
            write(*,*) c(n-1)
        else    
            write(*,*) c(n)
        end if
    end do
    deallocate(a,c)
    stop
contains
    ! n行m列の配列をp列目でsort
    ! 1次元配列ならm=p=1
    subroutine hsort(n,m,p,array)
        implicit none
        integer,intent(in)::n, m, p
        integer,intent(inout)::array(n,m)

        integer ::i,k,j,l
        integer::t(m)

        if(n.le.0)then
        write(6,*)"Error, at heapsort"; stop
        end if
        if(n.eq.1)return

        l=n/2+1
        k=n
        do while(k.ne.1)
        if(l.gt.1)then
            l=l-1
            t=array(L,:)
        else
            t=array(k,:)
            array(k,:)=array(1,:)
            k=k-1
            if(k.eq.1) then
                array(1,:)=t
                exit
            end if
        end if
        i=l
        j=l+l
        do while(j.le.k)
            if(j.lt.k)then
                if(array(j,p).lt.array(j+1,p))j=j+1
            end if
            if (t(p).lt.array(j,p))then
                array(i,:)=array(j,:)
                i=j
                j=j+j
            else
                j=k+1
            end if
        end do
        array(i,:)=t
        end do

        return
    end subroutine hsort
end program

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n);
    for(int i=0;i<n + 1;i++){
        cin >> a.at(i);
    }
    for(int i=0;i<n;i++){
        cin >> b.at(i);
    }
    
    long long answer = 0;
    
    for(int i = 0;i < n;i++){
        if(b.at(i) > a.at(i)){
            b.at(i) -= a.at(i);
            answer += a.at(i);
            
            if(b.at(i) > a.at(i + 1)){
                answer += a.at(i + 1);
                a.at(i + 1) = 0;
            }else{
                a.at(i + 1) -= b.at(i);
                answer += b.at(i);
            }
        }else{
            answer += b.at(i);
        }
    }
    
    cout << answer << endl;
    
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int n,k,i,g,o;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		g=n;
		o=0;
		for(i=0;i<n;i++){
			scanf("%d",&k);
			if(k==0){
				g--;
			}
			if(k<2){
				o++;
			}
		}
		g=g+1;
		if(o==n){
			printf("NA\n");
		}
		else{
			printf("%d\n",g);
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
	int w, h, x, y, r;
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
	if ((x + r <= w && x - r >= 0) && (y + r <= h && y - r >= 0))
	{
		printf("Yes\n");
	}
	else 
	 {
	 	printf("No\n");
	 }
}


Measured memory_bytes: 2692
A, B, C, X, Y = map(int, input().split())
ans = 0
#A+B < 2ABの場合はそれぞれ単品で買ったほうがお得
if A + B < 2 * C:
    ans = A*X + B*Y
#A+B > 2ABの場合は買えるだけかう
else:
    for _ in range(min(X, Y)):
        ans += 2 * C

    if X - Y >= 0:
        if A < 2 * C:
            ans += A * (X-Y)
        else:
            ans += 2 * C * (X-Y)
    else:
        if B < 2 * C:
            ans += B * (Y-X)
        else:
            ans += 2 * C * (Y-X)

print(ans)

Measured memory_bytes: 9200
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
 
        if(a > b){
            if(b > c){
                System.out.printf("%d %d %d\n", c, b, a);
            }else if(a > c){
                System.out.printf("%d %d %d\n", b, c, a);
            }else{
                System.out.printf("%d %d %d\n", b, a, c);
            }
        }else{
            if(a > c){
                System.out.printf("%d %d %d\n", c, a, b);
            }else if(b > c){
                System.out.printf("%d %d %d\n", a, c, b);
            }else{
                System.out.printf("%d %d %d\n", a, b, c);
            }
        }
 
    }
}


Measured memory_bytes: 26312
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    ll n, q; cin >> n >> q;
    string s; cin >> s;
    vector<ll> a(n, 0);
    ll cnt = 0;
    for(int i=1; i<n; i++){
        if(s[i] == 'C'){
            if(s[i-1] == 'A'){
                cnt++;
                a[i] = cnt;
            }
            else a[i] = cnt;
        }
        else a[i] = cnt;
    }
    //cout << a << endl;
    REP(i, q){
        ll l, r; cin >> l >> r;
        cout << a[r-1] - a[l-1] << endl;
    }

}

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

Measured memory_bytes: 1872
def main():
    A = int(input())
    B = list(map(int, input().split(" ")))
    result = B[0]
    if A > 3:
        for i in range(0, A - 2):
            result += min(B[i], B[i + 1])
    elif A == 3:
        result += B[0]
    result += B[-1]
    print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#n,x=map(int,input().split())
#a=[int(i) for i in input().split()]
import string
alp=string.ascii_lowercase
di={}
for i in range(26):
    di[alp[i]]=i
s=input()
a=[]
for i in s:
    a.append(i)
l=a.pop()
if a:
    a=a[::-1]
k=int(input())
ans=''
i=0
while a:
    t=a.pop()
    d=(26-di[t])%26
    if d<=k:
        k-=d
        ans+='a'
    else:
        ans+=t
    i+=1
kk=k%26
ans+=alp[(alp.index(l)+kk)%26]
print(ans)


Measured memory_bytes: 5532
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

from functools import reduce

# gcdを求める
def findGCD(a:int, b:int) -> int:
    # ユークリッドの互除法
    while 1:
        if a%b == 0:
            return b
        else:
            a = a%b
        
        if b%a == 0:
            return a
        else:
            b = b%a

n,x = li()
a = li()

a_diff = [abs(ai - x) for ai in a]
ans = reduce(findGCD, a_diff)

print(ans)

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

int main(void){
  int a,b;
  cin >> a;
  cin >> b;
      if(a < b) {
          cout << "a < b";
      }
      else if(a > b) {
          cout << "a > b";
      }
       else {
           cout << "a == b";
      }
      cout  << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i<n; i++) cin >> a[i];
    vector<long long> acc(n+1);
    vector<long long> x(n+1);
    for (int i = 0; i<n+1; i++){
        acc[i] = 0;
        x[i] = 0;
    }
    for (int i = 0; i<n; i++){
        acc[i+1] = acc[i] + a[i];
        x[i+1] = x[i]^a[i];
    }
    int left = 0;
    int right = 1;
    long long ans = 0;
    while (left < n){
        while (right <= n && acc[right] - acc[left] == (x[right]^x[left])){
            ans++;
            right++;
        }
        left++;
        ans += right - left - 1;
    }
    cout << ans << endl;
}




Measured memory_bytes: 4992
import numpy as np
s=input()
n=len(s)
MOD=1000000007
wayA=np.array([0,0,0,0],dtype=np.int64)
wayB=np.array([0,0,0,0],dtype=np.int64)
wayC=np.array([0,0,0,0],dtype=np.int64)
MOD2=np.array([MOD,MOD,MOD,MOD],dtype=np.int32)
hatena=0
for c in s:
	if c=="A":
		wayA[0]+=1
	if c=="B":
		wayB+=wayA
	if c=='C':
		wayC+=wayB
	if c=='?':
		wayC[1]=wayC[1]+wayB[0]
		wayC[2]=wayC[2]+wayB[1]
		wayC[3]=wayC[3]+wayB[2]
		wayB[1]=wayB[1]+wayA[0]
		wayB[2]=wayB[2]+wayA[1]
		wayA[1]=wayA[1]+1
		hatena+=1
	wayA%=MOD2
	wayB%=MOD2
	wayC%=MOD2
ans=0
for i in range(0,4):
	ans=ans+pow(3,hatena-i)*wayC[i]
	ans=ans%MOD
print(int(ans))

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

int main()
{
    vector<int> a(3);
    rep(i, 3) cin >> a.at(i);

    if (a.at(0) + a.at(1) + a.at(2) >= 22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }
}

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

int main(){
  int N,T,A;
  cin >> N >> T >> A;
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin >> H.at(i);
  }
  int bangou=0;
  double min_distance=100000;
  for(int i=0;i<N;i++){
    double B=T-H.at(i)*0.006;
    if(abs(A-B)<=min_distance){
      min_distance=abs(A-B);
      bangou=i+1;
    }
  }
  cout << bangou << endl;
}  

Measured memory_bytes: 256
/*
ID: Aldew
LANG: C++14
PROG:
*/
/*
Realize that you will gain money as long as the
next day's stock price is greater than today's. If
that is the case buy as many stocks as you can afford
and sell them at the increased rate.
*/

#include <bits/stdc++.h>
#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define INF 11000000000000000LL

typedef long long ll;
typedef unsigned long long ull;

int pct(int x) { return __builtin_popcount(x); }

using namespace std;

//ifstream fin("lamps.in");
//ofstream fout("lamps.out");
const int BT = (1 << 16);

int x[20], y[20], p[20];
ll score[BT];
ll dp[BT][20];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n ;i++) cin >> x[i] >> y[i] >> p[i];
    for (int s = 1; s < 1 << n; s++){
        score[s] = INF;

        for (int i = 0; i < n; i++){
            int xi = x[i];
            ll sx = 0;
            for (int k = 0; k < n; k++){
                if (s >> k & 1)
                    sx += (ll) abs(x[k] - xi) * (ll) p[k];
            }
            score[s] = min(score[s], sx);

            int yi = y[i];
            ll sy = 0;
            for (int k = 0; k < n; k++){
                if (s >> k & 1)
                    sy += (ll) abs(y[k] - yi) * (ll) p[k];
            }
            score[s] = min(score[s], sy);
        }
    }
    for (int s = 0; s < 1 << n; s++){
        ll score = 0;
        for (int k = 0; k < n; k++){
            if (s >> k&1)
                score += (ll) min(abs(x[k]), abs(y[k])) * (ll) p[k];
        }
        for (int k = 0; k <= n; k++){
            dp[s][k] = score;
        }
    }
    for (int k = 0; k <= n; k++) dp[0][k] = 0;
    for (int s = 0; s < 1 << n; s++){
        for (int k = 0; k < n; k++){
            if (dp[s][k] == INF) continue;

            int z = (1 << n) - 1 - s;
            for (int t = z; t > 0; t = (t-1) & z){
                dp[s|t][k+1] = min(dp[s|t][k+1], dp[s][k] + score[t]);
            }
        }
    }
    for (int i = 0; i <= n; i++){
        cout << dp[(1 << n ) - 1][i] << endl;
    }



    return 0;
}


Measured memory_bytes: 8984
s = input()
k = int(input())


ans_set = set()
for i in range(len(s)):
    c = s[i]
    ans_set.add(c)
    for j in range(i + 1, len(s)):
        c += s[j]
        if len(c) > k:
            break
        ans_set.add(c)


ans_lst = list(ans_set)
ans_lst.sort()
ans = ans_lst[k-1]


print(ans)

Measured memory_bytes: 4464
import math

words = lambda t : list(map(t, input().split()))


def gcd (a,b):
    if a > b:
        t = b
        b = a
        b = t
    v = b
    while (a % b != 0):
        t = a % b
        a = b
        b = t
        v = b
    return v


n = int(input())
a = words(int)

if n == 2:
    print(max(a[0],a[1]))

else:
    cgcdm1 = max(gcd(a[0],a[1]),gcd(a[1],a[2]),gcd(a[2],a[0]))
    allgcd = gcd(a[0],gcd(a[1],a[2]))

    for i in range(3,len(a)):
        cgcdm1 = max(gcd(cgcdm1,a[i]),allgcd)
        allgcd = gcd(allgcd, a[i])

    print(cgcdm1)


def gcd (a,b):
    if a > b:
        t = b
        b = a
        b = t
    v = b
    while (a % b != 0):
        t = a % b
        a = b
        b = t
        v = b
    return v


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

int main()
{
  int n;
  int k;
  int i;
  int x;
  
  cin >> n >> k;
  x = 1;
  i = 0;
  while (i < n)
  {
    if ( x * 2 <= x + k)
      x = x * 2;
    else 
      x = x + k;
    i++;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string a,b,c,d,e;
  cin>>a;
  b=a[0];
  c=a[1];
  d=a[2];
  e=a[3];
  if(b==c&&c==d&&d==e)
    cout<<"No"<<endl;
  else if(b==c){
    if(d==e)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }else if(b==d){
    if(c==e)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }else if(b==e){
    if(c==d)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
f = [' ' * w] + [list(' ' + input().strip() + ' ') for _ in range(h)] + [' ' * w]

for i, l in enumerate(f):
    for j, b in enumerate(l):
        if b == '.':
            c = int(l[j - 1] == '#') + int(l[j + 1] == '#')
            c += f[i - 1][j - 1:j + 2].count('#')
            c += f[i + 1][j - 1:j + 2].count('#')
            l[j] = c
for l in f[1:h + 1]:
    print(''.join(map(str, l[1:w + 1])))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int n,k;
    cin >>n>>k;
    vector<long long> h(n);
    rep(i,n) cin>> h[i];
    sort(h.begin(), h.end(),greater<long long>());
    long long sum =0;

    if (k<=n){
            for (int i=k;i<n;i++){
                sum +=h[i];
            }
    }
    cout << sum;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  int ave;
  int sum = 0;
  rep(i,N) sum += a[i];
  ave = sum / N;
  int ansum = 0;
  int ansum2 = 0;
  rep(i,N)
  {
    ansum += (ave-a[i])*(ave-a[i]);
  }
  rep(i,N)
  {
    ansum2 += (ave+1-a[i])*(ave+1-a[i]);
  }
  cout << min(ansum,ansum2) << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

type City struct {
	Index        int
	PrefectureNo int
	Year         int
	ServiceNo    string
}

type By func(c1, c2 *City) bool

func (by By) Sort(cities []City) {
	cs := &citySorter{
		cities: cities,
		by:     by,
	}
	sort.Sort(cs)
}

type citySorter struct {
	cities []City
	by     func(c1, c2 *City) bool
}

func (c *citySorter) Len() int {
	return len(c.cities)
}

func (c *citySorter) Swap(i, j int) {
	c.cities[i], c.cities[j] = c.cities[j], c.cities[i]
}

func (c *citySorter) Less(i, j int) bool {
	return c.by(&c.cities[i], &c.cities[j])
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	cs := make([]City, m)
	for i := range cs {
		cs[i].Index = i
		sc.Scan()
		cs[i].PrefectureNo, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		cs[i].Year, _ = strconv.Atoi(sc.Text())
	}

	By(func(c1, c2 *City) bool {
		if c1.PrefectureNo == c2.PrefectureNo {
			return c1.Year < c2.Year
		}
		return c1.PrefectureNo < c2.PrefectureNo
	}).Sort(cs)
	p := 0
	var y int
	for i, v := range cs {
		if p != v.PrefectureNo {
			p = v.PrefectureNo
			y = 0
		}
		y++
		cs[i].ServiceNo = fmt.Sprintf("%06d%06d", p, y)
	}

	By(func(c1, c2 *City) bool {
		return c1.Index < c2.Index
	}).Sort(cs)
	for _, v := range cs {
		fmt.Println(v.ServiceNo)
	}
}


Measured memory_bytes: 9856
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;
    ll a[312345];

    cin >> n;
    REP(i, n)
    cin >> a[i];

    ll res = 0;

    REP(i, 60)
    {
        ll one = 0;
        REP(j, n)
        {
            if (a[j] & (1LL << i))
                one++;
        }

        (res += (1LL << i) % MOD * one % MOD * (n - one) % MOD) %= MOD;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <sstream>

#define enp     puts("**chkchkchkchkchk**")
#define A       first
#define B       second
#define MP      make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;

const int INF = 0x60000000;
const int MINF = -1000000000;
const ll mod = 1000000007;
const ll cons = 100000000000;
const double pi = 3.141592653589793;

ll ans = 0;
string s;

void fn(int pos, ll sum)
{
	if (pos == s.length())
	{
		ans += sum;
		return;
	}

	for (int i = pos; i < s.length(); i++)
	{
		ll tmp = 0;
		for (int j = pos; j <= i; j++)
		{
			tmp = tmp * 10 + s[j] - '0';
		}

		fn(i + 1, tmp + sum);
	}
}

int main()
{

	cin >> s;

	fn(0, 0);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;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 INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    ll h,w;cin>>h >> w;
    if(h==1 || w ==1) {cout <<1 << endl;return 0;}
    else{
    if(h*w % 2 ) {cout << /*floor(h*w/2.0) +1*/ (h*w + 1) / 2 << endl;return 0;}//奇数の時
    else {cout << h*w/2 << endl;return 0; }//偶数の時
}
    /*ll count = 0;
    REP(i,h){
        REP(j,w){
                if((i+j)%2==0){
                    count++;
                }
        }
    }
    cout << count<<endl;
  */
}

Measured memory_bytes: 256
H, W = map(int,input().split())
board = []
for h in range(H):
    board.append(input())

dp=[[1000 for i in range(W+1)] for j in range(H+1)]
dp[0][1] = 0
dp[1][0] = 0

for h in range(H):
    for w in range(W):
        dp[h+1][w+1] = min(
            dp[h][w+1] + (board[h][w]=='#' and (h==0 or board[h-1][w]=='.')),
            dp[h+1][w] + (board[h][w]=='#' and (w==0 or board[h][w-1]=='.'))
        )

print (dp[-1][-1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int X, N;
    cin >> X >> N;
    
    vec<int> p(130,10000);
    rep(i, N) {
        int t;
        cin >> t;
        p[t] = 99999;
    }

    int mn = 10000;
    for(int i=0;i<=101;++i){
        if(p[i] == 99999) continue;
        p[i] = abs(X-i);
        mn = min(mn,p[i]);
    }

    for(int i=0;i<=101;++i){
        if(p[i]==mn){
            cout << i << endl;
            return 0;
        }
    }
    
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int main(){
    ll n;
    cin >> n;
    ll aoki, takahashi;
    cin >> takahashi >> aoki;

    REPN(loop, 1, n) {
        ll a, t;
        cin >> t >> a;
        ll nt, na;
        if(takahashi % t == 0) {
            nt = takahashi / t;
        } else {
            nt = takahashi / t + 1;
        }
        if(aoki % a == 0) {
            na = aoki / a;
        } else {
            na = aoki / a + 1;
        }

        na = max(na, nt);
        
        takahashi = na * t;
        aoki = na * a;
    }

    cout << takahashi + aoki << endl;

    return 0;
}


Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



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

    int N;cin >> N;
    if(N >= 24){
        cout << 0 << endl;
        return 0;
    }
    vector<int> retu(N);
    for(int i = 0;i<N;i++){
        cin >> retu.at(i);
        if(retu.at(i) == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    sort(retu.begin(),retu.end());
    vector<int> right_first,left_first;
    //右左右左右左…
    right_first.push_back(0);
    left_first.push_back(0);
    for(int i = 0;i<N;i++){
        if(i % 2 == 0){
            right_first.push_back(retu.at(i));
        }
        else{
            right_first.push_back(24-retu.at(i));
        }
    }
    for(int i = 0;i<N;i++){
        if(i % 2 == 1){
            left_first.push_back(retu.at(i));
        }
        else{
            left_first.push_back(24-retu.at(i));
        }
    }

    int ans1 = 24,ans2 = 24;
    for(int i = 0;i<N+1;i++){
        for(int j = 0;j<N+1;j++){
            if(i == j) continue;
            ans1 = min(ans1,min(24-abs(right_first.at(i)-right_first.at(j)),abs(right_first.at(i)-right_first.at(j))));
            ans2 = min(ans2,min(24-abs(left_first.at(i)-left_first.at(j)),abs(left_first.at(i)-left_first.at(j))));
        }
    }
    cout << max(ans1,ans2) << endl;
}

Measured memory_bytes: 3604
// header {{{
// header {{{
#include <bits/stdc++.h>
using namespace std;
 
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
 
#define ASSERT(expr...) assert((expr))
 
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
 
using f32 = float;
using f64 = double;
// }}}
 
constexpr i64 INF = 1'010'000'000'000'000'017LL;
 
constexpr i64 MOD = 1'000'000'007LL;
 
constexpr f64 EPS = 1e-12;
 
constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

 
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define ll long long int
#define VI vector <int>
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
 
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
 
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
 
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}
 
// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
 
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}
 
//--------------------------------------------------------------------
 
bool isOK(int mid, double key){
 
    if((double)mid*mid > key) {
             return true;
     } else {
              return false;
     }
}

 int binary_search(double key) {
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2000000000;
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}


bool isKaibun(string st){
    bool ans = true;
    int n = st.length();
    REP(i,n/2){
        if(st[i] != st[n-i-1]){
            return false;
        }
    }
    return true;
}

int toInt(char a){
    return a-'0';
}



void solve() {
    int X,Y,Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y;

   }




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


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

#define LL long long int
#define LD long double
#define inp_s ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define mod 1000000007

int main(){
      int n, k;
      cin >> n >> k;
      if(n % k == 0){
            cout << "0\n";
      } else {
            cout << "1\n";
      }
      return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}

uint32_t nextpint(void){
	char c=getchar();
	while(c<'0'||'9'<c) c=getchar();
	uint_fast32_t x=0;
	while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); }
	return x;
}

#define V 202
#include <vector>
using namespace std;

struct edge{
	int to, cap, rev;
};

bool used[V];
vector<vector<edge>> G(V);

void add_edge(int from, int to, int cap){
	edge F, T;
	F.to = to;
	F.cap = cap;
	F.rev = G[to].size();
	G[from].push_back(F);

	T.to = from;
	T.cap = 0;
	T.rev = G[from].size()-1;
	G[to].push_back(T);
}

int dfs(int v, int t, int f){
	if(v==t) return f;
	used[v]=1;
	int i, l=G[v].size();
	for(i=0; i<l; i++){
		edge &e=G[v][i];
		if(used[e.to]==0 && e.cap>0){
			int d = dfs(e.to, t, min(f, e.cap));
			if(d>0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t){
	int flow = 0;
	while(1){
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INT_MAX);
		if(f==0) return flow;
		flow += f;
	}
}

int main(void){
	int n, i, j;
	int a[100][2], b[100][2];
	scanf("%d", &n);
	for(i=0; i<n; i++){ scanf("%d%d", &a[i][0], &a[i][1]); add_edge(n*2, i, 1);}
	for(i=0; i<n; i++){ scanf("%d%d", &b[i][0], &b[i][1]); add_edge(i+n, n*2+1, 1);}
	for(i=0; i<n; i++){
		for(j=0; j<n; j++){
			if(a[i][0]<b[j][0] && a[i][1]<b[j][1]) add_edge(i, j+n, 1);
		}
	}
	int ans=max_flow(n*2, n*2+1);
	/*
	int ans=0;
	while(1){
		int k=dfs(n*2, n*2+1, 1);
		if(k==0) break;
		ans+=k;
	}
	*/
	printf("%d\n", ans);
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline
from collections import defaultdict, Counter

N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        x = (4*h*n-N*n-N*h)
        if x == 0:
            continue
        w = int(N*n*h/x)
        if w < 1 or 3500 < w:
            continue
        if N*(w*n+h*w+h*n) == 4*h*n*w:
            print(h, n, w)
            exit()


Measured memory_bytes: 41436
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,x[100000],dif[99999];
	cin>>n>>m;
	for(int i=0;i<m;i++)
		cin>>x[i];
	sort(x,x+m);
	for(int i=0;i<m-1;i++)
		dif[i]=x[i+1]-x[i];
	sort(dif,dif+m-1);
	int ans=0;
	for(int i=0;i<m-n;i++)
		ans+=dif[i];
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int C[3][3];
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
			cin >> C[i][j];
	}
	vector<int> A(3);
	vector<int> B(3);
	bool ans = false;
	for (int i = 0; i <= 100; i++)
	{
		A[0] = i;
		B[0] = C[0][0] - A[0];
		A[1] = C[1][0] - B[0];
		A[2] = C[2][0] - B[0];
		B[1] = C[0][1] - A[0];
		B[2] = C[0][2] - A[0];
		if (C[1][1] == A[1]+B[1] && C[1][2] == A[1]+B[2] &&
			C[2][1] == A[2]+B[1] && C[2][2] == A[2]+B[2])
			ans = true;
	}
	cout << (ans ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	if (a%3 ==0 || b%3==0 || (a+b)%3==0){
		cout << "Possible" << endl;
	}else{
		cout << "Impossible" << endl;
	}
	return 0;
}

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

using namespace std;
#define int long long
int MOD = 1000000007;


signed main(){
    int M,D;
    cin >> M >> D;
    
    int one=0,ten=0,cnt=0;
    for(int k=0;k<=M;k++){
        for(int i=22;i<=D;i++){
            one = i%10;
            ten = i/10;
            if(k==ten*one && one>1) cnt++;
        }
    }
    
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        for(int i = 0; i<W+2; i++) {
            System.out.print("#");
        }
        System.out.println();
        for(int k = 0; k<H; k++) {
            for(int i = 0; i<3; i++) {
                if(i==0 || i == 2) {
                    System.out.print("#");
                }else {
                    System.out.print(sc.next());
                }
            }
            System.out.println();
	}
        for(int i = 0; i<W+2; i++) {
            System.out.print("#");
        }
        System.out.println();
    }
}

Measured memory_bytes: 21332
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

# ある経路をきめる.
# そのとき(白マスから黒マスに移動する回数)＝(その経路がいい経路にするための操作回数）
dp = [[float("inf")]*w for _ in range(h)]
if s[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0
# dp[i][j]は00からijに行くときに白マスから黒マスに移動する回数の最小値
for i in range(h):
    for j in range(w):
        if i+1 < h:
            if s[i][j] == "." and s[i+1][j] == "#":
                dp[i+1][j] = min(dp[i+1][j], dp[i][j]+1)
            else:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j])

        if j+1 < w:
            if s[i][j] == "." and s[i][j+1] == "#":
                dp[i][j+1] = min(dp[i][j+1], dp[i][j]+1)
            else:
                dp[i][j+1] = min(dp[i][j+1], dp[i][j])
print(dp[h-1][w-1])


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define M 1000006
# define N 10000001
# define A 10000007
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }




int main()
{
	int n;
	cin >> n;
	int N1=3*n;
	ll a[N1];
	for(int i=0;i<N1;i++)
		cin >> a[i];
	sort(a,a+N1);
	//for(int i=0;i<N1;i++)
		//cout << a[i]<<" ";
	ll ans=0;
	int cnt=0;
	for(int i=N1-2;i>=0;i-=2)
	{
		if(cnt>=n)
			break;
		ans+=a[i];
		cnt++;
		//trace2(cnt,ans);
	}
	cout << ans;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>
#include <cassert>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[100005];
  fastio(){
	  it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    len = fread(s,1,100000,stdin);
    it = 0;
    return len ? s[it++] : EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x,char c){
  if(x == 0) bufo.put('0');
  if(x < 0) bufo.put('-'), x = -x;
  char s[15]; int k = 0;
  while(x){
    s[++k] = x % 10 + '0';
    x /= 10;
  }
  for(;k >= 1;k--) bufo.put(s[k]);
  bufo.put(c);
}
int n,k;
int main(){
//  freopen("a.in","r",stdin);
//  freopen("a.out","w",stdout);
  n = getint(), k = getint();
  putint(n % k ? 1 : 0,'\n');
  bufo.flush();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  //  ios::sync_with_stdio(false);
  int q,n;
  cin>>q;
  list<int> ls;
  auto itr=ls.end();
  rep(i,q){
    cin>>n;
    //cout<<i<<endl;
    int num;
    if(n==0){
      cin>>num;
      itr=ls.insert(itr,num);
      
    }
    else if(n==1){
      cin>>num;
      if(num>0){
	rep(i,num) itr++;
      }else{
	rep(i,abs(num)) itr--;
      }
    }else{
      itr=ls.erase(itr);
      
    }
    
   
  }
  for(auto it=ls.begin();it!=ls.end();it++){
    cout<<*it<<endl;
    
  }
  return 0;
}



Measured memory_bytes: 18636
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int n,d;

bool inside(int x,int y){
	if(x>=0 && x<d && y>=0 && y<d)return true;
	else return false;
}

int main(){
	cin>>n;
	rep(p,n){
		if(p!=0)cout<<endl;
		cin>>d;
		char ch[d][d];
		rep(i,d)rep(j,d)ch[i][j]='.';
		int dir=0;
		int x=0,y=d-1;
		while(1){
			int check=0;
			if(dir==0){
				while(inside(x,y)){
					ch[y][x]='#';
					if(inside(x,y-1) && ch[y-1][x]=='.'){
						ch[y][x+1]='-';
						y--;
						check|=1;
					}else{if(ch[y][x+1]!='-')x++;break;} 
				}
			}else if(dir==1){
				while(inside(x,y)){
					ch[y][x]='#';
					if(inside(x+1,y) && ch[y][x+1]=='.'){
						ch[y+1][x]='-';
						x++;
						check|=2;
					}else{if(ch[y+1][x]!='-')y++;break;}
				}
			}else if(dir==2){
				while(inside(x,y)){
					ch[y][x]='#';
					if(inside(x,y+1) && ch[y+1][x]=='.'){
						ch[y][x-1]='-';
						y++;
						check|=4;
					}else{if(ch[y][x-1]!='-')x--;break;}
				}
			}else{
				while(inside(x,y)){
					ch[y][x]='#';
					if(inside(x-1,y) && ch[y][x-1]=='.'){
						ch[y-1][x]='-';
						x--;
						check|=8;
					}else{if(ch[y-1][x]!='-')y--;break;}
				}
			}
			dir++;
			dir%=4;
			if(check==0)break;
		}
		rep(i,d){
			rep(j,d){
				if(ch[i][j]=='#')cout<<'#';
				else cout<<' ';
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
int main() {
	int c[111111], n, i, m, a, b;
	cin >> n >> m;
	for (i = 1; i <= n; i++)
		c[i] = 0;
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		c[a]++;
		c[b]++;
	}
	for (i = 1; i <= n; i++) {
		if (c[i] % 2 == 1) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 5376