akhauriyash/Code-Regression huggingface dataset:
// Created by Tanuj Jain
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int recursive_min_cost(vector<int>&v,int end,int &ans)
{
	//cout<<"call:"<<end<<endl;
	if(end==0)
		return 0;
	if(end<0)
		return 1e6;
	//find left child ans
	//int ans=0;
	int left_child=recursive_min_cost(v,end-1,ans);
	int right_child=recursive_min_cost(v,end-2,ans);
	//find the current answer
	ans=min(left_child+abs(v[end]-v[end-1]),right_child+abs(v[end]-v[end-2]));
	//cout<<ans<<endl;
	return ans;

}
int top_down(vector<int>&v,int end, int &ans, unordered_map<int,int>&memo)
{
	//cout<<end<<endl;
	if(end==0)
		return 0;
	if(end<0)
		return 1e6;
	//find left child ans
	//int ans=0;
	if(memo.find(end)==memo.end())
	{
		int left_child=top_down(v,end-1,ans,memo);
		int right_child=top_down(v,end-2,ans,memo);
		//find the current answer
		ans=min(left_child+abs(v[end]-v[end-1]),right_child+abs(v[end]-v[end-2]));
		memo[end]=ans;
		//cout<<ans<<endl;
		return ans;
	}
	else
		return memo[end];
	
}
int main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	//#ifndef ONLINE_JUDGE
	//freopen("inputf.in","r",stdin);
	//freopen("outputf.in","w",stdout);
	//#endif

	int t;
	cin>>t;
	vector<int>v(t); 
	for(int i=0;i<t;i++)
		cin>>v[i];
	int ans=0;
	//recursive_min_cost(v,t-1,ans);

	//top down dp with memoization
	unordered_map<int,int>memo;
	top_down(v,t-1,ans,memo);
	//for(auto it:memo)
	//	cout<<it.first<<" "<<it.second<<endl;
	cout<<ans;
	
}

Measured memory_bytes: 11044
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B;
    cin >> A >> B;

    int ans = A + B;
    int tmp = A - B;
    ans = max(ans, tmp);
    tmp = A * B;
    ans = max(ans, tmp);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    readint;
    auto a = readints;

    auto dp = new long[a.length];
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for (int i = 2; i < a.length; i++) {
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]),
                    dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    writeln(dp[a.length - 1]);
}


Measured memory_bytes: 4384
h,w = map(int,input().split())
A = [input() for _ in range(h)]
for i in range(h):
  #print(A[i])
  A[i] =  "#" + A[i] +"#"
  #print(A[i])
for i in range(h + 2):
  if i == 0:
    print("#"*(w + 2))
  elif i == h + 1:
    print("#"*(w + 2))
  else:
    print(A[i - 1])

Measured memory_bytes: 3064
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8,i8[:],i8[:])", cache=True)
def binary_search(K, A, F):
    """Meguru type binary search"""
    ng = -1
    ok = A[-1] * F[0]

    def is_ok(A, F, K, x):
        count = 0
        for a, f in zip(A, F):
            count += max(0, a - x // f)
        return count <= K

    while (ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(A, F, K, mid):
            ok = mid
        else:
            ng = mid

    return ok


def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)
    F = np.array(input().split(), dtype=np.int64)

    A.sort()
    F[::-1].sort()

    ans = binary_search(K, A, F)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 131288
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<math.h>
using namespace std;
  

int main(){
    string S;
    cin >> S;
    if(S=="ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
    
    
    return 0;
    
    
    
    
    
    
}


Measured memory_bytes: 3600
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <ctime>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#pragma comment(linker, "/STACK:256000000")
using namespace std;

#define in(s) freopen(s, "r", stdin)
#define out(s) freopen(s, "w", stdout)
#define forn(i, n) for (int i = 0; i < n; i++)
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef long double ld;

int main()
{
	//in("input.txt");
	//out("output.txt");
	srand(1373737);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	string s;
	cin >> n >> s;

	int ans = 0;
	for (int i = 0; i < n - 2; i++) {
		if (s.substr(i, 3) == "ABC")
			ans++;
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 256
input = Array.new(5){gets.to_i}
ans = []
 
def calc(w)
  tmp = w%10
  return tmp==0 ? 0 : (10-tmp)
end
 
input.permutation(5).to_a.each do |ary|
  ans << ary.inject([]) {|memo, w|
    memo + [w, calc(w)]
  }[0..-2].map.inject(:+)
end
 
p ans.min

Measured memory_bytes: 1788
//	ZapZu's code hohoho
//	#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef double db;
typedef long long li;
typedef long double ld;

typedef pr<int, int> ii;
typedef pr<ld,ld> dd;

typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;

typedef set<int> s_i;
typedef set<char> s_c;

const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
int n, c;
int solve(int x[], int v[])
{
	int ans=0;
	int dp[n+1];
	int curr=0;
	for(int i=n+1; i>=1; i--)
	{
		if(i<=n) curr+=v[i];
		if(i==n+1) dp[i]=0;
		else dp[i]=max(dp[i+1], curr-(c-x[i]));
//		cout<<dp[i]<<" ";
	}
	curr=0;
	for(int i=0; i<=n; i++)
	{
		if(i) curr+=v[i];
		ans=max(ans, curr-2*x[i]+dp[i+1]);
	}
	return ans;
}
signed main()
{
//	freopen(".inp", "r", stdin);
//	freopen(".out", "w", stdout);
	cin>>n>>c;
	int x[n+1], v[n+1];
	x[0]=v[0]=0;
	for(int i=1; i<=n; i++)
	{
		cin>>x[i]>>v[i];
	}
	int ans=solve(x, v);
	for(int i=1; i<=n; i++)
	{
		x[i]=c-x[i];
	}
	reverse(x+1, x+n+1);
	reverse(v+1, v+n+1);
	ans=max(ans, solve(x, v));
	cout<<ans;
}




Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  constexpr lint c = 1e9;
  lint s; cin >> s;
  if (s == c * c) {
    cout << "0 0 " << c << " 0 0 " << c << '\n';
  } else {
    int y = s / c;
    cout << s % c << " 0 0 " << y << ' ' << c << ' ' << y + 1 << '\n';
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n  = sc.nextInt();
        int wm = sc.nextInt();

        int[] w     = new int[n];
        long[] v    = new long[n];
        long[][] dp = new long[n + 1][wm+1];
        
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
            v[i] = sc.nextLong();
        }
        
        for (int i = 0; i < n; i++) {
            for (int a = 0; a < wm; a++) {
                dp[i+1][a] = Math.max(dp[i+1][a], dp[i][a]);
                
                if (a + w[i] <= wm) {
                   dp[i + 1][a + w[i]] = Math.max(dp[i + 1][a + w[i]], dp[i][a] + v[i]);
                }
            }
        }
        
        long max = 0;
        for (long aaa : dp[n]) {
            if (max < aaa) max = aaa;
        }
        System.out.println(max);
    }
}


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

int main() {
  int N,M;
  scanf("%d %d", &N,&M);
  int P[M],Y[M];
  vector<pair<pair<int,int>,int>> cities;
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", &P[i],&Y[i]);
    cities.push_back(make_pair(make_pair(Y[i], P[i]), i));
  }

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

  vector<int>num(M), cnt(N+1);

  for (int i = 0; i < cities.size(); ++i){
    ++cnt[cities[i].first.second];
    num[cities[i].second] = cnt[cities[i].first.second];
  }

  for (int i = 0;i < M;++i) printf("%06d%06d\n", P[i],num[i]);
  


  

}



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

int main(void){
    int l, r, d;
    cin >> l >> r >> d;
    int cnt = 0;
    for(int i = l; i <= r; ++i)
        if(i % d == 0) ++cnt;
    cout << cnt << endl;
    return 0;
}

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

typedef long long int ll;

int main()
{
	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	int ans=(h2-h1)*60+m2-m1-k;
	cout<<ans<<endl;
}


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

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define MAXN 100013
#define LLINF 2696969696969696969

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, M;
pair<pii, ll> arr[MAXN];
vpi edges[MAXN];
ll fen[MAXN], dist[MAXN];
ll ans;
bitset<MAXN> done;

void update(int idx, ll v)
{
    for (int e = idx + 1; e <= N; e += e & (-e))
    {
        ckmin(fen[e], v);
    }
}
ll query(int idx)
{
    ll res = LLINF;
    for (int e = idx + 1; e; e -= e & (-e))
    {
        ckmin(res, fen[e]);
    }
    return res;
}


int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N >> M;
    FOR(i, 0, M)
    {
        int l, r, d;
        cin >> l >> r >> d; l--; r--;
        edges[l].PB({r, d});
        //anybody in [l...r] can go to anybody else in [l...r] with cost c.
    }
    FOR(i, 0, N + 1) fen[i] = LLINF;
    update(N - 1, 0);
    FOR(i, 0, N)
    {
        dist[i] = query(N - i - 1);
        for (pii p : edges[i])
        {
            update(N - 1 - p.fi, dist[i] + p.se);
        }
    }
    cout << (dist[N - 1] >= LLINF ? -1 : dist[N - 1]) << '\n';
    return 0;
    //in each node of the segtree you store the edges: given that you're in this range, you can go to anywhere in p with cost c.
    //each edge gets put in O(logN) nodes, but only processed the first time?
}


Measured memory_bytes: 7424
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    LL X;
    cin >> X;
    LL l = 0;
    LL r = X;
    LL m;
    while (l <= r)
    {
        m = (l + r) / 2;
        if ((m * (m + 1)) / 2 <= X)
        {
            l = m + 1;
        }
        else
        {
            r = m - 1;
        }
    }
    m = (l + r) / 2;
    if ((m * (m + 1)) / 2 < X) ++m;
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 256
#include <math.h>
int main(void){
    double a,b,angle;
    
    scanf("%lf %lf %lf",&a,&b,&angle);
    
    printf("%f\n",a*b*sin(angle/180*M_PI)/2);
    printf("%f\n",a+b+sqrt(a*a+b*b-2*a*b*cos(angle/180*M_PI)));
    printf("%f\n",b*sin(angle/180*M_PI));
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,k ,x,y,cnt=0;
    cin>>n>>k>>x>>y;
    if(k<=n)
         cout<<k*x+(n-k)*y<<endl;
    else
        cout<<x*n<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

int main() {

	int a[100];
	int N;
	
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	for (int j = 0; j < N; j++) {
		if (a[j] % 2 == 0) {
			if (a[j] % 3 != 0 && a[j] % 5 != 0) {
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;


	return 0;
}

Measured memory_bytes: 256
INF = (10 ** 9 + 7)
L = gets.chomp.to_s
dp_not_tight = 1
dp_tight = 2
L[1..-1].each_char.with_index do |char, index|
  if char == "0"
    dp_not_tight *= 3
  else
    dp_not_tight = dp_not_tight * 3 + dp_tight
    dp_tight *= 2
  end
end
puts (dp_not_tight + dp_tight) % INF

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






int main(){


  int n,m;
  cin>>n>>m;
  
  vector<int> data(m);
  
  for (int i=0;i<m;i++){
    int tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  sort(data.begin(),data.end());
  
  vector<int> dis(m-1);
  
  for (int i=0;i<m-1;i++){
    dis.at(i)=data.at(i+1)-data.at(i);
  }
  
  sort(dis.begin(),dis.end());
  
  
  
  
  int answer=0;
  
  if (n>=m){
    answer=0;
  }

  
  else {
    for (int i=0;i<m-n;i++){
      answer+=dis.at(i);
    }
  }
  
  cout<<answer<<endl;
  
    
  
  

  

        
}

Measured memory_bytes: 1024
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}



int solve(int b , int n){
    int res = 0;
    while(n > 0){
        res += n % b;
        n /= b;
    }
    return res;
}

signed main(){
    int n,s;
    cin >> n >> s;
    if(n == s){
        cout << n + 1 << endl;
        return 0;
    }

    int b = 2;
    int ans = INF;
    if(n < 100){
        while(1){
            if(solve(b,n) == s){
                cout << b << endl;
                return 0;
            }
            b ++;
            if(b > n + 1){
                cout << - 1 << endl;
                return 0;
            }
        }
    }

    while(1){
        if( (b -1 ) * (b - 1) > n ) break;
        if(solve(b,n) == s){
            cout << b << endl;
            return 0;
        }
        b ++;
    }

    ans = INF;
    int shou = 1;
    while( (shou + 1) * (shou + 1) < n) shou++;
    while(shou > 0){
        int amari = s - shou;
        if( amari >= 0 and (n - amari) % shou  == 0){
            b = (n - amari) / shou;
            if(amari < b and shou < b){
                chmin(ans,b);
            }
        }
        shou --;
    }
    
    if(ans == INF) cout << - 1 << endl;
    else cout << ans << endl;

}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;


int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < w + 2; i++) {
        cout << '#';
    }
    cout << endl;
    for (int i = 0; i < h; i++) {
        cout << '#' << s[i] << '#' << endl;
    }
    for (int i = 0; i < w + 2; i++) {
        cout << '#';
    }
    cout << endl;
}


Measured memory_bytes: 256
main(){
	double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;
	for(;~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&xa1,&ya1,&xa2,&ya2,&xb1,&yb1,&xb2,&yb2);){
		if(xa2<xb1 || xb2<xa1 || ya2<yb1 || yb2<ya1)	puts("NO");
		else	puts("YES");
	}
	exit(0);
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void)
{
	int H, W, i, j, k;

	for (;;)
	{
		scanf("%d %d", &H, &W);

		if (H != 0 && W != 0)
		{
			for (i = 0; i < W; i++)
			{
				printf("#");
			}
			printf("\n");

			for (k = 0; k < H - 2; k++)
			{
				printf("#");
				for (j = 0; j < W - 2; j++)
				{
					printf(".");
				}
				printf("#\n");
			}

			for (i = 0; i < W; i++)
			{
				printf("#");
			}
			printf("\n\n");
		}
		else
		{
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <math.h>

using namespace std;
int main(){
    int i,count=1,A,B;
   
    cin >> A;
    cin >> B;

    for(i=0;;i++){
        if(count < B){
            count += (A-1);
        }
        else{
            break;
        }
    }

    cout << i << endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
char s[1005][1005];
int f[1005][1005],g[1005][1005],n,m;
inline int Min(int a,int b){return a<b?a:b;}
int main(){
	int i,j,ans=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)scanf("%s",s[i]+1);
	memset(f,0x3f,sizeof(f));
	memset(g,0x3f,sizeof(g));
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j){
			if(s[i][j]=='.')f[i][j]=Min(f[i-1][j],f[i][j-1])+1;
			else f[i][j]=0;
			g[i][j]=Min(g[i][j],f[i][j]);
		}
	memset(f,0x3f,sizeof(f));
	for(i=1;i<=n;++i)
		for(j=m;j;--j){
			if(s[i][j]=='.')f[i][j]=Min(f[i-1][j],f[i][j+1])+1;
			else f[i][j]=0;
			g[i][j]=Min(g[i][j],f[i][j]);
		}
	memset(f,0x3f,sizeof(f));
	for(i=n;i;--i)
		for(j=1;j<=m;++j){
			if(s[i][j]=='.')f[i][j]=Min(f[i+1][j],f[i][j-1])+1;
			else f[i][j]=0;
			g[i][j]=Min(g[i][j],f[i][j]);
		}
	memset(f,0x3f,sizeof(f));
	for(i=n;i;--i)
		for(j=m;j;--j){
			if(s[i][j]=='.')f[i][j]=Min(f[i+1][j],f[i][j+1])+1;
			else f[i][j]=0;
			g[i][j]=Min(g[i][j],f[i][j]);
		}
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)if(g[i][j]>ans)ans=g[i][j];
	printf("%d\n",ans);
	return 0;
}

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

typedef long long ll;

const int INF = 100000000;

int main() {
    int N;
    int ans = 0;
    cin >> N;
    for (int i = 1; i <= N; i += 2) {
        int cnt = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) {
                cnt++;
            }
        }
        if (cnt == 8) {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import sys 

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

ans = sys.maxsize 
for i in range(N-K+1):
  ans = min(ans, 
          abs(x[i])+abs(x[i+K-1]-x[i]), 
          abs(x[i+K-1])+abs(x[i]-x[i+K-1]))

print(ans)

Measured memory_bytes: 14384
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdlib>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=true;

int main(){
  int n;
  string s[10]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};

  cin>>n;
  for(int i=0;i<n;i++){
    //cout<<"DEBUG"<<endl;
    string ss;
    cin>>ss;
    int cnt=0;
    for(int j=0;j<ss.size();j++){
      if(ss[j]=='0'&&cnt!=0){
	int x=int(ss[j-1])-48;
	//cout<<x<<endl;
	cout<<s[x][(cnt-1)%int(s[x].size())];
	cnt=0;
      }else if(ss[j]=='0'&&cnt==0){
	cnt=0;
      }else{
	cnt++;
      }
    }
    cout<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%(m))
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int K;
int A, B;

int main() {

    cin >> K;
    cin >> A >> B;

    for (int i = 0; i * K <= B; ++i) {
        if (A <= i*K && i*K <= B) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;

    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;

const double PI=acos(-1.0);

int N,M; vi X;
void input()
{
    cin>>N>>M;
    for(int i=0;i<M;++i){
        int a; cin>>a; X.emplace_back(a);
    }
}

void solve()
{
    sort(X.begin(),X.end());
    vi sa;
    for(int i=0;i<M-1;++i) sa.emplace_back(X[i+1]-X[i]);
    sort(sa.begin(),sa.end());
    vi ans(M,0);
    for(int i=1;i<M;++i) ans[i]=ans[i-1]+sa[i-1];
    cout<<ans[((M-N>=0)?(M-N):0)]<<endl;
}

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

Measured memory_bytes: 4628
function Main(input) {
  input = input.split(' ')
  const A = parseInt(input[0])
  const B = parseInt(input[1])

  var answer = 0

  if (A + B > A - B && A + B > A * B) {
    answer = A + B
  } else if (A - B > A * B) {
    answer = A - B
  } else {
    answer = A * B
  }

  console.log(answer)
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7500
N, M = list(map(int, input().split()))
start = set([])
end = set([])
for i in range(M):
    a, b = list(map(int, input().split()))
    if a == 1 or b == 1:
        start.add(a*b)
    if a == N or b == N:
        end.add(a * b / N)
flag = 0
for i in start:
    if i in end:
        print("POSSIBLE")
        flag = 1
        break
if not(flag):
    print("IMPOSSIBLE")


Measured memory_bytes: 18212
N = int(input())
A = input()
B = input()
C = input()

count = 0

for i in range(N):
    if A[i] == B[i] == C[i]:
        count += 0
    elif A[i] == B[i] or A[i] == C[i] or B[i] == C[i]:
        count += 1
    else:
        count += 2

print(count)

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
   long int a[1000],n,k,max=0,count=0,i,min=9999;
   scanf("%ld%ld",&n,&k);
  i=(n+k<10)?1:0;
  if(i==0)
  {
      printf("error");
  }else{
      printf("%ld",n+k);
  }
    return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": "
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;

void Search(int l, int r, int& x, vector<ll>& sum) {
	ll s = sum[r]+sum[l];
	int idx = lower_bound(sum.begin(), sum.end(), s / 2) - sum.begin();
	if (abs(s / 2 - sum[idx - 1]) < abs(s / 2 - sum[idx])) {
		x = idx - 1;
	}
	else x = idx;
}

int main() {
	int n; cin >> n;
	vector<ll> a(n),sum(n+1,0);
	rep(i, 0, n) cin >> a[i];
	rep(i, 0, n) {
		sum[i + 1] = sum[i] + a[i];
	}
	ll ans = INF;
	rep(i, 2, n-1) {
		int f; Search(0, i, f, sum);
		ll lmax = max(sum[i] - sum[f], sum[f] - sum[0]);
		ll lmin = min(sum[i] - sum[f], sum[f] - sum[0]);
		int g; Search(i, n, g, sum);
		ll rmax = max(sum[g] - sum[i], sum[n] - sum[g]);
		ll rmin = min(sum[g] - sum[i], sum[n] - sum[g]);
		ans = min(ans, max(lmax, rmax) - min(lmin, rmin));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
n=int(input())
a=list(map(str,input().split()))
import copy
b=copy.copy(a)
k=copy.copy(a)
for i in range(n):
	for j in range(n-1,i,-1):
		if int(a[j][1])<int(a[j-1][1]):
			a[j],a[j-1]=a[j-1],a[j]
for i in range(n):
	mini=i
	for j in range(i,n):
		if int(b[j][1])<int(b[mini][1]):
			mini=j
	b[i],b[mini]=b[mini],b[i]
print(*a)
print("Stable")
print(*b)
r=True
for i in range(n):
	if not r:
		break
	for j in range(i+1,n):
		for aa in range(n):
			for bb in range(aa+1,n):
				if k[i][0]==k[j][0] and k[i]==b[bb] and k[j]==a[aa]:
					r=False
					break
if r==False:
	print("Not stable")
else:
	print("Stable")




Measured memory_bytes: 6344
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
int main()
{
  string s;
  cin>>s;
  int n=s.size();
  vector<int>L = lcp_array(s, suffix_array(s));
  cout<<1ll*n*(n+1)/2-accumulate(L.begin(),L.end(),0LL);
}

Measured memory_bytes: 15692
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
        int n, t;
        vector<int> vt;
        int m, p, x;
        int sum = 0;

        cin >> n;
        for (int i = 0; i < n; i++) {
                cin >> t;
                vt.push_back(t);
                sum += t;
        }
        cin >> m;
        for (int i = 0; i < m; i++) {
                cin >> p >> x;
                cout << sum - (vt[p-1] - x) << endl;
        }

        return 0;
}


Measured memory_bytes: 256
# coding:utf-8

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
# print(c)
black = 0
H = []
W = []
ans = 0

for bit_h in range(2**h):
    for bit_w in range(2**w):
        black = 0
        for i in range(h):
            if not ((bit_h >> i) & 1):
                continue
            for j in range(w):
                if not ((bit_w >> j) & 1):
                    continue
                if c[i][j] == '#':
                    black += 1
        if black == k:
            ans += 1
print(ans)


Measured memory_bytes: 8880
//1-indexedは混乱するので、0-indexedで考える.
#include <iostream>
#define int long long
using namespace std;

int n, k;

signed main() {
	int j, i;
	int ans = 0;
	
	cin >> n >> k;
	
	for (j = 1; j <= 5; j++) {
		for (i = 1; ; i++) {
			int num = i * 7 + j + 1;
			int ssum = num * 9;
			if (ssum % 11 == k) {
				break;
			}
		}
		if (i >= n - 1) { continue; }
		
		//i行j列目を(i,j)と書くと, 中心=(i+11の倍数, j)としたときが条件を満たす
		ans += (n - 2 - i) / 11 + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// AtCoder template
// 見た奴全員saba!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int h,w; cin >> h >> w;
    int a[h][w]; rep(i,h) rep(j,w) cin >> a[i][j];
    
    queue<pair<int,int>> que;
    rep(i,h) rep(j,w){
        if(i%2 == 0) que.emplace(i,j);
        else que.emplace(i,w-j-1);
    }

    int n = 0;
    queue<pair<int,int>> que1,que2;
    while(!que.empty()){
        int y = que.front().first, x = que.front().second;
        que.pop();
        if(a[y][x]%2 == 0) continue;
        if(que.empty()) break;

        int ny = que.front().first, nx = que.front().second;
        a[ny][nx]++;
        n++;
        que1.emplace(y+1,x+1);
        que2.emplace(ny+1,nx+1);
    }

    cout << n << endl;
    while(!que1.empty()){
        cout << que1.front().first << " " << que1.front().second << " ";
        cout << que2.front().first << " " << que2.front().second;
        cout << "\n";
        que1.pop(); que2.pop();
    }
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
int main()
{	
	int n;
	cin>>n;
	vector<pair<int,int> >pi[n];
	for(int i=0;i<n;i++){
		int num;cin>>num;
		for(int j=0;j<num;j++){
			int x,y;cin>>x>>y;
			pi[i].emplace_back(x,y);
		}
	}
	int num=0;
	for(int i=0;i<(1<<n);i++){
		vector<int>t;
		for(int j=0;j<n;j++){
			if((i>>j)&1){
				t.push_back(j);
			}
		}
		for(int j=0;j<t.size();j++){
			for(auto it:pi[t[j]]){
				if(it.second==1){
					if(find(t.begin(),t.end(),it.first-1)==t.end()){
						 goto cc;
					}
				}
				else{
					if(find(t.begin(),t.end(),it.first-1)!=t.end()){
						goto cc;
					}
					
				}
			}
		}
		num=max((int)t.size(),num);
		cc:
			continue;
	}
	cout<<num<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
	const int M = 11 * 7 * 5 * 3 * 3 * 2 * 2 * 2 * 2;
	int n, d, t, q;
	while(scanf("%d", &n), n){
		int v[25][24] = {};
		for(int i = 0; i < n; ++i){
			scanf("%d%d", &d, &t);
			for(int j = 0; j < d; ++j){
				scanf("%d", &q);
				v[d][(j + d - t) % d] += q;
			}
		}
		int ans = 0;
		int s[M] = {};
		for(int i = 1; i <= 24; ++i){
			if(i == 13 || i == 17 || i == 19 || i == 23){
				ans += *max_element(v[i], v[i] + i);
			}
			else{
				for(int j = 0; j < M; ++j){
					s[j] += v[i][j % i];
				}
			}
		}
		ans += *max_element(s, s + M);
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1252
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<57;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

int n;

int main(){
	cin>>n;
	int tmp=1;
	ll res=0;
	for(int i=0;i<n;i++){
		int A;
		cin>>A;
		if(tmp==1){
			res+=A-1;
			tmp++;
		}
		else if(A==tmp) tmp++;
		else if(A>tmp) res+=(A-1)/tmp;
	}
	cout<<res<<endl;
}

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

int main(){
    int N;
    cin >> N;
    queue<int> que[N+1];
    queue<int> que2[N*N+1];
    rep2(i, 1, N+1){
        que2[0].push(i);
    }
    int a[N-1];
    rep2(i, 1, N+1){
        rep(j, N-1){
            cin >> a[j];
            que[i].push(a[j]);
        }
    }
    bool check[N+1];
    long long res = 0;
    while(true){
        rep2(i, 1, N+1){
            check[i] = true;
        }
        int cnt = 0;
        while(!que2[res].empty()){
            int i = que2[res].front();
            que2[res].pop();
            if(!que[i].empty()){
                int j = que[i].front();
                if(que[j].front() == i && check[i] && check[j]){
                    cnt++;
                    check[i] = false;
                    check[j] = false;
                    que[i].pop();
                    que[j].pop();
                    que2[res+1].push(i);
                    que2[res+1].push(j);
                }
            }
        }
        if(cnt == 0){
            break;
        }
        res++;
    }
    rep2(i, 1, N+1){
        if(!que[i].empty()){
            res = -1;
            break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 676608
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define MAXN 100005

int n;
int a[MAXN];
int ma,mi=(int)1e9;
int cnt;
int p;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		ma=std::max(ma,a[i]);
		mi=std::min(mi,a[i]);
	}
	if(ma-mi>1||ma>n-1){
		p=0;
	}else if(ma==mi){
		if(ma==n-1) p=1;
		else if(ma*2<=n) p=1;
		else p=0; 
	}else{
		for(int i=1;i<=n;i++)
			if(a[i]==mi) cnt++;
		if(2*(ma-cnt)<=n-cnt&&ma>cnt) p=1;
		else p=0;
	}
	printf("%s\n",p?"Yes":"No");
}






Measured memory_bytes: 512
#include <iostream>

using namespace std;

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

int main()
{
   int a, b, c, d, e, f;
   cin >> a;
   b=0;
   c=0;
   d=0;
for(int i=1;i<=a;i++){
for(int j=1;j<=a;j++){
    b=gcd(i, j);
    for(int k=1;k<=a;k++){
        c=gcd(b, k);
        d=d+c;
    }
}    
}
   cout << d << endl;
   return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    int A[N]; rep(i, N) cin >> A[i];
    int saisyou[N]; saisyou[0] = A[0];
    for(int i = 1; i < N; i++){
        if(A[i] < saisyou[i-1]) saisyou[i] = A[i];
        else saisyou[i] = saisyou[i-1];
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(A[i] <= saisyou[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdio.h>

void maxHeapify(int[],int);
void builtMaxHeap(int[]);
int H;

int main()
{
  int i;

  scanf("%d",&H);
  
  int a[H+1];

  for(i=1; i<=H; i++){
    scanf("%d",&a[i]);
  }

  builtMaxHeap(a);

  for(i=1; i<=H; i++)
    printf(" %d",a[i]);

  printf("\n");
}

void maxHeapify(int a[],int i){
  int l,r,largest,tmp;
  l = 2*i;
  r = 2*i+1;

  if(l <= H && a[l] > a[i])
    largest = l;
  else
    largest = i;
  if(r<=H && a[r] > a[largest])
    largest = r;

  if(largest != i){
    tmp = a[i];
    a[i] = a[largest];
    a[largest] = tmp;
    maxHeapify(a,largest);
  }
}

void builtMaxHeap(int a[]){
  for(int i=H/2; i>=1; i--){
    maxHeapify(a,i);
  }
}



Measured memory_bytes: 4544
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>


int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a == b && a != c) printf("Yes");
    else if (b == c && b != a) printf("Yes");
    else if (c == a && c != b) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 128
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import product
def main():
    n,m,x=map(int,input().split())
    CA=[[int(_) for _ in input().split()] for i in range(n)]
    ans=10**10
    n_lis=list(product([True,False],repeat=n))
    for comb in n_lis:
        cunt=0
        A=[0]*m
        for i,ca in enumerate(CA):
            if comb[i]:
                cunt+=ca[0]
                for j,aa in enumerate(ca[1:]):
                    A[j]+=aa
        for a in A:
            if a<x:
                break
        else:
            ans=min(ans,cunt)
    if ans==10**10:
        print(-1)
    else:
        print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 69136
N,M,X,Y = map(int,raw_input().split())
x = map(int,raw_input().split())
y = map(int,raw_input().split())

x.append(X)
y.append(Y)

x.sort()
y.sort()

if x[N]<y[0]:
    print "No War"
else:
    print "War"    

Measured memory_bytes: 2568
#include<stdio.h>

int main() {
  int i, j, N, A[100], key, k;

  scanf("%d", &N);

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

  for(i = 1; i <= N - 1; i++) {
    for(k = 0; k < N; k++) {
      printf("%d", A[k]);
      if(k == N - 1) printf("\n");
      if(k != N - 1) printf(" ");
    }
    key = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = key;
  }
  for(k = 0; k < N; k++) {
    printf("%d", A[k]);
    if(k == N - 1) printf("\n");
    if(k != N - 1) printf(" ");
  }

  return 0;
}



Measured memory_bytes: 2144
// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#define pc(...)
#endif

#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 2e5 + 5, MOD = 1000000007;

class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        ll x;
        cin >> x;
        int a = x / 500;
        int b = x % 500;
        cout << a * 1000 + b / 5 * 5 << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int a[100];
	for (int i = 0; i < n; i++)
	{
		cin >> a[n - i - 1];
	}
	for (int i = 0; i < n; i++)
	{
		cout << a[i];
		if(i!=n-1) cout << " ";
		else cout << endl;
	}
} 

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
"""
C - Green Bin
https://atcoder.jp/contests/abc137/tasks/abc137_c

"""
import sys

from collections import Counter
from string import ascii_lowercase

def solve(N, strings):
    cnt = Counter()
    for s in strings:
        x = ''.join('{}-{}'.format(ch, s.count(ch)) for ch in ascii_lowercase)
        cnt[x] += 1
    ans = [(1 + v - 1) * (v - 1) // 2 for v in cnt.values() if v > 1]
    return sum(ans)


def main(args):
    N = int(input())
    strings = [input() for _ in range(N)]
    ans = solve(N, strings)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 31344
#include <iostream>

using namespace std;

int main() {
	int N, M, X;
	cin >> N >> M >> X;
	int A[100];
	for (int i = 0; i < M; i++) {
		cin >> A[i];
	}
	int sum_zero = 0;
	int sum_N = 0;

	// XからNまで
	for (int i = X; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (A[j] == i) {
				sum_N += 1;
				break;
			}		
		}
	}

	// Xから0まで
	for (int i = X; i > 0; i--) {
		for (int j = 0; j < M; j++) {
			if (A[j] == i) {
				sum_zero += 1;
				break;
			}		
		}
	}

	cout << min(sum_N, sum_zero) << "\n";
}

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

int main() {
  ll h,n;
  cin >> h >> n;
  vector<ll> sp(n);
  rep(i, n)
    cin >> sp.at(i);
  
  ll sum=0;
  rep(i, n)
    sum += sp.at(i);
  
  if(sum >= h)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> x(n);
    vector<ll> y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    mint sx = 0;
    mint sy = 0;
    rep(i, n-1) {
        mint res = mint(x[i+1]-x[i]);
        res *= (i+1);
        res *= (n-1-i);
        sx += res;
    }
    rep(i, m-1) {
        mint res = mint(y[i+1]-y[i]);
        res *= (i+1);
        res *= (m-1-i);
        sy += res;
    }

    mint ans = sx*sy;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4764
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>

#define mod 1000000007
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;

int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};

void solve() {
    ll x, t;
    cin >> x >> t;
    
    if(x - t < 0){
        cout << 0 << endl;
    }else{
        cout << x-t << endl;
    }
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;cin>>s;
	for(auto &e:s)e='x';
	cout<<s<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int X;cin>>X;
  while(1){
    int i=2;
    while(i*i<=X){
      if(X%i==0)break;
      i++;
    }
    if(i*i>X)break;
    X++;
  }
  cout<<X<<endl;
}

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

int main()
{
    int n;
    scanf("%d", &n);

    int a[n + 1] = {0};
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    
    
    
    int idx = 1;
    int cnt = 1;
    for (int i = 0; i < n; i++) {
        if (a[idx] == 2) {
            printf("%d\n", cnt);
            break;
        } else {
            idx = a[idx];
            cnt++;
        }
    }
    if (cnt == n + 1) printf("%d\n", -1);
    
}


Measured memory_bytes: 640
# # ####################################################################
# import io
# import sys

# _INPUT = """\
# 1
# 10
# 3
# 10 1
# 1 2
# 3 1
# """
# sys.stdin = io.StringIO(_INPUT)
####################################################################


N = int(input())
A = [int(i) for i in input().split()]
Q = int(input())

from collections import Counter
C = Counter(A)

sumA = sum(A)

for _ in range(Q):
  b,c = map(int, input().split())

  k = C[b]

  # if b==c:
  #   print(sumA)
  #   continue

  # if d[b] == 0:
  #   print(sumA)
  #   continue

  sumA += (c-b) * k
  print(sumA)

  C[c] += k
  C[b] = 0






Measured memory_bytes: 24000
def f(a,b,i):
  if i==4:
    if b==7:
      print(a+"=7")
      exit()
  else:
    return f(a+"+"+s[i],b+int(s[i]),i+1),f(a+"-"+s[i],b-int(s[i]),i+1)

s=input()
f(s[0],int(s[0]),1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n;cin>>n;
    ll t[n+1],x[n+1],y[n+1];
    t[0]=0;
    x[0]=0;
    y[0]=0;
    ll lt[n],lx[n];
    bool bb=false;
    for(ll i=1;i<=n;i++){
        cin>>t[i]>>x[i]>>y[i];
        lt[i]=t[i]-t[i-1];
        lx[i]=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
        if(lt[i]%2!=lx[i]%2 || lt[i]<lx[i]){
            bb=true;
        }
    }
    if(bb){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
    return 0;
}



Measured memory_bytes: 4096
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
S = input()
n = len(S)
for bit in range(1<<(n-1)):
    val = int(S[0])
    ans_string = S[0]
    for i in range(n-1):
        if (bit>>i)&1:
            val += int(S[i+1])
            ans_string += "+"+S[i+1]
        else:
            val -= int(S[i+1])
            ans_string += "-"+S[i+1]
    if val == 7:
        ans_string += "=7"
        break

print(ans_string)

Measured memory_bytes: 13040
#include <iostream>
#include <map>
#include <cmath>

using namespace std;
int main() {
    int n;
    scanf("%d", &n);
    std::map< std::pair<int,int>, int > cnt;
    for(int rep = 0; rep < n; ++rep) {
        double x;
        scanf("%lf", &x);
        long long i = llround(x * 1e9);
        int two = 0, five = 0;
        while(i % 2 == 0) {
            two++;
            i /= 2;
        }
        while(i % 5 == 0) {
            five++;
            i /= 5;
        }
        ++cnt[{two,five}];
    }
    long long answer = 0;
    for(auto p1 : cnt) {
        for(auto p2 : cnt) {
            if(p1.first.first+p2.first.first >= 18 && p1.first.second+p2.first.second >= 18) {
                if(p1 < p2) {
                    answer += (long long) p1.second * p2.second;
                }
                else if(p1 == p2) {
                    answer += (long long) p1.second * (p1.second - 1) / 2;
                }
            }
        }
    }
    printf("%lld\n", answer);
}


Measured memory_bytes: 3220