akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <array>
#include <vector>
#include <iterator>
#include <algorithm>
#include <initializer_list>

using namespace std;


template <class It> string join(It begin, It end)
{
    ostringstream ss;
    for (auto it = begin; it != end; ++it)
        ss << ((it == begin) ? "" : ", ") << (*it);
    return ss.str();
}

#define Show(x) cerr << #x << " = " << x << endl;
#define Shows(x) cerr << #x << " : { " << join(x.begin(), x.end()) << " }" << endl;


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

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

    vector<long> S(N, 0);
    for (int i = 0; i < N; ++i)
        S[i] = A[i] + ((i > 0) ? S[i - 1] : 0);

    auto R = [&](int i, int j) -> long
    {
        if (i == 0)
            return S[j - 1];
        else
            return S[j - 1] - S[i - 1];
    };
    auto delta = [&](array<int, 3> &C) -> long
    {
        array<long, 4> sums({ R(0, C[0]), R(C[0], C[1]), R(C[1], C[2]), R(C[2], N) });
        long s_min(0), s_max(0);
        for (auto s : sums)
        {
            if (s < s_min || s_min == 0) s_min = s; 
            if (s > s_max || s_max == 0) s_max = s;
        }
        return (s_max - s_min);        
    };
    auto search = [&](int i, int j, int k)
    {
        long d0 = abs(R(i, j) - R(j, k));
        long d_min = d0;
        int j_min = j;
        for (++j; j < k; ++j)
        {
            long d = abs(R(i, j) - R(j, k));
            if (d < d_min)
            {
                d_min = d;
                j_min = j;
            }
            if (d > d0)
                break;
        }
        return j_min;
    };

    array<int, 3> C({ 1, 2, 3 });
    long d_min = -1;
    
    for (; C[1] < N - 1; ++C[1])
    {
        C[0] = search(0, C[0], C[1]);
        C[2] = search(C[1], C[2], N);
        
        long d = delta(C);
        if (d_min > d || d_min < 0)
            d_min = d;

        Show(d);
        Shows(C);
    }
    
    cout << d_min << endl;
}


Measured memory_bytes: 3328
import java.util.*;

class Main {

    static boolean[] SUM = new boolean[200 * 20 + 1];
    
    public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	int n = in.nextInt();
	int[] A = new int[n];
	for(int i = 0; i < n; i++) {
	    A[i] = in.nextInt();
	}
	calc(0, A, 0, true);
	calc(0, A, 0, false);

	int q = in.nextInt();
	for(int i = 0; i < q; i++) {
	    System.out.println(SUM[in.nextInt()] ? "yes" : "no");
	}
    }

    public static void calc(int sum, int[] arr, int idx, boolean use) {
	if (idx == arr.length - 1) {
	    SUM[sum + (use ? arr[idx] : 0)] = true;
	} else {
	    if (use) { sum += arr[idx]; }
	    calc(sum, arr, idx + 1, true);
	    calc(sum, arr, idx + 1, false);
	}
    }
}



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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(){
#define int ll
  string s; cin >> s;
  int ans = 0;
  rep(i,sz(s)-1) if(s[i] != s[i+1]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 512
a = gets.strip.split('')
r  = %w[A C G T]
l = 0
c = 0
a.each_with_index do |char, i|
  if r.include? char
    c += 1
  end
  if (!r.include?(char)) || (i == a.size - 1)
    l = c if c > l
    c = 0
  end
end
puts l


Measured memory_bytes: 1788
require "prime"

def getprimenum x
	# counter = 0

	# (x + 1).upto(2 * x) {|i|
		# next if (i % 2 == 0 && i > 2 || i % 3 == 0 && i > 3 || i % 5 == 0 && i > 5)

		# counter += 1 if Prime.instance.prime?(i)
	# }

	# return counter

	return Prime.each(x * 2).to_a.length - Prime.each(x).to_a.length
end

loop {

	begin
		l = gets.chomp.to_i

		puts getprimenum(l) if l > 0
	rescue
		break
	end
}

Measured memory_bytes: 6436
#include <iostream>
#include <sstream>
#include <float.h>
using namespace std;

#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>


const int mod = 1e9 + 7;
typedef long long ll;
typedef pair<int, int> ii;


// Custom comparator
struct cmp {
    bool operator()(int a, int b) {
        return b < a;
    }
};


// Solution class
class Solution {
public:
    char sol(char c) {
        return c >= 'a' && c <= 'z' ? 'a' : 'A';
    }
};



// Run code
int main(int argc, char const *argv[])
{

//    Solution* sol = new Solution();
//    cout<<sol->sol(n, k, arr);

    // Start

    long n;
    cin>>n;

    // Get the length of the result string
    int len = 1;
    long cnt = 0;
    while (cnt + pow(26, len) < n) {
        cnt += pow(26, len);
        len++;
    }

//    cout<<len<<" "<<cnt<<endl;

    // Get the actual string
    long idx = n - 1 - cnt;
    string res = "";
//    cout<<idx<<endl;
    for (int i = 0; i < len; i++) {
        long step = pow(26, len - i - 1);
        long c = idx / step;
//        cout<<c<<endl;
        res += (char)(c + 'a');
        idx = idx % step;
    }

    cout<<res;

    return 0;
}


Measured memory_bytes: 3512
#include <stdio.h>
 
int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  if (b == 1)
    printf("0");
  else
  {
    int c = 1;
    int i = 0;
    while (c < b)
    {
      c = a + i * (a - 1);
      i++;
    }
    printf("%d",i);
  }
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    int A,B,C;
    cin >> A >> B >> C;
    
    cout << A + B + C + max({A,B,C})*9 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int n, i, ans;
  char s[10001];
  scanf("%d %s", &n, s);
  for(i=0;i<strlen(s);i++){
    ans=s[i]-'A';
    ans=(ans+n)%26;
    putchar(ans+'A');
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int64_t>A(3*N);
  for(int i=0;i<3*N;i++)
    cin>>A.at(i);
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  int64_t ans=0;
  for(int i=0;i<N;i++){
  ans+=A.at(2*i+1);
  }cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 2560
N = int(input())
S = input()


for s in ['SS', 'SW', 'WS', 'WW']:
    ss = s
    jdg = False
    for i in range(1, N):
        if S[i] == 'o':
            if ss[i] == 'S':
                ss += ss[i - 1]
            else:
                if ss[i - 1] == 'W': ss += 'S'
                else: ss += 'W'
        else:
            if ss[i] == 'S':
                if ss[i - 1] == 'W': ss += 'S'
                else: ss += 'W'
            else:
                ss += ss[i - 1]
    if ss[N] == ss[0]:
        if S[0] == 'o':
            if (ss[0] == 'S' and ss[N-1] == ss[1]) or (ss[0] == 'W' and ss[N-1] != ss[1]):
                jdg = True
                break
        else:
            if (ss[0] == 'S' and ss[N-1] != ss[1]) or (ss[0] == 'W' and ss[N-1] == ss[1]):
                jdg = True
                break
print(ss[:-1] if jdg else -1)


Measured memory_bytes: 9416
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 3000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
#define INF 1000000
const int MAX = 1000000;
const int MOD = 1000000007;

int main(){
	int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n){
        cin>>a[i];
    }
    map<int,int> m;
    REP(i,n){
        m[a[i]]++;
    }
    vector<ll> ans(n);
    ll sum=0;
    for(auto s:m){
        sum+=(ll)s.second*(s.second-1)/2;
    }
    REP(i,n){
        ans[i]=sum-(m[a[i]]-1);
    }
    REP(i,n){
        OUT(ans[i]);
    }
    return 0;
}

Measured memory_bytes: 10752
N=int(input())
S=[]
for _ in range(N):
    S.append(input())
S.sort()
#print(S)

m=1
c=1
L={S[0]}
for i in range(N-1):
    if S[i]==S[i+1]:
        c+=1
        if c==m:
            L.add(S[i])
        elif c>m:
            L.clear()
            L.add(S[i])
            m=c
    else:
        if c==m:
            if 0<=i<N-2:
                L.add(S[i])
            else:
                L.add(S[i])
                L.add(S[i+1])
        c=1
    #print(S,m,c,L)

R=sorted(list(L))
for j in range(len(R)):
    print(R[j])
    




Measured memory_bytes: 30524
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#define ALL(X) X.begin(), X.end()
#define SZ(A) int((A).size())
#define RALL(X) X.rbegin(), X.rend()
#define FOR(B) for (size_t i = 0; i < B; i++)
#define FOR2(B) for (size_t j = 0; j < B; j++)
#define FORE(B) for (size_t i = 1; i <= B-1; i++)
#define FORC(A, B) for (size_t i = A; i < B; i++)
#define PRINT(X) cout << X << endl
#define PRINTALL(E, X) { FOR(X) {cout << E[i] << endl; } }
#define PRINTSIDE(E, X) { FOR(X) {cout << E[i] << " ";} }
#define READALLI(V, N) FOR(N) {int x; cin >> x; V.push_back(x); }
#define READALL(V, N) FOR(N) {LL x; cin >> x; V.push_back(x); }
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXN 100000
#define SQRSIZE  317
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll>VL;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef map<char, int>mci;
typedef map<string, int> msi;
typedef set<int> si;
const int INF = (1 << 30);

int main() {
    vector<int> values;
    for(int i = 0; i < 3; i++){
        int x = 0;
        cin >> x;
        values.push_back(x);
    }
    sort(values.begin(), values.end());
    int ans = values[2] * 10 + values[1] + values[0];
    cout << ans << endl;

    return 0;

    return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	vector<int>a(N); rep(i, 0, N) { cin >> a[i]; }

	int ans = 0;
	rep(i, 0, N) {
		if (~i & 1 and a[i]&1) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    lint x, y;
    scanf("%lld%lld", &x, &y);
    int ans = 0;
    while(x <= y){
        ++ans;
        x *= 2;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
cards = []
mark = ["S", "H", "C", "D"]

n = int(input())

for i in range(1, n + 1) :
    s, r = input().split()
    r = int(r)
    
    if s == "S" :
        cards.append(r + 0)
    elif s == "H" :
        cards.append(r + 13)
    elif s == "C" :
        cards.append(r + 26)
    elif s == "D" :
        cards.append(r + 39)
    
for j in range(1, 53) :
    if not (j in cards) :
        print(mark[(j - 1) // 13], (j - 1) % 13 + 1)


Measured memory_bytes: 5612
#include <iostream>
#include <algorithm>

using namespace std;

class Solver {
public:
	static void solve() {
		int n;
		cin >> n;

		for (int i = n; i < 1000; i++) {
			int d1 = i / 100;
			int d2 = (i / 10) % 10;
			int d3 = i % 10;

			if (d1 == d2 && d2 == d3) {
				cout << i << endl;
				return;
			}
		}
	}
};

int main() {
	Solver::solve();
}

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

int main(){
  double x1,y1,x2,y2,x3,y3,xp,yp,xp_,yp_;
  double c,d,a1x,a1y,a2x,a2y;
  while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>xp>>yp){
    // cout <<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<x3<<" "<<y3<<" "<<xp<<" "<<yp;
    a1x=x2-x1;
    a1y=y2-y1;
    a2x=x3-x1;
    a2y=y3-y1;
    xp_=xp-x1;
    yp_=yp-y1;
    // cout <<a1x<<a1y<<a2x<<a2y<<xp_<<yp_<<endl;
    c = (xp_*a2y-yp_*a2x)/(a1x*a2y-a2x*a1y);
    d = (-xp_*a1y+yp_*a1x)/(a1x*a2y-a2x*a1y);
    // cout <<"C: "<<c<<",D: "<<d<<endl;
    if (c<0){cout<<"NO"<<endl;continue;}
    if (d<0){cout<<"NO"<<endl;continue;}
    if ((c+d)>1){cout<<"NO"<<endl;continue;}
    cout <<"YES"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3064
#include <cassert>
#include <map>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

using mint = modint<998244353>;

mint power(mint x, int k){
  mint ret = 1;
  while(k > 0){
    if(k%2)
      ret *= x;
    x *= x;
    k /= 2;
  }
  return ret;
}

template<typename T>
struct BIT{//0-indexed
private:
  vector<T> data;
  const int n;
public:
  BIT(int sz) : data(sz+1,0), n(sz) {}
  BIT(vector<T> t) : data(t), n((int)t.size()) {}
  T sum(size_t i){//sum[0,i)
    //++i;
    T s = 0;
    while(i > 0){
      s += data[i];
      i -= i&(-i);
    }
    return s;
  }

  T sum(size_t i, size_t j){ return sum(j) - sum(i); }//sum[i,j)

  void add(int i, T x){
    ++i;
    assert(i > 0);
    while(i <= n){
      data[i] += x;
      i += i&(-i);
    }
  }
};

int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> P;
  vector<int> X, Y;
  for(int i = 0; i < N; ++i){
    int x, y;
    cin >> x >> y;
    P.emplace_back(x,y);
    X.push_back(x);
    Y.push_back(y);
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  sort(P.begin(), P.end());
  map<int,int> M;
  for(int i = 0; i < N; ++i) M[Y[i]] = i;
  BIT<int> bit(N);
  mint ans = 0;
  for(int i = 0; i < N; ++i){
    int x = P[i].first, y = P[i].second;
    int s = i, t = N - i - 1;
    int v = lower_bound(Y.begin(), Y.end(), y) - Y.begin();
    int u = N - 1 - v;
    int b = bit.sum(M[y]);
    int a = s - b, c = u - a, d = t - c;
    // cerr << "(" << x << ", " << y << ") : " << a << " " << b << " "  << c << " " << d << endl;
    ans += power(2,N) - 1 - power(2,s) - power(2,t) - power(2,u) - power(2,v) + power(2,a) + power(2,b) + power(2,c) + power(2,d);
    bit.add(M[y],1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 13556
#include <bits/stdc++.h>
#define int long long
using namespace std ;
long long n , m ,t[ 200005 ][ 64 ] ;
signed main() {
        // cout << (1ll << 62) << '\n';
    cin >> n >> m ;
    for( int i = 1 ; i <= n ; ++i )
        cin >> t[ i ][ 0 ] ;
    for( int j = 1 ; j <= 62 ; ++j )
        for( int i = 1 ; i <= n ; ++i ) 
        t[ i ][ j ] = t[ t[ i ][ j - 1 ] ][ j - 1 ] ;
    signed s = 1 ;
    // cout << (1ll << 63) << '\n';
    for( int i = 62 ; i >= 0 ; --i ) {
        if( m < ( 1ll << i ) ) continue ;
        s = t[ s ][ i ] ;
        m -= ( 1ll << i ) ;
        //--------------------------------------------------
        // if ( m & ( 1ll << i ) ) s = t[ s ][ i ] ;
    }
    cout << s << '\n';
    return 0 ;
}

Measured memory_bytes: 103572
n,k = map(int,input().split())
a = list(map(int,input().split()))

tt = [0] * n
tt[0] = 1
ans_l = [1]
i = 1
c = 0

while True:
    if c == k:
        break
    c += 1
    i = a[i-1]
    if tt[i-1] == False:
        tt[i-1] = 1
        ans_l.append(i)
    else:
        break

d = ans_l.index(i)
k -= d
ans = k % (len(ans_l)-d)
print(ans_l[ans+d])


Measured memory_bytes: 102400
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;

ll n,k,x,y;


////////////////2つの要素をまとめてソート、前の変数が優先。flag=0で小さい順、1で大きい順
void mysort2(vi &a,vi &b,ll flag){
  if (a.size()>0){
    vector<pair<ll, ll>> p(a.size());
    REP(i,a.size()){
      p[i].first=a[i];
      p[i].second=b[i];
    }
    sort(p.begin(),p.end());
    if (flag==1){
      reverse(p.begin(),p.end());
    }
    REP(i,a.size()){
      a[i]=p[i].first;
      b[i]=p[i].second;
    }
  }
  return;
}
////////////////2同時ソートここまで


int main(){
  ll ans=0;
  cin >> n ;
  vi a(n),b(n),c(n),d(n),ddmy(n);

  REP(i,n) cin>>a[i]>>b[i];

  for(ll i=0;i<n;i++){
      c[i]=a[i]+b[i];
      d[i]=a[i]-b[i];
      a[i]=i;
      b[i]=i;
      ddmy[i]=d[i];
  }


  mysort2(c,a,0);
  mysort2(d,b,0);


  for(ll i=0;i<n;i++){
    ll cc=c[i];
    ans=max(abs(c[0]-cc),ans);
    ans=max(abs(c[n-1]-cc),ans);
    ll idx=a[i];
    ll myd=ddmy[idx];
    
    ans=max(abs(d[0]-myd),ans);
    ans=max(abs(d[n-1]-myd),ans);
    
  }






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






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

int main(void){
  int N; cin >> N;
  ll K; cin >> K;
  vector<ll> A(N);
  vector<int> c(41, 0);
  for(auto& _a: A) cin >> _a;

  for(int i = 0; i < (int)c.size(); i++){
    for(int j = 0; j < (int)A.size(); j++){
      if(A[j] & (ll)((ll)1 << (ll)i)){
        c[i]++;
      }
    }
  }

  ll ans = 0;
  for(int i = 0; i <= 40; i++){
    ll tmp = 0;
    if(((K+1) & (1LL << (ll)i)) == 0) continue;
    for(int j = 40; j > i; j--){   // make the value different at 40 i.
      tmp = tmp | ((K+1) & (1LL << (ll)j));
    }
    // if(tmp > K) continue;
    // tmp = tmp & ~(0 << i);
    for(int j = i - 1; j >= 0; j--){
      if(c[j] <= N - c[j]){
        tmp = tmp | (1LL << (ll)j);
      }
    }

    ll f = 0;
    for(int k = 0; k < N; k++){
      f += tmp ^ A[k];
    }
    ans = max(ans, f);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int x,y,z,a,b;
    scanf("%d%d%d",&x,&y,&z);
    a=x;
    x=y;
    y=a;
    b=x;
    x=z;
    z=b;
   printf("%d ",x);
    printf("%d ",y);
     printf("%d",z);

     return 0;

}


Measured memory_bytes: 128
from collections import deque

H, W, K = map(int, input().split())

chart = [list(input()) for _ in range(H)]

start = (-1, -1)
for h in range(H):
    for w in range(W):
        if chart[h][w] == 'S':
            start = (h, w)
            chart[h][w] = '.'

minDist  = [[float('inf')] * W for _ in range(H)]
que = deque([(start[0], start[1], 0)])
while que:
    nh, nw, dist = que.popleft()

    if minDist[nh][nw] <= dist:
        continue

    minDist[nh][nw] = dist
    if dist == K:
        continue

    for toH in [nh - 1, nh + 1]:
        if toH < 0 or toH >= H:
            continue
        if chart[toH][nw] == '.':
            que.append((toH, nw, dist + 1))
    for toW in [nw - 1, nw + 1]:
        if toW < 0 or toW >= W:
            continue
        if chart[nh][toW] == '.':
            que.append((nh, toW, dist + 1))

ans = float('inf')
for h in range(H):
    for w in range(W):
        if minDist[h][w] == float('inf'):
            continue
        d = min(h, w, H - h - 1, W - w - 1)
        if d == 0:
            ans = min(ans, 1)
        else:
            ans = min(ans, -(-d // K) + 1)

print(ans)

Measured memory_bytes: 124764
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L+9LL)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

ll N,A,B,C,D;

ll f(ll n, map<ll,ll> &memo){
    if(n==0) return 0;
    if(n==1) return D;

    if(memo[n] > 0) return memo[n];

    ll res = MAXINF;

    if(n<res/D) chmin(res, D*n);
    chmin(res, D*abs(n-(n/2)*2)   +A+ f(n/2, memo));
    chmin(res, D*abs(n-((n+1)/2)*2) +A+ f((n+1)/2, memo));
    chmin(res, D*abs(n-(n/3)*3)   +B+ f(n/3, memo));
    chmin(res, D*abs(n-((n+2)/3)*3) +B+ f((n+2)/3, memo));
    chmin(res, D*abs(n-(n/5)*5)   +C+ f(n/5, memo));
    chmin(res, D*abs(n-((n+4)/5)*5) +C+ f((n+4)/5, memo));

    memo[n] = res;
    return res;
}

int main(void)
{
    int t;
    cin >> t;
    int n = 100;
    while(t--){
        cin >> N >> A >> B >> C >> D;

        map<ll, ll> memo;
        pr(f(N, memo));
    }
}

Measured memory_bytes: 4388
n=int(input())
s=input()
flag=1
if n%2==1:
  print('No')
else:
  for i in range(n//2):
    if s[i]==s[i+n//2]:
      flag*=1
    else:
      flag*=0
  if flag==1:
    print('Yes')
  else:
    print('No')
  

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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main(){
    string s;
    cin >> s;
    int day=0;
    if (s=="SUN") day=7;
    if (s=="MON") day=6;
    if (s=="TUE") day=5;
    if (s=="WED") day=4;
    if (s=="THU") day=3;
    if (s=="FRI") day=2;
    if (s=="SAT") day=1;
    cout << day << endl;
      
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mem(dp,a) memset(dp,a,sizeof(dp))
#define pb(x) push_back(x)
#define m_p(x,y) make_pair(x,y)
#define f(n) for(ll i=0;i<n;i++)
#define r(n) for(ll j=0;j<n;j++)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define pi 3.141592653589793238462
#define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;
typedef long double ld;
ll ESP=1e18;
ll INF=1e9+7;

int main()
{
 hs;
 string str;
 cin>>str;
 if(str=="ABC")
    cout<<"ARC";
 else
    cout<<"ABC";
 cout<<"\n";
 return 0;

}


Measured memory_bytes: 3608
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
edge = [[] for i in range(m)]
for i in range(m):
  a,b,c=map(int,input().split())
  edge[i]=[a-1,b-1,-c]
d=[float("inf")]*n
d[0]=0

for _ in range(n):
  for i in range(m):
    e0,e1,e2=edge[i]
    d[e1]=min(d[e1],d[e0]+e2)
ans1=d[-1]
for _ in range(n):
  for i in range(m):
    e0,e1,e2=edge[i]
    if d[e1]>d[e0]+e2:
      d[e1]=-float("inf")
ans2=d[-1]
print("inf" if ans1!=ans2 else -ans1)


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

using namespace std;

using ll = long long;


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

    ll x, y, z, k;
    cin >> x >> y >> z >> k;

    vector<ll> a(x), b(y), c(z);
    for (int i = 0; i < x; ++i) cin >> a[i];
    for (int i = 0; i < y; ++i) cin >> b[i];
    for (int i = 0; i < z; ++i) cin >> c[i];

    vector<ll> ab;
    ab.reserve(x * y);
    for (int i = 0; i < x; ++i)
        for (int j = 0; j < y; ++j)
            ab.push_back(a[i] + b[j]);

    partial_sort(ab.begin(), ab.begin() + min(k, x * y), ab.end(), greater<ll>());
    partial_sort(c.begin(), c.begin() + min(k, z), c.end(), greater<ll>());

    vector<ll> abc;
    abc.reserve(min(k, x * y));
    for (int i = 0; i < min(k, x * y); ++i) {
        for (int j = 0; j < min(k, z); ++j) {
            abc.push_back(ab[i] + c[j]);
        }
    }

    partial_sort(abc.begin(), abc.begin() + k, abc.end(), greater<ll>());
    for (int i = 0; i < k; ++i)
        cout << abc[i] << '\n';

    return 0;
}


Measured memory_bytes: 34216
r,g,b,n=map(int,input().split())
l=[r,g,b,n]
count=0
for i in range(n+1):
  for j in range(n+1):
    if (n-(i*r+j*g))/b==int((n-(i*r+j*g))/b) and (n-(i*r+j*g))/b>=0:
      count+=1
print(count)


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

int search(int A[],int n,int key){
    int i=0;
    A[n]=key;
    while (A[i]!=key)i++;
    return i!=n;
}

int main(){
    int n,A[10000+1],q,key,sum=0;
    cin>>n;
    for (int i=0; i<n; i++)cin>>A[i];
    cin>>q;
    for (int i=0; i<q; i++) {
        cin>>key;
        if(search(A,n,key))sum++;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> 				void _DO(I&&x){	cerr<<x<<endl;	}
template<typename I,typename...T>	void _DO(I&&x,T&&...tail){	cerr<<x<<" , ";	_DO(tail...);	}
template<typename _a,typename _b> 	ostream& operator << (ostream &_s,const pair<_a,_b> &_p)
{	return _s<<'('<<_p.first<<','<<_p.second<<')';	}
#define IOS
#else
#define debug(...)
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0);
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define stp setprecision(18)<<fixed
const ll INF=0x3f3f3f3f3f3f3f3f;
const int NF=0x3f3f3f3f;
const ll MAX=1e5+5,Mlg=__lg(MAX)+2;
const ll MOD=1e9+7;
// ready~ go!
// let's coding and have fun!
// I can't solve this problem!
int main(){
	IOS
	int x;	cin>>x;
	if(x<1200)	cout<<"ABC\n";
	else if(x<2800)	cout<<"ARC\n";
	else cout<<"AGC\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC155B()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		int A;
		cin >> A;
		if (A % 2 == 0 && A % 3 != 0 && A % 5 != 0)
		{
			cout << "DENIED" << endl;
			return;
		}
	}
	cout << "APPROVED" << endl;
}
 
int main()
{
	ABC155B();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int X,A,B;
    cin >> X >> A >> B;
    if(A >= B){
        cout << "delicious" << endl;
    }
    else if(A+X < B){
        cout << "dangerous" << endl;
    }
    else{
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 256
//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

int main() {
	int a, b, c;
	ll k;
	rd(a, b, c), rd(k);
	print(k & 1 ? b - a : a - b); 
	return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;
 
public class Main {
  public static void main (String[] args){
    
   int n,a,b,c=0,d=0,e=0; 

   Scanner sc = new Scanner (System.in);
   n=sc.nextInt();
   a=sc.nextInt();
   b=sc.nextInt();
 
   for(int i=1;i<n+1;i++){
    c=i%10;
    d=i/10;
    c=c+(d%10);
    d=d/10;
    c=c+(d%10);
    d=d/10;
    c=c+(d%10);
    d=d/10;
    c=c+(d%10);
    
    if(c>=a && c<=b){
     e=e+i;
    }
   }    
   System.out.println(e);
  }
}

Measured memory_bytes: 22864
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;

    ll dp[n];
    for(int i=0;i<n;i++)dp[i]=INF;
    ll arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=i+2 && j<n;j++){
            dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));
        }
    }
    cout<<dp[n-1]<<"\n";
}


Measured memory_bytes: 1792
#include<stdio.h>
int main() {
	int d, n,ans;
	scanf("%d %d", &d, &n);
	switch (d) {
	case 0:
		ans = n * 1;
		if (n == 100) {
			ans = 101;
		}
		break;
	case 1:
		ans = n * 100;
		if (n == 100) {
			ans = 10100;
		}
		break;
	case 2:
		ans = n * 10000;
		if (n == 100) {
			ans = 1010000;
		}
		break;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#!/usr/bin/env python
# coding: utf-8

# In[34]:


s = input()


# In[35]:


import itertools

lens = len(s)
sum_ = int(s)

for i in range(1, lens):
    for comb in itertools.combinations(range(1, lens), i):
        #comb = (1, 2)
        sum_ += int(s[:comb[0]])
        for j in range(i-1):
            sum_ += int(s[comb[j]:comb[j+1]])
        sum_ += int(s[comb[-1]:])
        
print(sum_)


# In[ ]:






Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int h, w;
char tb[2001][2001];
char tb2[2001][2001];



int r[2001][2001];
int r2[2001][2001];

int c[2001][2001];
int c2[2001][2001];

int main() {

	cin >> h >> w;
	
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> tb[i][j];
		}
	}

	for (int i = 0; i < h; i++) {
		int val = 0;
		for (int j = 0; j < w; j++) {
			if (tb[i][j] == '.')r[i][j]=val;
			if (tb[i][j] == '#')val=j+1;
		}
	}

	for (int i = 0; i < h; i++) {
		int val = w;
		for (int j = w; j>=1; j--) {
			if (tb[i][j-1] == '.')r2[i][j-1]=val;
			if (tb[i][j-1] == '#')val=j-1;
		}
	}

	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			tb2[i][j] = tb[j][i];
		}
	}
	
	swap(h, w);

	for (int i = 0; i < h; i++) {
		int val = 0;
		for (int j = 0; j < w; j++) {
			if (tb2[i][j] == '.')c[j][i] = val;
			if (tb2[i][j] == '#')val = j + 1;
		}
	}

	for (int i = 0; i < h; i++) {
		int val = w;
		for (int j = w; j >= 1; j--) {
			if (tb2[i][j - 1] == '.')c2[j-1][i] = val;
			if (tb2[i][j - 1] == '#')val = j - 1;
		}
	}

	int ans = 0;

	swap(h, w);

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (tb[i][j] == '.') {
				int tmp = (r2[i][j] - r[i][j])+ (c2[i][j] - c[i][j])-1;

				ans = max(ans, tmp);
			}
		}
	}

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

/*
1 7
##.#..#
*/

Measured memory_bytes: 70656
import java.util.*;
public class Main{
	public static void main(String sp[]){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int diff = a-b;
int hold=c-(Math.min(diff,c));
System.out.println(hold);
}
}


Measured memory_bytes: 21716
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		int numcount[10]={0};
		for(int j=0;j<8;j++){
			numcount[s[j]-'0']++;
		}

		int maxnum = 0,minnum = 0;
		for(int j=0;j<10;j++){
			for(int k=0;k<numcount[j];k++){
				minnum *= 10;
				minnum += j;
				
			}
		}

		for(int j=9;j>=0;j--){
			for(int k=0;k<numcount[j];k++){
				maxnum *= 10;
				maxnum += j;
				
			}
		}

		cout << maxnum - minnum << endl;
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

signed main() {
    int n;
    int p;
    int cnt = 0;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p;
        if (p != i + 1) cnt++;
    }

    if (cnt > 2) cout << "NO" << endl;
    else cout << "YES" << endl;


}

Measured memory_bytes: 256
s = input()
a = s[:(len(s)-1)//2]
b = s[(len(s)+3)//2-1:]
c1 = s == s[::-1]
c2 = a == a[::-1]
c3 = b == b[::-1]
if all((c1, c2, c3)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
def main():
    n = int(input())
    t0, a0 = 1, 1
    for _ in range(n):
        t, a = map(int, input().split())
        mult = max((t0 + t - 1) // t, (a0 + a - 1) // a)
        t0, a0 = t * mult, a * mult
    print(t0 + a0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        if (N % 1000 == 0) {
            System.out.println(0);
            return;
        }
        int ans = ((N / 1000) + 1) * 1000 - N;
        System.out.println(ans);
    }
}


Measured memory_bytes: 35920
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e18;

const ll MAX_V=50;
const ll MAX_S=50*MAX_V+5;


struct Edge{
    ll to,a,b;
    Edge(ll to,ll a,ll b):to(to),a(a),b(b){}
};

struct Data{
    ll v,s,x;
    Data(ll v,ll s,ll x):v(v),s(s),x(x){}
    bool operator < (const Data& a) const{
        return x>a.x;
    }
};

vector<Edge> g[MAX_V];
ll dp[MAX_V][MAX_S+5];

int main()
{
    ll n,m,s;
    cin >> n >> m >> s;
    rep(i,m){
        ll u,v,w,x;
        cin >> u >> v >> w >> x;
        u--; v--;
        g[u].emplace_back(v,w,x);
        g[v].emplace_back(u,w,x);
    }
    vector<ll> c(n),d(n);
    rep(i,n){
        cin >> c[i] >> d[i];
    }
    rep(i,n){
        rep(j,MAX_S+5){
            dp[i][j]=INF;
        }
    }
    s=min(s,MAX_S);
    priority_queue<Data> pq;
    auto push = [&](ll v,ll s,ll x){
        if(s<0) return ;
        if(dp[v][s]<=x) return ;
        dp[v][s]=x;
        pq.emplace(v,s,x);
    };
    push(0,s,0);
    while(!pq.empty()){
        Data hoge=pq.top();
        pq.pop();
        ll v=hoge.v;
        ll s=hoge.s;
        ll x=hoge.x;
        if(dp[v][s]!=x) continue;
        ll ns=min(s+c[v],MAX_S);
        push(v,ns,x+d[v]);
        for(Edge e:g[v]){
            push(e.to,s-e.a,x+e.b);
        }
    }
    for(ll i=1;i<n;i++){
        ll ans=INF;
        rep(j,MAX_S){
            ans=min(ans,dp[i][j]);
        }
        cout << ans << endl;
    }
    return 0;
} 

Measured memory_bytes: 7292
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b);

const int MOD = 1000 * 1000 * 1000 + 7;

bool res() {
	string s;
	cin >> s;
	if (!cin) return false;

	int ndiv = 1;
	bool dob = false;
	for (int i = 1; i < s.size(); ++i) {
		if (s[i] != s[i - 1]) {
			++ndiv;
			dob = false;
		}
		else if (s[i] == s[i - 1] && dob) {
			++ndiv;
			dob = false;
		}
		else {
			if (i != s.size() - 1) {
				++i;
				++ndiv;
				dob = true;
			}
			else {

			}
		}
	}

	cout << ndiv << '\n';

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector <string> a(n);
    vector <int> b(n);
    for(int i=0;i<n;++i)
    {
        cin>>a[i]>>b[i];
    }
    string s;
    cin>>s;
    int ans=0;
    for(int i=(n-1);i>=0;i--)
    {
        if(a[i]==s)
        {
            cout<<ans;
            return 0;
        }
        else
        {
            ans+=b[i];
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <string.h>
#define INF 1000000000000000LL
#define SIZE 4005
#define MOD 998244353

using namespace std;
typedef long long ll;

int ball[SIZE][2];
ll dp[SIZE][SIZE];

int main()
{
	string s;
  	cin >> s;
  	int N = s.length();
  	ball[0][0] = ball[0][1] = 0;
  	for(int i = 0; i < N; i++){
    	if(s[i] == '0'){
        	ball[i][0]+=2;
        } else if(s[i] == '1'){
        	ball[i][0]+=1;
          	ball[i][1]+=1;
        } else {
        	ball[i][1]+=2;
        }
      	if(i > 0){
        	ball[i][0] += ball[i-1][0];
          	ball[i][1] += ball[i-1][1];
        }
    }
  	dp[0][0] = 1;
  	int red = ball[N-1][0];
  	int blue = ball[N-1][1];
  	for(int i = 0; i <= red;i++){
      	for(int j = 0; j <= blue; j++){
          	if(dp[i][j] == 0) continue;
            int num = min(i+j, N-1);
            int r = ball[num][0] - i;
            int b = ball[num][1] - j;
      		if(r > 0){
            	dp[i+1][j] += dp[i][j];
              	if(dp[i+1][j] >= MOD) dp[i+1][j]-=MOD;
            }
      		if(b > 0){
            	dp[i][j+1] += dp[i][j];
              	if(dp[i][j+1] >= MOD) dp[i][j+1]-=MOD;            
            }
        }
    }
  	cout << dp[red][blue] << endl;
  
}

Measured memory_bytes: 123392
#include <cstdio>
#include <algorithm>
using namespace std;
int icecream[10];

int main(){
    int n, t;
    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        fill(icecream, icecream+10, 0);
        for (int i = 0; i < n; i++) {
            scanf("%d", &t);
            icecream[t]++;
        }
        for (int i = 0; i < 10; i++) {
            if (icecream[i] == 0) printf("-\n");
            else {
                for (int j = 0; j < icecream[i]; j++) printf("*");
                printf("\n");
            }
        }
    }
    return 0;
}




Measured memory_bytes: 2624