akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-


def main():
    """Function."""
    n = int(input())
    plus, p_check = [], set()
    for _ in range(n):
        temp = str(input())
        plus.append(temp)
        p_check.add(temp)
    m = int(input())
    minus, m_check = [], set()
    for _ in range(m):
        temp = str(input())
        minus.append(temp)
        m_check.add(temp)

    diffs = []
    for dum in p_check:
        dif = plus.count(dum) - minus.count(dum)
        diffs.append(dif)

    maxdif = max(diffs)
    if maxdif < 0:
        print(0)
    else:
        print(maxdif)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007
#define endl "\n" 
#define p pair<int, int>
#define arrinp(i, a, start, end); for(ll i = start; i <= end; i++) cin >> a[i];
#define arrout(i, a, start, end); for(ll i = start; i <= end; i++) cout << a[i] << " ";
#define swap(a, b) {a = a + b; b = a - b; a = a - b;
#define forfront(i, start, end) for(ll i = start; i <= end; i++)
#define forback(i, start, end) for(ll i = start; i >= end; i--)
#define out(x) cout << x << " ";
#define outline(x) cout << x << endl;
#define sortvector(v) sort(v.begin(), v.end());
#define sortvectorrev(v) sort(v.rbegin(), v.rend());
#define inf INT64_MAX
int32_t main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int sum = INT_MAX;
    int n = s.size(), m = t.size();
    for(int i = 0; i <= n - m; i++)
    {
        int cursum = 0;
        for(int j = 0; j < m; j++)
        {
            if(t[j] != s[i + j]) cursum++;
        }
        sum = min(sum, cursum);
    }
    outline(sum)
    return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#include <map>
#include <vector>
#include <algorithm>
#include <functional>

#include <sstream>
#include <iostream>

using namespace std;
typedef long long llint;
const llint inf = 1000000000000000000LL;

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

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

const int MAXN = 305;

int A[MAXN][MAXN];

int main(void) 
{
  int N;
  scanf("%d", &N);
  REP(i, N) REP(j, N) scanf("%d", &A[i][j]);

  bool ok = true;
  REP(i, N) REP(j, N) REP(k, N)
    if (A[i][j] > A[i][k] + A[k][j])
      ok = false;

  if (!ok) {
    puts("-1");
    exit(0);
  }

  llint sol = 0;
  REP(i, N) FOR(j, i + 1, N) {
    bool important = true;
    REP(k, N) {
      if (i == k) continue;
      if (j == k) continue;
      if (A[i][k] + A[k][j] == A[i][j])
	important = false;
    }
    if (important)
      sol += A[i][j];
  }

  printf("%lld\n", sol);

  return 0;
}




Measured memory_bytes: 640
#include <stdio.h>

int main(){
    
    int a,b;
    char moji;
    
    while(1){
    scanf("%d %c %d",&a,&moji,&b);
    
    if(moji == '+'){printf("%d\n",a+b); continue;}
    else if(moji == '-'){printf("%d\n",a-b);continue;}
    else if(moji == '*'){printf("%d\n",a*b);continue;}
    else if(moji == '/'){printf("%d\n",a/b);continue;}
    else if(moji == '?') break;
    }
    
    return 0;
}



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

void solve(long long N, long long K, std::vector<long long> A){
    for(int i=0;i<K;i++){
        ll minV = ll(1e18)+5;
        vector<ll> sum(N+1,0);
        for(int j=0;j<N;j++){
            ll l = max(0ll,j-A[j]);
            ll r = min(N-1,j+A[j]);
            sum[l]++;
            sum[r+1]--; 
        }
        for(int j=0;j<N;j++){
            A[j] = sum[j];
            minV = min(minV,A[j]);
            sum[j+1] += sum[j];
        }
        if(minV == N){
            break;
        }
    }
    for(int i=0;i<N;i++){
        if(i!= N-1){
            cout <<A[i] <<" ";
            continue;
        }
        cout << A[i];
        
    }
    cout << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


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

void main()
{
    auto nk = readln.split.to!(int[]);
    auto K = nk[1]-1;
    auto S = readln.chomp.to!(char[]);
    if (S[K] == 'A') {
        S[K] = 'a';
    } else if (S[K] == 'B') {
        S[K] = 'b';
    } else if (S[K] == 'C') {
        S[K] = 'c';
    }
    writeln(S);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int h,w,a,b,i,j;
  cin >> h >> w >> a >> b;
  for(i=0;i<b;i++){
    for(j=0;j<a;j++)
      cout << "0";
    for(j=a;j<w;j++)
      cout << "1";
    cout << endl;
  }
  for(i=b;i<h;i++){
    for(j=0;j<a;j++)
      cout << "1";
    for(j=a;j<w;j++)
      cout << "0";
    cout << endl;
  }
  return 0;
}

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

int main(){

	int D,T,S;
	cin>>D>>T>>S;

	if(D==0){
		cout<<"Yes"<<endl;
	}

	else if(S==0){
		cout<<"No"<<endl;
	}

	else{

    float time= (float)D/(float)S;

    if(time<=(float)T)
    	cout<<"Yes"<<endl;

    else
    	cout<<"No"<<endl;

}
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    bool check[40001]{0};
    check[0]=true;
    int a;
    for(int i=0;i<n;++i) {
        cin>>a;
        for(int j=40000;j>-1;--j) {
            if(check[j])check[j+a]=true;
        }
    }
    int q;
    cin>>q;
    for(int i=0;i<q;++i) {
        cin>>a;
        cout<<(check[a]?"yes":"no")<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld",a)

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//char ch;
//string S, T, U;
ll gcd(ll a, ll b)
{
    if (b == 0)
    {
        return a;
    }
    return gcd(b, a % b);
}


ll findGCD(ll x, ll y)
{
    ll result;

    result = gcd(x,y);
    return result;
}

ll findLCM(ll x, ll y)
{
    ll ans = x;

    ans = ( (x * y) / (gcd(x,y)) );

    return ans;
}

ll i, j, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    while(cin>>x>>y)
    {
       cout<<findGCD(x,y)<<" "<<findLCM(x,y)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3144
#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>;

int main(){
   ll a,b,c,k;
   cin >> a >> b >> c >> k;
   ll sum = 0;
   if(k>=a){
      sum += a;
      k -= a;
   }else{
      cout << k << endl;
      return 0;
   }
   if(k>=b){
      k -= b;
   }else{
      cout << sum << endl;
      return 0;
   }
   if(k>=c){
      sum -= k;
   }else{
      sum -= k;
      cout << sum << endl;
      return 0;
   }
   cout << sum << endl;
   return 0;  
}

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

int main (){
    string a,b;
    int ab;
    cin >>a>>b;
    a = a+b;
    ab = stoi(a);
    for(int i = 0;i < ab/2 ;i++){
        if(ab == pow(i,2)){cout << "Yes" << endl;
        return 0;}
    }
    cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(n%2==0)
    {
    for(int i=n-1;i>=0;i-=2)
    {
        cout<<a[i]<<" ";
    }
    for(int i=0;i<n;i+=2)
    {
        cout<<a[i]<<" ";
    }
    }
    else
    {
        for(int i=n-1;i>=0;i-=2)
        {
            cout<<a[i]<<" ";
        }
        for(int i=1;i<n;i+=2)
        {
            cout<<a[i]<<" ";
        }
    }
}


Measured memory_bytes: 3072
#include <map>
#include <string>
#include <queue>
#include <utility>
#include <iostream>
using namespace std;

int main(){
    int d[] = {-1,1,-4,4};

    map<string,int> ans;            //答えを入れていく
    ans["01234567"];                //ゴールの状態

    queue< pair<int,string> > que;    //BFS用
    que.push(make_pair(0,"01234567"));  //ゴールの状態を最初に設定

    while(!que.empty()){             //BFS

        pair<int,string> p(que.front());    //この状態での０の位置がintに入っている
        que.pop();                  //queueから取り出し

        int k(ans[p.second]);       //一つ前の状態の手数

        for(int i=0;i<4;i++){

            int n(p.first+d[i]);    //入れ替える際の０の位置

            if(i==0 && n==3)    continue;
            if(i==1 && n==4)    continue;

            if(n>=0 && n<8){
                string tmp(p.second);
                tmp[p.first] = tmp[n];  //入れ替え
                tmp[n] = '0';

                if(ans.find(tmp) == ans.end()){     //ansにない場合か判断
                    ans[tmp] = k + 1;
                    que.push( make_pair(n, tmp ) );
                }
            }
        }
    }

    string s;               //入力用
    char t;
    while(cin >> t){
        s += t;

        for(int i=0;i<7;i++){
            cin >> t;
            s += t;
        }
        cout << ans[s] << endl;
        s.clear();
    }

    return 0;
}


Measured memory_bytes: 5404
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
  
const int MAXR = 21;
const int MAXC = 21;
const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};
  
struct State {
  int i, j, d, m;
  State();
  State(int i, int j, int d, int m)
    : i(i), j(j), d(d), m(m) {}
};
  
int R, C;
char G[MAXR][MAXC];
bool vis[MAXR][MAXC][4][16];
  
bool canFinish() {
  State s(0,0,0,0);
  queue<State> que;
  que.push(s);
  fill(vis[0][0][0], vis[MAXR][0][0], false);
  vis[s.i][s.j][s.d][s.m] = true;
  
  while(!que.empty()) {
    s = que.front();
    que.pop();
  
    if(isdigit(G[s.i][s.j])) {
      s.m = G[s.i][s.j] - '0';
    } else {
      switch(G[s.i][s.j]) {
      case '<':
        s.d = 2;
        break;
      case '>':
        s.d = 0;
        break;
      case '^':
        s.d = 3;
        break;
      case 'v':
        s.d = 1;
        break;
      case '_':
        if(s.m == 0) s.d = 0;
        else s.d = 2;
        break;
      case '|':
        if(s.m == 0) s.d = 1;
        else s.d = 3;
        break;
      case '?':
        s.d = -1;
        break;
      case '.':
        //
        break;
      case '@':
        return true;
      case '+':
        s.m = (s.m+1)%16;
        break;
      case '-':
        s.m = (s.m-1+16)%16;
        break;
      }
    }
  
    vector<State> next;
    if(s.d == -1) {
      for(s.d = 0; s.d < 4; ++s.d) {
        next.push_back(s);
      }
    } else {
      next.push_back(s);
    }
  
    for(int k = 0; k < next.size(); ++k) {
      State &t = next[k];
      t.i = (t.i + di[t.d] + R) % R;
      t.j = (t.j + dj[t.d] + C) % C;
      if(vis[t.i][t.j][t.d][t.m]) continue;
      vis[t.i][t.j][t.d][t.m] = true;
      que.push(t);
    }
  }
  return false;
}
  
int main() {
  cin >> R >> C;
    for(int i = 0; i < R; ++i) {
      for(int j = 0; j < C; ++j) {
        cin >> G[i][j];
      }
    }
    if(canFinish()) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }

  return 0;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
vector<int> seen(200010);
void dfs(const Graph &G, int v ,int count) {
    seen[v] = count;
    for (int next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v ,count); // 再帰的に探索
    }
}

int main (){
  int N,M;
  cin>>N>>M;
  Graph friends(N);
  rep(i,M){
    int x,y,z=0;
    cin>>x>>y;
 /*   rep(j,friends[x-1].size()){
      if(friends[x-1][j]==y-1)z=1;
    }
    if(z==0){*/
    friends[x-1].push_back(y-1);
    friends[y-1].push_back(x-1);
    //}
  }
    int count = 1;
  //  seen.assign(N, 0);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue; // v が探索済みだったらスルー
        dfs(friends, v ,count); // v が未探索なら v を始点とした DFS を行う
        ++count;
    }
  int ans=0;
  rep(i,N){
    ans=max(ans,seen[i]);
  }
  cout<<ans-1;
}


Measured memory_bytes: 10336
#include <bits/stdc++.h>
using namespace std;
#define lint long long
//#define P pair<int, int>

const int INF = 1E9;
int N, A, B, C;
int l[8];

//解説見た
int dfs(int cur, int a, int b, int c){
    if(cur == N){
        if(min(a, min(b, c)) > 0){
            return abs(a - A) + abs(b - B) + abs(c - C) - 30;
        } else {
            return INF;
        }
        
    }
    vector<int> ret(4);
    ret[0] = dfs(cur + 1, a, b, c);
    ret[1] = dfs(cur + 1, a + l[cur], b, c) + 10;
    ret[2] = dfs(cur + 1, a, b + l[cur], c) + 10;
    ret[3] = dfs(cur + 1, a, b, c + l[cur]) + 10;
    return *min_element(ret.begin(), ret.end());
    
}

int main(){
    cin >> N >> A >> B >> C;
    
    for(int i = 0; i < N; ++i){
        cin >> l[i];
    }
    cout << dfs(0, 0, 0, 0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cstdlib>

using namespace std;

int main()
{
   string s;
   cin>>s;
   if(s[2]==s[3]&&s[4]==s[5]){cout<<"Yes"<<endl;}
   else{cout<<"No"<<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<pair<int,int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(all(a));
  for (int i = 0; i < n; i++) {
    cout << a[i].second << (i < n - 1 ? ' ' : '\n');
  }
  return 0;
}

Measured memory_bytes: 3904
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <bitset>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
//#define double long double
using namespace std; const int N=200010, Mod=1e9+7;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch-'0'), ch=getchar();
    return s*w;
}
void print(int x) { if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
int n,a[N],book[N*10],res;
signed main()
{
    n=read();
    for(ri int i=1;i<=n;i++) a[i]=read(), book[a[i]]++;
    for(ri int i=1;i<=n;i++)
    {
        if(a[i]==1&&book[a[i]]==1) { res++; continue; }
        int qwq=1;
        for(ri int j=1;j*j<=a[i];j++)
        {
            if(a[i]%j) continue;
            int x=a[i];
            if(book[j] || (x/j!=x && book[x/j]) || (x/j==x && book[x/j]>1)) { qwq=0; break; }
        }
        res+=qwq;
    }
    printf("%lld\n",res);
    return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, int b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

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

    int mn = 1;
    int max_div = 0;
    for (int i = 1; i <= n; i++)
    {
        int tmp = i;
        int cnt = 0;
        while (tmp / 2)
        {
            cnt++;
            tmp /= 2;
        }
        if (max_div < cnt)
        {
            mn = i;
            max_div = cnt;
        }
    }
    cout << mn << endl;
}


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

#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int main(){
	fastio
	int n,k;
	cin >> n >> k;
	int arr[n];
	for(auto &x : arr) cin >> x;
	sort(arr,arr+n);
	int sum = 0;
	for(int i = 0;i < k;i++) sum += arr[i];
	cout << sum << "\n";
}

Measured memory_bytes: 3644
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define N_ 101000
#define pii pair<int,int>
int w[N_], C[N_], D[1<<16], P[N_], cnt, CC[N_];
int n;
priority_queue<pii>PQ;
void Put(int mask, int d) {
	if (D[mask] <= d)return;
	D[mask] = d;
	PQ.push(pii(-d, mask));
}
int main() {
	int i, a, b, c, j;
	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d%d%d", &a, &b, &c);
		a++, b++;
		w[a] ^= c;
		w[b] ^= c;
	}
	int s = 0, res = 0;
	for (i = 1; i <= n; i++) {
		if (w[i])C[w[i]]++, res++;
	}
	for (i = 1; i <= 15; i++)if (C[i] & 1)s |= (1 << i);
	for (i = 0; i < (1 << 16); i++) {
		D[i] = 1e9;
		for (j = 0; j < 16; j++)if ((i >> j) & 1)CC[i]++;
	}
	Put(s, 0);
	for (i = 2; i < (1 << 16); i += 2) {
		int t = 0;
		for (j = 1; j <= 15; j++)if ((i >> j) & 1)t ^= j;
		if (t == 0)P[cnt++] = i;
	}
	while (!PQ.empty()) {
		pii tp = PQ.top();
		PQ.pop();
		int x = tp.second;
		if (-tp.first != D[x])continue;
		for (i = 0; i < cnt; i++) {
			int y = P[i];
			if (!(x&y))continue;
			Put(y^x, D[x] + CC[y] - 2);
		}
	}
	printf("%d\n", (res + D[0])/2);
	return 0;
}

Measured memory_bytes: 1280
#include <cstdio>
#include <algorithm>

using namespace std;

#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define INF 1 << 30

int P, N[6], p[6] = {1, 5, 10, 50, 100, 500};

int change(int m){
  int c = m-P, res = 0, use;
  for(int i = 5; i >= 0; i--){
    if(c/p[i]){
      use = c/p[i];
      res += use;
      c -= use*p[i];
    }
  }
  return res;
}

int pay(int m){
  int res = 0, use;
  for(int i = 5; i >= 0; i--){
    if(m/p[i]){
      use = min(m/p[i], N[i]);
      res += use;
      m -= use*p[i];
    }
  }
  if(m) return INF;
  else return res;
}

int main(){
  while(scanf("%d%d%d%d%d%d%d", &P, &N[0], &N[1], &N[2], &N[3], &N[4], &N[5]) && P){
    int res = INF, sum = N[0]*p[0]+N[1]*p[1]+N[2]*p[2]+N[3]*p[3]+N[4]*p[4]+N[5]*p[5];
    REP(i, P, sum+1) res = min(res, change(i)+pay(i));
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void){
	char a[1200];
	int i,l;
	fgets(a,1200,stdin);
	l=strlen(a
	);
	for(i=0;i<l;i++){
		if('a'<=a[i]&&a[i]<='z')
			a[i]=toupper(a[i]);
		else
			a[i]=tolower(a[i]);
	}
	printf("%s",a);
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
 
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()
 
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

typedef long long lint;
#define int long long

int calculate(lint x, lint y) {
    int res = 0;
    while (x > y) {
        y *= 4;
        ++res;
    }
    return res;
}

int calculate2(lint x, lint y) {
    int res = 0;
    while (x * 4 <= y) {
        ++res;
        x *= 4;
    }
    return res;
}

std::vector<int> solve(const std::vector<lint>& vec) {
    int N = vec.size();
    std::vector<int> res(N);
    std::stack<int> next;
    next.push(N);
    for (int i = N - 2; i >= 0; --i) {
        res[i] += res[i + 1];
        int need = calculate(vec[i], vec[i + 1]);
        if (need == 0) {
            int push = calculate2(vec[i], vec[i + 1]);
            while (push--) next.push(i + 1);
            continue;
        }
        int add = 0, prev = i + 1;
        for (int coeff = need; coeff > 0; --coeff) {
            int border = next.top();
            add += (border - prev) * coeff;
            prev = border;
            if (border == N) {
                break;
            }
            next.pop();
        }
        res[i] += add;
    }
    return res;
}

signed main() {

    int N;
    std::cin >> N;
    std::vector<lint> A(N);
    rep (i, N) std::cin >> A[i];

    std::vector<lint> B = A;
    std::reverse(all(B));
    rep (i, N) B[i] *= 2;

    std::vector<int> fr = solve(A), ba = solve(B);
    std::reverse(all(ba));
    rep (i, N) {
        fr[i] *= 2;
        ba[i] = ba[i] * 2 + i + 1;
    }

    int answer = std::min(fr.front(), ba.back());
    rep (i, N - 1) chmin(answer, ba[i] + fr[i + 1]);
    std::cout << answer << '\n';
    return 0;

}


Measured memory_bytes: 6528
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int i,j,n;cin>>n;
	string str;cin>>str;
	vector<llint>dp(1,1);
	for(i=1;i<n;i++){
		if(i>1&&str[i-1]!=str[i-2]){REV(dp);}
		llint g=0;
		for(j=0;j<i;j++){g+=dp[j];g%=mod;dp[j]=g;}
		dp.ins(dp.begin(),0);
	}
	llint ans=0;
	for(i=0;i<n;i++){ans+=dp[i];}ans%=mod;
	cout<<ans<<endl;
	return 0;
}


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

#define int long long

using namespace std;

int INF = 1e16 + 7;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> logs(n);
    int mx = 0;
    for (auto& x : logs) {
        cin >> x; 
        mx = max(mx, x);
    }
    int l = 0, r = mx;
    while (l + 1 != r) {
        int m = (l + r) / 2, cnt = 0;
        for (int i = 0; i < n; ++i) cnt += (logs[i] - 1) / m;
        if (cnt > k) l = m;
        else r = m;
    }
    cout << r;
}

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    solve();

    return 0;
}

Measured memory_bytes: 4348
#include<bits/stdc++.h>
using namespace std;
const int N=1205;
int n,sum,tot,num,id[N][N],dp[N*N],d[N*N],a[N][N],head[N*N],nex[N*N],to[N*N];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<i;j++)
        id[i][j]=id[j][i]=++sum;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<n;j++)
        {
            int x;
            scanf("%d",&x);
            a[i][j]=id[i][x];
        }
        for(int j=2;j<n;j++)
            add(a[i][j-1],a[i][j]),d[a[i][j]]++;
    }
    queue<int>q;
    for(int i=1;i<=sum;i++)
        if(!d[i]) q.push(i),dp[i]=1;
    if(q.empty()){printf("-1\n");return 0;}
    int ans=0;
    while(!q.empty())
    {
        int u=q.front();q.pop();
        num++;
        ans=max(ans,dp[u]);
        for(int i=head[u];i;i=nex[i])
        {
            int v=to[i];d[v]--;
            dp[v]=max(dp[v],dp[u]+1);
            if(!d[v]) q.push(v);
        }
    }
    if(num!=sum) printf("-1\n");
    else printf("%d\n",ans);
}


Measured memory_bytes: 35072
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int main(void)
{
    string str;
    getline(cin, str);
    
    vector<int> v;
    int tmp;
    for(int i=0 ;i<str.size(); i++)
    {
        tmp = str[i] - '0';
        v.push_back(tmp);
    }
    
    int len = v.size();
    int count = 0;
    int pos = 0;

    for(int i=0; i<len;)
    {
        if( i < v.size()-1 )
        {
            if( (v[i]+v[i+1]) == 1 )
            {
                count+=2;
                len -= 2;
                v.erase(v.begin()+i);
                v.erase(v.begin()+i);
                i = 0;
            }
            else
            {
                i++;
            }
        }
        else
        {
            break;
        }
    }

    printf("%d", count);
    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    string s;
    cin>>s;
    if(s.size()==2){
        if(s[0]==s[1]) cout<<"1 2"<<endl;
        else cout<<"-1 -1"<<endl;
        return 0;
    }
    rep(i,s.size()-2){
        string t=s.substr(i,i+2);
        int a=t[0]^t[1]^t[2];
        if(a==0||a==t[0]||a==t[1]||a==t[2]){
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
        }
    }
    cout<<"-1 -1"<<endl;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++){
            h[i] = scan.nextInt();
        }
        for(int i = n - 1; i > 0; i--){
            if(h[i - 1] - h[i] <= 0){
                
            }else if(h[i - 1] - h[i] <= 1){
                h[i - 1]--;
            }else{
                System.out.println("No");
                System.exit(0);
            }
        }
        System.out.println("Yes");
    }
}

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

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

    int K;
    string S;
    cin >> K >> S;

    if (S.size() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3640
LR = readlines.drop(1).map{|l| l.split.map(&:to_i)}

require 'prime'
c = 0
cs = (0 .. 1e5).map{|n| n.prime? && ((n+1)/2).prime? ? c += 1 : c}
LR.each{|l, r| puts cs[r] - cs[l - 1]}

Measured memory_bytes: 20220
#include<stdio.h>
int main(void)
{
	int a,aa,b,bb,c,s,ss,sss,s1;
	int flg1,flg2;
	scanf("%d %d %d",&a,&b,&c);	
	while(!(a==-1 && b==-1 && c==-1)){
	flg1=flg2=0;
	s=a*3600;
	ss=b*60;
	sss=s+ss+c;
	s1=7200-sss;
	a=s1/3600;
	aa=s1%3600;
	b=aa/60;
	c=aa%60;
	printf("%02d:%02d:%02d\n",a,b,c);
	if(a!=0){
		a=a*3;
	}
	if(b!=0){
		b=b*3;
	}
	if(c!=0){
		c=c*3;
	}
	while(1){
		flg1=flg2=0;
		if(c>=60){
			c=c-60;
			b=b+1;
			flg1=1;
		}
		if(b>=60){
			b=b-60;
			a=a+1;
			flg2=1;
		}
		if(flg1==0 && flg2==0){
			break;
		}
	
	}
	printf("%02d:%02d:%02d\n",a,b,c);
	scanf("%d %d %d",&a,&b,&c);	
	}
	return 0;
}

Measured memory_bytes: 1044
#include <stdio.h>
#include <string.h>
int main() {
    char s[200001], a[200001];
    int l, last=0;
    scanf("%s", s);
    l = strlen(s);
    for (int i=0; i<l; i++) {
        if (s[i] == 'S')
            a[++last] = 'S';
        else {
            if (a[last] == 'S')
                last--;
            else
                a[++last] = 'T';
        }
    }
    printf("%d\n", last);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
int lcm(int x,int y){
  return x/__gcd(x,y)*y;
}
int mpow(int n,int x){
  int res=1LL;
  for(int i=0;i<x;i++) res*=n;
  return res;
}
int mod_pow(int x,int n,int mod){
  int res=1;
  while(n>0){
    if(n&1) (res*=x)%=mod;
    (x*=x)%=mod;
    n>>=1;
  }
  return res;
}
int ker(int n){
  int res=1;
  map<int,int> m;
  for(int i=2;i*i<=n;i++){
    if(n%i) continue;
    while(n%i==0) n/=i,m[i]++;
  }
  if(n!=1) m[n]++;
  for(auto p:m){
    if(p.first==2){
      if(p.second==1) res=lcm(res,1);
      else if(p.second==2) res=lcm(res,2);
      else res=lcm(res,mpow(2,p.second-2));
    }else{
      res=lcm(res,mpow(p.first,p.second-1)*(p.first-1));
    }
  }
  return res;
}

signed main(){
  int n,b;
  cin>>n;
  b=n;
  map<int,int> m;
  for(int i=2;i*i<=n;i++){
    if(n%i) continue;
    while(n%i==0) n/=i,m[i]++;
  }
  if(n!=1) m[n]++;
  if(b==n){
    cout<<1<<endl;
    return 0;
  }
  if((int)m.size()>2){
    cout<<-1<<endl;
    return 0;
  }
  int x=-1,y;
  int ans=1LL;
  for(auto p:m){
    if(p.second>1){
      cout<<-1<<endl;
      return 0;
    }
    ans*=(p.first-1);
    //cout<<ans<<endl;
    if(x<0) x=p.first;
    else y=p.first;
  }
  if(__gcd(x+y-1,(x-1)*(y-1))!=1LL){
    cout<<-1<<endl;
    return 0;
  }
  //cout<<x<<" "<<y<<endl;
  //cout<<x+y-1<<" "<<(x-1)*(y-1)<<endl;
  int k=ker(ans);
  //cout<<k<<endl;
  int tmp=k;
  for(int i=2;i*i<=k;i++){
    if(k%i) continue;
    //cout<<i<<" "<<mod_pow(x,mod_pow(b,i,ans),b)<<endl;
    //cout<<k/i<<" "<<mod_pow(x,mod_pow(b,k/i,ans),b)<<endl;
    if(mod_pow(x,mod_pow(b,i,ans),b)==x&&
       mod_pow(y,mod_pow(b,i,ans),b)==y&&
       mod_pow(x+1,mod_pow(b,i,ans),b)==x+1&&
       mod_pow(y-1,mod_pow(b,i,ans),b)==y-1) tmp=min(tmp,i);
    if(mod_pow(x,mod_pow(b,k/i,ans),b)==x&&
       mod_pow(y,mod_pow(b,k/i,ans),b)==y&&
       mod_pow(x+1,mod_pow(b,k/i,ans),b)==x+1&&
       mod_pow(y-1,mod_pow(b,k/i,ans),b)==y-1) tmp=min(tmp,k/i);
  }
  cout<<tmp<<endl;
  return 0;
}

Measured memory_bytes: 3088
H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]

ans = 0
for mask_h in range(2**H):
    for mask_w in range(2**W):
        cnt = 0
        for i in range(H):
            for j in range(W):
                if ((mask_h >> i) & 1) == 0 and ((mask_w >> j) & 1) == 0 \
                    and C[i][j] == '#':
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Measured memory_bytes: 9204
def ifprime(n):
    if n%2==0:
        print(' 2',end="")
        return(int(n/2))
    else:
        for i in range(3,int(n**0.5)+1):
            if n%i==0:
                print(f' {i}',end="")
                return(int(n/i))
        print(f' {n}',end="")
        return(1)
n=int(input())
print(f'{n}:',end="")
while 1:
    n=ifprime(n)
    if n==1:break
print()


Measured memory_bytes: 5664
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
#include <chrono>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef tuple<ll,ll,ll> tll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//templete
int main() {
	int D;
	cin>>D;
	cout<<"Christmas";
	for(int i=0;i<25-D;i++)
		cout<<" Eve";
	cout<<endl;
    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long N = in.nextLong();
		long K = in.nextLong();
		System.out.println(absolutediff(N,K));
	}
	
	public static long absolutediff(long N, long K) {
		if(N < K) {
			return Math.min(Math.abs(N-K),Math.abs(Math.abs(N-K)-K));
		}
		else {
			return absolutediff(N%K, K);
		}
	}
	
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>> s;
  for(int i=0;i<s.size();++i){
    if(i==s.size()-1){
      if(s[i]!='s')
        cout << s + "s";
      else
        cout << s + "es";
    }
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;

int main(){
	int n;
	int x[51];
	cin >> n;

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

	int ans = 0;
	for (int i = 0; i < n; i++){
		for (int j = i+1; j < n; j++){
			ans += x[i] * x[j];
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
    unsigned int X;
    unsigned int R;
    cin >> X;
    for (int i = 1; i <= 31; i++) {
        for (int j = 2; j <= 10; j++) {
            unsigned long long Y;
            Y = pow(i, j);
            if (Y <= X && Y > R) {
                R = Y;
            }
        }
    }
    cout << R;
}

Measured memory_bytes: 640
fn main() {
    let (h, w) = read_tuple::<i64>();

    if h == 1 || w == 1 {
        println!("1");
    } else {
        // h > 1 and w > 1
        println!("{:?}", ((h + 1) / 2) * ((w + 1) / 2) + (h / 2) * (w / 2));
    }
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}



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

ans = 1
flag_over = False
flag_0 = False
len0 = 0

if 0 in A:
    flag_0 = True
for b in B:
    len0 += len(b) - 1
if len0 > 18:
    flag_over = True

if flag_0 == False and flag_over == 0:
    for a in A:
        ans *= a

if ans > 10**18:
    flag_over = True

if flag_0:
    print(0)
elif flag_over:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 85588
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

S = str(input())

ans = 1
if len(S) % 2 == 0:
    for i in range(len(S)):
        if i % 2 == 0:
            if "h" == S[i]:
                pass
            else:
                ans = 0
        else:
            if "i" == S[i]:
                pass
            else:
                ans = 0
else:
    ans = 0

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 7244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 2019;



int main(){
    ll N; cin >> N;
    vector<pair<ll, ll>> V(N);

    for(int i = 0; i < N; i++){
        int x; cin >> x;
        V[i] = make_pair(x, i);
    }
    sort(V.begin(), V.end());
    map<ll, ll> M;
    for(int i = 0; i < N; i++){
        if(i < N/2) M[V[i].second] = V[N/2].first;
        else M[V[i].second] = V[N/2-1].first;
    }
    for(int i = 0; i < N; i++) cout << M[i] << endl;

}

Measured memory_bytes: 17792
from collections import defaultdict
import heapq

def a(N,A,B,C,D):
    E = defaultdict(lambda:N*D)
    arr = [(2,A),(3,B),(5,C)]
    # Nから0までのコストを計算する
    # ヒープは最小の要素が先頭に来る
    # D[0]を超えたら打ち切る
    aa = 0
    bb = 0
    num = 0
    H = [N]
    E[N] = 0
    while len(H) != 0:
        num = heapq.heappop(H)
        if E[num] >= E[0]:
            continue
        E[0] = min(E[0],E[num] + D * num)
        for k,v in arr:
            aa = num // k
            bb = E[num] + D * (num - aa * k) + v
            if E[aa] > bb:
                E[aa] = bb
                heapq.heappush(H,aa)
            aa += 1
            bb = E[num] + D * (aa * k - num) + v
            if E[aa] > bb:
                E[aa] = bb
                heapq.heappush(H,aa)
    print(E[0])

T = int(input())
A = [0]*T
for i in range(T):
    A[i] = tuple(map(int,input().split()))
    
for i in range(T):
    a(*A[i])

Measured memory_bytes: 87656
#[allow(unused_imports)]
use std::collections::HashSet;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let hw = read_vec::<usize>();
    let h = hw[0];
    let w = hw[1];

    let mut shogai_yoko : Vec<Vec<usize>> = Vec::with_capacity(h);
    let mut shogai_tate : Vec<Vec<usize>> = Vec::with_capacity(w);
    for _i in 0..w {
        let v : Vec<usize> = Vec::with_capacity(h);
        shogai_tate.push(v)
    }
    
    for i in 0..h {
        let mut v : Vec<usize> = Vec::with_capacity(w);
        let s = read::<String>();
        for (j, c) in s.chars().enumerate() {
            if c == '#' {
                v.push(j);
                shogai_tate[j].push(i)
            }
        }
        v.push(w);
        shogai_yoko.push(v);
    }
    for j in 0..w {
        shogai_tate[j].push(h)
    }


    let answer = solve(h, w, &shogai_yoko, &shogai_tate);
    println!("{}", answer);
}

fn solve(h: usize, w: usize, shogai_yoko: &[Vec<usize>], shogai_tate: &[Vec<usize>]) -> usize {
     // (yoko, tate)
     let mut dp : Vec<Vec<(usize, usize)>> = Vec::with_capacity(h);
     for _i in 0..h {
        let v : Vec<(usize, usize)> = vec![(0, 0); w];
        dp.push(v);
     }

     // yoko
     for i in 0..h {
        let mut from = 0;
        for x in &shogai_yoko[i] {
            let d = x - from;
            if d > 0 {
                for j in from..*x {
                    dp[i][j].0 = d - 1;
                }
            }
            from = x + 1;
        }
    }

    // tate
    for j in 0..w {
        let mut from = 0;
        for x in &shogai_tate[j] {
            let d = x - from;
            if d > 0 {
                for i in from..*x {
                    dp[i][j].1 = d - 1;
                }
            }
            from = x + 1;
        }
    }

    // total
    let mut max : usize = 0;
    for i in 0..h {
        for j in 0..w {
            let val = dp[i][j].0 + dp[i][j].1 + 1;
            if val > max {
                max = val;
            }
        }
    }

    return max
}


Measured memory_bytes: 227580
#include <cstdio>

using namespace std;

char s[200001];
char t[200001];

int main() {
    int h, w, n, x, y, l, r, u, d, i;
    
    scanf("%d %d %d", &h, &w, &n);
    scanf("%d %d", &x, &y);
    scanf("%s", s);
    scanf("%s", t);
    
    l = 0, r = w + 1;
    
    for (i = n - 1; i >= 0; i--) {
        if (t[i] == 'L') {
            if (r <= w) r++;
        } else if (t[i] == 'R') {
            if (l > 0) l--;
        }
        
        if (s[i] == 'L') {
            l++;
        } else if (s[i] == 'R') {
            r--;
        }
        
        if (l + 1 >= r) {
            puts("NO");
            
            return 0;
        }
    }
    
    if (y <= l || y >= r) {
        puts("NO");
        
        return 0;
    }
    
    u = 0, d = h + 1;
    
    for (i = n - 1; i >= 0; i--) {
        if (t[i] == 'U') {
            if (d <= h) d++;
        } else if (t[i] == 'D') {
            if (u > 0) u--;
        }
        
        if (s[i] == 'U') {
            u++;
        } else if (s[i] == 'D') {
            d--;
        }
        
        if (u + 1 >= d) {
            puts("NO");
            
            return 0;
        }
    }
    
    if (x <= u || x >= d) {
        puts("NO");
        
        return 0;
    }
    
    puts("YES");
    
    return 0;
}


Measured memory_bytes: 512
function main(input) {
    var args = input.trim().split(" ").map((v) => parseInt(v));
    var A = Number(args[0]);
    var B = Number(args[1]);

    console.log(Math.max(A + B, A - B, A * B));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        const long MOD = 1000000007;
        var sc = new Scanner();
        int n = sc.nextInt();
        var h = new int[n];
        for (int i = 0; i < n; i++)
        {
            h[i] = sc.nextInt();
        }

        var dp = new long[n];
        dp[0] = 0;
        dp[1] = Math.Abs(h[1] - h[0]);
        for (int i = 2; i < n; i++)
        {
            dp[i] = Math.Min(dp[i - 1] + Math.Abs(h[i] - h[i - 1]), dp[i - 2] + Math.Abs(h[i] - h[i - 2]));
        }

        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        Console.WriteLine(dp[n - 1]);
        Console.Out.Flush();
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 18912
#include<stdio.h>
#include<math.h>

typedef struct point2d{
  double x,y;
} point;

double distance(point a,point b){
  double dx=a.x-b.x;
  double dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int solve(const point *p,const int n){
  int i,j;
  int max=1;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      double d=distance(p[i],p[j]);
      if(d>2.0) continue;
      double dx=p[i].x-p[j].x;
      double dy=p[i].y-p[j].y;
      point mid=(point){(p[i].x+p[j].x)/2,(p[i].y+p[j].y)/2};
      point c=(point){mid.x-dy/d*sqrt(1-d*d/4),mid.y+dx/d*sqrt(1-d*d/4)};
      int cnt=2;
      int k;
      for(k=0;k<n;k++){
	if(k==i || k==j) continue;
	if(distance(c,p[k])<=1.0) cnt++;
      }
      if(max<cnt) max=cnt;
      c=(point){mid.x+dy/d*sqrt(1-d*d/4),mid.y-dx/d*sqrt(1-d*d/4)};
      cnt=2;
      for(k=0;k<n;k++){
	if(k==i || k==j) continue;
	if(distance(c,p[k])<=1.0) cnt++;
      }
      if(max<cnt) max=cnt;
    }
  }
  return max;
}

void run(void){
  while(1){
    int n;
    scanf("%d",&n);
    if(n==0) break;
    point p[300];
    int i;
    for(i=0;i<n;i++){
      double x,y;
      scanf("%lf%lf",&x,&y);
      p[i]=(point){x,y};
    }
    int ans=solve(p,n);
    printf("%d\n",ans);
  }
}

int main(void){
  run();
  return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N,M; scanf("%d %d",&N, &M);
	int K;
	int like[M] = {0};

	REP(i,N){
		scanf("%d", &K);

		int A;
		REP(j,K){
			scanf("%d",&A);
			like[A-1]++;
		}
	}

	int ans = 0;
	REP(i,M){
		if(like[i] == N) ans++;
	}

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

	return 0;

}


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

using namespace std;

typedef long long int lli;

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

    int n;
    lli a[100010], b[100010];
    cin >> n;
    for (int i=0; i<n+1; i++) cin >> a[i];
    for (int i=0; i<n; i++)   cin >> b[i];

    lli ans = 0, tmp;
    for (int i=0; i<n; i++) {
        tmp = a[i];
        ans += min(a[i], b[i]);
        a[i] -= min(a[i], b[i]);
        b[i] -= min(tmp, b[i]);

        tmp = a[i+1];
        ans += min(a[i+1], b[i]);
        a[i+1] -= min(a[i+1], b[i]);
        b[i] -= min(tmp, b[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int total = 0;
		int[] times = new int[n];
		for (int i = 0; i < times.length; i++) {
			times[i] = scanner.nextInt();
			total += times[i];
		}
		
		int m = scanner.nextInt();
		for (int i = 0; i < m; i++) {
			int p = scanner.nextInt(), x = scanner.nextInt();
			int ans = total + x - times[p-1];
			System.out.println(ans);
		}
		
		
		
		scanner.close();
	}
}

Measured memory_bytes: 21844