akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  for(int i=0;i<N;i++)  cin >> p.at(i);

  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<N;i++)  ans+=p.at(i);
  ans-=p.at(N-1)/2;
  cout << ans << endl;

  return 0;
}


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

int main() {
  string S, T;
  cin >> S >> T;
  
  int s, t;
  cin >> s >> t;
  
  string U;
  cin >> U;
  
  if(U == S){
    s = s -1;
  } else {
    t = t - 1;
  }
  
  cout << s  << " " << t;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

typedef struct _PT {
	double x;
	double y;
} PT;

void printp(PT p) {
	cout << fixed << setprecision(5) << p.x << " " << p.y << endl;
}

void kock(int n, PT p1, PT p2) {
	if (n == 0)
		return;

	// p1, p2 から s, t, u を計算
	PT u, v, p, q, r;
	u.x = p2.x - p1.x; u.y = p2.y - p1.y;
	v.x = p1.y - p2.y; v.y = p2.x - p1.x;
	p.x = p1.x + u.x / 3; p.y = p1.y + u.y / 3;
	q.x = p1.x + u.x / 2 + sqrt(3) * v.x / 6;
	q.y = p1.y + u.y / 2 + sqrt(3) * v.y / 6;
	r.x = p1.x + u.x * 2 / 3; r.y = p1.y + u.y * 2 / 3;

	kock(n-1, p1, p);
	printp(p);
	kock(n-1, p, q);
	printp(q);
	kock(n-1, q, r);
	printp(r);
	kock(n-1, r, p2);
}

int main() {
	int n;
	PT p1, p2;
	p1.x = 0.0; p1.y = 0.0;
	p2.x = 100.0; p2.y = 0.0;
	cin >> n;
	printp(p1);
	kock(n, p1, p2);
	printp(p2);

	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

    int N = 0;
    int J = 0;
    int max = 0;
    cin >> N;

    std::vector<int> NN(N,0);

    for(int i = 0; i < N; i++){
        cin >> J;
        NN[i] = J;
    }

    std::sort(NN.begin(), NN.end());

    int total = 0;

    for(int i = 0; i < N - 1; i++){
        total += NN[i];
    }

    if(total > NN[N - 1]){
        cout << "Yes";
    }else{
        cout << "No";
    }

}

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

int main(){
  int n, i, j, point;

  char name[100];
  cin >> n;

  pair<pair<string, int>, int> p[110];
  for(i=0; i<n; i++) {
    cin >> name >> point;
    p[i] = make_pair(make_pair(name, -point), i);
  }

  sort(p, p+n);
  for(i=0; i<n; i++) cout << p[i].second+1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    char s[100];
    int k;
    cin >> k >> s;
    if(strlen(s) <= k) cout << s << endl;
    else{
        for(int i=0;i<k;i++){
            cout << s[i];
        }
        cout << "..." << endl;
    }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007

int main(){
    int n;
    cin >> n;
    vector<ll>a,b,c;
    rep(i,n){
        ll temp;
        cin >> temp;
        a.push_back(temp);
    }
    rep(i,n){
        ll temp;
        cin >> temp;
        b.push_back(temp);
    }
    rep(i,n){
        ll temp;
        cin >> temp;
        c.push_back(temp);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll ans = 0;
    ll indexa = 0;
    ll indexc = 0;
    //int a_b[n];
    rep(i,n){
        ll mid = b[i];
        auto itera = lower_bound(a.begin(),a.end(),mid);
        indexa = itera - a.begin();
        ll counta = indexa;
        auto iterc = lower_bound(c.begin(),c.end(),mid+1);
        ll countc = c.end() - iterc;
        ans += counta * countc;
    }
    cout << ans << endl;
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    int N,W; cin >> N >> W;
    int w[N], v[N];
    rep(i,0,N){
        cin >> w[i] >> v[i];
    }

    ll dp[N+1][100100];
    rep(i,0,100100){
        rep(j,0,N+1){
            if(i == 0) dp[j][i] = 0;
            else dp[j][i] = MOD;
        }
    }
    rep(i,0,N){
        rep(j,0,100001){
            if(j -v[i] >= 0 && dp[i][j-v[i]] + w[i] <= W)
                dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]] + w[i]);
            else
                dp[i+1][j] = dp[i][j];
            //cout << dp[i+1][j] << " ";
        }
        //cout << "\n";
    }
    ll ans = 0;
    rep(i,0,100001){
        if(dp[N][i] != MOD) ans = i;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 82596
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(int argc, char* argv[])
{
double r;
cin >> r;
cout << setprecision(6) << setiosflags(ios::showpoint) << setiosflags(ios::fixed) << M_PI*pow(r,2) << " " << setprecision(6) << setiosflags(ios::showpoint) << setiosflags(ios::fixed) << M_PI*2*r << endl;
return 0;
}


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

using namespace std;

#define MXN 200005

int p[MXN], q[MXN], r[MXN], s[MXN], pa[MXN];
int d[MXN];
map<pair<int, int>, int> m;

void init(int n) {
    for (int i = 1; i <= n; ++i) pa[i] = i;
}

int find(int a) {
    if (pa[a] != a) pa[a] = find(pa[a]);
    return pa[a];
}

void un(int a, int b) {
    int c = find(a), d = find(b);
    if (c != d) pa[c] = d;
}

int main() { 
    int n, k, l;
    while (cin >> n >> k >> l) {
        init(n);
        for (int i = 0; i < k; ++i) {
            cin >> p[i] >> q[i];
            un(p[i], q[i]);
        }
        for (int i = 1; i <= n; ++i) find(i);
        memcpy(d, pa, sizeof(d));
        init(n);
        for (int i = 0; i < l; ++i) {
            cin >> r[i] >> s[i];
            un(r[i], s[i]);
        }
        for (int i = 1; i <= n; ++i) find(i);
        for (int i = 1; i <= n; ++i) {
            m[make_pair(d[i], pa[i])]++;
        }
        /*
        for (int i = 1; i <= n; ++i) cout << d[i] << " ";
        cout << "\n";
        for (int i = 1; i <= n; ++i) cout << pa[i] << " ";
        cout << "\n";
        */
        for (int i = 1; i <= n; ++i) 
            cout << m[make_pair(d[i], pa[i])] << " ";
        cout << "\n";
        m.clear();
    }

    return 0;
}


Measured memory_bytes: 16256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A[3];
    rep(i, 3) cin >> A[i];
    sort(A, A + 3);
    if (A[0] == 5 && A[1] == 5 && A[2] == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


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

using ll = long long;
using namespace std;

const int N = 1e5 + 1;
array<int, 3> a, dp;

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

#ifdef LOCAL_DEFINE
	freopen("in.txt", "r", stdin);
#endif

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		for (auto &x : a)
			cin >> x;
		array<int, 3> dp2;
		dp2.fill(-1e9);
		for (int i = 0; i < 3; ++i)
		{
			for (int j = 0; j < 3; ++j)
			{
				if (i != j)
					dp2[i] = max(dp2[i], dp[j] + a[j]);
			}
		}
		dp = dp2;
	}

	cout << max(max(dp[0], dp[1]), dp[2]) << '\n';

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct edge{
  int to, cost;
};
typedef pair<int, int> pii;//cost vertex
typedef pair<int ,pii> piii;//cost vertex state
int main(int argc, char *argv[]){
  int n, m;
  while(cin >> n >> m, n){
    string s, p, goal;
    map<string, int> msi;
    cin >> s >> p >> goal;
    msi[s] = msi.size() - 1;
    msi[p] = msi.size() - 1;
    msi[goal] = msi.size() - 1;
    int S = msi[s], P = msi[p], GOAL = msi[goal];
    vector<vector<edge> > g(n, vector<edge>());
    vector<vector<int> > dp(2, vector<int>(n, 1e9));
    for (int i = 0; i < m; i++) {
      int d, t, from, to;
      string a, b;
      cin >> a >> b >> d >> t;
      if(msi.find(a) == msi.end())
        msi[a] = msi.size() - 1;
      if(msi.find(b) == msi.end())
        msi[b] = msi.size() - 1;
      to = msi[a];
      from = msi[b];
      //std::cout << "to:" << to << " from:" << from << std::endl;
      g[to].push_back(edge{from, d/40 + t});
      g[from].push_back(edge{to, d/40 + t});
    }
    priority_queue<piii, vector<piii>, greater<piii> > que;
    que.push(piii(0, pii(S, 0)));
    dp[0][S] = 0;
    while(!que.empty()){
      int v = que.top().second.first;
      int c = que.top().first;
      int state = que.top().second.second;
      que.pop();
      for (int i = 0; i < g[v].size(); i++) {
        int st = state;
        edge e = g[v][i];
        if(dp[state][e.to] > c + e.cost){
          if(e.to == P)st = 1;
          dp[state][e.to] = c + e.cost;
          que.push(piii(c + e.cost, pii(e.to, st)));
        }
      }
    }
    std::cout << dp[1][GOAL] << std::endl;
  }
  return 0;
}

 

Measured memory_bytes: 1504
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll unsigned long long int
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e18;
int main()
{
IOS
ll n;
cin>>n;
vector<ll> v(n);
ll zero=0;
for(ll i=0;i<n;i++)
{
    cin>>v[i];
    if(v[i]==0)
        zero++;
}
if(zero>0)
{
    cout<<0;
    return 0;
}
ll prod=1;
for(ll i=0;i<n;i++)
{
    if(v[i]<=1000000000000000000/prod)
        prod*=v[i];
    else
    {
        cout<<"-1";
        return 0;
    }
}
cout<<prod;
return 0;
}


Measured memory_bytes: 3888
sx, sy, tx, ty = map(int, input().split())
lr, ud = abs(tx - sx), abs(sy - ty)
print('R' * lr + 'U' * ud + 'L' * lr + 'D' * ud, end='')
print('L' + 'U' * (ud+1) + 'R' * (lr+1) + 'D' + 'R' + 'D' * (ud+1) + 'L' * (lr+1) + 'U')


Measured memory_bytes: 38256
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	string s;
	cin>>s;
	int n = s.size()-1;
	if(s[n]=='s'){
		cout<<s<<"es"<<endl;
	}else{
		cout<<s<<"s"<<endl;
	}
	
	return 0;
}


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

typedef long long int ll;
constexpr int kN = int(5E3 + 10), LOGN = 31;
constexpr ll kInf = ll(3E18 + 10);

int p[LOGN][kN];
ll c[kN], val[LOGN][kN], ans[kN];

int main() {
	int n, k, npos, lim;
	ll a = -kInf, tmp;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%d", &p[0][i]);
	for (int i = 1; i <= n; i++) scanf("%lld", &c[i]);
	for (int i = 1; i <= n; i++) val[0][i] = c[p[0][i]];
	for (int i = 1; i < LOGN; i++) for (int j = 1; j <= n; j++) {
		p[i][j] = p[i - 1][p[i - 1][j]];
		val[i][j] = val[i - 1][j] + val[i - 1][p[i - 1][j]];
	}

	for (int i = 1; i <= n; i++) {
		npos = i;
		for (int j = LOGN - 1; j >= 0; j--) if (k & (1 << j)) {
			ans[i] += val[j][npos]; 
			npos = p[j][npos];
		}
	}

	lim = min(n, k);
	for (int kk = 1; kk <= lim; kk++) {
		for (int i = 1; i <= n; i++) {
			npos = i;
			tmp = 0;
			for (int j = LOGN - 1; j >= 0; j--) if (kk & (1 << j)) {
				tmp += val[j][npos]; 
				npos = p[j][npos];
			}
			ans[i] = max(ans[i], tmp);
		}
	}
	lim = max(1, k - n);
	for (int kk = lim; kk <= k; kk++) {
		for (int i = 1; i <= n; i++) {
			npos = i;
			tmp = 0;
			for (int j = LOGN - 1; j >= 0; j--) if (kk & (1 << j)) {
				tmp += val[j][npos]; 
				npos = p[j][npos];
			}
			ans[i] = max(ans[i], tmp);
		}
	}

	for (int i = 1; i <= n; i++) a = max(a, ans[i]);
	printf("%lld\n", a);
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

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

int main(){
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


Measured memory_bytes: 3748
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int abs(int a,int b){
	return (a>b)?a:b;
}
int main(){
	fast_io
	vector<char> c(3);
	for(char& i:c) cin>>i;
	sort(c);
	if(c[0]=='a' and c[1]=='b' and c[2]=='c') cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string t;
    cin >> t;
    int n = t.size();
    for (int i = 0; i < n; ++i) {
        if (t[i] == '?')
            t[i] = 'D';
    }
    cout << t << "\n";
    return 0;
}

Measured memory_bytes: 3748
#include <stdio.h>
#include <string>
#include <map>

using namespace std;

int main(){
	while(1){
		int n;
		scanf("%d", &n);
		if(n==0) break;
		
		map<string,int> data;
		
		int i;
		char s[100];
		int v;

		for(i=0;i<n;i++){
			scanf(" %s %d", s, &v);
			data.insert(pair<string,int>(string(s),v));
		}
		
		scanf("%d", &n);
		for(i=0;i<n;i++){
			int w;
			scanf(" %s %d", s, &w);
			int v = data[string(s)];
			int nv=0;
			for(int j=0;j<w;j++){
				char ns[100];
				scanf(" %s", ns);
				nv += data[string(ns)];
			}
			if(nv < v) data[string(s)]=nv;
		}
		scanf(" %s", s);
		printf("%d\n", data[string(s)]);
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<stdint.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MAX 20
using namespace std;

int n;
uint64_t d[MAX],v[MAX];

int main()
{
 
  while(cin >> n,n)
    {
      uint64_t LCM,GCD;
      rep(i,n)
	{
	  cin >> d[i] >> v[i];
	  uint64_t div = __gcd(d[i],v[i]);
	  d[i] /= div, v[i] /= div;
	  GCD = (i==0?v[i]:__gcd(GCD,v[i]));
	  LCM = (i==0?d[i]:d[i]/__gcd(d[i],LCM)*LCM);
	}

      rep(i,n)cout << (uint64_t)((LCM/d[i])*(v[i]/GCD)) << endl;

    }
  return 0;
}

Measured memory_bytes: 1164
import itertools as it

def next_sosu(x):
  if x%2==0:
    if x==2:
      return x
    else:
      x+=1
  l=[i for i in range(3,x,2)]
  for i in it.count(x,2):
    if len(list(filter(lambda a:i%a==0,l)))==0:
      return i
print(next_sosu(int(input())))

Measured memory_bytes: 5144
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <cstring>

using namespace std;

int main() {
	unsigned long long n, k;
	cin >> n >> k;
	vector<int> a(n+1);
	vector<int> b;
	set<int> s;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int i = 1;
	b.push_back(1);
	while (s.find(a[i]) == s.end()) {
		b.push_back(a[i]);
		s.insert(a[i]);
		i = a[i];
	}
	unsigned int d = distance(b.begin(), find(b.begin(), b.end(), a[i]));
	if (k < d) cout << b[k] << endl;
	else {
		k -= d;
		k = k % (b.size() - d);
		cout << b[d + k] << endl;
	}
	return 0;
}


Measured memory_bytes: 13916
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    vector<int> m(n + 1);
    
    for (int i = 2; i <= n; i++) {
        int x = i;
        for (int j = 2; j * j <= i; j++) {
            while (x % j == 0) {
                m[j]++;
                
                x /= j;
            }
        }
        
        if (x != 1) {
            m[x]++;
        }
    }
    
    long long ans = 0;
    
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int k = j + 1; k <= n; k++) {
                if (i != j && i != k && j != k && m[i] >=2 && m[j] >= 4 && m[k] >= 4) {
                    ans++;
                }
            }
        }
    }
    
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if (i != j) {
                if (m[i] >= 2 && m[j] >= 24) {
                    ans++;
                }
                
                if (m[i] >= 4 && m[j] >= 14) {
                    ans++;
                }
            }
        }
    }
    
    for (int i = 0; i <= n; i++) {
        if (m[i] >= 74) {
            ans++;
        }
    }
    
    cout << ans << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int w, h;
    while (cin >> h >> w, h)
    {
        int max_area = 0;
        int m[h][w];

        rep(i, h)
        {
            rep(j, w)
            {
                char c;
                cin >> c;
                m[i][j] = (c == '.' ? 1 : 0);
            }
        }
        int a[w + 1] = {};
        a[w] = -1;
        rep(i, h)
        {
            rep(j, w) a[j] = (m[i][j] == 1 ? a[j] + 1 : 0);
            stack<int> st;
            rep(j, w + 1)
            {
                while (!st.empty() && a[st.top()] > a[j])
                {
                    int t = st.top();
                    st.pop();
                    max_area = max(max_area, a[t] * (st.empty() ? j : j - st.top() - 1));
                }
                st.push(j);
            }
        }
        OP(max_area);
    }
    return 0;
}


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

using i64 = int64_t;

constexpr i64 MOD = 1e9 + 7;

int main(){
    i64 n, m;
    cin >> n >> m;
    vector<i64> a, b;
    vector<i64> v(n*m+1), cum_a(n*m+1), cum_b(n*m+1);
    bool ok = true;
    for(int i=0;i<n;++i){
        i64 tmp;
        cin >> tmp;
        if(v[tmp]&1)ok = false;
        v[tmp] |= 1;
        a.push_back(tmp);
        cum_a[tmp]++;
    }
    for(int i=0;i<m;++i){
        i64 tmp;
        cin >> tmp;
        if(v[tmp]&2)ok = false;
        v[tmp] |= 2;
        b.push_back(tmp);
        cum_b[tmp]++;
    }
    
    if(!ok){
        cout << 0 << endl;
        return 0;
    }

    for(i64 i=n*m-1;i>0;--i){
        cum_a[i] += cum_a[i+1];
        cum_b[i] += cum_b[i+1];
    }

    i64 ans = 1;
    for(i64 i=n*m;i>0;--i){
        if(v[i] == 2){
            ans *= cum_a[i];
            ans %= MOD;
        }else if(v[i] == 1){
            ans *= cum_b[i];
            ans %= MOD;
        }else if(v[i] == 0){
            ans *= (cum_a[i] * cum_b[i] - (n*m-i)) % MOD;
            ans %= MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 23680
import java.util.*;

public class Main {
	public static void main(String[] args) {

		String s = "2017/01/";
		Scanner scanner = new Scanner(System.in);
		s= scanner.next();
		String st = "2018/01/";
		System.out.println(st+s.substring(8));
		scanner.close();
	}

}


Measured memory_bytes: 23124
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    // 出力
    if ((a + b) > (c + d))
    {
        cout << "Left";
    }
    else if ((a + b) < (c + d))
    {
        cout << "Right";
    }
    else
    {
        cout << "Balanced";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <map>

using namespace std;

int main()
{
  int n, count = 0;
  string input;
  map<char, string> map;

  map['1'] = ".,!? ";
  map['2'] = "abc";
  map['3'] = "def";
  map['4'] = "ghi";
  map['5'] = "jkl";
  map['6'] = "mno";
  map['7'] = "pqrs";
  map['8'] = "tuv";
  map['9'] = "wxyz";

  cin >> n;
  int j = 0, i;
  for(i = 0 ; i < n ; i++){
    cin >> input;
    for(j = 0 ; input[j] == '0' && j < (int)input.length() ; j++);

    for( ; j <  (int)input.length() ; j++){
      if(input[j] == '0'){
	if(input[j-1] == '0')continue;
	string hoge = map[input[j-1]];
	cout << hoge[(count-1)%(hoge.length())];
	count = 0;
      }else{
	count++;
      }
    }
    cout << '\n';
      } 
  
}

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

int main()
{ 
  string a,b,c ;
  cin >> a >> b >> c ;
 int l1 = a.size();
 int l2 = b.size() ;
 int l3 = c.size() ;
 if(a[l1-1] == b[0] && b[l2-1] == c[0]) cout << "YES\n" ;
else cout << "NO\n";
return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    long long N;
    cin >> N;
    for(long long h=1; h<=3500; h++){
        for(long long n=1; n<=3500; n++){
            if(4*h*n-(h+n)*N<=0)continue;
            if(N*h*n%(4*h*n-(h+n)*N)==0){
                cout << h << ' ' << n << ' ' << N*h*n/(4*h*n-(h+n)*N) << endl;
                return 0;
            }
        }
    }
}

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

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

Measured memory_bytes: 256
H, N = map(int, input().split())
dp = [ 1001001001 for _ in range(H+1)]
dp[0] = 0
for i in range(N):
  A, B = map(int, input().split())
  for j in range(H):
    nj = min(j+A, H)
    dp[nj] = min(dp[nj], dp[j] + B)

print(dp[H])


Measured memory_bytes: 43868
// topological sort (breadth first search)

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <utility>

const int N = 10010;
const int M = 100010;

struct Edge {
	int to, next;
} es[M];

int SIZE = 0; // number of edges
int h[N]; // pointer to edge list
int in[N], queue[N]; // in-degree, queue for BFS

inline void add(int u, int v) {
	int i = ++SIZE;
	es[i].to = v;
	es[i].next = h[u];
	h[u] = i; 
}

void run() {
	int n, m, x, y;
	scanf("%d%d", &n, &m);
	memset(h, 0, sizeof(h));
	memset(in, 0, sizeof(in));
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &x, &y);
		add(x, y);
		in[y] += 1;
	}
	int front = 0, back = 0;
	for (int i = 0; i < n; i++)
		if (in[i] == 0)
			queue[back++] = i;
	while (front < back) {
		int x = queue[front++];
		for (int i = h[x]; i != 0; i = es[i].next) {
			int y = es[i].to;
			in[y] -= 1;
			if (in[y] == 0)
				queue[back++] = y;
		}
	}
	for (int i = 0; i < n; i++)
		printf("%d\n", queue[i]);
}

int main() {
	run();
}

Measured memory_bytes: 3108
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC135D
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Cin.String();
            var solver = new Solver(s);

            Console.WriteLine(solver.Solve());
        }
    }

    class Solver
    {
        private string S;
        private long MOD = 1000000007;

        public Solver(string s)
        {
            S = s;
        }

        public IConvertible Solve()
        {
            Dictionary<int, long>[] dp = new Dictionary<int, long>[S.Length + 1];
            for (int i = 0; i <= S.Length; i++)
            {
                dp[i] = new Dictionary<int, long>();
                for (int j = 0; j < 13; j++)
                {
                    dp[i].Add(j, 0);
                }
            }

            dp[0][0] = 1;

            int m = 1;
            for (int i = 0; i < S.Length; i++)
            {
                var c = S[S.Length - 1 - i];
                if (c == '?')
                {
                    for (int j = 0; j < 10; j++)
                    {
                        for (int k = 0; k < 13; k++)
                        {
                            var key = (k + m * j % 13) % 13;
                            dp[i + 1][key] = (dp[i + 1][key] + dp[i][k]) % MOD;
                        }
                    }
                }
                else
                {
                    for (int k = 0; k < 13; k++)
                    {
                        var key = (k + m * int.Parse(c.ToString())) % 13;
                        dp[i + 1][key] += dp[i][k];
                    }
                }

                m = m * 10 % 13;
            }

            return dp[S.Length][5];
        }
    }

    internal static class Cin
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(String());
        }

        public static int[] IArr()
        {
            return Split().Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(String());
        }

        public static long[] LArr()
        {
            return Split().Select(long.Parse).ToArray();
        }

        public static double Double()
        {
            return double.Parse(String());
        }

        public static double[] DArr()
        {
            return Split().Select(double.Parse).ToArray();
        }

        private static IEnumerable<String> Split()
        {
            return String().Split(' ');
        }
    }
}

Measured memory_bytes: 93120
N = int(input())

BA = 0
A = 0
B = 0
num = 0

for i in range(N):
	S = input()
	num += S.count('AB')

	if S[0] == 'B' and S[-1] == 'A':
		BA += 1
	elif S[0] == 'B':
		B += 1
	elif S[-1] == 'A':
		A += 1

ans = num

if A + B > 0:
	ans += min(A, B) + BA
else:
	ans += max(0, BA-1)

print(ans)

Measured memory_bytes: 3064
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::Ordering;
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

impl<T: Copy> Copy for Rev<T> {}

fn main() {
    input! {
        n: usize,
        k: usize
    }

    let mut s = 0.0;
    for i in 1..n + 1 {
        let mut p = 1.0;
        let mut t = i;
        while t < k {
            p = p * 0.5;
            t = t * 2;
        }
        s += p;
    }

    let ans = s / n as f64;
    println!("{:.12}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main() {
	string a, b;
	int l;
	cin >> a >> b;
	if (a.size() <= b.size()) l = b.size();
	else l = a.size();
	for (int i = 0;i < l;i++) {
		if(i<a.size())cout << a[i] ;
		if (i < b.size())cout << b[i];
	}
}

Measured memory_bytes: 256
#include <stdio.h>
int main () {
int W,H;
int x,y,r;
scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
W -= r,H -= r;
if( r <= x && x <= W && r <= y && y <= H)  printf("Yes\n");
else  printf("No\n");
return 0;
}


Measured memory_bytes: 2128
def main():
    N = int(input())
    S = list(input())

    CW = [0 for i in range(N + 1)]
    CE = [0 for i in range(N + 1)]

    count_w = count_e = 0

    for i in range(N):
        if S[i] == "W":
            count_w += 1
        CW[i + 1] = count_w

    S.reverse()
    
    for i in range(N):
        if S[i] == "E":
            count_e += 1
        CE[i + 1] = count_e

    ans = 10**6
    for i in range(N):
        change = CW[i] - CW[0] + CE[N - (i + 1)] - CE[0]

        if ans > change:
            ans = change

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 25640
n = gets.chomp.to_i
monster = gets.chomp.split(" ").map(&:to_i)
hero = gets.chomp.split(" ").map(&:to_i)

total = 0
n.times do |i|
    if monster[i] <= hero[i]
        total += monster[i]
        hero[i] -= monster[i]
        if monster[i + 1] <= hero[i]
            total += monster[i + 1]
            monster[i + 1] = 0
        else
            total += hero[i]
            monster[i + 1] -= hero[i]
        end
    else
        total += hero[i]
    end
end

puts total


Measured memory_bytes: 17556
INTEGER N,A
INTEGER(16),ALLOCATABLE,DIMENSION(:)::X
READ*,N
A=30
ALLOCATE(X(N))
READ*,X
DO I=1,N
  DO WHILE(MOD(X(I),2**A)/=0)
    A=A-1
  END DO
END DO
PRINT"(I0)",A
END

Measured memory_bytes: 256
#include<stdio.h>

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


Measured memory_bytes: 2020
N = int(input())


def dfs(s):  # 文字列 s で始まる七五三数の個数
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0  # s 自体が七五三数なら+1
    for c in '753':
        ret += dfs(s + c)
    return ret


print(dfs('0'))  # 本当はdfs('')と書きたいがint(s)でエラーを吐かないように仕方なく


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
#define deb(x) each(x.begin(),x.end(),(int& y){cout << y <<" ";})
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int N,K; cin>>N>>K;

  int ans=0;
  rep(i,N){
    int h; cin>>h;
    if(h>=K)++ans;
  }

  cout<< ans <<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

int main(){
    ll h, w;
    cin >> h >> w;
    if(h == 1 && w == 1){
        cout << 1 << endl;
    }else if(h == 1){
        cout << w - 2 << endl;
    }else if(w == 1){
        cout << h - 2 << endl;
    }else{
        cout << (h - 2) * (w - 2) << endl;
    }
}


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

int main(){
    int n,m,a,b,c;
    cin >> a >> b >> c;
    if(a==b){
        if(a==c){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else if(a==c){
        if(a==b){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else if(b==c){
        if(a==c){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
n,q=map(int,input().split())
data=[]
for i in range(n):
    data.append(list(input().split()))
    data[i][1]=int(data[i][1])

time=0
while(len(data)!=0):
    if(data[0][1] <=q):
        time+=data[0][1]
        print(f"{data[0][0]} {time}")
        data.pop(0)
    else:
        time+=q
        data[0][1]-=q
        data.append(data.pop(0))


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

const int N = 1e5 + 5;

int n, L, q;
int a[N], nxt[18][N];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	
	cin >> L;
	int ptr = 1;
	for (int i = 1; i <= n; ++i) {
		while (ptr <= n && a[ptr] - a[i] <= L) ptr++;
		nxt[0][i] = ptr - 1;
	}
	
	for (int i = 1; i <= 17; ++i) {
		for (int j = 1; j <= n; ++j) {
			nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
		}
	}
	
	cin >> q;
	while (q--) {
		int u, v; cin >> u >> v;
		if (u > v) swap(u, v);
		int res = 1;
		for (int i = 17; i >= 0; --i) {
			if (nxt[i][u] < v) res += (1 << i), u = nxt[i][u];
		}
		cout << res << '\n';
	}
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
 
string keitai[]{".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
int main(){
	int n;cin>>n;
    string s;
    rep(j,n){
		cin>>s;
        int cnt=0;
        string ans;
        rep(i,s.size()){
            if(s[i]=='0'){
                if(cnt)ans+=keitai[s[i-1]-'1'][(cnt-1)%keitai[s[i-1]-'1'].size()];
                cnt=0;
            }
            else cnt++;
        }
        if(ans!="")cout<<ans<<endl;
    }
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
int main(){
    int n,d,x,j=0;
    cin >> n >> d >> x;
    vector<int> vec(n);
    rep(i,n)cin >> vec.at(i);
    sort(vec.begin(),vec.end());
    while(vec.at(0)*j<=d){
        rep(i,n){
            if(vec.at(i)*j+1<=d)x++;
        }
        j++;
    }
    cout << x << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string str;
    cin>>str;
    bool flag=true;
    if(str[0]!='A') flag=false;
    bool judge2=false;
    for(char j='a';j<='z';j++){
        if(str[1]==j) judge2=true;
    }
    if(!judge2) flag=false;
    int cnt=0;
    for(int i=2;i<str.size()-1;i++){
        if(str[i]=='C'){
            cnt++;
            continue;
        }
        bool judge=false;
        for(char j='a';j<='z';j++){
            if(str[i]==j) judge=true;
        }
        if(!judge) flag=false;
    }
    if(cnt!=1) flag=false;
    bool judge3=false;
    for(char j='a';j<='z';j++){
        if(str[str.size()-1]==j) judge3=true;
    }
    if(!judge3) flag=false;
    if(flag) cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
    
    return 0;
}



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

int main(){
  string S, T;
  cin >> S;
  cin >> T;

  string ans = "No";

  for(int i = 0; i < S.length(); i++) {
   string tmp = S;

   if(S == T) ans = "Yes";

   S[0] = tmp[S.length()-1];

   for(int j = 1; j < S.length()-1; j++){
     S[j] = tmp[j-1];
   }
   S[S.length()-1] = tmp[S.length()-2];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    cin >> A;
    vector<lint> imos1(M * 2 + 2), imos2(M * 2 + 2);
    lint ret = 0;
    REP(i, N - 1) {
        if (A[i] < A[i + 1]) {
            imos2[A[i] + 2]++;
            imos2[A[i + 1] + 1]--;
            int w = A[i + 1] - A[i] - 1;
            imos1[A[i + 1] + 1] -= w;
            ret += w + 1;
        }
        if (A[i] > A[i + 1]) {
            imos2[A[i] + 2]++;
            imos2[A[i + 1] + M + 1]--;
            int w = A[i + 1] + M - A[i] - 1;
            imos1[A[i + 1] + M + 1] -= w;
            ret += w + 1;
        }
    }
    REP(i, M * 2 + 1) imos1[i + 1] += imos1[i];
    REP(_, 2) REP(i, M * 2 + 1) imos2[i + 1] += imos2[i];
    FOR(i, 1, M + 1) imos1[i] += imos1[M + i] + imos2[i] + imos2[M + i];
    cout << ret - *max_element(imos1.begin(), imos1.begin() + M + 1) << endl;
}


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

MOD = 10 ** 9 + 7
alpha_dict = {}
for alpha in 'abcdefghijklmnopqrstuvwxyz':
    alpha_dict[alpha] = 1
     

for s in S:
    alpha_dict[s] += 1
ans = alpha_dict['a'] % MOD
for alpha in 'bcdefghijklmnopqrstuvwxyz':
    ans = (ans * (alpha_dict[alpha] % MOD)) % MOD
    
if ans == 0:
    print(MOD - 1)
else:
    print(ans - 1)

Measured memory_bytes: 3188
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    Integer[] array = new Integer[N];
    
    int sumLength = 0;
    
    for(int i = 0; i < N; i++){
      array[i] = sc.nextInt();
    }
    
    Arrays.sort(array,Comparator.reverseOrder());
    
    for( int i =0; i < K ; i++) {
      sumLength += array[i];
    }
    
    System.out.println(sumLength);   
  }
}

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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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

int gcd(int a, int b){
  if (b>a) swap(a,b);
  if (b==0) return a;
  return gcd(b, a%b);
}

int solve(){
  int n,a;cin>>n>>a;
  int x[n];
  rep(i, n){
    cin>>x[i];
    x[i] -= a;
    x[i] = abs(x[i]);
  }

  int res = x[0];
  rep(i, 1, n){
    res = gcd(res, x[i]);
  }

  cout << res << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>

using ll = long long;
ll N, M;
std::vector<ll> A, B;

using union_find = std::vector<ll>;


ll find_root(union_find& uf, ll x) {
    if (uf[x] == -1 || uf[x] == x) {
        // root
        return x;
    }
    uf[x] = find_root(uf, uf[x]);
    return uf[x];
}


ll union_and_calculate_connected_pairs(union_find& uf, ll a, ll b, std::unordered_set<ll>& rootset, std::vector<ll>& group_size) {
    auto a_root = find_root(uf, a);
    auto b_root = find_root(uf, b);
    if (a_root != b_root) {
        auto tmp = group_size[a_root] * group_size[b_root];
        if (a_root > b_root) {
            uf[b_root] = a_root;
            rootset.erase(b_root);
            group_size[a_root] += group_size[b_root];
            group_size[b_root] = group_size[a_root];
        } else {
            uf[a_root] = b_root;
            rootset.erase(a_root);
            group_size[b_root] += group_size[a_root];
            group_size[a_root] = group_size[b_root];
        }
        return tmp;
    }
    return 0;
}


int main() {
    std::cin >> N >> M;
    for (ll i = 0; i < M; i++) {
        ll ai, bi;
        std::cin >> ai >> bi;
        A.push_back(ai - 1);
        B.push_back(bi - 1);
    }
    union_find uf;
    std::unordered_set<ll> rootset;
    std::vector<ll> group_size;
    for (ll i = 0; i < N; i++) {
        uf.push_back(i);
        rootset.insert(i);
        group_size.push_back(1);
    }
    std::vector<ll> results;
    ll n_pairs = N * (N - 1) / 2;
    results.push_back(n_pairs);
    for (ll i = M - 1; i >= 1; i--) {
        auto ai = A[i];
        auto bi = B[i];
        auto n_connected = union_and_calculate_connected_pairs(uf, ai, bi, rootset, group_size);
        n_pairs -= n_connected;
        results.push_back(n_pairs);
    }
    std::reverse(std::begin(results), std::end(results));
    for (auto i: results) {
        std::printf("%lld\n", i);
    }
    return 0;
}


Measured memory_bytes: 10476
X,N = map(int,input().split())
if N == 0:
	print(X)
	exit()

P = list(map(int,input().split()))

P.sort()
for i in range(N):
	if P[i] > X:
		print(X)
		break
	elif P[i] == X:
		#下に
		under = X
		underflag = False
		upper = X
		upperflag = False
		for j in range(i):
			if P[i - j - 1] != X - j - 1:
				under = X - j - 1
				underflag = True
				break
		if underflag == False:
			under = P[0] - 1

		for j in range(N - i - 1):
			if P[i + j + 1] != X + j + 1:
				upper = X + j + 1
				upperflag = True
				break
		if upperflag == False:
			upper = P[N - 1] + 1
		print(under if abs(X - under) <= abs(X - upper) else upper)
		break


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string S;
	cin >> S;

	S.erase(unique(all(S)), S.end());
	cout << (SZ(S) - 1) << endl;

	return 0;
}

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

long long cnt;

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size() / 2; i++)
  	if (s[i] != s[s.size() - i - 1])
  		cnt++;
  cout << cnt << '\n';
 	return 0; 
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	private static Scanner scan;

	public static void main(String[] args) {
	    scan = new Scanner(System.in);
	    while(true) {
		    int h=scan.nextInt();
		    int w=scan.nextInt();

		    if(h == 0 && w == 0) return ;

		    for(int j = 0 ; j < h ; j ++) {
		    	for(int  i = 0; i < w; i++) {
		    		System.out.print((i + j) % 2 == 0  ? "#" : ".");
		    	}
		    	System.out.println();
		    }
		    System.out.println();
	    }
	}
}



Measured memory_bytes: 34992