akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;

  int temp_n = N;
  int num;
  while (1){
    if (temp_n != 0){
	  num += temp_n % 10; 
      temp_n /= 10;
	}
    else{
      break;
    }
  }

  if(  N % num == 0 ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int n; cin >> n;
    ll h[n]; rep(i,n) cin >> h[i];
    for(int i = n-1; i >= 1; --i){
        if(h[i] < h[i-1]) h[i-1]--;
        if(h[i] < h[i-1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int W, H, N, x, y, a;
    cin >> W >> H >> N;
    int x0 = 0, x1 = W, y0 = 0, y1 = H;
    for (int i = 0; i < N; i++) {
        cin >> x >> y >> a;
        if (a == 1 && x > x0) x0 = x;
        if (a == 2 && x < x1) x1 = x;
        if (a == 3 && y > y0) y0 = y;
        if (a == 4 && y < y1) y1 = y;
    }
    cout << max(x1 - x0, 0) * max(y1 - y0, 0) << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <cmath>

int main()
{
    int H, W;
    std::cin >> H >> W;

    std::vector<std::vector<char>> s(H, std::vector<char>(W));

    for (int h = 0; h < H; h++)
    {
        for (int w = 0; w < W; w++)
        {
            std::cin >> s[h][w];
        }
    }

    for (int h = 0; h < H; h++)
    {
        for (int w = 0; w < W; w++)
        {
            if (s[h][w] == '.') continue;
            if (h - 1 >= 0 && s[h - 1][w] == '#') continue;
            if (w - 1 >= 0 && s[h][w - 1] == '#') continue;
            if (h + 1 < H && s[h + 1][w] == '#')continue;
            if (w + 1 < H && s[h][w + 1] == '#')continue;

            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
s = deque(input())
q = int(input())
rev= 0
for i in range(q):
    x = list(input().split())
    if x [0] == '1':
        rev += 1
    else:
        if x[1] == '1':
            if rev % 2 == 0:
                s.appendleft(x[2])
            else:
                s.append(x[2])
        else:
            if rev % 2 == 0:
                s.append(x[2])
            else:
                s.appendleft(x[2])
if rev % 2 == 1:
    s.reverse()
print("".join(s))

Measured memory_bytes: 8564
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
    _typer init = 0;
    char ch = getchar(), k = 0;
    for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
    for ( ; isdigit(ch); ch = getchar())
        init = (init << 3) + (init << 1) + (ch ^ 48);
    return k ? -init : init;
}
const ll N = 200005, INF = 1e9;

/*******************************************************************************
 *
 *
 *
 ******************************************************************************/

int n, A[N], Ans[N], S[N], cnt;

int main() {
    n = read<int>();
    rep (i, 1, n) {
        A[i] = read<int>();
        if (i * 2 > n) Ans[i] = A[i];
        if (Ans[i]) ++cnt;
    }
    dep (i, n / 2, 1) {
        int res = 0;
        rep (j, 2, n / i) res += Ans[i * j];
        Ans[i] = (A[i] + (res & 1)) & 1;
        if (Ans[i]) ++cnt;
    }

    cout << cnt << endl;
    int d = 0;
    rep (i, 1, n)
        if (Ans[i]) printf("%d%c", i, " \n"[++d==cnt]);
    return 0;
}



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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] != T[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn
#define per(i,a,n) for (int i=a-1;i>=n;i--)//iをnからa
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
 
 
//sort(all(a)); ソート
//sort(all(a),greater<int>()); 逆順ソート
 
int main() {
  int d;
  cin >>d;
  
  if(d){
 cout<<"0"<<endl;
  }else{
cout<<"1"<<endl;
  }
 
 return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        int n;
        cin>>n;
        cout<<n/3600<<":"<<n%3600/60<<":"<<n%60<<endl;
        return 0;
}

Measured memory_bytes: 1164
n = gets.to_i
w = [nil, nil]
arr1 = gets.chomp.split.map(&:to_i)
arr2 = gets.chomp.split.map(&:to_i)
arr1.zip(arr2){|x, y| w[x] = y if w[x].nil? || w[x] > y}

if w.any?{|ww| ww.nil?}
    puts 0
else
    puts w[0] + w[1]
end


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

const int N = 2005;

int n;
bitset<N> a[N], l[2][N], r[2][N], d[2][N];

int main(){
	scanf("%d", &n);
	for(int i = 2; i <= n; i++){
		for(int j = 1; j < i; j++){
			int x;
			scanf("%1d", &x);
			a[i][j] = x;
			a[j][i] = !x;
		}
	}
	for(int i = 1; i <= n; i++) l[1][i][i] = r[1][i][i] = d[1][i][i] = 1;
	for(int len = 2; len <= n; len++){
		for(int st = 1; st + len - 1 <= n; st++){
			l[len & 1][st] = l[~len & 1][st];
			l[len & 1][st][st + len - 1] = ((d[~len & 1][st] & a[st + len - 1]).count() != 0);
			r[len & 1][st] = r[~len & 1][st + 1];
			r[len & 1][st][st] = ((d[~len & 1][st + 1] & a[st]).count() != 0);
			d[len & 1][st] = l[len & 1][st] & r[len & 1][st];
		}
	}
	printf("%d\n", d[n & 1][1].count());
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n); i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)	
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define LOOP while(true)
#define INF 1e9
const long long MOD = 1000000007;
typedef long long ll;

int main(void){
	int A, B;
	cin >> A >> B;
	if(A > B)A--;
	cout << A << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	map<int, int> mp;
	rep(i,n){
		int a;
		cin >> a;
		++mp[a];
	}
	vector<int> v;
	for(auto p : mp){
		v.push_back(p.second);
	}
	sort(v.rbegin(), v.rend());
	int ans = 0;
	for(int i = k; i < v.size(); ++i){
		ans += v[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13628
#include <bits/stdc++.h>
using namespace std;
int abs(int x) {
  if(x >= 0) {
    return x;
  }
  else {
    return -1 * x;
  }
}
int main() {
  int A, B, C;
  cin >> A >> B;
  C = abs(A - B);
  if(C % 2 == 0) {
    cout << min(A, B) + C / 2;
  }
  else {
    cout << "IMPOSSIBLE" << endl;
  }
}


Measured memory_bytes: 3596
//
//  main.cpp
//  fibonacci_number
//
//  Created by ???????????? on 2017/10/17.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    scanf("%d", &n);
    int A[n];
    A[0]=A[1]=1;
    for(int i = 2; i <= n; i++ ){
        A[i] = A[i-2]+A[i-1];
    }
    cout << A[n] <<endl;;
    return 0;
}

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

const int dx[] = {0, 1};
const int dy[] = {1, 0};

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<int>> d(h, vector<int>(w, -1));
  queue<P> q1, q2;
  int sx = 0, sy = 0;
  int gx = h - 1, gy = w - 1;
  q1.push(P(sx, sy));
  d[0][0] = 0;
  char here = s[0][0];
  while (!q1.empty() || !q2.empty()) {
    while (!q1.empty()) {
      P p = q1.front();
      int cx = p.first, cy = p.second;
      q1.pop();
      // if (cx == gx && cy == gy) break;
      rep(i, 2) {
        int nx = cx + dx[i], ny = cy + dy[i];
        if (nx < 0 || h <= nx || ny < 0 || w <= ny) continue;
        if (d[nx][ny] != -1) continue;
        if (s[nx][ny] == here) {
          d[nx][ny] = d[cx][cy];
          q1.push(P(nx, ny));
        } else {
          d[nx][ny] = d[cx][cy] + 1;
          q2.push(P(nx, ny));
        }
      }
    }
    swap(q1, q2);
    here = (here == '.' ? '#' : '.');
    // rep(i, h) rep(j, w) printf("%+d%c", d[i][j], (j == w - 1 ? '\n' : ' '));
    // cout << endl;
  }

  int ans;
  if (s[sx][sy] == '.')
    ans = (d[gx][gy] + 1) / 2;
  else
    ans = d[gx][gy] / 2 + 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3672
import Numeric

solve :: [Float] -> [String]
solve (x1:y1:x2:y2:x3:y3:xs)
  | null xs = []
  | otherwise = ((showFFloat (Just 3) p " ")++(showFFloat (Just 3) q " ")++r) : solve xs
  where p = ((/1000) . fromIntegral . round . (*1000)) ((y1-y3)*(y1^2-y2^2+x1^2-x2^2)-(y1-y2)*(y1^2-y3^2+x1^2-x3^2))/(2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3))
        q = ((/1000) . fromIntegral . round . (*1000)) ((x1-x3)*(x1^2-x2^2+y1^2-y2^2)-(x1-x2)*(x1^2-x3^2+y1^2-y3^2))/(2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3))
        r = showFFloat (Just 3) (((/1000) . fromIntegral . round . (*1000) . sqrt) ((p-x1)^2+(q-y1)^2)) ""

main = getContents >>= mapM_ putStrLn . solve . (++[1,1,1,1,1,1]) . map read . tail . words

Measured memory_bytes: 4488
#include <iostream>   
#include <string>   
#include <set>   
#include <map>   
using namespace std;   
  
int main()   
{   
    int n;   
    string str;   
    map<string, set<int> > m;   
    map<string, set<int> >::iterator p;   
  
    while (cin >> str>> n)   
        m[str].insert(n);   
  
    for (p = m.begin(); p != m.end(); p++)   
    {   
        cout << p->first << endl;   
        set<int>::iterator q = (p->second).begin();   
        for (; q != (p->second).end(); )   
        {   
            cout << *q;   
            cout << (++q != (p->second).end() ? ' ' : '\n');   
        }   
    }   
  
    return 0;   
}  

Measured memory_bytes: 0
#入力
N, L = list(map(int,input().split()))
A = [None for _ in range(N)]
#食べるリンゴは絶対値が最も小さいリンゴであるので絶対値が最小のリンゴを求め、その味をMに記録
m = float('inf')
M = 0
for i in range(N):
  A[i] = L + i
  if m > abs(A[i]):
    m = abs(A[i])
    M = A[i] 
#結果
print(sum(A) - M)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

//int mod = 1000000007;
int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

int modpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

signed main(){

    int N; cin >> N;
    vec a(N); readv(a);

    int M = 90000;
    mat dp(N + 1, vec(2 * M + 1, 0));
    dp[0][M] = 1;
    REP(i, N){
        REP(j, 2 * M + 1){
            if(j + a[i] <= 2 * M) Add(dp[i + 1][j + a[i]], 2 * dp[i][j]);
            if(j - a[i] >= 0) Add(dp[i + 1][j - a[i]], dp[i][j]);
        }
    }
    int x = 0;
    FOR(j, M + 1, 2 * M + 1) Add(x, dp[N][j]);

    mat dp2(N + 1, vec(2 * M + 1, 0));
    dp2[0][M] = 1;
    REP(i, N){
        REP(j, 2 * M + 1){
            if(j + a[i] <= 2 * M) Add(dp2[i + 1][j + a[i]], dp2[i][j]);
            if(j - a[i] >= 0) Add(dp2[i + 1][j - a[i]], dp2[i][j]);
        }
    }
    int y = 0;
    FOR(j, M + 1, 2 * M + 1) Add(y, dp2[N][j]);
    x -= 2 * y + modpow(2, N, mod) - 2;
    x = (x % mod + mod) % mod; 

    int p = modpow(3, N, mod) - 3 * modpow(2, N, mod) + 3;
    p = (p % mod + mod) % mod;
    int ans = 3 * x - 2 * p;
    ans = (ans % mod + mod) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 848768
def c(strs):
    count = 0
    count_a = 0
    count_b = 0
    flag = 1
    for s in strs:
        count += s.count('AB')
        if s[0]=='B' and s[-1]=='A':
            count_a += 1
            count_b += 1
        elif s[0]=='B':
            count_b += 1
            flag = 0
        elif s[-1]=='A':
            count_a += 1
            flag = 0
    if count_a:
        return count + min(count_a,count_b) - flag
    return count


if __name__=='__main__':
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    print(c(s))



Measured memory_bytes: 3700
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    vector<long> b(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &b[i]);
    }

    vector<long> ans;
    long cnt=n;
    while(cnt>0) {
        for(i=cnt-1; i>=0; i--) {
            if(b[i]==i+1) {
                break;
            }
        }
        if(i==-1) {
            printf("-1\n"); return 0;
        }
        ans.push_back(i+1);
        long k;
        for(k=i; k<cnt-1; k++) {
            b[k]=b[k+1];
        }
        cnt--;
    }
    for(i=0; i<n; i++) {
        printf("%ld\n", ans[n-1-i]);
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200007];
int main()
{
	int n,m,b;
	scanf("%d",&n);
	m=n-1;
	while(m--){
		scanf("%d",&b);
		a[b]++;
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",a[i]);
	}
	return 0;
 } 

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

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

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

using namespace std;

typedef long long ll;

struct fenwick_tree {
    typedef int T;
    T n;
    vector<T> bit;
    fenwick_tree(T num) : bit(num+1, 0) { n = num; }
    void add(T i, T w) {
        for (T x = i; x <= n; x += x & -x) {
            bit[x] += w;
        }
    }
    T sum(T i) {
        T ret = 0;
        for (T x = i; x > 0; x -= x & -x) {
            ret += bit[x];
        }
        return ret;
    }
};

ll a[100005];

bool judge(ll mid, ll n) {
    // offset => 履かせる下駄
    int offset = n+1;
    ll num_inverse = 0;
    fenwick_tree bit(n*2+10);

    int sum_v = 0;
    bit.add(offset, 1);

    for (int i = 0; i < n; i++) {
        int s = (a[i] <= mid) ? 1 : -1;
        sum_v += s;
        num_inverse += (bit.sum(sum_v-1+offset));
        bit.add(sum_v+offset, 1);
    }
    return num_inverse > (n+1)*n/2/2; 
}

int main() {
    ll n; cin >> n;

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

    ll high = 1e18, low = 0; 

    while (low < high) {
        ll mid = ( high + low ) / 2;
        if ( judge(mid, n) ) {
            high = mid;
        } else {
            low = mid+1;
        }
    }

    cout << high << endl;

    return 0;
}

Measured memory_bytes: 1804
import sys

alphabet = {"a": 0, "b": 0, "c": 0, "d": 0, "e": 0, "f": 0, "g": 0, "h": 0, "i": 0, "j": 0, "k": 0, "l": 0, "m": 0,
            "n": 0, "o": 0, "p": 0, "q": 0, "r": 0, "s": 0, "t": 0, "u": 0, "v": 0, "w": 0, "x": 0, "y": 0, "z": 0}
text = sys.stdin.read().lower()
for character in text:
    if character.lower() in alphabet.keys():
        alphabet[character.lower()] += 1

for key in alphabet.keys():
    print("%s : %i" % (key, alphabet[key]))



Measured memory_bytes: 5568
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << x << "\n"
#define endwith return
constexpr int mod = 1000000007;
using namespace std;
int input() { int t; cin >> t; return t; }
signed main() {
	char c; cin >> c;
	if (c >= 'a')puts('a'); else puts('A');
}

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

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

using namespace std;

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

template<class T>
void add_directed_edge(weighted_graph<T>& G,int u,int v,const T& wt){
	G[u].emplace_back(v,wt);
}

template<class T>
vector<T> Dijkstra(const weighted_graph<T>& G,int s){
	constexpr T INF=numeric_limits<T>::max();
	int n=G.size();
	vector<T> d(n,INF); d[s]=0;
	priority_queue<pair<T,int>> Q; Q.emplace(0,s);
	while(!Q.empty()){
		T d0=-Q.top().first;
		int u=Q.top().second; Q.pop();
		if(d0>d[u]) continue;
		for(const auto& e:G[u]){
			int v=e.to;
			if(d[v]>d[u]+e.wt) d[v]=d[u]+e.wt, Q.emplace(-d[v],v);
		}
	}
	return d;
}

int main(){
	int h,w; cin>>h>>w;
	int sx,sy,gx,gy; cin>>sx>>sy>>gx>>gy; sx--; sy--; gx--; gy--;
	vector<string> B(h);
	rep(i,h) cin>>B[i];

	weighted_graph<int> G(h*w);
	rep(i,h) rep(j,w) if(B[i][j]=='.') {
		for(int dx=-2;dx<=2;dx++) for(int dy=-2;dy<=2;dy++) if(dx!=0 || dy!=0) {
			int x=i+dx,y=j+dy;
			if(0<=x && x<h && 0<=y && y<w && B[x][y]=='.'){
				add_directed_edge(G,i*w+j,x*w+y,abs(i-x)+abs(j-y)==1?0:1);
			}
		}
	}

	int ans=Dijkstra(G,sx*w+sy)[gx*w+gy];
	cout<<(ans<INT_MAX?ans:-1)<<'\n';

	return 0;
}


Measured memory_bytes: 102444
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

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

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



int main () {
	SpeedForce;
	cin >> s;
	bool good = 0;
	for (auto it : s) if (it == '7') good = 1;
	cout << (good? "Yes" : "No");

	return Accepted;
}

// B...a

Measured memory_bytes: 17724
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

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

int main(void){
  string in;
  while(getline(cin,in)){
    if(in=="0") break;
    vector<int> num;
    stringstream ss(in);
    int tmp;
    while(ss>>tmp) num.push_back(tmp);
    int ace = 0;
    int ans = 0;
    REP(i,num.size()){
      if(num[i]>10) num[i] = 10;
      if(num[i]==1){
        ace++;
        num[i] = 11;
      }
      ans += num[i];
    }
    while(ace&&ans>21){
      ace--;
      ans-=10;
    }
    cout<<((ans>21)?0:ans)<<endl;
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  map<int, bool> paper;
  
  rep(i, n) {
    int a;
    cin >> a;
    paper[a] = !paper[a];
  }
  
  int ans = 0;
  for(auto x : paper) {
    if(x.second) ++ans;
  }
  
  cout << ans << endl;
  
  
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mx=1e18;
ll arr[100000];


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
     ll n;
     cin>>n;
     for(ll i=0; i<n; ++i){
        cin>>arr[i];
     }
     for(ll i=0; i<n; ++i){
        if(arr[i]==0){
            cout<<0<<"\n";
            return 0;
        }
     }
     ll p=1;
     for(ll i=0; i<n; ++i){
        if(arr[i]<=mx/p) p*=arr[i];
        else {
            cout<<-1<<"\n";
            return 0;
        }
     }
     cout<<p<<"\n";   

}






Measured memory_bytes: 4448
// Created by PRATEEK RANJAN
#include <bits/stdc++.h>
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
const int mod = 1e9+7;

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    int dp[n+1]{};
    dp[0] = 1, dp[1] = 1;
    for(int i=2;i<=n;i++){
        (dp[i] = dp[i-1]*i)%=mod;
    }    cout<<dp[n]<<"\n";
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <vector>

void printInt(long long value);
void br();
void scanInt(long long* value);
void scanIntArray(long long* array, long long count);
void scanIntVector(std::vector<long long>* v, long long count);

int main() {
	long long L, R;
	scanInt(&L);
	scanInt(&R);
	R = L + std::min((R - L) / 2019, 1LL) * 2019 + (R - L) % 2019;
	if (R == L) {
		printInt(0);
		return 0;
	}

	long long result = 2018;

	for (long long i = L; i < R; ++i) {
		for (long long j = i + 1; j <= R; ++j) {
			result = std::min(result, (i * j) % 2019);
		}
	}

	printInt(result);
}

void printInt(long long value) {
	printf("%lld", value);
}

void br() {
	printf("\n");
}

void scanIntArray(long long* array, long long count) {
	for (long long i = 0; i < count; ++i) {
		scanInt(array + i);
	}
}

void scanIntVector(std::vector<long long>* v, long long count) {
	for (long long i = 0; i < count; ++i) {
		long long value;
		scanInt(&value);
		v->push_back(value);
	}
}

void scanInt(long long* value) {
	scanf("%lld", value);
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<String> grade = new ArrayList<String>();
        while (true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if (m == -1 & f == -1 & r == -1) {
                for (int i=0; i<grade.size();i++)
                    System.out.println(grade.get(i));
                break;
            }
            if (m == -1 | f == -1)
                grade.add("F");
            else {
                if (m + f >= 80)
                    grade.add("A");
                else if (m + f >= 65)
                    grade.add("B");
                else if (m + f >= 50)
                    grade.add("C");
                else if (m + f >= 30) {
                    if (r >= 50)
                        grade.add("C");
                    else
                        grade.add("D");
                }
                else if (m + f < 30)
                    grade.add("F");
            }
        }
    }
}


Measured memory_bytes: 26044
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a;
  cin >> a;
  if (a < 10) {
    cout << a;
  } else if (a < 100) {
    cout << 9;
  } else if (a < 1000) {
    cout << a-90;
  } else if (a < 10000) {
    cout << 909;
  } else {
    cout << min(a-9999+909,90909);
  }
}
  /*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
  //配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


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

int main() {
    int a, b, c, t;
    cin >> a >> b >> c;
    if (b < a) {
        t = a; a = b; b = t;
    }
    if (c < b) {
        t = b; b = c; c = t;
    }
    if (b < a) {
        t = a; a = b; b = t;
    }
    // printf("%d %d %d\n", a, b, c);
    cout << a << " " << b << " " << c << endl;
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
int v[200001];
int main(){
    int n,m;
    int a,b;
    bool ispos=false;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin >>a>>b;
        if(a==1){
            v[b]++;
            if(v[b]==2){ispos=true;break;}
        }
        if(b==n){
            v[a]++;
            if(v[a]==2){ispos=true;break;}
        }
    }
    if(ispos)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

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

int main() {
  int x, y;
  cin >> x >> y;

  if (x == 0 || y == 0 || y % 2 != 0 || y > x * 4 || x > y / 2) {
    cout << "No" << endl;
    return 0;
  }

  string ans = "Yes";
  while (y > 0) {
    if (y >= 4) {
      y -= 4;
    } else if (y >= 2) {
      y -= 2;
    } else {
      ans = "No";
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3624
n, m = map(int, input().split())
nli = []
mli = []

for i in range(n):
    a = input()
    nli.append(a)

for i in range(m):
    b = input()
    mli.append(b)

for i in range(n):
    mans = []
    for j in range(m):
        xns = mli[j]
        a, b = map(int, xns.split())
        yns = nli[i]
        c, d = map(int, yns.split())
        ans = abs(a-c) + abs(b-d)
        mans.append(ans)
    e = min(mans)
    print(mans.index(e)+1)


Measured memory_bytes: 3064
N, L = map(int, input().split())

aji = [0] * N
aji2 = [0] * N
flag = 0

for i in range(N):
    aji[i] = L + (i+1) - 1
    aji2[i] = abs(aji[i])
    if aji[i] >= 0:
        flag = 1

if flag == 0:
    print(sum(aji) + min(aji2))
else:
    print(sum(aji) - min(aji2))

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;

const int maxn = 1e5 + 5;


int main () {
    int n;
    cin >> n;
    ll ans =0;
    int a;
    for (int i=0; i < n; i++) {
        cin >> a;
        ans+=(a-1);
    }    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define f(i,a,b) for(int i = a; i < b ; i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
ll dp[405][405],num[405],acc[405];
ll solve(ll l,ll r){
	if(l==r) return 0;
	if(dp[l][r]!=0) return dp[l][r];
	ll ans=100000000000000;
	for(ll i=l;i<r;i++){
		ll x= solve(l,i) + solve(i+1,r) + acc[r]-acc[l-1];
		ans=min(ans,x); 
	} 
	dp[l][r]=ans;
	return ans;
}
int main(){
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++) cin>>num[i];
	for(ll i=1;i<=n;i++) acc[i]=num[i]+acc[i-1];
	cout<<solve(1,n);
}

Measured memory_bytes: 1536
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll k,n,i,j;
            cin>>k>>n;
            ll ar[n+1];
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
            }
            ll ans=1e18;
            ans=min(ans,ar[n]-ar[1]);
            for(i=2;i<=n;++i)
            {
                ans=min(ans,k-ar[i]+ar[i-1]);
            }
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 1792
// AOJ DPL_4_B Coin Combination Problem II
// 2018.5.10 bal4u
 
#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
 
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

long long inLL()
{
    long long n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

#define MAX  ((1<<20)+5)

long long a[42]; int w;
long long s1[42][MAX]; int w1[42];
long long s2[42][MAX]; int w2[42];

int binarysearch_upper(long long *a, long long x, int r)
{
	int m, l = 0;

    while (l < r) {
        m = (l+r) >> 1;
		if (a[m] == x) return m+1;
		if (a[m] < x) l = m + 1; else r = m;
    }
	return l;
}

int binarysearch_lower(long long *a, long long x, int r)
{
	int m, l = 0;

    while (l < r) {
        m = (l+r) >> 1;
        if (a[m] < x) l = m + 1; else r = m;
    }
	return l;
}

int cmp(long long *a, long long *b)
{
	if (*a < *b) return -1;
	return (*a != *b);
}

long long combi(int n, int k)
{
	long long ans;

	if (s1[n][k]) return s1[n][k];
	if ((k << 1) > n) k = n-k;
	if (k == 0) ans = 1;
	else if (k == 1) ans = n;
	else ans = combi(n-1, k) + combi(n-1, k-1);
	return s1[n][k] = ans;
}

int main()
{
	int N, K, i, j, k, m1, m2, n, lim;
	long long L, R, x, y, ans;

	N = in(), K = in(), L = inLL(), R = inLL();

	w = 0;
	x = y = inLL(); if (y + K-1 <= R) a[w++] = y;
	for (i = 1; i < N; i++) {
		x = inLL();
		if (x != y) y = 0;
		if (x + K-1 <= R) a[w++] = x;
	}

	// identical a[i]
	if (x == y) {
		if (w >= K && (y = x*K) >= L && y <= R) printf("%lld\n", combi(w, K));
		else puts("0");
		return 0;
	}

	m1 = w / 2, lim = 1 << m1;
	for (i = 0; i < lim; i++) {
		x = 0, n = 0;
		for (j = 0; ; j++) {
			if (j == m1) { s2[n][w2[n]++] = x; break; }
			if ((i >> j) & 1) {
				x += a[j];
				if (++n > K) break;
			}
		}
	}

	m2 = w - m1;
	lim = 1 << m2;
		for (i = 0; i < lim; i++) {
		x = 0, n = 0;
		for (j = 0; ; j++) {
			if (j == m2) { s1[n][w1[n]++] = x; break; }
			if ((i >> j) & 1) {
				x += a[j+m1];
				if (++n > K) break;
			}
		}
	}

	for (i = 0; i <= K; i++) qsort(s2[i], w2[i], sizeof(long long), cmp);

	ans = 0;
	for (i = 0; i <= K; i++) {
		k = K-i;
		for (j = 0; j < w1[i]; j++) {
			y = R-s1[i][j];
			if (y >= 0) {
				ans += (long long)binarysearch_upper(s2[k], y, w2[k]);
				x = L-s1[i][j];
				if (x > 0) ans -= (long long)binarysearch_lower(s2[k], x, w2[k]);
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 19608
n,k=map(int,input().split())
h=[int(i) for i in input().split()]
dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(1,n):
    a=[]
    for j in range(max(i-k,0),i):
        a.append(dp[j]+abs(h[j]-h[i]))
    dp[i]=min(a)
print(dp[n-1])

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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	cout<<(n>=30?"Yes":"No")<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
/*RMQ  update:O(logN)  query:O(lonN)*/



struct RAQ{
  vector<ll> dat;
  int n;

  //?????????
  RAQ(){};
  RAQ(int n_){
    //????´???°n???2???????????????
    n=1;
    while(n<n_)n*=2;
    dat=vector<ll>(n*2,0);
  }

  //[a,b)???????°????????±???????
  //query(a,b,0,0,n)
  
  void add(int a,int b,int x=0,int k=0,int l=0,int r=-1){
    if(r==-1)r=n;

    if(r<=a||b<=l)return ;
    if(a<=l&&r<=b){
      dat[k]+=x;
      return;
    }
    dat[k*2+1]+=dat[k];
    dat[k*2+2]+=dat[k];
    dat[k]=0;
    add(a,b,x,k*2+1,l,(l+r)/2);
    add(a,b,x,k*2+2,(l+r)/2,r);
  }

  ll find(int a){
    add(a,a+1);
    return dat[a+n-1];
  }
};



int main(){
  int n,q;
  cin>>n>>q;
 
  RAQ raq(n);
  
  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd==0){
      int s,t,x;
      cin>>s>>t>>x;
      raq.add(s-1,t,x);
    }
    else {
      int idx;
      cin>>idx;
      cout <<raq.find(idx-1)<<endl;
    }
  }
  return 0;
}

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

int main(){

    int N;
    cin >> N;

    string S[N];
    for(int i=0;i<N;i++){
        cin >> S[i];
    }
    
    unordered_map<string,long long int>  ans;

    long long int a=0;

    for(int i=0;i<N;i++){
        sort(S[i].begin(),S[i].end());
        auto itr = ans.find(S[i]);
        if(itr != ans.end()){
            itr->second++;
            a+=itr->second;
        }else{
            ans[S[i]]=0;
        }
    }


    cout << a << endl;


    return 0;
}

Measured memory_bytes: 17700
//DubiousDocument.cpp (C)
#include <iostream>
#include <string>
using namespace std;

int main(){
  int n;
  cin >> n;
  string S;
  int chk[60][30] = {0};
  for(int i = 0; i < n; i++){
    cin >> S;
    for(int j = 0; j < S.size(); j++){
      ++chk[i][S[j]-'a'];
    }
  }
  int Min = 0;
  for(int i = 0; i < 26; i++){
      for(int j = 0; j < n; j++){
        if(j == 0) Min = chk[0][i];
        else Min = min(Min,chk[j][i]);
      }
      cout << string(Min,'a'+i);
  }
  cout << endl;
  return 0;



}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String string = sc.next();
		boolean isHuiwen = isHuiWen(string);
		System.out.println(isHuiwen? "Yes" : "No");
	}

	private static boolean isHuiWen(String string) {
		int m = (string.length()-1)/2;
		int n = (string.length()+3)/2-1;

		for (int i = 0; i < m; i++) {
			if (string.charAt(i) != string.charAt(string.length()-1-i)) {
				return false;
			}
		}
		for (int i = 0; i < m/2; i++) {
			if (string.charAt(i) != string.charAt(m-1-i)) {
				return false;
			}
		}
		for (int i = n; i < (3 * string.length()-1)/4; i++) {
			if (string.charAt(i) != string.charAt(string.length()-1-i)) {
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 23380
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            while (true) {
                String tmp = String.valueOf(n);
                if (tmp.charAt(0) == tmp.charAt(1) && tmp.charAt(0) == tmp.charAt(2)) {
                    System.out.println(n);
                    break;
                }
                n++;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


Measured memory_bytes: 21460
a=list(input())
for i in range(1<<3):
    ans=""
    ans+=a[0]
    for j in range(3):
        if i&(1<<j):
            ans+="+"
        else:
            ans+="-"
        ans+=a[j+1]
    temp=eval(ans)
    if temp==7:
        print(ans+"=7")
        exit()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

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

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	LL n, ans = 0;
	cin >> n;
	vector<LL> a(3 * n);
	REP(i, 3 * n)cin >> a[i];

	SORT(a);
	REVE(a);
	for (int i = 1; i <= n * 2 - 1; i += 2)ans += a[i];
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
using namespace std;
using ll=long long;
static const int MAX_N=100;

//品物を表す構造体
typedef struct{
    ll weight;
    ll value;
}Goods;

int main(void){
    int N,W;
    Goods G[MAX_N+1];//構造体の配列
    cin >> N >> W;
    for(int i=1; i<=N; i++){
        cin >> G[i].weight >> G[i].value;
    }

    //dp[i][j]はi番目の品物までを使って重さをj以下にしたときの価値の最大値
    //1スタートで考える
    ll dp[N+1][W+1];
    for(int i=0; i<=N; i++){
        for(int j=0; j<=W; j++){
            dp[i][j] = 0;
        }
    }
    for(int i=1; i<=N; i++){
        for(int j=1; j<=W; j++){
            //ここの不等式"="がつかない(1スタートで考えて,dp[i][0]=0にしてる)
            if(j<G[i].weight){
                dp[i][j] = dp[i-1][j];
            }
            else
            {
                dp[i][j] = max(dp[i-1][j-G[i].weight]+G[i].value, dp[i-1][j]);
            }
            
        }
    }

    cout << dp[N][W];

    return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll N, A, B, C;
vector<ll> lengths;

ll dfs(int index, ll targetA, ll targetB, ll targetC, ll useCount)
{
    if(index == N){
        if(targetA == 0 || targetB == 0 || targetC == 0)
        {
            return 1e12;
        } else {
            return abs(targetA - A) + abs(targetB - B) + abs(targetC - C) + (useCount - 3) * 10; 
        }
    }
    ll answer = 1e12;
    answer = min(answer, dfs(index + 1, targetA, targetB, targetC, useCount));
    answer = min(answer, dfs(index + 1, targetA + lengths[index], targetB, targetC, useCount + 1));
    answer = min(answer, dfs(index + 1, targetA, targetB + lengths[index], targetC, useCount + 1));
    answer = min(answer, dfs(index + 1, targetA, targetB, targetC + lengths[index], useCount + 1));
    return answer;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++)
    {
        ll l;
        cin >> l;
        lengths.push_back(l);
    }
    cout << dfs(0, 0, 0, 0, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
long long arr[3009];
long long dp[3009][3009];
long long bt(int l,int r){
	if(l == r){
		return arr[l];
	}
	long long &ret = dp[l][r];
	if(ret != -100000000000000009ll)return ret;
	ret = max(arr[l] - bt(l+1,r), arr[r] - bt(l,r-1));
	return ret;
}
int main(){
	for(int i=0;i<=3000;i++){
		for(int j=0;j<=3000;j++){
			dp[i][j] = -100000000000000009ll;
		}
	}
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	cout<<bt(0,n-1)<<endl;
}


Measured memory_bytes: 71040
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned char uchar;
#define umap unordered_map
const static ull INVALID_DIGIT = ~(ull)0;

static const ull MEMO_MAX_SIZE = 100001;
ull possiblePatternMemo[MEMO_MAX_SIZE];

umap<ull, int> isBroken;

static const ull DIVIDER = 1000000007l;

ull findPossibleWayCount(ull currentFloor, ull targetN)
{
    if (currentFloor == targetN) {
        return 1;
    }

    if (possiblePatternMemo[currentFloor] != INVALID_DIGIT) {
        return possiblePatternMemo[currentFloor] % DIVIDER;
    }

    ull wayCount = 0;
    // Up one
    ull oneUpNext = std::min(currentFloor + 1, targetN);
    if (!isBroken[oneUpNext])
    {
        wayCount += findPossibleWayCount(oneUpNext, targetN);
        wayCount %= DIVIDER;
    }
    // Up two
    ull twoUpNext = std::min(currentFloor + 2, targetN);
    if (oneUpNext != twoUpNext && !isBroken[twoUpNext])
    {
        wayCount += findPossibleWayCount(twoUpNext, targetN);
        wayCount %= DIVIDER;
    }

    possiblePatternMemo[currentFloor] = wayCount;

    return wayCount;

}

int main()
{
    std::fill(possiblePatternMemo, possiblePatternMemo + MEMO_MAX_SIZE, INVALID_DIGIT);

    ull N, M;
    cin >> N >> M;

    vector<ull> brokenIndices(M);
    for (ull i = 0; i < M; i++) {
        cin >> brokenIndices[i];
        isBroken[brokenIndices[i]] = 1;
    }

    auto ways = findPossibleWayCount(0, N);
    cout << ways << endl;
    

    return 0;
}

Measured memory_bytes: 9892
#include<stdio.h>

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

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

        for(i=99; i>0; i--) a[i-1] += a[i];

        int ans = 0;
        for(i=0; i<100; i++){
                if(a[i]>i) ans = i+1;
        }

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


Measured memory_bytes: 2128