akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**6)
def input():
	return sys.stdin.buffer.readline()[:-1]

MOD = 10**9 + 7
list_size = 200001

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(2, list_size + 1):
	f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n-1):
	a, b = map(int, input().split())
	adj[a-1].append(b-1)
	adj[b-1].append(a-1)


dp_pat = [0 for _ in range(n)]
dp_num = [0 for _ in range(n)]


def dfs1(x, p):
	num = 0
	res = 1
	for v in adj[x]:
		if v == p:
			continue
		dfs1(v, x)
		num += dp_num[v]
		res *= comb(num, dp_num[v]) * dp_pat[v]
		res %= MOD
	dp_num[x] = num+1
	dp_pat[x] = res
	return

dfs1(0, -1)
ans = [0 for _ in range(n)]
ans[0] = dp_pat[0]

def dfs2(x, p):
	for v in adj[x]:
		if v == p:
			continue
		pres = [dp_pat[x], dp_num[x], dp_pat[v], dp_num[v]]
		dp_pat[x] *= pow(comb(dp_num[x]-1, dp_num[v]) * dp_pat[v], MOD-2, MOD)
		dp_pat[x] %= MOD
		dp_num[x] -= dp_num[v]

		dp_pat[v] *= comb(dp_num[x] + dp_num[v] - 1, dp_num[x]) * dp_pat[x]
		dp_pat[v] %= MOD
		dp_num[v] += dp_num[x]
		ans[v] = dp_pat[v]
		dfs2(v, x)
		dp_pat[x], dp_num[x], dp_pat[v], dp_num[v] = pres
	return

dfs2(0, -1)
print(*ans, sep="\n")

Measured memory_bytes: 88640
import java.io.IOException;
import java.util.Scanner;

public class Main {
    private static StringBuilder sb = new StringBuilder();

    public static void main(String... args) throws IOException {
        final int[] targetAry = load();

        insertionSort(targetAry);

        System.out.print(sb.toString());
    }

    public static int[] load() throws IOException {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int[] nums = new int[n];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = scanner.nextInt();
        }

        return nums;
    }

    public static void insertionSort(final int[] targetAry) {
        for (int i = 0; i < targetAry.length; i++) {
            for (int j = i; 0 < j; j--) {
                if (targetAry[j - 1] > targetAry[j]) {
                    swap(targetAry, j - 1, j);
                }
                if ((1 < j) && (targetAry[j - 1] > targetAry[j - 2])) {
                    break;
                }
            }

            append(targetAry);
        }
    }

    public static void swap(final int[] targetAry, final int from, final int to) {
        final int tmp = targetAry[to];
        targetAry[to] = targetAry[from];
        targetAry[from] = tmp;
    }

    public static void append(final int[] targetAry) {
        for (int j = 0; j < targetAry.length; j++) {
            sb.append(targetAry[j]).append(j != targetAry.length - 1 ? ' ' : '\n');
        }
    }
}

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

using namespace std;

int main()
{
    int n; 
    cin >> n;
    vector<int> t1(n);
    int total = 0;
    for (int i = 0; i < n; i++) {
        cin >> t1[i];
        total += t1[i];
    }
    
    int m;
    cin >> m;
    vector<int> tp(m);
    for (int i = 0; i < m; i++) {
        int p, x;
        cin >> p >> x;
        tp[i] = total - t1[p-1] + x;
    }

    for (int i = 0; i < m; i++) {
        cout << tp[i] << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool flag[10];
int N,M;
vector<vector<int>>G;
int rec(int now){
  flag[now]=true;
  int cnt=0;
  for(int i=1;i<=N;i++){
    if(!flag[i])break;
    cnt++;
  }
  if(cnt==N)return 1;
  int ans=0;
  for(auto e:G[now]){
    if(!flag[e]){
      ans+=rec(e);
      flag[e]=false;
    }
  }
  return ans;
}
int main(){
  cin>>N>>M;
  G.resize(N+1);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cout<<rec(1)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int K, S;
	cin >> K >> S;
	int count = 0;
	for (int x = 0; x <= K; x++) {
		for(int y = 0; y <= K; y++) {
			int z = S - x - y;
			if (z >= 0 && z <= K) {
				count++;
			}
		}

	}
	cout << count << endl;
}



Measured memory_bytes: 256
//
// Created by moono on 2018/10/27.
//

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;



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

    //
    long a, b;
    vector<pair<long, long>> students;
    for (int i = 0; i < N; ++i) {
        cin >> a >> b;
        students.push_back(make_pair(a, b));
    }

    vector<pair<long, long>> points;
    for (int i = 0; i < M; ++i) {
        cin >> a >> b;
        points.push_back(make_pair(a, b));
    }


    //
    for(auto student: students){
        long min_dist=abs(student.first - points[0].first) + abs(student.second - points[0].second), min_index=0;

        for (int i = 1; i < points.size(); ++i) {
            auto point = points[i];
            long dist = abs(student.first - point.first) + abs(student.second - point.second);
            if(dist < min_dist){
                min_dist = dist;
                min_index = i;
            }
        }
        cout << (min_index+1) << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()
#define vi vector<int>

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;

int main(void) {
  int N;
  ll P;
  string S;
  cin >> N >> P >> S;
  if (P==2) {
    per(i, 0, N) {
      ll d = (ll)(S[i]-'0');
      if (d%2==0) ans += i+1;
    } 
  } else if (P==5) {
    per(i, 0, N) {
      ll d = (ll)(S[i]-'0');
      if (d==5 || d==0) ans += i+1;
    } 
  
  } else {
    ll dw = 1, num = 0;
    map<ll, ll> m;
    m[0]++;
    
    per(i, 0, N) {
      ll d = (ll)(S[i]-'0');
      num  = (((d*dw)%P)+num)%P;
      ll r  = num%P;
      ans += m[num];
      m[num]++;
      dw = (dw*10)%P;
    }
    
  
  }
  

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





Measured memory_bytes: 4236
let () =
  Scanf.scanf "%d\n%s\n" @@ fun n s ->
  let ans = ref 0 in
  let checkStr = ref 'A' in
  for i = 0 to n - 1 do
    if s.[i] = 'A' then checkStr := 'B'
    else if s.[i] = 'B' && !checkStr = 'B' then checkStr := 'C'
    else if s.[i] = 'C' && !checkStr = 'C' then (checkStr := 'A'; ans:= !ans + 1)
    else checkStr := 'A'
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef pair<string, int> Psi;
typedef pair<ll, ll> Pll;
int main(){
	int N,K;
	cin >> N >> K;
	int ans = K;
	reps(i,1,N){
		ans *= K-1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N, M = map(int, input().split())
    ks = [list(map(int, input().split())) for _ in range(M)]
    p = list(map(int, input().split()))

    ans = 0
    # スイッチのパターン
    for i in range(2**N):
        # 電球
        flg = True
        for j in range(M):
            # 電球に繋がれたスイッチ
            c = 0
            for k in range(ks[j][0]):
                if (i>>(ks[j][k+1]-1))&1:
                    c += 1
            if c%2!=p[j]:
                flg = False
        if flg:
            ans += 1
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  ld A,B,H,M;
  cin>>A>>B>>H>>M;
   double pi = 3.141592653589793238;
  if(12<=H){
H-=12;
  }
  ld C=H*30+M/2-M*6;
  ld r=360-C;
  if(C<0){
    C*=-1;
  }
 if(r<0){
   C*=-1;
 }
    cout<<setprecision(15)<<fixed<<sqrt(A*A+B*B-2*A*B*cos(C/180*pi))<<endl;
}




Measured memory_bytes: 4148
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    ll N,i,j,k,ans;
    string S;
    cin>>N>>S;
    ans=0;

    for(i=0;i<N-2;i++){
        for(j=i+1;j<N-1;j++){
            for(k=j+1;k<N;k++){
                if(S[i]!=S[j]&&S[j]!=S[k]&&S[k]!=S[i]&&j-i!=k-j)ans++;
            }
        }
    }

    cout<<ans<<endl;
}

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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void func_to_create(){
    uint32_t N;
    cin >> N;
    N = (N % 10);
    switch(N){
        case 2:
            cout << "hon" << endl;
            break;
        case 3:
            cout << "bon" << endl;
            break;
        case 4:
            cout << "hon" << endl;
            break;
        case 5:
            cout << "hon" << endl;
            break;
        case 7:
            cout << "hon" << endl;
            break;
        case 9:
            cout << "hon" << endl;
            break;
        default:
            cout << "pon" << endl;
    }
}
int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 3;
    while(TEST_CASES--){
    #endif // DEBBUG

    func_to_create();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main(void) {
	int n, i, j, maxValue;
	int arr[1001][1001],dp[1001][1001];
	char c;

	while (cin >> n,n){
        memset(arr, 0, sizeof(arr));
		memset(dp, 0, sizeof(dp));

		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				cin >> c;
				if (c == '.') {
					arr[i][j] = 1;
				}
				else {
					arr[i][j] = 0;
				}
			}
		}

		maxValue = 0;
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				if (i == 0 || j == 0) {
					dp[i][j] = arr[i][j];
				}
				else if(arr[i][j] == 1)
				{
					dp[i][j] = min(min(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]) + 1;
				}
				maxValue = max(maxValue, dp[i][j]);
			}
		}

		cout << maxValue << endl;
	}

	return 0;
}




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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new SplittingPile();
			Instance.Exec();
		}
	}

	public class SplittingPile
	{
		public void Exec()
		{
			long n = long.Parse(Console.ReadLine());
			var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

			long sum = array.Sum();
			//Console.WriteLine($"{sum}");
			//int pivot = new Random().Next(n);

			long min = (long)int.MaxValue;
			long sunuke = array[0];
			long arai = sum - sunuke;
			long diff = Math.Abs(arai - sunuke);
			if (min > diff) {
				min = diff;
			}

			//Console.WriteLine($"{sunuke}, {arai}");

			for (var i = 1; i < n - 1; ++i) {
				sunuke += array[i];
				arai = sum - sunuke;
				diff = Math.Abs(arai - sunuke);
				if (min > diff) {
					min = diff;
				}

				//Console.WriteLine($"{i}, {sunuke}, {arai}");
			}

			Console.WriteLine($"{min}");

			Console.Out.Flush();

			Console.ReadLine();
		}
	}
}

Measured memory_bytes: 36672
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define INF 1145141919

int M, N;
int P[10100];
int C[510];
int E[510];
int dp[510][10100];

int main() {
  cin >> M >> N;
  for (int i=0; i<M; i++) cin >> P[i];
  for (int i=0; i<N; i++) cin >> C[i] >> E[i];

  for (int i=0; i<=N; i++) {
    for (int s=0; s<=M; s++) {
      dp[i][s] = INF;
    }
  }
  dp[0][0] = 0;
  for (int i=1; i<=N; i++) {
    for (int s=0; s<=M; s++) {
      int ns = min(M, s + C[i-1]);
      dp[i][ns] = min(dp[i][ns], dp[i-1][s] + E[i-1]);
      dp[i][s]  = min(dp[i][s], dp[i-1][s]);
    }
  }
  sort(P, P+M, greater<int>());
  int ans = 0;
  int p = 0;
  for (int s=1; s<=M; s++) {
    p += P[s-1];
    if (dp[N][s] == INF) continue;
    ans = max(ans, p - dp[N][s]);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 22980
#include <stdio.h>
#define N 1000000001
int L[500000],R[500000];
int count;
void X (int hi[],int n,int l,int m,int r);
void Y (int hi[],int n,int l,int r);
int main()
{
  int i,j,k;
  int hi[500000];
  scanf ("%d",&k);
  for (i=0;i<k;i++){
    scanf ("%d",&hi[i]);
  }
  Y(hi,k,0,k);
  for (i=0;i<k;i++){
    printf ("%d",hi[i]);
    if (i!=k-1)
      printf (" ");
  }
  printf ("\n");
  printf ("%d\n",count);
  return 0;
}
void X (int hi[],int n,int l,int m,int r){
  int s,t;
  int i=0,j=0,p;
  s=m-l;
  t=r-m;
  for(i=0;i<s;i++)
    L[i]=hi[l+i];
  for(i=0;i<t;i++)
    R[i]=hi[m+i];
  
  L[s]=N;
  R[t]=N;

  i=0, j=0;
  for (p=l;p<r;p++){
    count++;
    if (L[i]<=R[j]){
      hi[p]=L[i++];
    }else{
      hi[p]=R[j++];
    }
  }
}
void Y (int hi[],int n,int l,int r){
  int m;
  if (l+1<r){
    m=(l+r)/2;
    Y(hi,n,l,m);
    Y(hi,n,m,r);
    X(hi,n,l,m,r);
  }
}



Measured memory_bytes: 5692
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}

int main(){
fastio();


    ll n,m;
    cin>>n;
    ll arr[n];
    unordered_map<ll,ll>mp;
    ll sum=0;
    for(int i=0;i<n;i++) cin>>arr[i],mp[arr[i]]++,sum+=arr[i];
    cin>>m;

    while(m--)
    {
        ll a,b;
        cin>>a>>b;
        sum-= mp[a]*a;
        sum+=mp[a]*b;
        mp[b]+=mp[a];
        mp[a]=0;
        cout<<sum<<endl;
    }










return 0;
}



Measured memory_bytes: 7880
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def ceil(a,b):
    return a//b + int(a%b != 0)

N,K = LI()
A = LI()

ok = max(A)
ng = 0

while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    count = 0
    for i in range(N):
        count += ceil(A[i],mid)-1
    if count <= K:
        ok = mid
    else:
        ng = mid

print(ok)

Measured memory_bytes: 94228
#include<cstdio>
double dp[3005] = {1}, p;
int n;
int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%lf", &p);
    for(int j = i+1; j > 0; j--){
      dp[j] += (dp[j-1] - dp[j])*p;
    }
  }
  printf("%.10f", dp[(n+1)/2]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
ll gcd(ll a,ll b){
  if(b==0) return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

int main() {
    ll n,m;
    cin >>n >>m;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll c=0;
    ll d=a[0];
    while(d%2==0){
        c++;
        d=d/2;
    }
    bool result=true;
    rep1(i,n-1){
        ll cc=0;
        ll b=a[i];
        while(b%2==0){
            b=b/2;
            cc++;
        }
        if(c!=cc){
            result=false;
            break;
        }
    }
    ll g=1;
    rep(i,n)g=lcm(g,a[i]/2);
    if(result){
        ll ans=m/g;
        ans=(ans+1)/2;
        cout << ans;
    }
    else{
        cout << 0 ;
    }
}


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

struct FordFulkerson {
    struct Edge {
        int to, cap, rev;
    };

    const int INF = numeric_limits<int>::max();

    vector<vector<Edge>> G;
    vector<bool> used;

    FordFulkerson(int V) : G(V), used(V) {}

    void add_edge(int u, int v, int cap) {
        G[u].emplace_back((Edge) {v, cap, (int) G[v].size()});
        G[v].emplace_back((Edge) {u, 0, (int) G[u].size() - 1});
    }

    // find a path
    // v: current node, t: sink node, f: current flow
    int dfs(int v, int t, int f) {
        if (v == t) return f;
        used[v] = true;
        for (auto& e : G[v]) {
            if (!used[e.to] && 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;
    }

    // find the max flow from s to t
    int max_flow(int s, int t) {
        int flow = 0;
        while (true) {
            fill(used.begin(), used.end(), false);
            int f = dfs(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }
};

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

    int V, E;
    cin >> V >> E;
    FordFulkerson flow(V);
    for (int i = 0; i < E; i++) {
        int u, v, c;
        cin >> u >> v >> c;
        flow.add_edge(u, v, c);
    }
    cout << flow.max_flow(0, V - 1) << endl;
}


Measured memory_bytes: 3248
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = scanInt()
	}
	sort.Ints(A)
	A = append(A, 0)

	ans := 0
	cnt := 1
	for i := 1; i <= N; i++ {
		if A[i] == A[i-1] {
			cnt++
		} else {
			if A[i-1] > cnt {
				ans += cnt
			} else {
				ans += (cnt - A[i-1])
			}
			cnt = 1
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 5208
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

struct edge{
  int from;
  int to;
  long long int score;
};

int main()
{
  long long int N,M;
  cin >> N >> M;
  vector<struct edge>es(M);
  for(int i=0; i < M; i++){
    long long int a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    es[i].from = a;
    es[i].to = b;
    es[i].score = c;
  }

  long long int inf = 1000000000001;
  vector<long long int>s(N);
  for(int i=0; i < N; i++)
    s[i] = -inf;
  s[0] = 0;
  for(int j=0; j < N; j++){
    for(int i=0; i < M; i++){
      struct edge e = es[i];
      if(s[e.from] != -inf && s[e.to] < s[e.from] + e.score){
	s[e.to] = s[e.from] + e.score;
      }
    }
  }
  vector<bool>ne(N);
  for(int i=0; i < N+1; i++)
    ne[i] = false;
  for(int i=0; i < N; i++){
    for(int j=0; j < M; j++){
      struct edge e = es[j];
      if(s[e.from] == -inf)
	continue;
      if(s[e.to] < s[e.from] + e.score){
	s[e.to] = s[e.from] + e.score;
	ne[e.to] = true;
      }
      if(ne[e.from])
	ne[e.to] = true;
    }
  }

  if(ne[N-1])
    cout << "inf" << endl;
  else
    cout << s[N-1] << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;

int main(){
  int k,x;
  cin >> k >> x;
  int one = x-(k-1);
  rep(i,2*k-1){
    cout << one+i << " ";
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){

  int N, M, a, b;
  cin >> N >> M;

  vector<int> vec(N);

  for (int i = 0; i < M; i++){
    cin >> a >> b;
    vec.at(a-1) += 1;
    vec.at(b-1) += 1;
  }

  for (int i = 0; i < N; i++) {
    cout << vec.at(i) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
long y,m,d;
while(cin>>y){
cin>>m>>d;
if(y<1868){cout<<"pre-meiji"<<endl;continue;}
else if(y==1868){
if(m>10)cout<<"meiji 1";
else if(m==9&&d>7)cout<<"meiji 1";
else{cout<<"pre-meiji"<<endl;continue;}
}
else if(y<1912)cout<<"meiji "<<y-1867;
else if(y==1912){
if(m<7)cout<<"meiji 45";
else if(m>7)cout<<"taisho 1";
else{if(d<30)cout<<"meiji 45";else cout<<"taisho 1";}
}
else if(y<1926)cout<<"taisho "<<y-1911;
else if(y==1926){
if(m<12)cout<<"taisho 15";
else{if(d<25)cout<<"taisho 15";else cout<<"showa 1";}
}
else if(y<1989)cout<<"showa "<<y-1925;
else if(y==1989){
if(m==1){if(d<8)cout<<"showa 64";else cout<<"heisei 1";}
else cout<<"heisei 1";
}
else cout<<"heisei "<<y-1988;
cout<<" "<<m<<" "<<d<<endl;
}
return 0;
}

Measured memory_bytes: 1164
def func_sum_(fast, N):
    last = fast * int(N / fast)
    return int((fast + last) / 2. * (last / fast))
    
def main():
    args = input().rstrip().split(' ')
    N = int(args[0])
    sum_ = int((N+1) * N / 2)
    print(sum_ - (func_sum_(3, N) + func_sum_(5, N) - func_sum_(15, N)))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 9192
#include<stdio.h>
#define N 100

int main()
{
  int i,j,n,k=0,flag=1,temp;
  int A[N];
  int count=0;
  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }

  while(flag == 1){
    flag = 0;

    for(j = n-1 ; j >= k+1 ; j--){

      if(A[j] < A[j-1]){
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
	flag =1;
	count+=1;
      }
 }  
    if(flag == 1) k=+1;
  }
    for(i = 0 ; i < n-1 ; i++){
    printf("%d ",A[i]);
    }

    printf("%d\n%d\n",A[i],count);
    return 0;
}
 

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            string ans = "Balanced";
            if (p[0] + p[1] > p[2] + p[3]) { ans = "Left"; }
            else if (p[0] + p[1] < p[2] + p[3]) { ans = "Right"; }


            Console.WriteLine(ans);
            //Console.Out.Flush();

        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}


Measured memory_bytes: 13268
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <random>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(int i=0; i<(n); i++)
#define LLREP(i,n) for(LL i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define SORT(x) sort(ALL(x))
#define REVE(x) reverse(ALL(x))
#define MP make_pair
#define PB push_back
#define INF INT_MAX

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef queue<int> QI;
typedef long long LL;

int main() {
	string s, ans; cin >> s;
	VI a(5);
	VB op(4);
	REP(i, 4)a[i] = s[i] - '0';
	for (int bit = 0; bit < (1 << 3); bit++) {
		REP(i, 3) {
			if (bit&(1 << i))op[i] = true;	// +
			else op[i] = false;				// -
		}

		int x=a[0];
		REP(i, 3) {
			if (op[i])x += a[i + 1];
			else x -= a[i + 1];
		}
		if (x == 7) {
			ans.PB(s[0]);
			REP(i, 3) {
				if (bit&(1 << i))ans.PB('+');
				else ans.PB('-');
				ans.PB(s[i + 1]);
			}
			break;
		}
	}
	cout << ans << "=7" << endl;
}

Measured memory_bytes: 256
N = int(input())

if N == 2:
    print(-1)
    exit()
elif N == 3:
    print('a..')
    print('a..')
    print('.aa')
    exit()

ans = [['.'] * N for _ in range(N)]
u = [['a', 'a'], ['b', 'b']]
v = [['c', 'd'], ['c', 'd']]
if N % 4 == 0:
    for i in range(0, N, 2):
        for h in range(2):
            for w in range(2):
                ans[i+h][i+w] = u[h][w]
        for h in range(2):
            for w in range(2):
                ans[i+h][N-i-w-1] = v[h][w]
elif N % 4 == 1:
    for i in range(0, N//2 - 2, 2):
        for h in range(2):
            for w in range(2):
                ans[i+h][i+w] = u[h][w]
        for h in range(2):
            for w in range(2):
                ans[i+h][N-i-w-1] = v[h][w]
    for i in range(N//2 + 3, N, 2):
        for h in range(2):
            for w in range(2):
                ans[i+h][i+w] = u[h][w]
        for h in range(2):
            for w in range(2):
                ans[i+h][N-i-w-1] = v[h][w]
    a = [['c', 'c', 'd', 'd', 'e'], ['f', 'g', '.', '.', 'e'], ['f', 'g', '.', '.', 'h'],
         ['i', '.', 'k', 'k', 'h'], ['i', 'j', 'j', 'l', 'l']]
    i0 = N//2 - 2
    for h in range(5):
        for w in range(5):
            ans[i0 + h][i0 + w] = a[h][w]
elif N % 4 == 2:
    for i in range(0, N//2 - 3, 2):
        for h in range(2):
            for w in range(2):
                ans[i+h][i+w] = u[h][w]
        for h in range(2):
            for w in range(2):
                ans[i+h][N-i-w-1] = v[h][w]
    for i in range(N//2 + 3, N, 2):
        for h in range(2):
            for w in range(2):
                ans[i+h][i+w] = u[h][w]
        for h in range(2):
            for w in range(2):
                ans[i+h][N-i-w-1] = v[h][w]
    a = [['c', '.', 'd', 'd', 'e', 'e'], ['c', 'f', '.', 'g', 'g', '.'], ['h', 'f', '.', '.', '.', 'i'],
         ['h', '.', '.', '.', 'k', 'i'], ['.', 'j', 'j', '.', 'k', 'n'], ['l', 'l', 'm', 'm', '.', 'n']]
    i0 = N//2 - 3
    for h in range(6):
        for w in range(6):
            ans[i0 + h][i0 + w] = a[h][w]
elif N % 4 == 3:
    for i in range(0, N//2 - 3, 2):
        for h in range(2):
            for w in range(2):
                ans[i+h][i+w] = u[h][w]
        for h in range(2):
            for w in range(2):
                ans[i+h][N-i-w-1] = v[h][w]
    for i in range(N//2 + 4, N, 2):
        for h in range(2):
            for w in range(2):
                ans[i+h][i+w] = u[h][w]
        for h in range(2):
            for w in range(2):
                ans[i+h][N-i-w-1] = v[h][w]

    a = [['c', '.', '.', 'd', 'd', 'e', 'e'], ['c', 'f', '.', '.', 'g', 'g', '.'], ['h', 'f', 'i', '.', '.', '.', '.'],
         ['h', '.', 'i', '.', '.', '.', 'k'], ['.', '.', '.', 'j', 'j', 'm', 'k'], ['.', 'l', 'l', '.', '.', 'm', 'p'],
         ['n', 'n', 'o', 'o', '.', '.', 'p']]
    i0 = N//2 - 3
    for h in range(7):
        for w in range(7):
            ans[i0 + h][i0 + w] = a[h][w]

[print(''.join(ans[i])) for i in range(N)]


Measured memory_bytes: 48496
// #pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma vector temporal
// #pragma simd
// #pragma GCC diagnostic ignored "-W"

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>
#include<functional>
#include<complex>
#include<climits>

// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define MS(x,v) memset((x),(v),sizeof(x))
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)
#define CPPinput ios_base::sync_with_stdio(0); cin.tie(0)
#define FIN(fname) freopen(fname,"r",stdin)
#define FOUT(fname) freopen(fname,"w",stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define Yes cout<<"Yes"<<endl,exit(0)
#define No cout<<"No"<<endl,exit(0)

#ifdef WEAK
#include"/home/edison/Coding/cpp/template/debug.cpp"
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define DEBUG 1
#define exit(x) cout<<"exit code "<<x<<endl, exit(0)
#else
#define PDE(...) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>
#endif

void JIZZ(string output=""){cout<<output; exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

int c[100004];

int main(){
    CPPinput;
    set<int> st;
    int n; cin>>n;
    for(int i=0,t;i<n;++i){
        cin>>t;
        ++c[t]; 
        st.insert(t);
    }
    if(st.size()>2u)No;
    if(*--st.end()-*st.begin()>1)No;
    int low=*st.begin(),hi=*--st.end();
    if(low==hi){
        if(low==n-1)Yes;
        if(low<=n/2)Yes;
        No;
    }
    int cl=c[low],ch=c[hi];
    int cmin=cl+1,cmax=cl+ch/2;
    if(cmin<=low+1 && hi<=cmax)Yes;
    No;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n), miv(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    if (i >= 1) miv[i] = min(p[i], miv[i-1]);
    else miv[0] = p[0];
  }
  
  
  int ans = 1;
  for (int i = 1; i < n; ++i) {
   if (p[i] < miv[i-1]) {
     ++ans;
   }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;

void Main() {
    // input
    u_int32_t N;
    cin >> N;;

    vector<u_int32_t> nums(N);
    for (u_int32_t i = 0; i < N; i++) {
        cin >> nums[i];
    }

    sort(nums.begin(), nums.end());

    u_int32_t MAX_A = 1000000;
    bool dp[MAX_A + 1];
    for (int i = 1; i <= MAX_A; i++) {
        dp[i] = true;
    }

    u_int32_t pre_num = -1;

    for (int i = 0; i < nums.size(); i++) {
        // cout << "-" << nums[i] << "-" << endl;
        if (nums[i] == pre_num) {
            pre_num = nums[i];
            dp[nums[i]] = false;
            continue;
        }

        for (int j = 2 * nums[i]; j <= MAX_A; j += nums[i]) {
            // cout << j << endl;
            dp[j] = false;
        }
        pre_num = nums[i];
    }

    u_int32_t ans = 0;
    for (int i = 0; i < nums.size(); i++) {
        // cout << nums[i] << endl;
        if (dp[nums[i]]) {
            ans++;
            // cout << "true" << endl;
        } else {
            // cout << "false" << endl;
        }
    }


    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

#define ll long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define infl 1e18+9
#define sz(a) ((int)a.size())

const int nax=1e5+5; 
int mod; 
vector<int> adj[nax]; 
vector<int> dp(nax); 
vector<int> dp2(nax); 

void self_mul(int &a, int b){
  a=(ll)a*b%mod; 
}

void dfs2(int u, int p,int upper){
  vector<int> pre(sz(adj[u]),1),suf(sz(adj[u]),1); 
  int i=0; 
  for(int v:adj[u]){
    if(v!=p){
      self_mul(pre[i],dp[v]+1); 
      if(i>0)
      self_mul(pre[i],pre[i-1]); 
    }
    else {
      if(i>0)
      pre[i]=pre[i-1]; 
    }
    i++; 
  }
  for(int j=sz(adj[u])-1;j>=0;j--){
    int v=adj[u][j]; 
    if(v!=p){
      self_mul(suf[j],dp[v]+1); 
      if(j+1<sz(adj[u]))
      self_mul(suf[j],suf[j+1]);
    }
    else {
      if(j<sz(adj[u])-1){
        suf[j]=suf[j+1]; 
      }
    }
  }
  dp2[u]=dp[u]; 
  self_mul(dp2[u],upper+1); 
  i=0; 
  for(int v:adj[u]){
    if(v!=p){
      int num=upper+1; 
      if(i>0)
        self_mul(num,pre[i-1]); 
      if(i+1<sz(adj[u]))
        self_mul(num,suf[i+1]); 
      dfs2(v,u,num); 
    }
    i++; 
  }
}
void dfs1(int u,int p){
  dp[u]=1; 
  for(int v:adj[u]){
    if(v!=p){
      dfs1(v,u); 
      self_mul(dp[u],dp[v]+1); 
    }
  }
}
void solve(){
  int n,m; cin>>n>>m; 
  mod=m; 
  for(int i=1;i<n;i++){
    int u,v; cin>>u>>v; 
    adj[u].push_back(v); 
    adj[v].push_back(u); 
  }
  dfs1(1,0); 
  dfs2(1,0,0); 
  for(int i=1;i<=n;i++){
    cout<<dp2[i]<<endl; 
  }
}

int main()
{
	fast_io;
	clock_t beg=clock(); 
	solve(); 
	clock_t end=clock(); 
	fprintf(stderr,"%.2lf sec\n",(double)(end-beg)/CLOCKS_PER_SEC); 
	return 0;
}

Measured memory_bytes: 18816
# B - Picture Frame
def main():
    h, w = map(int, input().split())

    for i in range(h):
        a = input()

        if i == 0:
            print(('#'*w)+'##')
            print('#'+a+'#')
        else:
            print('#'+a+'#')
    else:
        print(('#'*w)+'##')


if __name__ ==  "__main__":
    main()

Measured memory_bytes: 9052
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X Fi
#define Y Se

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef double D;

/* const */
const int INF = 999999999;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* class */
class P {
  public:
    D x, y;
    P(D x, D y) { this->x = x; this->y = y; }
    P operator+ (P a) { return P(this->x + a.x, this->y + a.y); }
    P operator- (P a) { return P(this->x - a.x, this->y - a.y); }
};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
inline D dot(P a, P b) { return a.x * b.x + a.y * b.y; }
inline D cross(P a, P b) { return a.x * b.y - a.y * b.x; }
template <typename T> void print(T x) { std::cout << x << '\n'; }
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int n = in();
  while (n-- >= 0) {
    getline(cin, s);
    string t = s;
    RREP(i, 26) {
      RREP(j, 26) {
        if (t.find("that") != -1 || t.find("this") != -1) {
          print(t);
          goto NEXT;
        }
        REP(k, s.size()) {
          if (isalpha(s[k])) {
            t[k] = (i * (s[k] - 'a') + j) % 26 + 'a';
          }
        }
      }
    }
NEXT:;
  }

  return 0;
}

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

namespace ConsoleApp1 {
    public class Class {
        static void Main(string[] args) {
            var a = int.Parse(Console.ReadLine());
            Console.Write(a + Math.Pow(a, 2) + Math.Pow(a, 3));
        }
    }
}

Measured memory_bytes: 27776
#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
using boost::adaptors::reversed;
namespace rng { using namespace boost; using namespace boost::range; }
struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
constexpr auto color_s_ = "\033[2m\033[33m", color_e_ = "\033[0m";
template<class T> void trace_(const T& v) { cerr << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cerr << "\n"; for (const auto& v : m) { trace_(v); cerr << "\n"; } }
template<class T> void trace_(const char* s, const T& v) { cerr << color_s_ << s << "="; trace_(v); cerr << color_e_ << "\n"; cerr.flush(); }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { cerr << color_s_; for (; *s != ','; ++s) { cerr << *s; } cerr << "="; trace_(v); cerr << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    int m = *rng::max_element(a);
    int r = 0;
    for (int ai : a) {
        if (ai == m) continue;
        if (abs(m - 2 * r) > abs(m - 2 * ai)) {
            r = ai;
        }
    }
    cout << m << " " << r << nl;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//#define ll long long
#define eps 1e-9
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int mask[4][2] = { {1, 0},{-1, 0},{0, 1},{0, -1} };
vector<set<int>>g;
vector<string>v;
vector<vector<int>>u;
int cnt = 1;
int h, w, ch, cw, dh, dw;

bool inrange(int x, int y) {
	return x >= 0 && y >= 0 && x < h && y < w;
}

void dfs(int x, int y) {
	u[x][y] = cnt;
	for (int i = 0; i < 4; ++i) {
		int nx = x + mask[i][0], ny = y + mask[i][1];
		if (inrange(nx, ny) && !u[nx][ny] && v[nx][ny] == '.')
			dfs(nx, ny);
	}
}

int main() {
	speed;
	cin >> h >> w >> ch >> cw >> dh >> dw;
	--ch, --cw, --dh, --dw;
	v.resize(h), u.resize(h, vector<int>(w));
	for (int i = 0; i < h; ++i)
		cin >> v[i];

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j)
			if (v[i][j] == '.' && !u[i][j]) {
				dfs(i, j);
				cnt++;
			}
	}

	g.resize(cnt);
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j)
			if (u[i][j])
				for (int k = i - 2; k < i + 3; ++k)
					for (int l = j - 2; l < j + 3; ++l)
						if (inrange(k, l) && u[k][l] && u[i][j] != u[k][l])
							g[u[k][l]].insert(u[i][j]), g[u[i][j]].insert(u[k][l]);
	}

	queue<int>q;
	q.push(u[ch][cw]);
	vector<int>d(cnt, -1);
	d[u[ch][cw]] = 0;
	while (!q.empty()) {
		int a = q.front();
		q.pop();
		for (auto to : g[a]) {
			if (d[to] == -1) {
				d[to] = d[a] + 1;
				q.push(to);
			}
		}
	}
	cout << d[u[dh][dw]];
}

Measured memory_bytes: 30132
while 1:
    r,w,c,a = map(int,raw_input().split())
    if r == w == c == a == 0:
        break
    b = 0
    sum = 0
    if r / c >= w:
            b = 1
    while b == 0:
        sum += 1
        r += a
        if r/c>=w:
            b = 1
    print sum

Measured memory_bytes: 6384
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long r = sc.nextLong();
      System.out.println(3*r*r);
    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}

Measured memory_bytes: 21972
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        
        if(n<=k){
            System.out.println(0);
            return;
        }
        
        for(int i=0; i<n; i++){
            h[i] = sc.nextInt();
        }
        
        Arrays.sort(h);
        long ans = 0;
        
        for(int i=n-1-k; i>=0; i--){
            ans+=h[i];
        }
        
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 60576
#include <iostream>
using namespace std;
int main(void){
    int a[55]={11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381};
    int N; cin>>N;
    for(int i=0;i<N-1;i++){
        cout<<a[i]<<" ";
    }
    cout<<a[N-1]<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramD
    {
        static void Main()
        {
            long x = NextLong;
            for (long a = 1000; a >= -1000; a--)
            {
                for (long b = 1000; b >= -1000 ; b--)
                {
                    if (a * a * a * a * a == b * b * b * b * b + x)
                    {
                        System.Console.WriteLine($"{a} {b}");
                        return;
                    }
                }
            }
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 27724
#include <stdio.h>
 
int main(void)
{
  int n;
  scanf("%d", &n);
  
  for(int i=0; i<=10; i++) {
	if(n>i*1000) {
    } else {
      printf("%d", (i*1000)-n);
      break;
    }
  }
}

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

int main()
{
    int i, n;
    int array[200];
    int ma = 0;
    int mi = 0;

    scanf("%d", &n);

    for(i = 0; i < n; i++)
      scanf("%d", &array[i]);

    ma = array[0];
    mi = array[0];

    for(i = 0; i < n; i++)
      ma = max(ma, array[i]);

    for(i = 0; i < n; i++)
      mi = min(mi, array[i]);

    printf("%d\n", ma - mi);

    return 0;
}


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

using namespace std;
typedef long long ll;




int main()
{
    
    int N;cin >> N;
    for (int i = 1; i <= 9; i++) {
        if (i+i*10+i*100 >= N) {
            cout << i+i*10+i*100 << endl;
            break;
        }
    }
    
    
    return 0;
}




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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int a; cin >> a;
    cout << 1-a << endl;
    return 0;
}

Measured memory_bytes: 3632