akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def is_prime(n):
    import math
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


N = int(read())

primes = []

for i in range(1, N + 1):
    if is_prime(i):
        primes.append(i)

p_cnt = [0] * len(primes)

for i in range(1, N + 1):
    num = i
    for idx, p in enumerate(primes):
        while num % p == 0:
            p_cnt[idx] += 1
            num //= p
ans = 0
# p**74
for _, v in zip(primes, p_cnt):
    if v >= 74:
        ans += 1
# p**2, q**24 / p**4, q**14
for p, v in zip(primes, p_cnt):
    for q, v_ in zip(primes, p_cnt):
        if p == q:
            continue
        if v >= 2 and v_ >= 24:
            ans += 1
        if v >= 4 and v_ >= 14:
            ans += 1
# p **2, q ** 4, r ** 4
for p, v1 in zip(primes, p_cnt):
    for q, v2 in zip(primes, p_cnt):
        for r, v3 in zip(primes, p_cnt):
            if r <= q or p == q or r == p:
                continue
            if v1 >= 2 and v2 >= 4 and v3 >= 4:
                ans += 1

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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



int main()
{
  int n;
  vector<pair<int, int>> p;

  cin >> n;
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    p.push_back(make_pair(a, b));
  }

  double sum = 0.0;
  /* 順列を全部作れば良い */
  vector<int> path(n);
  /*  まず初期の順列、つまり昇順になっている順列を作る */
  rep(i,n) path[i] = i;
  do {
    rep(j,n-1) {
      sum += sqrt(pow(p[path[j]].first - p[path[j+1]].first, 2) + pow(p[path[j]].second - p[path[j+1]].second, 2));
    }
  } while (next_permutation(path.begin(), path.end())); /*これが順列を作っていく関数*/
  /*順列は下記のように作られる*/
  // 1 2 3
  // 1 3 2
  // 2 1 3
  // 2 3 1
  // 3 1 2
  // 3 2 1

  int kaijo = 1;
  for (int i = n; i > 0; i--) {
    kaijo *= i;
  }

  printf("%.7f\n", sum / kaijo);
}



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

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;

    bool judge = true;
    if ( x-r < 0 || x + r > W)
        judge = false;
    if ( y - r < 0 || y + r > H )
        judge = false;
    
    string ans;
    if( judge )
        ans = "Yes";
    else
        ans = "No";

    cout << ans << endl;
}


Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <iomanip>


using namespace std;
 

int main() {

    int N;
    cin >> N;

    while(N > 0){
        if(N % 10 == 7){
            cout << "Yes";
            return 0;
        }
        N /= 10;
    }
    cout << "No";

      return 0;
}

Measured memory_bytes: 3632
n = int(input())
a = list(map(int,input().split()))
ruisekiwa = [0]*(n+1)
for i in range(n):
    ruisekiwa[i+1] = a[i] + ruisekiwa[i]
ans = 999999999999
for i in range(1,n):
    num = abs(ruisekiwa[i] - (ruisekiwa[-1] - ruisekiwa[i]))
    ans = min(ans,num)
print(ans)


Measured memory_bytes: 24824
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

    int n,q;
    cin >> n;

    long long int s[n];
    for(int i=0;i<n;i++)cin >> s[i];

    cin >> q;
    long long int t[q];
    for(int i=0;i<q;i++)cin >> t[i];

    int m=0;

    for(int i=0;i<q;i++){
        if(lower_bound(s,s+n,t[i])!=upper_bound(s,s+n,t[i]))m++;
    }

    cout << m << endl;

}


Measured memory_bytes: 4264
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, f;
int field[10][10];
int memo[3][2][1 << 16][8];
int win;

int GetP(int fs, int turn, int prev, int next) {
  int ret = 0;
  if (turn != 0) {
    if (fs == 0) {
      ret = field[next][prev];
    } else {
      ret = field[prev][next];
    }
  }
  return ret;
}

int calc(int yowai, int fs, int use, int prev) {
  int turn = __builtin_popcount(use);
  if (turn == 2 * n) { return f; }
  if (memo[yowai][fs][use][prev] != 0x0f0f0f0f) { return memo[yowai][fs][use][prev]; }
  int used = 0;
  if (fs == 0) {
    used = use & ((1 << n) - 1);
  } else {
    used = (use >> n) & ((1 << n) - 1);
  }
  int ret = -10000000;
  if (yowai == fs) { ret = 10000000; }
  REP(i, n) {
    int nused = used | (1 << i);
    if (used == nused) { continue; }
    int nret = GetP(fs, turn, prev, i);
    int nuse = use | (nused << (fs * n));
    nret -= calc(yowai, fs ^ 1, nuse, i);
    if (yowai == fs) {
      ret = min(ret, nret);
    } else {
      ret = max(ret, nret);
    }
  }
  return memo[yowai][fs][use][prev] = ret;
}

int Search(int fs, int use, int prev, int p, int beta, int alpha) {
  int turn = __builtin_popcount(use);
  if (turn == 2 * n) { return 2 * n; }
  if (p + calc(fs ^ 1, fs, use, prev) < 0) { return turn + 1; }
  int used = 0;
  if (fs == 0) {
    used = use & ((1 << n) - 1);
  } else {
    used = (use >> n) & ((1 << n) - 1);
  }
  int ret = turn + 1;
  if (win == fs) { ret = 100; }
  REP(i, n) {
    if (beta <= alpha) { break; }
    int nused = used | (1 << i);
    if (used == nused) { continue; }
    int np = p + GetP(fs, turn, prev, i);
    int nuse = use | (nused << (fs * n));
    if (win == fs && np - calc(2, fs ^ 1, nuse, i) < 0) { continue; }
    int nret = Search(fs ^ 1, nuse, i, -np, beta, alpha);
    if (win == fs) {
      ret = min(ret, nret);
      beta = min(beta, ret);
    } else {
      ret = max(ret, nret);
      alpha = max(alpha, ret);
    }
  }
  return ret;
}

int main() {
  while (scanf("%d %d", &n, &f) > 0) {
    MEMSET(memo, 0x0f);
    REP(y, n) {
      REP(x, n) {
        scanf("%d", &field[y][x]);
      }
    }
    int ans = calc(2, 0, 0, 0);
    if (ans > 0) {
      win = 0;
      puts("First");
      printf("%d\n", Search(0, 0, 0, 0, 100, -100));
    } else if (ans == 0) {
      puts("Draw");
      printf("%d\n", 2 * n);
    } else {
      win = 1;
      puts("Second");
      printf("%d\n", Search(0, 0, 0, 0, 100, -100));
    }
  }
}

Measured memory_bytes: 12000
sx, sy, tx, ty = map(int, input().split())
print(
    "U" * (ty - sy)
    + "R" * (tx - sx)
    + "D" * (ty - sy)
    + "L" * (tx - sx)
    + "L"
    + "U" * (ty - sy + 1)
    + "R" * (tx - sx + 1)
    + "DR"
    + "D" * (ty - sy + 1)
    + "L" * (tx - sx + 1)
    + "U"
)


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

int main(){
    string S;
    int K;
    cin >> S >> K;
    int N = S.length();
    set<string> SET;
    vector<string> ans;
    
    for(int i = 0; i < N; i++){
        for(int j = 1; j < 6; j++){
            if(N < i + j)break;
            SET.insert(S.substr(i, j));
        }
    }
    
    for(auto s : SET)ans.push_back(s);
    sort(ans.begin(), ans.end());
    cout << ans[K - 1] << endl;
    return 0;
}

Measured memory_bytes: 1920
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double lb;

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


int main() {
    ll N,x;
    cin >> N >> x;
    vector<ll> a(N);
    rep(i,N){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    
    ll count =0;
    rep(i,N){
        x -= a[i];
        if(x < 0){
            cout << count << endl;
            return 0;
        }
        count++;
    }
    if(x != 0){
        count--;
    }
    
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define int long long
typedef pair<int,int> pii;

const int mod = 1e9 + 7;
const int MOD = 998244353;
const int N = 5e5 + 5;


void solve(){
    string s, t; cin >> s >> t;
    t.pop_back();
    cout << ((s == t)? "Yes" : "No") << endl;

}

int32_t main(){
    // ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    // cin >> t;
    for(int T = 1 ; T <= t ; T++){
        // cout << "Case #" << T << ": " << endl;
        solve();
    }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<long> data(N);
  for(int i = 0; i < N; i++)cin >> data.at(i);
  sort(data.begin(), data.end());
  long cent = -1, flag = 0; 
  for(int i = 0; i < N - 1; i++){
    if(data.at(i) > data.at(N - 1) / 2){
       if(cent < data.at(N - 1) - data.at(i)){
        cent = data.at(N - 1) - data.at(i);
        flag = 1;
      }
    } else {
      if(cent < data.at(i)){
        cent = data.at(i);
        flag = 0;
      }
    }
  }
  if(flag == 0)cout << data.at(N - 1) << ' ' << cent << endl;
  else cout << data.at(N - 1) << ' ' << data.at(N - 1) - cent << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#define rep(i, a, n) for(int i = a;i < n;++i)
#define repe(i, a, n) for(int i = a;i <= n;++i)
#define repr(i, a, n) for(int i = a;i > n;--i)
#define reper(i, a, n) for(int i = a;i >= n;--i)
using namespace std;


int main(){
	int A, B, C;
	cin >> A >> B >> C;

	if(C <= A+B) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll int mod=1e9+7;
int n;
ll f[1<<22];
int a[25][25];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for (int j = 1; j <= n ; ++j) {
            scanf("%d",&a[i][j]);
        }
    }
    f[0]=1;
    for(int s=0;s<(1<<n);s++){
        int num=__builtin_popcount(s);
        for(int j=1;j<=n;j++)
            if(s&(1<<(j-1))&&a[num][j])
                f[s]=(f[s]+f[s^(1<<(j-1))])%mod;
    }
    printf("%d\n",f[(1<<n)-1]);
    return 0;
}


Measured memory_bytes: 18688
#include<iostream>

using namespace std;

int main(void)
{
	int a[1000],b[1000],c[1000],size;
	cin>>size;
	for(int i=0;i<size;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	for(int i=0;i<size;i++){
		if(
			a[i]*a[i]+b[i]*b[i]==c[i]*c[i]||
			a[i]*a[i]+c[i]*c[i]==b[i]*b[i]||
			b[i]*b[i]+c[i]*c[i]==a[i]*a[i]
			){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);

  int ans = 1;
  int x;

  cin >> x;

  for(int i=2;i<=x;i++){
    int t = i * i;
    while(t <= x){
      ans = max(ans, t);
      t *= i;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  Int n=s.size();
  Int ans=0;
  for(Int i=0;i<n;i++){    
    Int res=0;
    for(Int j=0;j<n;j++) res+=s[j]-'0';
    chmax(ans,res);
  }
  for(Int i=0;i<n;i++){
    if(s[i]=='0') continue;
    string t(s);
    t[i]--;
    for(Int j=i+1;j<n;j++) t[j]='9';
    Int res=0;
    for(Int j=0;j<n;j++) res+=t[j]-'0';
    chmax(ans,res);
  }
  cout<<ans<<endl;
  return 0;
}


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

void main()
{
    auto S = readln.chomp.to!(dchar[]);
    auto Q = readln.chomp.to!int;

    dchar[] as, bs;
    int f;
    foreach (_; 0..Q) {
        auto q = readln;
        if (q[0] == '1') {
            ++f;
        } else {
            auto c = q[4].to!dchar;
            if ((q[2] == '1' && f%2 == 0) || (q[2] == '2' && f%2 == 1)) {
                as ~= c;
            } else {
                bs ~= c;
            }
        }
    }
    if (f%2 == 1) {
        S.reverse();
        bs.reverse();
        writeln(bs ~ S ~ as);
    } else {
        as.reverse();
        writeln(as ~ S ~ bs);
    }
}

Measured memory_bytes: 5528
using System;

namespace B___Exchange
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var a = int.Parse (input[0]);
            var b = int.Parse (input[1]);
            var k = int.Parse (input[2]);
            for (var i = 0; i < k; i++)
            {
                if (i % 2 == 0)
                {
                    if (a % 2 == 1)
                    {
                        a -= 1;
                    }
                    b += a / 2;
                    a /= 2;
                }
                else
                {
                    if (b % 2 == 1)
                    {
                        b -= 1;
                    }
                    a += b / 2;
                    b /= 2;
                }
            }
            Console.WriteLine ($"{a} {b}");
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
using namespace std;
int main()
{
  float f,g;
  while(cin >> f >> g){
    if (f < 35.5 && g < 71.0) cout << "AAA" << endl;
    else if(f < 37.5 && g < 77.0) cout << "AA" << endl;
    else if(f < 40.0 && g < 83.0) cout << "A" << endl;
    else if(f < 43.0 && g < 89.0) cout << "B" << endl;
    else if(f < 50.0 && g < 105.0) cout << "C" << endl;
    else if(f < 55.0 && g < 116.0) cout << "D" << endl;
    else if(f < 70.0 && g < 148.0) cout << "E" << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

vector<int> adj[100009];
int p[100009];
int h[100009];

int dfs(int x){
	vector<int> vs;
	for(int i:adj[x]){
		vs.PB(dfs(i));
	}
	if(SZ(vs)==0){
		return h[x]=0;
	}
	sort(ALL(vs),greater<int>());
	REP(i,SZ(vs)){
		h[x]=max(h[x],vs[i]+i+1);
	}
	return h[x];
}

int main(){
	DRI(n);
	REPP(i,1,n){
		RI(p[i]);p[i]--;
		adj[p[i]].PB(i);
	} 
	printf("%d",dfs(0));
}


Measured memory_bytes: 15872
import java.util.*;
public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc = new Scanner(System.in);
        int ans = 0;


        int h,w;

        h = sc.nextInt();
        w = sc.nextInt();
        int[][] a = new int[h][w];
        int[] nul_h = new int[h];
        int[] nul_w = new int[w];

        String[] s = new String[h];
        sc.nextLine();

        for(int i = 0;i < h;i++){
            s[i] = sc.nextLine();
        }


        for(int i = 0;i < h;i ++){
            for(int j = 0;j < w;j ++){
                a[i][j] = s[i].charAt(j) == '.'?0:1;
            }
        }

        int sum=0;
//
        for(int i = 0;i < h;i ++){
            for(int j = 0;j < w;j ++){
                sum+=a[i][j];
            }
            if(sum == 0) nul_h[i] = 1;
            sum = 0;
        }

        for(int i = 0;i < w;i ++){
            for(int j = 0;j < h;j ++){
                sum += a[j][i];
            }
            if(sum == 0) nul_w[i] = 1;
            sum = 0;
        }

        for(int i = 0;i < h;i ++){
            if(nul_h[i] != 1) {
                for (int j = 0; j < w; j++){
                    if (nul_w[j] != 1) System.out.print(a[i][j]==0?".":"#");
                }
                System.out.println("");
            }
//            System.out.println(s[i]);
        }


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

    }
}

Measured memory_bytes: 25684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n,t;
  cin>>n>>t;
  int sum=0;
  int cur=0;
  rep(i,0,n){
    int a;
    cin>>a;
    if(cur<=a){
      sum+=t;
    }
    else{
      sum+=a+t-cur;
    }
    cur=a+t;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < (n); i++)
using pint = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n;
    cin >> n;
    ll a[n + 1], b[n];
    rep (i, n + 1) cin >> a[i];
    rep (i, n) cin >> b[i];
    ll ans = 0;
    rep (i, n) {
        if (a[i] > b[i]) {
            ans += b[i];
            continue;
        }
        b[i] -= a[i];
        ans += a[i];
        if (a[i + 1] < b[i]) {
            ans += a[i + 1];
            a[i + 1] = 0;
        } else {
            ans += b[i];
            a[i + 1] -= b[i];
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1792
import math
from functools import lru_cache

@lru_cache(maxsize=10**6)
def cached_gcd(i, j):
    return math.gcd(i, j)

if __name__ == '__main__':
    N = int(input())
    total = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            g = cached_gcd(j, i)
            for k in range(1, N + 1):
                total += cached_gcd(k, g)
    print(total)



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

typedef int integer;

#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define pb push_back
#define bs binary_search
#define up upper_bound
#define lw lower_bound
#define fs first 
#define sd second 
#define mp make_pair    

#define fore(i,a,b) for(ll i = a; i < b; i++)
#define rfore(i, a, b) for(ll i = a - 1; i >= b; i--)
#define forev(a,b) fore(i,0,b)cout<<a[i]<<" "; 
#define mm(a,b) memset(a , b , sizeof a) 
#define ALL(a) a.begin(),a.end() 
#define SZ(n) ((ll) (n).size())

#define infi  2e9
#define int long long
#define endl '\n'
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll INF = 1e10;
const ld EPS = 1e-8;

typedef pair<ll,ll> pll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

const int MAXN = 3001;
const int K=20;

int n,m;
int a[MAXN];
int dp[MAXN][MAXN][2];

int solve(int i, int j,int t){
	if(i>j)return 0;
	int &r = dp[i][j][t];
	if(r!=-1)return r;
	r=0;
	if(t==0){
		r=max(a[i]+solve(i+1,j,1),a[j]+solve(i,j-1,1));
	}else{
		r=min(solve(i+1,j,0)-a[i],solve(i,j-1,0)-a[j]);
	}
	return r;
}

integer main(){
	cin>>n;
	mm(dp,-1);
	fore(i,0,n)cin>>a[i];
	int r = solve(0,n-1,0);
	cout<<r;
    return 0;
}



Measured memory_bytes: 141184
#include <bits/stdc++.h>
#define int long long int
#define ldouble long double
#define  vint vector<int>
#define rep(i,n) for(i=0;i<n;i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

signed main() {
    int n,i;
    cin>>n;
    vint a(n);
    rep(i,n){
        cin>>a.at(i);
    }

    sort(a.begin(),a.end());
    int ai=a.at(n-1);
    a.at(n-1)=INF;
    ldouble raj;
    raj=((ldouble)(ai+1))/2.0; //理想r
    int aj;
    ldouble dif=INF;
    rep(i,n){
        if(abs(raj-a.at(i))<dif){
            dif=abs(raj-a.at(i));
            aj=a.at(i);
        }
    }
    cout<<ai<<" "<<aj<<endl;
return 0;
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1])

r = 0  # いま切ってる一番右端
ans = 0
for a, b in X:
    if r < a:
        r = b - 1
        ans += 1
        
print(ans)


Measured memory_bytes: 29852
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;

typedef long long LL;
LL a[100];
int main()
{
	int i, n; 
	a[0] = 2LL, a[1] = 1LL;
	for(i = 2;i <= 86;i++)
		a[i] = a[i - 1] + a[i - 2];
		scanf("%d",&n);
		printf("%lld\n",a[n]);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k = 0;

		k = sc.nextInt();
		long ans = 0;
        for (int i = 1; i < k+1; i++) {
            for (int j = 1; j < k+1; j++) {
            	for (int m = 1; m < k+1; m++) {
            		if(i == 1 || j == 1 || m == 1){
            			ans += 1;
            		}else if(i == j && j == m){
            			ans += i;
            		}else{
                		ans += gcd(i,j,m);
            		}

            	}
            }
        }
			System.out.println(ans);
	}

	public static final int gcd(final int... param) {
	    final int len = param.length;
	    int g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}


	public static final int gcd(int a, int b) {
	    //a > b にする（スワップ）
	    if (a < b) {
	        int tmp = a;
	        a = b;
	        b = tmp;
	    }

	    //ユークリッドの互除法
	    int r = -1;
	    while (r != 0) {
	        r = a % b;
	        a = b;
	        b = r;
	    }

	    return a;    //b には r=0 の値が入るため、a を返す
	}
}

Measured memory_bytes: 30296
N, M, X = map(int, input().split())
C = []
A = []
for _ in range(N):
    c, *a = map(int, input().split())
    C.append(c)
    A.append(a)
res = 10**18
for i in range(2**N):
    D = [0 for _ in range(M)]
    cost = 0
    for j in range(N):
        if (i >> j) & 1:
            cost += C[j]
            for k in range(M):
                D[k] += A[j][k]
    for k in range(M):
        if D[k] < X:
            break
    else:
        res = min(res, cost)
print(res if res != 10**18 else -1)

Measured memory_bytes: 9224
#-*-coding:utf-8-*-

def main():
    h, w = map(int, input().split())

    a_list = [list('#' * (w + 2))]
    for _ in range(h):
        temp = list(input())
        temp.insert(0, '#')
        temp.append('#')
        a_list.append(temp)
    a_list.append(list('#' * (w + 2)))
    
    for i in a_list:
        print(''.join(i))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.Scanner;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while (true) {
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();
			if ("+".equals(op)) {
				ln(a + b);
			} else if ("-".equals(op)) {
				ln(a - b);
			} else if ("*".equals(op)) {
				ln(a * b);
			} else if ("/".equals(op)) {
				ln(a / b);
			} else {
				break;
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
import sys
input = sys.stdin.buffer.readline

def main():
    R, C, K = map(int, input().split())
    State = [[0]*R for _ in range(C)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        State[c-1][r-1] += v

    dp = [[0]*4 for _ in range(C+1)]

    for r in range(R):
        ndp = [[0]*4 for _ in range(C+1)]
        for c in range(C):
            ndp[c+1][0] = max(ndp[c+1][0], max(dp[c+1]))
            ndp[c+1][1] = ndp[c+1][0] + State[c][r]
            for n in range(4):
                if ndp[c][n] > ndp[c+1][n]:
                    ndp[c+1][n] = ndp[c][n]
                if n < 3 and ndp[c][n] + State[c][r] > ndp[c+1][n+1]:
                    ndp[c+1][n+1] = ndp[c][n] + State[c][r]
        dp = ndp
        
    print(max(dp[C]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 208936
#include <stdio.h>

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


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define endl '\n'
#define PB push_back
#define PF push_front
#define MP make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
 
const int INF = 1e9 + 7;
const ll LINF = 1e18 + 14;

void print(unsigned int a){
    if (a == 0)
        return;
    print(a >> 1);
    cout << (a & 1);
}

int main(){
    ios_base::sync_with_stdio(false); //cin.tie(nullptr); cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<unsigned int> keys(m);
    vector<ull> costs(m);
    for (int i = 0; i < m; i++){
        int b;
        cin >> costs[i] >> b;
        for (int j = 0; j < b; j++){
            int c;
            cin >> c;
            keys[i] |= (1 << (c - 1));
        }
    }
    vector<vector<ull> > dp(m+1, vector<ull> ((1 << n), INF));
    dp[0][0] = 0;
    for (int i = 0; i < m; i++){
        for (unsigned int j = 0; j < (1 << n); j++){
            dp[i+1][j] = min(dp[i][j], dp[i][j - (j & keys[i])] + costs[i]);
            //print(j); cout << ' ';
            //print(j - (j & keys[i])); cout << ' ' << dp[i+1][j] << endl;
        }
    }
    if (dp[m][(1 << n) - 1] == INF)
        cout << -1;
    else
        cout << dp[m][(1 << n) - 1];
    return 0;
}  


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i, n+1) {
    if (i > 0 && i < 10) ans++ ;
    if (i >= 100 && i < 1000) ans++;
    if (i >= 10000 && i < 100000) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

long long n;
vector<long long> p, id, lmemo[2], rmemo[2];

long long solve();

int main() {
  cin >> n;
  p.resize(n);
  for(int i = 0; i < n; ++i) cin >> p[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  id.resize(n);
  for(int i = 0; i < n; ++i) id[p[i] - 1] = i;
  for(int i = 0; i < 2; ++i) {
    lmemo[i].assign(n, -1);
    rmemo[i].assign(n, n);
  }
  set<int> str;
  set<int, greater<int>> stl;
  stl.insert(-1);
  str.insert(n);
  for(int i = 0; i < n; ++i) {
    int now = id[n - 1 - i];
    auto rid = str.upper_bound(now);
    rmemo[0][now] = *rid;
    rid = str.upper_bound(*rid);
    if(rid != str.end()) rmemo[1][now] = *rid;
    auto lid = stl.upper_bound(now);
    lmemo[0][now] = *lid;
    lid = stl.upper_bound(*lid);
    if(lid != stl.end()) lmemo[1][now] = *lid;

    str.insert(now);
    stl.insert(now);
  }
  for(int i = 0; i < n; ++i) {
    long long now = 0;
    now += (rmemo[0][i] - i) * (lmemo[0][i] - lmemo[1][i]);
    now += (rmemo[1][i] - rmemo[0][i]) * (i - lmemo[0][i]);
    ans += now * p[i];
  }
  return ans;
}

Measured memory_bytes: 14336
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<queue>
using namespace std;

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

    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++)
        cin >> A[i] >> B[i];

    vector<vector<int>> v(M+1, vector<int>());
    for (int i = 0; i < N; i++) {
        if (A[i] > M)
            continue;

        v[A[i]].push_back(B[i]);
    }

    //for (int i = 0; i <= M; i++) {
    //    sort(v[i].rbegin(), v[i].rend());
    //    cout << i << " : ";
    //    for (int j = 0; j < (int)v[i].size(); j++)
    //        cout << v[i][j] << " ";
    //    
    //    cout << endl;
    //}

    int ans = 0;
    priority_queue<int> salary;
    for (int i = 0; i <= M; i++) {
        for (int j = 0; j < (int)v[i].size(); j++)
            salary.push(v[i][j]);

        if (salary.empty())
            continue;

        ans += salary.top();
        salary.pop();
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6400
// package agc.agc023;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

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

        Map<Long,Long> count = new TreeMap<>();
        count.put(0L, 1L);

        long sum = 0;
        long answer = 0;
        for (int i = 0 ; i < n ; i++) {
            sum += a[i];
            long same = count.getOrDefault(sum, 0L);
            answer += same;
            count.put(sum, same+1);
        }

        out.println(answer);
        out.flush();
    }

    public static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }

    public static class InputReader {
        private static final int BUFFER_LENGTH = 1 << 12;
        private InputStream stream;
        private byte[] buf = new byte[BUFFER_LENGTH];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int next() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            return (char) skipWhileSpace();
        }

        public String nextToken() {
            int c = skipWhileSpace();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = skipWhileSpace();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            return Double.valueOf(nextToken());
        }

        int skipWhileSpace() {
            int c = next();
            while (isSpaceChar(c)) {
                c = next();
            }
            return c;
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}

Measured memory_bytes: 51244
#include<bits/stdc++.h>
using namespace std;
int a[100]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51},k;
int main()
{
	cin>>k;
	cout<<a[k];
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		  try(Scanner sc = new Scanner(System.in)) {
			  while(sc.hasNext()) {
				  String str=sc.nextLine();
				  String[] tokens=str.split(" ");
				  int[] count=new int[1010];
				  int max=0, lengthmax=0;
				  
				  for(int i=0; i<tokens.length; i++) {
					  if(tokens[i].length()>lengthmax) {
						  lengthmax=tokens[i].length();
					  }
					  for(int j=i+1; j<tokens.length; j++) {
						  if(tokens[i].equals(tokens[j])) {
							  count[i]++;
							  max=Math.max(count[i], max);
						  }
					  }
				  }
				  for(int i=0; i<tokens.length; i++) {
					  if(count[i]==max) {
						  System.out.print(tokens[i]);
						  break;
					  }
				  }
				  System.out.print(" ");
				  for(int i=0; i<tokens.length; i++) {
					  if(lengthmax==tokens[i].length()) {
						  System.out.println(tokens[i]);
						  break;
					  }
				  }
			  }
		  }
	}
}


Measured memory_bytes: 26080
import math


N,M= list(map(int,input().split(" ")))

red = [False] * (N + 1)
nums = [1] * (N+1)
red[1] = True


for i in range(M):
    x, y =  list(map(int,input().split(" ")))

    nums[x]-=1
    nums[y]+=1
    if red[x]:
        red[y] = True
    if nums[x] == 0:
        red[x] = False
print(red.count(True))



Measured memory_bytes: 50904
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
using namespace std;

int main(){
  int n,k; string s;
  cin >> n >> s >> k;
  for(int i=0;i<s.size();i++){
    if(s[i]!=s[k-1]) s[i]='*';
  }
  cout << s <<endl;
}

Measured memory_bytes: 256
/*
By Snickeen
*/
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VI vector<int>
#define VL vector<LL>
#define VII vector<PII >
#define VLL vector<PLL >
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define FF first
#define SS second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL MAXN=1e5+10;
LL t,n,m,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;

string s;

int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0;
	LL a,b,c,d;
	cin>>a>>b>>c>>d;
	repu(i,a,c-1)cout<<"R";
	repu(i,b,d-1)cout<<"U";
	repd(i,c,a+1)cout<<"L";
	repd(i,d,b+1)cout<<"D";
	
	cout<<"D";
	repu(i,a,c-1)cout<<"R";
	cout<<"RU";
	repu(i,b,d-1)cout<<"U";
	cout<<"LU";
	repd(i,c,a+1)cout<<"L";
	cout<<"LD";
	repd(i,d,b+1)cout<<"D";
	cout<<"R";
	
	return 0;
}

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

int getParent(int node) {
  return node/2;
}

int getLeft(int node) {
  return node*2;
}

int getRight(int node) {
  return node*2+1;
}

void printProperties(vector< int > tree, int node) {
  cout << "node " << node << ": key = " << tree[node-1] << ", ";
  if (getParent(node))
    cout << "parent key = " << tree[getParent(node)-1] << ", ";
  if (getLeft(node) <= tree.size())
    cout << "left key = " << tree[getLeft(node)-1] << ", ";
  if (getRight(node) <= tree.size())
    cout << "right key = " << tree[getRight(node)-1] << ", ";
  cout << endl;
}

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector< int > heap (n, 0);
  for (int i = 0; i < n; i++)
    cin >> heap[i];
  for (int i = 0; i < n; i++)
    printProperties(heap, i+1);
  return 0;
}



Measured memory_bytes: 3164
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := nextInts(3 * n)
	sort.Sort(sort.IntSlice(a))
	ans := 0
	for i := n; i < 3*n; i += 2 {
		ans += a[i]
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 6400
#include <iostream>
#include <string>

using namespace std;

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

    if (S <= "2019/04/30") {
        std::cout << "Heisei" << std::endl;
    } else {
        std::cout << "TBD" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(i,j,k)
print(ans)

Measured memory_bytes: 69508
use proconio::input;

fn main() {
    input! {
        n: i64,
    }

    if let Some(ans) = (1..)
        .take_while(|x| x * x <= n)
        .filter(|x| n % x == 0)
        .last()
        .map(|x| x + n / x - 2)
    {
        println!("{}", ans);
    }
}


Measured memory_bytes: 2132
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

uint16_t bubble_sort(uint8_t *a, uint8_t n)
{
    uint16_t n_loop        = 0;
    for(uint8_t i=0; i<n; ++i)
        for(uint8_t j=n-1; j>i; --j)
            if(a[j] < a[j-1]){
                uint8_t tmp  = a[j  ];
                a[j  ]       = a[j-1];
                a[j-1]       = tmp   ;
                ++n_loop             ;
            }

    return n_loop;
}

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

    uint8_t a[n];
    for(uint8_t i=0; i<n; ++i)
        scanf("%"PRIu8, a + i);

    uint16_t n_loop = bubble_sort(a, n);

    printf("%"PRIu8, a[0]);
    for(uint8_t i=1; i<n; ++i)
        printf(" %"PRIu8, a[i]);
    printf("\n%"PRIu16"\n", n_loop);

    return 0;
}

Measured memory_bytes: 1860
n = int(input())


m = n // 1.08

if int(m * 1.08) == n:
    print(int(m))
elif int((m+1)* 1.08) == n:
    print(int(m+1))
elif int((m-1)*1.08) == n:
    print(int(m-1))
else:
    print(':(')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;
 
int H, W;
string a[105];
 
signed main()
{
    cin >> H >> W;
    REP(i,H) cin >> a[i];
 
    REP(i,W+2) cout << '#';
    cout << endl;
    REP(i,H) cout << '#' << a[i] << '#' << endl;
    REP(i,W+2) cout << '#';
    cout << endl;
}

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

struct point {
    int x,y;

};

int main(void){
    int N,M;
    cin>>N>>M;
    vector<point> st(N),cp(M);
    for (int i=0;i<N;i++){
        cin>>st[i].x>>st[i].y;
    }
    for (int i=0;i<M;i++){
        cin>>cp[i].x>>cp[i].y;
    }
    vector<int> ans(N);

    for (int i=0;i<N;i++){
        ll min = 1e9;
        for (int j=M-1;j>=0;j--){
            ll dist = abs(st[i].x-cp[j].x) + abs(st[i].y-cp[j].y);
            if (min>=dist) {
                min = dist;
                ans[i]=j+1;
            }
        }
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

////////// 二項係数(N<=10^7) //////////

ll fac[MAX],finv[MAX],inv[MAX];
// fac[i] i!
// finv[i] i!の逆元
// inv[i] iの逆元

// テーブルを作る前処理
void COM_init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(ll 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;
  }
}

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

//////////////////////////////////////////////////

int main(){
  ll N,ans=0;
  cin>>N;
  
  COM_init();
  for(int i=1; i<=N/3; ++i){
    ll T=N-3*i;
    ans+=COM(T+i-1,i-1);
    ans%=MOD;
  }
  
  ans=(ans%MOD+MOD)%MOD;
  co(ans);
  return 0;
}

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

int main() {
  long long int N, ans = 0;
  cin >> N ;
  if((N % 2 == 1) || (N == 0)){
  cout << ans << endl;
  }
  else{
    N /= 10;
    ans += N;
    while(N){
      N = (N / 5);
      ans = ans + N;
    }
    cout << ans << endl;
  }
  return 0;
  
}

Measured memory_bytes: 256
/*Program from Luvwgyx*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=1e5+10;
struct node{int to,nxt,w;}e[maxn<<1];
int n,m,tot,bel,sec,flag,cnt[3],head[maxn],vis[maxn],col[maxn];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(ll x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(ll x){print(x);puts("");}
void add(int u,int v,int w){e[++tot].to=v;e[tot].w=w;e[tot].nxt=head[u];head[u]=tot;}
void dfs(int x){
    cnt[col[x]]++;vis[x]=1;bel++;
    for(int i=head[x],v=e[i].to;i;i=e[i].nxt,v=e[i].to){
        if(e[i].w==1)sec++;
        if(!vis[v])col[v]=(col[x]+e[i].w+3)%3,dfs(v);
        else if(col[v]!=(col[x]+e[i].w+3)%3)flag=1;
    }
}
int main(){
    n=read();m=read();ll ans=0;
    for(int i=1;i<=m;i++){int u=read(),v=read();add(u,v,1);add(v,u,-1);}
    for(int i=1;i<=n;i++){
        if(vis[i])continue;
        memset(cnt,0,sizeof(cnt));
        bel=sec=flag=0;dfs(i);
        if(flag)ans+=1ll*bel*bel;
        else if(cnt[0]&&cnt[1]&&cnt[2])ans+=1ll*cnt[0]*cnt[1]+1ll*cnt[1]*cnt[2]+1ll*cnt[2]*cnt[0];
        else ans+=sec;
    }write(ans);
    return 0;
}


Measured memory_bytes: 6784