akhauriyash/Code-Regression huggingface dataset:
/* ----------------------- reclone_rk -------------------------*/ 
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int mod=1e9+7;

int gcd(int a, int b){ if(a == 0) return b; return gcd(b%a, a);}
int MOD(int n){ return ((n%mod)+mod)%mod;}
int power(int a,int b){ if(b==0)return 1LL;int s=power(a,b/2LL);s*=s;s%=mod;if(b&1LL)return (s*a)%mod;return s;}
int inv(int a){return power(a,mod-2);}
int nCr(int n,int r){if(r>n)return 0LL;if(n-r<r)r=n-r;int ans=1;for(int i=0;i<r;i++){ans*=(n-i);ans=MOD(ans);ans*=inv(i+1);ans=MOD(ans);}return ans;}
 
signed main()
{
	string s;
	cin>>s;
	if(s == "ABC")
		cout<<"ARC"<<endl;
	else
		cout<<"ABC"<<endl;
	return 0;
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
	int r;
  cin >> r;
  cout << r*r << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
ex = -1
for i in range(N):
    ans += B[A[i]-1]
    if i != 0 and ex + 1 == A[i]:
        ans += C[ex-1]
    ex = A[i]
print(ans)

Measured memory_bytes: 3064
import math
DEBUG = False
S = input()

cnt = 0
mid = int(math.floor(len(S)/2))

for i in range(mid):
    fch = S[i]
    bch = S[-(i+1)]
    if fch != bch:
        cnt += 1
    if DEBUG: print("(fch, bch)= (%s , %s)"%(fch, bch))
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int         // 10^18
#define INF 1000000001           // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//---------------------------

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

    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    
    int n;string s,t;cin>>n>>s>>t;
    if(s==t){
        P(n);
    }else{
        for(int i=1;i<=n;i++){
            string u=s.substr(0,i) + t;
            if(u.substr(0, n)==s){
                P(i+n);
                return 0;
            }
        }
    }
    return 0;
}

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

int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

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

	qsort(l, n, sizeof(int), compare_int);
	
	long long ans = 0;
	int tmp = 0;
	for (int a = 0;a < n;a++) {
		for (int b = a+1;b < n;b++) {
			for (int c = b+1;c < n;c++) {
				if (l[a]+l[b] > l[c]) {
					ans++;
				}
			}
		}
	}

	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 1728
import Control.Applicative
import Control.Monad

main = do
    rect <- map read.words<$>getLine
    if all ( == 0) rect then return ()
                        else do
                            n       <- readLn
                            rs   <- replicateM n readLn
                            mapM_ putStrLn $ map (printResult rect) $ rs
                            main

printResult :: [Double] -> Double -> String
printResult rect r = if rect `isAbleToThrough` r then "OK"
                                                 else "NA"

isAbleToThrough :: [Double] -> Double -> Bool
isAbleToThrough [d,w,h] r = minLength < r
    where minLength = minimum $ map halfDiag [(d,w),(d,h),(w,h)]
          halfDiag (x,y) = (sqrt (x^2 + y^2)) / 2

Measured memory_bytes: 4284
#include "bits/stdc++.h"

//region Template
#include "ext/pb_ds/assoc_container.hpp"

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;
using namespace std;
#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);
#define endl '\n'

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
void print() {}
template<typename T, typename... Args>
void print(T firstArg, Args... args) {
	#ifdef LOCAL
	cout << firstArg << " ";
	print(args...);
	#endif
}
//endregion

/* Notes:
 * Farah </3
 */

const int MAXN = 1e6 + 5;

int dp[MAXN][3];

int main() {
	//usaco("milkvisits");

	#ifdef LOCAL
	setIn("in.txt");
	setOut("out.txt");
	#endif

	int n, k, r, s, p;
	cin >> n >> k >> r >> s >> p;

	string st;
	cin >> st;

	ll ans = 0;
	vector<string> g;
	for(int i = 0; i < k; i++){
		string str;
		for(int j = i; j < n; j += k){
			memset(dp[j % k], 0, sizeof dp[j % k]);
			str += st[j];
		}

		for(int j = 0; j < str.size(); j++){
			if(j == 0){
				dp[j][0] = str[j] == 's' ? r : 0;
				dp[j][1] = str[j] == 'p' ? s : 0;
				dp[j][2] = str[j] == 'r' ? p : 0;
			}
			else{
				dp[j][0] = max(dp[j - 1][1], dp[j - 1][2]) + (str[j] == 's' ? r : 0);
				dp[j][1] = max(dp[j - 1][0], dp[j - 1][2]) + (str[j] == 'p' ? s : 0);
				dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]) + (str[j] == 'r' ? p : 0);

			}
		}
		ans += max(max(dp[str.size() - 1][0], dp[str.size() - 1][1]), dp[str.size() - 1][2]);
	}

	cout << ans;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(ll i=s;i<n;i++) 
#define forj(s,n) for(ll j=s;j<n;j++) 
#define vii vector<int>
ll n, m;
vii w, v;
ll dp[101][100001];
ll solve(ll x,ll rest) {
	if (x == n + 1) return 0;
	ll& ret = dp[x][rest];
	if (~ret) return ret;
	ll r1 = 0, r2 = 0;
	 if(rest>=w[x])
	 r1 = v[x] + solve(x + 1,rest-w[x]);
	 r2 = solve(x + 1,rest);
	return ret=max(r1, r2);
}
signed main()
{
	fast;
	memset(dp, -1, sizeof dp);
	cin >> n >> m;
	v = vii(n+1); w = vii(n+1);
	fori(1,n+1)
	{
		cin >> w[i] >> v[i];
	}
	cout << solve(1,m) << endl;
}

Measured memory_bytes: 82568
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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


	    int n =sc.nextInt();
	    int[] a = new int[n];
	    for(int i =0; i < n; i++) {
	    	a[i] = sc.nextInt();
	    }

	    	Arrays.sort(a);

	        long s = 0;

	        for(int i = 0; i < n; i++) {
	            s += a[i];
	        }

	        System.out.println(a[0] + " " + a [n-1] + " " +  s );
	    }












	}


Measured memory_bytes: 41972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

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

  int h, w;
  cin >> h >> w;
  vector<string> field(h);
  for (int i = 0; i < h; i++) cin >> field[i];
  vector<vector<int>> dp(h, vector<int>(w, -1));

  dp[h-1][w-1] = ((field[h-1][w-1]=='.') ? 0 : 1);
  for (int y = h-2; y >= 0; y--) {
    dp[y][w-1] = (((field[y][w-1] == '#') && (field[y+1][w-1] == '.')) ? dp[y+1][w-1] + 1 : dp[y+1][w-1]);
  }

  for (int x = w-2; x >= 0; x--) {
    for (int y = h-1; y >= 0; y--) {
      if (y == h-1) {
        dp[y][x] = dp[y][x+1] + (((field[y][x] == '#') && (field[y][x+1] == '.')) ? 1 : 0);
      }
      else {
        dp[y][x] = min(dp[y][x+1] + (((field[y][x] == '#') && (field[y][x+1] == '.')) ? 1 : 0), dp[y+1][x] + (((field[y][x] == '#') && (field[y+1][x] == '.') ? 1 : 0)));
      }
    }
  }

  cout << dp[0][0] << endl;
}


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

void solve(std::string S) {
  if (S == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (S == "Cloudy") {
    cout << "Rainy" << endl;
  } else {
    cout << "Sunny" << endl;
  }
}

int main() {
  std::string S;
  std::cin >> S;

  solve(S);
  return 0;
}


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

int n;
int pan(int x){
	for(int i=2;i*i<=x;i++)
		if(x%i==0) return 0;
	return 1;
}
int main(){
	scanf("%d",&n);
	for(;!pan(n);n++);
	printf("%d\n",n);
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1]*(n+1)
    self.rnk = [0]*(n+1)
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]
  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if(x == y):
      return 
    if self.root[x] > self.root[y]:
      x, y = y, x
    self.root[x] += self.root[y]
    self.root[y] = x 
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)
  def Count(self, x): # xが属するグループのサイズを返す
    return -self.root[self.Find_Root(x)]
  def Members(self, x): # xが属するグループに属する要素をリストで返す
    return [i for i in range(self.n) if self.Find_Root(i)==self.Find_Root(x)]
  def Roots(self): # 全ての根の要素をリストで返す
    return [i for i, x in enumerate(self.root) if x < 0]
  def Group_Count(self): # グループの数を返す
    return len(self.Roots())

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
uf = UnionFind(N+1)
root_cnt = {i:1 for i in range(1, N+1)}
pair = N*(N-1)//2
ans = []
for i in range(M-1, -1, -1):
  ans += [pair]
  a, b = ab[i]
  ra = uf.Find_Root(a)
  rb = uf.Find_Root(b)
  if uf.isSameGroup(a, b):
    continue
  pair -= root_cnt[ra] * root_cnt[rb]
  uf.Unite(a, b)
  if root_cnt[ra] == root_cnt[uf.Find_Root(a)]:
    root_cnt[ra] += root_cnt[rb]
    root_cnt[rb] = 0
  else:
    root_cnt[rb] += root_cnt[ra]
    root_cnt[ra] = 0
  #root_cnt[uf.Find_Root(a)] += mem_a + mem_b - 1

for n in ans[::-1]:
  print(max(n, 0))

Measured memory_bytes: 44312
#include <iostream>

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

int main() {

    int N, Y, c;
    scanf("%d%d", &N, &Y);

    REP(a, N+1){
        REP(b, N+1-a){
            c = N - a - b;
            if (Y == 10000 * a + 5000 * b + 1000 * c) {
                printf("%d %d %d\n", a, b, c);
                return 0;
            }
        }
    }

    printf("%d %d %d\n", -1, -1, -1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF const ll INF = 1001001001;
#define PI const ld PI = 3.14159265358979323846;



int main() {
    int M1,D1,M2,D2;
    cin>>M1>>D1>>M2>>D2;
    if(D1>D2){
        cout<<1<<endl;
    }
    else{
        cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
        int n, a[1000000], i, j, r=0, tmp;

        scanf("%d", &n);

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

        for(i = 0; i < n-1; i++) {
                if(a[i] > a[i+1]) {
                        tmp = a[i+1];
                        a[i+1] = a[i];
                        a[i] = tmp;
                }
                while((r = a[i+1]%a[i]) != 0) {
                        a[i+1] = a[i];
                        a[i] = r;
                }
                a[i+1] = a[i];
        }

        printf("%d", a[i]);
        return 0;
}


Measured memory_bytes: 2560
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        
        int count = 0;
        for (long i = 1; i <= 3234566667L; i++) {
            //System.out.println(i);
            String str = String.valueOf(i);
            char c[] = str.toCharArray();
            boolean ok = true;
            for (int j = 0; j < c.length - 1; j++) {
                int a = c[j] - '0';
                int b = c[j+1] - '0';
                if (Math.abs(a-b) > 1) {
                    ok = false;
                    String str2 = str.substring(0, j);
                    int cz = a + 1;
                    for (int l = 0; l < c.length - j; l++) {
                        String str4 = String.valueOf(cz);
                        if (a == 9 && b == 0) {
                            i--;
                            a = c[j] - '0';
                            b = c[j+1] - '0';
                            //a++;
                            for (int y = 0; y < c.length - j; y++) {
                                str2 += a;
                                a--;
                            }
                            break;
                        }
                        str2 += cz;
                        cz--;
                        if (cz == 9) cz = 0;
                        if (cz == -1) cz = 0;
                    }
                    
                    i = Long.parseLong(str2);
                    i--;
                    break;
                }
            }
            
            if (ok) count++;
            
            if (count == k) {
                System.out.println(i);
                return;
            }
        }
    }
}


Measured memory_bytes: 45916
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int n, a[100000]; cin >> n;
  REP(i, n) cin >> a[i];
  int left[100010], right[100010];

  left[1] = a[0]; right[n-2] = a[n-1];
  for(int i = 2; i <= n; i++)
    left[i] = GCD(left[i-1], a[i-1]);
  for(int i = n-3; i >= 0; i--)
    right[i] = GCD(right[i+1], a[i+1]);

  int ans = -INF;
  REP(i, n) {
    int comp;
    if(i == 0) comp = right[i];
    else if(i == n-1) comp = left[i];
    else comp = GCD(left[i], right[i]);
    ans = max(ans, comp);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	string s,t;
	cin >> s >> t;
	
	string now=t,bef="";

	rep(i,1,22){
		string chk = now;
		int idx = 0;
		char c = chk[idx];
		
		bool f = false;
		rep(j,0,s.size()){
			if( s[j] == c ){
				if(++idx >=chk.size()){
					f++;
					break;
				}
				c = chk[idx];
			}
		}
		
		//P(now);
		//P(f);
		if(f){
			bef = now;

		}
		else{
			P(i-1);
			break;
		}


		if( s.size() < (long long)bef.size() * (t.size() + 1)){
			P(i);
			break;
		}

		if(i>0){
			string tmp=bef;
			rep(j,0,t.size())	tmp += t[j] + bef;
			now=tmp;
		}

	}

	ret 0;
}


Measured memory_bytes: 3352
#include <stdio.h>

int i, N, H[20];

int main () {

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

        int maximum = 0;
        int count = 0;
        for (i = 0; i < N; i++) {
                if (H[i] >= maximum) {
                        count++;
                        maximum = H[i];
                }
        }

        printf("%d\n", count);

        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false);
#define rmod(x, y) ((((x)%(y))+(y))%(y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set(){
	return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}

const int maxn = 1e5+5;
int x, y, a, b, c, k;
deque<int> p, q, r;

int main(){
	scanf("%d %d %d %d %d", &x, &y, &a, &b, &c);
	for(int i = 0; i<a; i++) scanf("%d", &k), p.push_back(k);
	for(int i = 0; i<b; i++) scanf("%d", &k), q.push_back(k);
	for(int i = 0; i<c; i++) scanf("%d", &k), r.push_back(k);
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	sort(r.begin(), r.end(), greater<int>());
	while(p.size()>x) p.pop_front();
	while(q.size()>y) q.pop_front();
	while(r.size()){
		int mn = min(p.front(), q.front());
		if (r.front()<=mn) break;
		if (p.front()<q.front()) p.push_back(r.front()), p.pop_front(), r.pop_front();
		else q.push_back(r.front()), r.pop_front(), q.pop_front();
	}
	ll ans = 0;
	for(int v: p) ans+= (ll)v;
	for(int v: q) ans+= (ll)v;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1536
S = input()
ans = 0
for i in range(len(S) + 1):
    for j in range(len(S), i, -1):
        s = S[i:j]
        for c in 'BDEFHIJKLMNOPQRSUVWXYZ':
            if c in s:
                break
        else:
            ans = max(ans, len(s))
print(ans)

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

int main() {
  int h,w;cin>>h>>w;
  vector<vector<char>> a(h,vector<char>(w));
  rep(i,h)rep(j,w)cin>>a[i][j];
  rep(i,w+2){
    cout<<'#';
    if(i==w+1)cout<<endl;
  }
  rep(i,h)rep(j,w){
    if(j==0)cout<<'#';
    cout<<a[i][j];
    if(j==w-1)cout<<'#'<<endl;
  }
  rep(i,w+2){
    cout<<'#';
    if(i==w+1)cout<<endl;
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

int main(){
    int N; cin >> N;
    vector<int> p(N),inv(N);
    for (int i = 0; i < N; i++){
        cin >> p[i];
        inv[p[i]-1] = i;
    }
    set<int> s;
    ll ans = 0;
    for (int i = -2; i < N+2; i++){
        s.insert(i);
    }
    for (int i = 0; i < N; i++){
        int k = inv[i];
        s.erase(k);
        auto it1 = s.upper_bound(k);
        auto it2 = it1;
        int r1 = *it1;
        int r2 = *++it1;
        int l1 = *--it2;
        int l2 = *--it2;
        if (r1 < N){
            ans += (ll)(r2-r1)*(ll)(k-l1)*(i+1);
        }
        if (l1 >= 0){
            ans += (ll)(l1-l2)*(ll)(r1-k)*(i+1);
        }
        s.erase(k);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include<stdio.h>

int main(){
		int n,m,i,ans=0;
		int a[1000][3];
		scanf("%d%d",&n,&m);
		for(i=0;i<m;i++){
				scanf("%d%d",&a[i][0],&a[i][1]);
				a[i][2]=0;
		}
		for(i=0;i<m;i++){
				a[i][2]=1;
				int p[10000]={0},j,flag[51]={0};
				p[0]=a[i][0];flag[a[i][0]-1]=1;
				int st=0,fin=1;
				while(st<=fin){
						for(j=0;j<m;j++){
								if((p[st]==a[j][0]&&a[j][2]!=1&&flag[a[j][1]-1]!=1)){
							//			printf("%d %d\n",a[j][0],a[j][1]);
										p[fin]=a[j][1];
										flag[a[j][1]-1]=1;
										fin++;
								}
								if((p[st]==a[j][1]&&a[j][2]!=1&&flag[a[j][0]-1]!=1)){
							//			printf("%d %d\n",a[j][1],a[j][0]);
										p[fin]=a[j][0];
										flag[a[j][0]-1]=1;
										fin++;
								}
						}
						st++;
				}
				a[i][2]=0;
				int f=0;
				for(j=0;j<n;j++){
	//					printf("%d\n",flag[j]);
						if(flag[j]==0)f=1;
						if(flag[j]==1){
								flag[j]=0;
						}
				}
				if(f==1)ans++;
		}
		printf("%d\n",ans);
		return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const double pi = acos(-1.0);
const long long inf = 100000000000LL;

int main() {
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	VL a(x), b(y), c(z);
	rep(i, x)cin >> a[i];
	rep(i, y)cin >> b[i];
	rep(i, z)cin >> c[i];

	VL n;
	rep(i, x)rep(j, y)n.pb(a[i] + b[j]);
	sort(all(n), greater<LL>());
	if (sz(n) > k) {
		n.erase(n.begin() + k, n.end());
	}

	VL ans;
	rep(i, sz(n))rep(j, z) {
		ans.pb(n[i] + c[j]);
	}
	sort(all(ans), greater<LL>());

	rep(i, k) {
		cout << ans[i] << endl;
	}
}

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

using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;


int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int32_t main() {
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    
    
    ini(n);
    ins(x);
    int dp[n][3];
    FOR(i,0,n)FOR(i1,0,3)dp[i][i1] = 0;
    for(int i  = n-1;i>=0;i--){
        if(x[i] == 'R')dp[i][0] = 1;
        if(x[i] == 'G')dp[i][1] = 1;
        if(x[i] == 'B')dp[i][2] = 1;
    }
    for(int i  = n-2;i>=0;i--)dp[i][0]+=dp[i+1][0];
    for(int i  = n-2;i>=0;i--)dp[i][1]+=dp[i+1][1];
    for(int i  = n-2;i>=0;i--)dp[i][2]+=dp[i+1][2];
    
    int tmp = 0;
    FOR(i,0,n-2){
        FOR(i1,i+1,n-1){
            if(x[i1] == x[i])continue;
            if(i1+i1-i<n and x[i1+i1-i]!=x[i] and x[i1+i1-i]!=x[i1])tmp--;
            if(x[i] == 'R' and x[i1] == 'G')tmp+=dp[i1+1][2];
            if(x[i] == 'G' and x[i1] == 'R')tmp+=dp[i1+1][2];
            if(x[i] == 'R' and x[i1] == 'B')tmp+=dp[i1+1][1];
            if(x[i] == 'B' and x[i1] == 'R')tmp+=dp[i1+1][1];
            if(x[i] == 'B' and x[i1] == 'G')tmp+=dp[i1+1][0];
            if(x[i] == 'G' and x[i1] == 'B')tmp+=dp[i1+1][0];
        }
    }
    out(tmp);

    
    
  
    
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 3688
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
a;*c;f;*i;j;m;n;s;u;v;w;C[72000];D[2001][2001];M[2001];
main(){
  c=C;
  for(;++n,~scanf("%d",&w)||(w=0,n%3-1);a=u,u=v,v=w,w=a)
    if(n%3<1)
      if(n<4)M[v]=M[w]=D[v][w]=D[w][v]=m=1e7;
      else{
        for(s=0;s++<2e3;)for(j=3;a=u,u=v,v=w,w=a,j--;)
          u-v|v-w?
            *++c=u,*++c=s,*++c=v-w?:D[s][v]+1,
            *++c=u,*++c=v,*++c=D[w][w]+1,
            *++c=u,*++c=v,*++c=m,
            *++c=u,*++c=s,*++c=M[s]
          :++f;
        for(;c>C;)
          w=*c--,v=*c--,u=*c--,
          D[u][v]>w||(D[u][v]=D[v][u]=w),M[u]>w||(M[u]=w),M[v]>w||(M[v]=w),m=m>w?m:w;
      }
  printf("%d",m+=f/6e3-1e7);
}


Measured memory_bytes: 17652
#include <iostream>

using namespace std;

int main() {
    int m, k;
    cin >> m >> k;

    if (m == 0 && k == 0) {
        cout << "0 0" << endl;
    } else if (m == 1 && k == 0) {
        cout << "0 0 1 1" << endl;
    } else if (m >= 2 && k < (1 << m)) {
        for (int i = 0; i < (1 << m); i++) {
            if (i != k) {
                cout << i << " ";
            }
        }
        cout << k << " ";
        for (int i = 0; i < (1 << m); i++) {
            if ((1 << m) - i - 1 != k) {
                cout << (1 << m) - i - 1 << " ";
            }
        }
        cout << k << endl;
    } else {
        cout << "-1" << endl;
    }
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007

void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}

int main() {
   fast();
   int n;
   cin>>n;
   int l[n];
   for(int i=0;i<n;i++){
    cin>>l[i];
   }
   int ans=0;
   for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
          int a[3]={l[i],l[j],l[k]};
          sort(a,a+3);
          
        if(a[0]+a[1]>a[2] && l[i]!=l[j] && l[j]!=l[k] && l[i]!=l[k] && i<j && j<k){
            ans++;
        }
      }
    }
   }
   cout<<ans<<"\n";


}

Measured memory_bytes: 3668
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main() 
{
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		cout << 'x';
	}
	cout << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	map<string, ll> mapa;
	for (ll i = 0; i < n; i++) {
		string s; cin >> s; mapa[s]++;
	}
	map<ll, vector<string>>mapa1;
	ll mx = LLONG_MIN;
	for (auto p : mapa) {
		ll cnt = p.Y;
		string s = p.X;
		mapa1[cnt].push_back(s);
		mx = max(mx, cnt);
	}
	sort(all(mapa1[mx]));
	for (auto s : mapa1[mx]) {
		cout << s << '\n';
	}
	return 0;
}

/*
3
0 1
3 0
1 0
*/

Measured memory_bytes: 25584
package main
  
import (
    "fmt"
)

func main() {
    var n, d int
    fmt.Scan(&n, &d)
    r := d*2 + 1
    if n%r == 0 {
        fmt.Println(n / r)
    } else {
        fmt.Println(int(n/r) + 1)
    }
}


Measured memory_bytes: 512
#include<cstdio>
const int N = 300+5;
const long long inf = 1e16+7;
long long cost[N][N];
long long d[N][N];

long long min(long long a,long long b){ return a>b?b:a; } 

int main(){
    int n,m;
    long long l;
    scanf("%d%d%lld",&n,&m,&l);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cost[i][j] = cost[j][i] = d[i][j] = d[j][i] = inf;
        }
    }
    for(int i = 0; i < m; i++){
        int u,v; long long c;
        scanf("%d%d%lld",&u,&v,&c);
        cost[u][v] = cost[v][u] = c;
    }
    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
                if(cost[i][j]<=l) d[i][j] = 1;
            }
        }
    }
    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    scanf("%d",&m);
    for(int i = 0; i < m; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        if(d[u][v]<inf) printf("%lld\n",d[u][v]-1);
        else printf("-1\n");
    }
    return 0;
}

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

int main(){
	int s[5];
	int t[5];
	int number = 0;
	for(int i=0;i<5;i++){
		cin>>s[i];
		if(s[i]%10!=0){
			number += 1;
			t[i]=(s[i]/10+1)*10;
		}	else{
			t[i]=s[i];
		}
	}
	int j=0;
	int u[5];
	int mini;
	if(number==5){
		for(int i=0;i<5;i++){
			u[i]=s[i]%10;
			if(i==0){
				mini=u[i];
				j=i;
			}
			if(i>0 && u[i]<mini){
				mini=u[i];
				j=i;
			}
		}
		t[j]=s[j];
	}
	mini=9;
	if(number!=5){
		for(int i=0;i<5;i++){
			if(s[i]%10!=0 && number!=0){
				if(mini>s[i]%10){
					mini=s[i]%10;
					j=i;
				}
			}
		}
		t[j]=s[j];
	}	
	int sum=0;
	for(int i=0;i<5;i++){
		sum += t[i];
	}
	cout<<sum;
	return 0;
}	


Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

p = [v[i] - c[i] for i in range(n)]

ans = 0
for i in range(n):
    if p[i] > 0:
        ans = ans + p[i]

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<int>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

int popHeap(vector<int>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  int i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  int i,j,k,cnt=0;
  int n,m;
  cin>>n>>m;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  ll s[n+1];
  s[0]=0;
  for(i=0;i<n;i++)s[i+1]=s[i]+a[i];
  map<ll,ll> b;
  for(i=0;i<=n;i++){
    b[s[i]%m]=0;
  }
  for(i=0;i<=n;i++){
    b[s[i]%m]++;
  }
  ll ans=0;
  for(auto i:b){
    ans+=(i.second*(i.second-1))/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int n;
    cin >> n;
    int t = 0, h = 0;
    rep(i, 0, n) {
        string x, y;
        cin >> x >> y;
        if (x > y) t += 3;
        else if ( x < y) h += 3;
        else {
            t ++;
            h ++;
        }
    }
    cout << t << " " << h << endl;
    return 0;
}



Measured memory_bytes: 3228
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>

#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)

using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
char str[50];

int main() {
	scanf("%s", str);
	n = strlen(str);
	if(n >= 4 && str[0] == 'Y' && str[1] == 'A' && str[2] == 'K' && str[3] == 'I') {
		printf("Yes");
	} else printf("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始

bool dp[30009][4][1009];


int main(){
    int n;
    string s;
    cin>>n>>s;
    // cout<<"DEBUG";
    dp[0][0][0] = true;
    // cout<<s<<n;

    for(int i = 0; i < n; i++){
        for(int j = 0; j <= 3; j++){
            for(int k = 0; k < 1000; k++){
                if(dp[i][j][k] == false) continue;
                dp[i+1][j][k] = true;
                if(j <= 2){
                    dp[i+1][j+1][k*10+(s[i]-'0')] = true;
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < 1000; i++){
        if(dp[n][3][i]==true) ans++;
    }
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;

const int maxn = 2e5 + 5;

int a[maxn<<1];
int Next[maxn<<1];
int num[maxn];
int q[maxn], top;
int main() {
    int n;
    long long k;
    scanf("%d%lld", &n, &k);
    for(int i=0;i<n;i++)
    {
        scanf("%d", a + i);
        a[i+n] = a[i];
    }
    memset(Next,-1,sizeof(Next));
    for(int i=2*n-1;i>=0;i--)
    {
        Next[i] = num[a[i]];
        num[a[i]] = i;
    }
    for(int i=0;i<n;i++)
    {
        if(Next[i] >= n) Next[i] -= n;
    }
    int cnt=1, now=0, current;
    memset(num, 0, sizeof(num));
    while(1)
    {
        //printf("%dss %d\n",now, cnt);
        if(num[now]){
            current = cnt - num[now];
            break;
        }
        else{
            num[now] = cnt;
            if(Next[now] <= now){
                cnt++;
            }
            now = Next[now];
            now++;
            if(now>=n){
                now=0;
                cnt++;
            }
        }
    }
    if(k>=cnt){
        k -= cnt;
        k %= current;
        k++;
    }
    else{
        now = 0;
    }
    //printf("%lld %d %d\n", k, current, cnt);
    top = 0;
    cnt = 0;
    while(cnt < k)
    {
        if(cnt < k-1||(Next[now] > now)){
            if(Next[now] <= now) cnt++;
            now = Next[now];
        }
        else{
            q[top++] = a[now];
        }
        now++;
        if(now>=n){
            now=0;
            cnt++;
        }
    }
    for(int i=0;i<top;i++)
    {
        printf("%d%c",q[i], i==top-1?'\n':' ');
    }
    return 0;
}


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

#define int long long
const int MOD = 1000000000000007LL;

int dp[3010][3010];
int a[3010];
int n;

int dfs(int l, int r, int turn){

    if(dp[l][r] != MOD) return dp[l][r];

    if(turn == 0){
        //最小化したい気持ち

        if(r - l == 1){
            dp[l][r] = -a[l];
            return dp[l][r];
        }

        int rec = min(dfs(l + 1, r, 1) - a[l], dfs(l, r - 1, 1) - a[r - 1]);
        dp[l][r] = rec;
        return dp[l][r];
    }else{
        //最大化したい気持ち

        if(r - l == 1){
            dp[l][r] = a[l];
            return dp[l][r];
        }

        int rec = max(dfs(l + 1, r, 0) + a[l], dfs(l, r - 1, 0) + a[r - 1]); 
        dp[l][r] = rec;
        return dp[l][r];
    }

}

signed main(){

    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            dp[i][j] = MOD;
        }
    }
    cout << -dfs(0, n, 0) << endl;
    return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

ll fact(ll n){
    if(n ==1) return 1;
    return n * fact(n-1);
}

void recursive_comb(ll *indexes, ll s, ll rest, std::function<void(ll *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(ll n, ll k, std::function<void(ll *)> f) {
  ll indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

vector<ll> A;
vector<ll> B;
vector<ll> C;
vector<ll> D;
ll ans = 0;
ll N, M, Q;


vector<int> buf;

void dfs(int i, const int size, const int range_start, const int range_end)
{
    if (i == size) {
        // ここで所望の作業を行う
        // for(int i = 0; i < buf.size(); ++i){
        //     cout << buf[i] << " ";
        // }
        // cout << ":" << endl;
        ll temp= 0;
        REP(j, Q){
            // cout << indexes[B[j]-1] << " " << indexes[A[j]-1] << endl;
            if(buf[B[j]-1] -buf[A[j]-1] == C[j]){
                temp += D[j];
                // cout << "D " << D[j] << endl;
            }
        }
        // cout << temp << endl;
        ans = max(ans, temp);
    }
    else{
        for(int j = range_start; j <= range_end; ++j){
            buf[i] = j;
            dfs(i + 1, size, j, range_end);
        }
    }
}
int main()
{
    cout << fixed << setprecision(15);
    cin >> N >> M >> Q;

    A.resize(Q);
    B.resize(Q);
    C.resize(Q);
    D.resize(Q);

    REP(i, Q){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        // cout << A[i] << " " << B[i] << " " << C[i] << " " << D[i] << endl;;
    }

    int size = N;
    int range_start = 1;
    int range_end = M;
    
    buf.resize(size);
    dfs(0, size, range_start, range_end);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
import sys
from collections import deque
MOD = 10 ** 9 + 7
def LI(): return map(int, sys.stdin.readline().split())

def main():
    n, k = LI()
    g = [[] for i in range(n+1)]
    for i in range(n-1):
        a, b = LI()
        g[a].append(b)
        g[b].append(a)

    Q = deque([1])
    ans = k
    Qappend = Q.append
    searched = [0] * (n+1)
    searched[1] = 1
    Qp = Q.popleft
    cand = k - 1
    while len(Q) != 0:
        v = Qp()
        for i in g[v]:
            if searched[i] == 1:
                continue
            searched[i] = 1
            ans = ans * cand % MOD
            cand = cand - 1
            Qappend(i)
        cand = k - 2
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 60592
N = int(raw_input())
cost = list()
for i in xrange(5):
    cost.append(int(raw_input()))

min_cost = 10 ** 16
for i in xrange(5):
    if cost[i] < min_cost: min_cost = cost[i]

if N <= min_cost: print '5'
elif N % min_cost == 0: print (4 + int(N / min_cost))
else:
    print (4 + int(N / min_cost) + 1)

Measured memory_bytes: 2568
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = 0
for i in range(k):
    c += a[i]
for i in range(k, n):
    d = c - a[i - k] + a[i]
    if d > c:
        print("Yes")
    else:
        print("No")
    c = d

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

using i64 = long long;

i64 solve(i64 a, i64 b) {
	if (a < b)
		swap(a, b);
	if (b == 0)
		return -a;

	return a / b * b * 2 + solve(a % b, b); }

int main() {
#ifdef HOME
	freopen("agc1b.in", "r", stdin);
	freopen("agc1b.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	i64 a, b;

	cin >> a >> b;

	cout << a + solve(a - b, b) << endl;

	return 0; }


Measured memory_bytes: 256