akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
#define INF 1000000000
#define endl '\n'
#define BLOCK 710
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
 
using namespace std;
struct query{
	int l;
	int r;
	int i;
};
query Q[500001];
int ar[500001] , ans[500001];
int fre[500001];
int cnt = 0;
 
bool comp(query a , query b)
{
	if(a.l / BLOCK != b.l/BLOCK)
	return a.l/BLOCK < b.l/BLOCK;
	
	return a.r < b.r;
}
 
void add(int pos)
{
	fre[ar[pos]]++;
	if(fre[ar[pos]] == 1)
	cnt++;
}
 
void remove(int pos)
{
	fre[ar[pos]]--;
	if(fre[ar[pos]] == 0)
	cnt--;
}
 
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	
	int n , q;
	cin>>n>>q;
	for(int i=0;i<n;i++)
	cin>>ar[i];
	
	for(int i=0;i<q;i++){
		cin>>Q[i].l>>Q[i].r;
		Q[i].i = i , Q[i].l-- , Q[i].r--;
	}
	
	sort(Q , Q+q , comp);
	
	//why ML = 0 , and MR = -1?
	int ML = 0 , MR = -1;
	for(int i=0;i<q;i++)
	{
		int L = Q[i].l;
		int R = Q[i].r;
		
		while(ML > L)
		ML-- , add(ML);
		
		while(MR < R)
		MR++ , add(MR);
		
		while(ML < L)
		remove(ML) , ML++;
		
		while(MR > R)
		remove(MR) , MR--;
		
		ans[Q[i].i] = cnt;
	}
	
	for(int i=0;i<q;i++)
	cout<<ans[i]<<'\n';
}


Measured memory_bytes: 15404
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int N;
  cin >> N;

  cout << N/3 << endl;

  return 0;
}


Measured memory_bytes: 256
N,x=map(int,input().split())
a=list(map(int,input().split()))

a.sort()

Q=0
for i in range(N):
    if x>=a[i] and i!=N-1:
        Q+=1
        x=x-a[i]
    elif i==N-1 and x==a[i]:
        Q+=1
print(Q)

Measured memory_bytes: 9124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

typedef complex<double> P;

double cross(P a,P b){
  return a.real()*b.imag() - a.imag()*b.real();
}

vector<P> ps(3);
P p;

bool isIn(){
  for(int i = 0 ; i < ps.size() ; i ++){
    P q = ps[i];
    P r = ps[(i+1)%ps.size()];
    if(cross(r-q,p-q) < 0.0)return false;
  }
  return true;
}

int main(void){
  while(cin>>ps[0].real()>>ps[0].imag()){
    loop(i,1,3)cin>>ps[i].real()>>ps[i].imag();
    cin>>p.real()>>p.imag();
    bool res = false;
    if(isIn() || (swap(ps[0],ps[1]), isIn() ) ){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;

}

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


int main()
{
	int ans=0;
	string s;
	cin>>s;
	for(int i=0;i<6;i++)
	{
		if(s[i]=='1')ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main()
{
    int n;
    cin >> n;
 
    vector<ll> numCnt(100001);
    ll sum = 0;
    rep (i, n)
    {
        int a;
        cin >> a;
        numCnt[a]++;
        sum += a;
    }
 
    int q;
    cin >> q;
 
    vector<ll> ans(q + 1);
    ans[0] = sum;
    rep (i, q)
    {
        int b, c;
        cin >> b >> c;
 
        ans[i + 1] = ans[i] - numCnt[b] * b + numCnt[b] * c;
        numCnt[c] += numCnt[b];
        numCnt[b] = 0;
    }
 
    rep (i, q)
        cout << ans[i + 1] << endl;
    return 0;
}

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

using namespace std;

int main(){
        int h,w;
        vector< vector<char> > a;

        cin >> h >> w;
        a.resize(h);
        for (int i=0; i<h; i++){
                a[i].resize(w);
                for(int j=0; j<w; j++){
                        cin >> a[i][j];
                }
        }
        vector<bool> hq(h,false);
        vector<bool> wq(w,false);

        for (int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                        if(a[i][j]=='#') {
                                hq[i]=true;
                                break;
                        }
                }
        }
        for (int j=0; j<w; j++){
               for(int i=0; i<h; i++){
                      if(a[i][j]=='#'){
                            wq[j]=true;
                            break;
                      }
               }
        }
        for (int i=0; i<h; i++){
                if (hq[i]){
                    for(int j=0; j<w; j++){
                            if (wq[j]){
                                cout << a[i][j];
                            }
                    }
                    cout << endl;
                }
        }
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
def gcd(a, b):
    if b ==0:
        return a
    else:
        return gcd(b,a%b)

mk = 1
for i in a:
    mk = mk * i//gcd(mk, i)

k = 0
for j in a:
    k +=  mk // j
print(k %MOD)


Measured memory_bytes: 4084
///////////////////////////////////////////////////
/* __                                       __   */
/*|  |--.-----.---.-.----.----.-----.-----.|  |_ */
/*|  _  |  -__|  _  |  __|  __|  -__|  _  ||   _|*/
/*|_____|_____|___._|____|____|_____|   __||____|*/
/*                                  |__|         */
///////////////////////////////////////////////////
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long lint; using namespace std;
#define rep(counter, limit) for (int counter = 0; counter < limit; counter++)
#define INF 1000000000000
#define MOD 10000007
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){cin.tie(0);ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}setupios;
int main() {

  int k,a,b;
  cin>>k>>a>>b;
  for(int i=a;i<b+1;i++){
    if(i%k==0){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  cout<<"NG"<<endl;

}


Measured memory_bytes: 3664
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
    int a[200000], n, k, ai, res = 0;
    scanf("%d %d", &n, &k);
    fill_n(a, n, 0);
    for(int i = 0; i < n; i++){
        scanf("%d", &ai);
        a[ai - 1]++;
    } 
    sort(a, a + n);
    for(int i = 0; i < n - k; i++)
        res += a[i];

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

Measured memory_bytes: 896
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

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

struct Edge {
  int to, cost;
};

struct P {
  int v, d;
};

template <typename T> vector<T> dijkstra(vector<vector<Edge>> &g, int s) {
  const auto inf = numeric_limits<T>::max();
  vector<T> dist((int)g.size(), inf);
  dist[s] = 0;
  priority_queue<pair<T, int>> q;
  q.push({-dist[s], s});
  while (q.size() > 0) {
    T cost;
    int u;
    tie(cost, u) = q.top();
    q.pop();
    cost *= -1;
    for (auto e : g[u]) {
      if (cost + e.cost < dist[e.to]) {
        dist[e.to] = cost + e.cost;
        q.push({-dist[e.to], e.to});
      }
    }
  }
  return dist;
}

int main() {

  int n, m;
  cin >> n >> m;

  map<pair<int, int>, int> idx;
  // {駅, 会社}
  vector<vector<Edge>> g(n + m * 2 + 1);
  auto add_edge = [&](pair<int, int> from, pair<int, int> to, int cost) {
    if (!idx.count(from)) idx[from] = idx.size();
    if (!idx.count(to)) idx[to] = idx.size();
    g[idx[from]].push_back(Edge{idx[to], cost});
  };
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    add_edge({a, c}, {b, c}, 0); // 同じ会社
    add_edge({b, c}, {a, c}, 0);
    add_edge({a, c}, {a, 0}, 0); // 降りる
    add_edge({b, c}, {b, 0}, 0);
    add_edge({a, 0}, {b, c}, 1); // 乗り換え
    add_edge({b, 0}, {a, c}, 1);
  }

  const auto inf = numeric_limits<int>::max();
  if (!idx.count({0, 0})) idx[{0, 0}] = idx.size();
  auto dist = dijkstra<int>(g, idx[{0, 0}]);
  if (!idx.count({n - 1, 0})) idx[{n - 1, 0}] = idx.size();
  auto ans = dist[idx[{n - 1, 0}]];
  if (ans == inf) ans = -1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 64376
/*
Problem :Atcoder Contest 115-C
Algorithm : bsearch
Status : 
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;

int n,k;
int h[100005];

bool check(int m){
	for(int i = 1;i <= n - k + 1;i++){
		if(h[i + k - 1] - h[i] <= m)
		    return true;
	}
	return false;
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%d",&n,&k);
	for(int i = 1;i <= n;i++)
	    scanf("%d",&h[i]);
	sort(h + 1,h + 1 + n);
	int l = 0,r = INF,ans = 0;
	while(l <= r){
		int mid = (r - l) / 2 + l;
		if(check(mid)){
			ans = mid;
			r = mid - 1;
		}else
		    l = mid + 1;
	}
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;

#define M_DEBUG if (1)

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define optimize_cin() \
    cin.tie(0);        \
    ios::sync_with_stdio(false)

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

using lint = long long;
typedef unsigned long long int ullint;

/******************************************************************************
	Main
******************************************************************************/
#define L_MAX_STEPS 100000

int main()
{
    int n = 0;
    cin >> n;
    assert(n >= 2 && n <= pow(10, 5));

    int steps[L_MAX_STEPS] = {0}; // 第 i + 1 足場の高さ
    int costs[L_MAX_STEPS] = {0}; // 第 i + 1 足場までの最小コスト。
    rep(i, n)
    {
        cin >> steps[i];
        assert(steps[i] >= 1 && steps[i] <= pow(10, 4));
        if (i == 0) continue;
        // 0 - i までの最小コストを調べたい
        // i - 1 から飛んでくるのと、i - 2 から飛ぶのと、どっちがローコストか？
        int cost_best = abs(steps[i] - steps[i - 1]);
        if (i > 1) {
            cost_best += costs[i-1];
            int cost = abs(steps[i] - steps[i - 2]);
            cost += costs[i-2];
            cost_best = (cost_best > cost)? cost : cost_best;
        }
        costs[i] = cost_best;
    }

    cout << costs[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = [int(hoge) for hoge in input().split()]
A.sort(reverse=True)
Twoused = (N - 2)//2
Twosum = 2*sum([A[i] for i in range(1,Twoused+1)])
if N%2:
    ans = Twosum + A[0] + A[Twoused+1]
else:
    ans = Twosum + A[0]
print(ans)
    

Measured memory_bytes: 31620
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  bool flg = true;
  if(S.size()%2 != 0) flg = false;
  rep(i,S.size()/2){
    if(S[i] != S[i+S.size()/2]){
      flg = false;
    }
  }

  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}



Measured memory_bytes: 384
s = list(input())

i = 0
bc = list("BC")

a_cnt = 0
res = 0
i = 0
while i <= len(s)-1:
  if s[i] == "A":
    a_cnt += 1
  elif s[i:i+2] == bc:
    res += a_cnt
    i += 1
  else:
    a_cnt = 0
  i += 1

print(res)

Measured memory_bytes: 4840
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_DISABLE_PERFCRIT_LOCKS
#define POPCNTI(a) __builtin_popcount(a)
#define fs  first  
#define sc  second
#define ARR array

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace  __gnu_pbds;


#include <bits/stdc++.h>
using namespace  __gnu_pbds; 
using namespace std;

// cf? uncomment : comment

// #ifndef _LOCAL_DEFINE
// inline int getchar_unlocked(){return _getchar_nolock();}
// inline void putchar_unlocked(char c) {_putchar_nolock(c);}
// #endif

typedef long long ll;  
inline void WRITE_CHAR(char c)  {putchar_unlocked(c);} 
template<typename T> 
inline bool READn (T &result) {
  int minus = 1;
  char ch;
  result=0;
  ch = (char) getchar_unlocked();
  while (!isdigit(ch) && ch!=EOF) minus = (ch == '-'? -1 : minus),ch= (char) getchar_unlocked();

  if(ch==EOF) return false;
  while (isdigit(ch))  result = result*10 + (int) (ch - '0'),ch = (char) getchar_unlocked();
  
  result *= minus;
  return ch != '\n';
}
template<typename T>
inline void WRITEn(T x) {
  if (x < 0) {putchar_unlocked('-'); x = -x; }
  char writeBuffer[20], *writePtr = writeBuffer;
  do {
    *writePtr++ = (char)('0' + x % 10);
    x /= 10;
  }
  while (x);
  do  { putchar_unlocked(*--writePtr); }
  while (writePtr > writeBuffer);
}
inline bool Read_CHAR(char &c)
{
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  c = READ_CHARACTER;
  return true;
} 
inline bool READ_CHAR_ARRAY(char *x) {
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  char *ptr = &x[0];
  while ((READ_CHARACTER != '\n' && READ_CHARACTER != '\t' && READ_CHARACTER != ' ' && READ_CHARACTER != EOF)) *ptr++ = READ_CHARACTER, READ_CHARACTER = (char)getchar_unlocked();

  *ptr = '\0';
  return true;
}
inline void WRITE_CHAR_ARRAY(const char *x) {
  while(*x != '\0')
    putchar_unlocked(*x++);
}
inline void WRITE_STRING(string &x) {
  for(char c: x) 
    putchar_unlocked(c);
}
const ll OOl = 1e18 ;
const int N = 2e5+1,OO = 1e9,OOm = 0x3f3f3f3f, MOD = 1e9 + 7;
int dp[1001][1001],grid[1001][1001];
int add(int x,int y)
{
  x+=y;
  if(x>MOD) x-=MOD;
  return x;
}
int main()
{
  int n,m;
  READn(n),READn(m);
  for(int i = 0; i < n; ++i) 
    for(int j = 0; j < m; ++j)
    {
      char c;
      Read_CHAR(c);
      if(c=='.') grid[i][j] = 1;
    }
    
  dp[0][0] = 1;
  for(int i=0;i<n;++i)
  {
    for(int j=0;j<m;++j)
    {
      if(!grid[i][j]) continue;
      if(i-1 >=0 && grid[i-1][j]) dp[i][j] = add(dp[i][j],dp[i-1][j]);
      if(j-1>=0 &&  grid[i][j-1]) dp[i][j] = add(dp[i][j],dp[i][j-1]);
    }
  }
  WRITEn(dp[n-1][m-1]);
  return 0; 
}

Measured memory_bytes: 11404
#include<bits/stdc++.h>
using namespace std;
int main()
{
int now=0,maxs=0;
int n;
cin>>n;
char s;
while(n--)
{
	cin>>s;
	if(s=='I')
	{
		now++;
		maxs=max(now,maxs);
	}
	else
	{
		now--;
	}
}
cout<<maxs<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin>>n;
    if(n<3)
        cout<<0;
    else if (n%3==0)
        cout<<n/3;
    else if(n%3!=0){
        while(true){
            n++;
            if(n%3==0){
                cout<<n/3-1;
             break;
            }
        }
    }
   return 0;
   }

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

const int N = 1e6+7;
int n,a,b,c,dp[3][N],h[3][N];

int32_t main()
{
	fast;

	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>h[0][i]>>h[1][i]>>h[2][i];

	dp[0][1]=h[0][1],dp[1][1]=h[1][1],dp[2][1]=h[2][1];
	for(int i=2;i<=n;i++)
	{
		dp[0][i] = h[0][i]+max(dp[1][i-1],dp[2][i-1]);
		dp[1][i] = h[1][i]+max(dp[0][i-1],dp[2][i-1]);
		dp[2][i] = h[2][i]+max(dp[0][i-1],dp[1][i-1]);
	}

	cout<<max(dp[0][n],max(dp[1][n],dp[2][n]));
	return 0;
}

Measured memory_bytes: 15360
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 200005
const ll INF = 1000000000000000001;
const ll MOD = 1000000000;

//vector< vector<ll> > g(N);
//vector< pair<ll, pair< ll, ll > > > g(N);
//ll vis[N] = {0}, par[N] = {0}, child[N] = {0},cnt = 0;


void solve(){
    string s; cin >> s;
    ll sum =0;
    f(0, s.size()-1) sum += s[i] - '0';
    if(sum % 9 == 0) cout << "Yes\n";
    else cout << "No\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    //ll t;cin >> t;for(ll index=1; index<=t; index++){
        //cout << "Case #" << index << ": " ;
        solve();
    //}
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())
#define bit(i) (1LL<<i)
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int H, W;
  while(cin >> H >> W){
    vector<string> S(H); cin >> S;

    int ans = 0;

    vector<vector<int>> up(H, vector<int>(W));
    REP(i,H){
      REP(j,W){
	if(i+1<H){
	  up[i+1][j] += up[i][j];
	  if(S[i][j] == '.') up[i+1][j] += 1;
	  else up[i+1][j] = 0;
	}
      }
    }

    
    vector<vector<int>> down(H, vector<int>(W));
    REV(i,H-1,0){
      REP(j,W){
	if(i-1>=0){
	  down[i-1][j] += down[i][j];
	  if(S[i][j] == '.') down[i-1][j] += 1;
	  else down[i-1][j] = 0;
	}
      }
    }

    
    vector<vector<int>> left(H, vector<int>(W));
    REP(j,W){
      REP(i,H){
	if(j+1<W){
	  left[i][j+1] += left[i][j];
	  if(S[i][j] == '.') left[i][j+1] += 1;
	  else left[i][j+1] = 0;
	}
      }
    }

    
    vector<vector<int>> right(H, vector<int>(W));
    REV(j,W-1,0){ 
      REP(i,H){
	if(j-1>=0){
	  right[i][j-1] += right[i][j];
	  if(S[i][j] == '.') right[i][j-1] += 1;
	  else right[i][j-1] = 0;
	}
      }
    }
    dump(up);
    dump(down);
    dump(left);
    dump(right);
    

    REP(i,H){
      REP(j,W){
	if(S[i][j] == '.'){
	  chmax(ans, up[i][j] + down[i][j] + right[i][j] + left[i][j] + 1);
	}
      }
    }

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


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

using namespace std;

using LL = long long;           using PII = pair<int, int>;
using ll = long long;           using DBL = double;
using VI = vector<int>;         using VD = vector<DBL>;
using VVI = vector<VI>;         using VVD = vector<VD>;
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define REP(i,n) FOR(i,0,n)
#define SZ(a) ((int)((a).size()))
#define ALL(x) (x).begin(), (x).end()
#define SET(a,v) memset((a), (v), sizeof(a))
#define EB emplace_back #define PB push_back
#define MP make_pair  #define ST first  #define ND second

// #define trace(...) {__f(#__VA_ARGS__, __VA_ARGS__);}
// template<typename Arg> void __f(const char* name, Arg&& arg) {
//   cerr << name << " = " << arg << std::endl;
// } template <typename Arg1, typename... Args>
// void __f(const char* names, Arg1&& arg1, Args&&... args) {
//   const char* comma = strchr(names + 1, ',');
//   cerr.write(names, comma - names) << " = " << arg1<<" | ";__f(comma+1, args...); }
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds; // OST: find_by_order, order_of_key
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// #pragma GCC optimize("Ofast")
// optimize("unroll-loops")
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// /*** RNGS ***/
// SEED=chrono::steady_clock::now().time_since_epoch().count();
// // or high_resolution_clock
// mt19937 rng(SEED); /*or*/ random_device rd; mt19937 rng(rd());
// uniform_int_distribution<> dis(MIN, MAX);// usage: dis(rng)
// struct chash {int operator()(int x) const {return x^SEED;}};
// gp_hash_table<int,int,chash>m;//use cc if very less updates
// /*** FAST IO ***/
// inline int scan(){ bool y=0; int x=0; char c=getchar_unlocked();
// while(c<'0'||c>'9'){ if(c=='-')y=1; c=getchar_unlocked();} 
// while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar_unlocked();}
// return y?-x:x; }

int a, b, c, d;
int dp[1024][1024];
const int MOD = 1000000007;
int fact[1024], ifact[1024];

int powmod(int a, int b) {
	if(!b) return 1;
	if(b&1) return (a * 1ll * powmod(a, b-1))%MOD;
	return powmod((a*1ll*a)%MOD, (b/2));
}

int C(int n, int r) {
	return (fact[n] * 1ll * ((ifact[r] * 1ll * ifact[n-r])%MOD) ) % MOD;
}

int calc(int n, int p) {
	int &y = dp[n][p];
	if(y != -1) return y;
	if(p == a-1) return y = (n == 0);
	y = calc(n, p-1);
	if(p*c <= n) {
		int coeff = (C(n, p*c) * 1ll * fact[p*c]) % MOD;
		coeff = (coeff * 1ll * powmod(ifact[p], c)) % MOD;
		for(int i=c; i<=d; ++i) {
			if(p*i > n) break;
			y = (y + (((coeff *1ll* calc(n-p*i, p-1))%MOD) * 1ll * ifact[i])) % MOD;
			if(p*(i+1) > n) break;
			coeff = (C(n-p*i, p) * 1ll * coeff) % MOD;
		}
	}
	return y;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    fact[0] = 1;
    for(int i=1; i<=1001; ++i) {
    	fact[i] = (i * 1ll * fact[i-1]) % MOD;
    }
    ifact[0] = 1;
    for(int i=1; i<=1001; ++i) {
    	ifact[i] = powmod(fact[i], MOD-2);
    }
    int n;
    cin >> n >> a >> b >> c >> d;
    SET(dp, -1);
    cout << calc(n, b) << endl;
    return 0;
}

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

using namespace std;
using ll = long long int;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n;
    cin >> n;
    vector<vector<ll>> G(n);
    for(ll i=0; i<n-1; i++) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<ll> c(n);
    for(auto &e: c) cin >> e;
    sort(c.begin(), c.end(), greater<>());

    vector<ll> res(n);
    {
        auto it = c.begin();

        ll s = accumulate(c.begin()+1, c.end(), 0);
        auto dfs = [&](auto dfs, ll cur, ll pre) -> void{
            res[cur] = *it++;
            for(auto &e: G[cur]) {
                if(e == pre) continue;
                dfs(dfs, e, cur);
            }
        };
        dfs(dfs, 0, -1);

        cout << s << endl;
        for(auto &e: res) cout << e << ' '; cout << endl;
    }
}


Measured memory_bytes: 1408
#include <algorithm>
#include <deque>
#include <iostream>

using namespace std;

int main() {

	int n;

	while(cin >> n) {
		if(!n) {
			break;
		}
		long long int sum=0, t=0;
		deque<long long int> m;
		for(int i=0; i<n; i++) {
			int x;
			cin >> x;
			m.push_back(x);
		}
		sort(m.begin(), m.end());
		for(int i=0; i<n; i++) {
			sum+=t;
			t+=m[i];
		}

		cout << sum << endl;
	}

	return 0;

}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

main(){
  int s = 0;
  for(int i=0;i<3;i++){
    int in;
    cin >> in;
    s <<= 1;
    s |= in;
  }
  if(s == 4 || s == 2 || s == 0) cout << "Close" << endl;
  if(s == 6 || s == 1) cout << "Open" << endl;
}

Measured memory_bytes: 1156
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1) {
        int r0, w0, c, r;
        cin >> r0 >> w0 >> c >> r;
        if (r0 == 0) break;
        int ans = 0;
        while(r0 < c * w0) {
            r0 += r;
            ans++;
        }
        cout << ans << endl;
    }
}



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

if n <= 500:
    print(n)
    for i in range(n):
        print(' '.join([str(i+1)]*n))
    exit()

m = (n + 4 - 1) // 4 * 2
print(m)
for i in range(m):
    if i % 2 == 0:
        print(' '.join([str((i + j) % m % n + 1) for j in range(m)]))
    else:
        print(' '.join([str((m + (i + j) % m) + 1 if (m + (i + j) % m) < n else ((i + j) % m) + 1) for j in range(m)]))


Measured memory_bytes: 3956
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();

		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= m; j++) {
				int tmp = i * m + j * n - i * j * 2;
				if (tmp == k) {
					pr.println("Yes");
					return;
				}
			}
		}

		pr.println ("No");
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  int ans=3;
  if(a==b)ans--;
  if(b==c)ans--;
  if(a==c)ans--;
  if(ans==0)ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int n;
    cin>>n;
    int res = 1;
    for(int i=1;i<50;i++){
        for(int j=2;j<10;j++){
            int m = pow(i,j);
            if(m<=n)res = max(res,m);
        }
    }
    cout<<res<<endl;
}

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

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

    vector<long long> A(N);
    for (long long &a : A)
    {
        cin >> a;
    }

    vector<long long> dp(205, 0);
    dp.back() = 1000;
    for (size_t i = 0; i < N; i++)
    {
        for (long long j = A[i]; size_t(j) < dp.size(); j++)
        {
            dp[A[i]] = max(dp[A[i]], dp[j]);
        }
        for (long long j = 100; j < A[i]; j++)
        {
            dp[A[i]] = max(dp[A[i]], dp[j] + (A[i] - j) * (dp[j] / j));
        }
    }
    long long ans = 0;
    for (long long a : dp)
    {
        ans = max(ans, a);
    }
    cout << ans << endl;
}


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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
  int x;
   
   cin >> x;

   while(!(IsPrime(x)))
    x++;
  cout << x << endl;
}

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

#define N 100001

#define INF 9999999

typedef struct{
  int x,y,z;
}dis;
 
int n,m[N];
dis d[500000];

void fanc1(int);

int main(){

  int i,j,a,b,ed=0,w=INF;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){

    scanf("%d%d",&a,&b);

    for(j=0;j<b;j++){
	d[ed].x=a;
	scanf("%d%d",&d[ed].y,&d[ed].z);
	ed++;
      }
  }
  
  fanc1(ed);

  for(i=0;i<n;i++) printf("%d %d\n",i,m[i]);
  
  return 0;
}


void fanc1(int edges){

  int i,flag;

  for(i=0;i<n;i++){
   m[i]=INF;
  }
  m[0]=0;
    
  flag=1;
  while(flag!=0){
    flag=0;

    for(i=0;i<edges;i++){

      if(d[i].z+m[d[i].x]<m[d[i].y]){
	m[d[i].y]=d[i].z+m[d[i].x];
	flag=1;
      }

    }
  }
}
  



Measured memory_bytes: 2088
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	ll n,W;
	cin>>n>>W;
	vvll vv(4);
	ll a1,b1;
	cin>>a1>>b1;
	vv[0].PB(b1);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		vv[a-a1].PB(b);
	}
	rep(i,4) sort(ALL(vv[i])),reverse(ALL(vv[i]));
	rep(i,4) vv[i].insert(vv[i].begin(),0);
	vvll sum = vv;
	rep(i,4){
		rep(j,vv[i].size()){
			if(j==0) sum[i][0] = vv[i][0];
			else sum[i][j] = sum[i][j-1] + vv[i][j];
		}
	}
	ll ans = 0;
	rep(i,vv[1].size()){
		rep(j,vv[2].size()){
			rep(k, vv[3].size()){
				ll w = a1*(i+j+k)+i+2*j+3*k;
				if(w>W) continue;
				w = W-w;
				ll tmp = sum[0][min(w/a1,(ll)vv[0].size()-1)]+sum[1][i]+sum[2][j]+sum[3][k];
				// cout<<w/a1<<" "<<i<<" "<<j<<" "<<k<<" "<<w<<" "<<tmp<<endl;
				maxs(ans, tmp);
			}
		}
	}
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
	char S[200010],T[200010];
	int i=0,count=0;
	if(scanf("%s",S)){};
	if(scanf("%s",T)){};
 
	for(i=0;S[i] != '\0';i++){
		if(S[i] != T[i]){
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 2084
#include <bits/stdc++.h>
#define aio()                         \
    do {                              \
        std::ios::sync_with_stdio(0); \
        std::cin.tie(0);              \
    } while (0)
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
    aio();

    string n;
    cin >> n;

    ll tmp = 0;
    for (auto &i : n) {
        tmp += i - '0';
    }

    cout << (tmp % 9 == 0 ? "Yes" : "No");
}


Measured memory_bytes: 3780
import java.util.*;

class Main {
	Scanner sc;
	int H, N;
	int[] A, B;
	
	private void calc() {
		sc = new Scanner(System.in);
		H = sc.nextInt();
		N = sc.nextInt();
		A = new int[N];
		B = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
		}
		
		// [hp] : min mp
		int[] dp = new int[H+1];
		dp[0] = 0;
		for (int i = 1; i <= H; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j = 0; j < N; j++) {
				dp[i] = Math.min(dp[i], dp[Math.max(0, i-A[j])] + B[j]);
			}
		}
		
		System.out.println(dp[H]);
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}


Measured memory_bytes: 26236
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
using namespace std;
int main()
{
  ll n,k;
  string s;
  cin>>n>>k>>s;
  if(s[k-1]=='A')
  s[k-1]='a';
  else if(s[k-1]=='B')
  s[k-1]='b';
  else
  s[k-1]='c';
  cout<<s;	
	
	
	
	
	
 return 0;
}

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

int main() {
  long a,b,r,x,y;
  cin >> a>> b;
  x =a*b;

  if(a<b) {
    y =a;
    a =b;
    b =y;
  }

  r =a%b;
  while (r !=0){
    a =b;
    b =r;
    r =a%b;
  }

  cout << x/b<< endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC154D - Dice in Line  ... TLE

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();

        int[] p = new int[n];
        int[] p3 = new int[n];

        int max = 0;
        int idx = 0;

        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            if (i == k - 1) {
                for (int j = 0; j < k; j++) {
                    p3[i - k + 1] += p[i - j];
                }
                max = p3[i - k + 1];
                idx = i - k + 1;
            } else if (i > k - 1) {

//                System.out.println("------------------");
//                System.out.println("p3[" + (i - k + 1) + "]=" + p3[i - k + 1]);
//                System.out.println("max=" + max);
//                System.out.println("idx=" + idx);
                p3[i - k + 1] = p3[i - k] + p[i] - p[i - k];
                if (max < p3[i - k + 1]) {
                    max = p3[i - k + 1];
                    idx = i - k + 1;
//                    System.out.println("->max=" + max);
//                    System.out.println("->idx=" + idx);
                }
            }
        }

        double[] e = new double[k];
        double ans = 0;

        // 期待値
        for (int i = 0; i < k; i++) {
            for (int j = 1; j <= p[idx + i]; j++) {
                e[i] += j;
            }
            e[i] /= p[idx + i];
            ans += e[i];
        }

        System.out.println(ans);
    }
}


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

using namespace std;

typedef long long ll;

const int N = 2e5 + 5;
const ll mod = 1e9 + 7;

ll fact[N];
int n, m;

ll bigmod(ll p, ll q) {
  ll res = 1;
  while(q > 0) {
    if(q & 1) {
      res = (res * p) % mod;
    }
    q >>= 1;
    p = (p * p) % mod;
  }
  return res;
}

ll inverse(ll p) {
  return bigmod(p, mod - 2);
}

ll ncr(ll p, ll q) {
  if(p < q or p < 0 or q < 0) return 0;
  ll up = fact[p];
  ll down = ((fact[q] % mod) * (fact[p - q] % mod)) % mod;
  return ((up % mod) * inverse(down)) % mod;
}

int main() {
  fact[0] = fact[1] = 1;
  for(int i = 2; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  scanf("%d %d", &n, &m);
  vector <int> prime;
  for(int i = 2; i * i <= m; i++) {
    if(m % i == 0) {
      int cnt = 0;
      while(m % i == 0) {
        m /= i;
        cnt++;
      }
      prime.push_back(cnt);
    }
  }
  if(m > 1) {
    prime.push_back(1);
  }
  ll ans = 1ll;
  for(auto c : prime) {
    ans = (ans * ncr(n + c - 1, c)) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int m[20],n,q,A[20];
int ans(int x,int y){
  if(x==0)return 0;
  if(y>=n)return 1;
 
  if(ans(x,y+1)==0 || ans(x-A[y],y+1)==0)return 0;
  else return 1;
}
 
int main(){ 
  cin>>n; 
  for(int i=0;i<n;i++)cin>>A[i];
  cin>>q;
  for(int i=0;i<q;i++)
    cin>>m[i];
  for(int i=0;i<q;i++)
    if(ans(m[i],0)==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  
  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
long long int dp[10000][100];
long long int dp2[10000][100];
int mod=1000000007;
int main()
{
	string s;
	cin>>s;
	int d;
	cin>>d;
	
	int n=s.size();
	//cout<<n<<endl;
	long long int ans=0;
	long long int ans2=0;
     if(n==1)
     {
      for (int i = 0; i <=9; ++i)
    {
    	if(s[n-1]-'0'>=i)
    	{
    		dp2[n-1][i%d]++;
    	}
    }
    cout<<dp2[n-1][0]-1<<endl;
}
else
{

     
	for (int i = 0; i <=9; ++i)
    {
    	dp[n-1][i%d]++;
    	
    }

    ans+=(dp[n-1][0]-1);
    
    
    	
    
    
    

    

    for (int i =n-2; i>=1; --i)
    {
    	for (int j = 0; j <=9; ++j)
    	{

    		for (int k = 0; k < d; ++k)
    		{
    			if(dp[i+1][k]>0)
    			{
    				dp[i][(k+j)%d]=(dp[i][(k+j)%d] + dp[i+1][k])%mod;

    			}
    			
    			
    		}

    	}
    	
    }
   
    for (int i = n-1; i>=2; --i)
    {
    	ans2=(ans2+dp[i][0])%mod;
    }

    
    for (int i =n-2; i>=1; --i)
    {
    	//cout<<dp[i][0]<<endl;
    	ans+=(dp[i][0]);
    }
   
    ans=(ans-ans2);
    ans=(ans+mod)%mod;
   
    for (int i = 0; i <=9; ++i)
    {
    	if(s[n-1]-'0'>=i)
    	{
    		dp2[n-1][i%d]++;
    	}
    }
    
	for (int i =n-2; i >=0 ; --i)
	{
		for (int j = 0; j <=9; ++j)
		{
			if(s[i]-'0'<j)
				break;
			if(i==0 && j==0)
				continue;
			else if(s[i]-'0'>j)
			{
				
				for (int k = 0; k < d; ++k)
				{
					if(dp[i+1][k]>0)
					  dp2[i][(k+j)%d]=(dp2[i][(k+j)%d]+dp[i+1][k])%mod;
				}
			}
			else
			{
				for (int k = 0; k < d; ++k)
				{
				    if(dp2[i+1][k]>0)
				    	dp2[i][(k+j)%d]=(dp2[i+1][k] + dp2[i][(k+j)%d])%mod;
				}

			}
		}
		
	}


	
	ans=(ans+dp2[0][0])%mod;
	cout<<ans<<endl;
	
}
	
    

}

Measured memory_bytes: 19204
import math

a, b, h, m = map(int, input().split())
h=h*60+m

ang=abs(h*0.5-m*6)
if ang > 180:
  ang = 360-ang
if ang==180:
  print(a+b)
elif(ang==0):
  print(abs(b-a))
else:
  ans=(a**2)+(b**2)-(2*a*b*math.cos(math.radians(ang)))
  print(math.sqrt(ans))


Measured memory_bytes: 9516
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

int dp[1010][3010] = {};

signed main(void) {
    int n;
    while(cin >> n,n){
        vp v(n);
        rep(i,n)cin >> v[i].first >> v[i].second;
        sort(all(v));
        int sumr = 0, sumw = 0;
        rep(i,n){
            sumr += v[i].first;
            sumw += v[i].second;
        }
        int ma = v.back().first;
        if(ma <= sumr - ma){
            cout << sumr + sumw << endl;
        }else{
            rep(i,1010)rep(j,3010)dp[i][j] = 0;
            dp[0][0] = 1;
            int MAX = 2*ma-sumr+1;
            rep(i,n)rep(j,MAX){
                dp[i+1][j] += dp[i][j];
                if(j+v[i].second < MAX && i < n-1){
                    dp[i+1][j+v[i].second] += dp[i][j];
                }
            }
            int tmp = -1;
            rep(i,MAX)if(dp[n][i])tmp = max(tmp, i);
            cout << ma*2 + sumw - tmp << endl;
        }
    }
}



Measured memory_bytes: 26864
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n=0;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    long long count=0;
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            int key=0;
            while(arr[i]==arr[j])
                {
                    j++;
                    if(j>=n)
                    {
                        key=1;
                        break;
                    }
                }
                if(key==1)
                    break;
            for(int k=j+1;k<n;k++)
            {
               int keyq=0;
            while(arr[j]==arr[k])
                {
                    k++;
                    if(k>=n)
                    {
                        keyq=1;
                        break;
                    }
                }
                if(keyq==1)
                    break;
              if(arr[i]+arr[j]>arr[k])
              {
                  count++;
              }
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int N, K;
bool dp[200005];
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    cin >> N >> K;
    vector<int> A(N);
    REP(i, N) cin >> A.at(i);

    REP(i, K) {
        REP(j, N) {
            if (!dp[i + A[j]]) {
                dp[i + A[j]] = !dp[i];
            }
        }
    }
    if (dp[K]) {
        cout << "First" << endl;
    } else {
        cout << "Second" << endl;
    }

    return 0;
}


Measured memory_bytes: 384
n = int(input())
a = [int(i) for i in input().split()]
cnt = [0 for i in range(8)]
meta = 0
for i in range(n):
    if a[i] >= 3200:
        meta += 1
    else:
        cnt[a[i]//400] = 1
if sum(cnt) == 0:
    print(1, meta)
else:
    print(sum(cnt), sum(cnt)+meta)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 9999999999;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define f first
#define s second
#define pi 3.141592653589793238
using namespace std;
ll pre[2000];
int main()
{
	std::ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;

	for(int i =1;i<=n;i++)
	{
		ll w;
		cin >> w;
		pre[i] = pre[i-1]+w;
	}
	ll ans = 1e18;
	for(int i = 1;i<=n-1;i++)
	{	
		ll s = pre[i];
		ll s2 = pre[n]-pre[i];
		ans=min(ans,abs(s-s2));
	}

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



Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define pb push_back
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, x, y;
	cin >> n >> x >> y;
	vector<int> cnt(n);
	for (int i = 1; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			int dis = j - i;
			dis = min(dis, abs(x - i) + 1 + abs(y - j));
			cnt[dis]++;
		}
	}
	for (int i = 1; i < n; i++)
		cout << cnt[i] << "\n";
	return 0;
}

Measured memory_bytes: 256
//2018.09.15 15min

#include <iostream>
using namespace std;

int main() {

    int N;
    cin >> N;

    int i;
    int a[N];
    bool alleven = true;
    int ans=0;

    for(i=0;i<N;i++){
        cin >> a[i];
        if(a[i]%2!=0) alleven=false;
    }

    while(alleven){
        ans++;
        for(i=0;i<N;i++){
            a[i]= a[i]/2;
            if(a[i]%2!=0) alleven=false;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	"""
	DP: 動的計画法を用いる
	"""
	a, b, c, d = list(input())
	sign = "+-"
	for i in range(2): #1つ目の記号
		for j in range(2): #2つ目の記号
			for k in range(2): #3つ目の記号
				if eval(a + sign[i] + b + sign[j] + c + sign[k] + d) == 7:
					print(str(a + sign[i] + b + sign[j] + c + sign[k] + d) +"=7")
					exit()

if __name__ == '__main__':
	main()

Measured memory_bytes: 12508
using System;
using System.Linq;

class Program
{
	static void Main()
	{
		var s = Console.ReadLine().ToCharArray();

		var answer = true;
		if (s.Contains('N') && !s.Contains('S')) {
			answer = false;
		}
		if (s.Contains('S') && !s.Contains('N')) {
			answer = false;
		}
		if (s.Contains('W') && !s.Contains('E')) {
			answer = false;
		}
		if (s.Contains('E') && !s.Contains('W')) {
			answer = false;
		}


		Console.WriteLine(answer ? "Yes" : "No");
	}
}


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

int main() {
	int a, b;
	scanf("%d %d" , &a, &b);//////////////////////
	if (a == b) {
		printf("a == b\n");
	}
	else{
		if (a > b) {
			printf("a > b\n");
		}
		else {
			printf("a < b\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2604
#include <stdio.h>

int main(void) {
	unsigned long a,b;
	int cnt;
	while(scanf("%ld %ld",&a,&b)!=EOF) {
		cnt=1;
		a+=b;
		while(a>=10) {
			a/=10;
			cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 600