akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define REP(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define MSG(a) cout << #a << " "  << a << endl;
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

const int INF = 1 << 30;
const int MAX_X = 1005;
ll dp[6][MAX_X][80];

int main()
{
	int n, m;
	while(scanf("%d %d", &n, &m) != EOF && n)
	{
		rep(x,MAX_X) rep(y,6) rep(d,m+1) dp[y][x][d] = INF;
		vector<vint> r(MAX_X, vint(n+10));
		vector<vint> xs(n);
		rep(i,MAX_X) rep(j,n) r[i][j]=0;

		rep(i,n)
		{
			int s;
			scanf("%d", &s);
			rep(j,s)
			{
				int x, d;
				//ifs >> x >> d;
				scanf("%d %d", &x, &d);
				r[x][i] = d;
				xs[i].push_back(x);
			}
		}

		rep(x,MAX_X)if(r[x][0]) dp[0][x][m] = 0;
		rep(x,MAX_X)if(r[x][1]) dp[1][x][m-1] = 0;

		for(int y = 1; y < n; y++)
		{
			if(1 < y) memcpy(dp[y%5], dp[5], sizeof(dp[y%5]));
			for(int x = 0; x < xs[y].size(); x++)
			{
				// ツ津環湘ュツジツδδδ督プ
				rep(nx, xs[y-1].size()) rep(d, m+1)
					//if(dp[(y-1)%5][xs[y-1][nx]][d] != INF)
						chmin(dp[y%5][xs[y][x]][d], dp[(y-1)%5][xs[y-1][nx]][d] + (r[xs[y][x]][y] + r[xs[y-1][nx]][y-1]) * abs(xs[y][x] - xs[y-1][nx]));

				// ツ暗ェツ段ツづづ篠つオ
				if(1 < y)
					rep(nx, xs[y-2].size()) REP(d, 1, m+1)
						//if(dp[(y-2)%5][xs[y-2][nx]][d] != INF)
							chmin(dp[y%5][xs[y][x]][d-1], dp[(y-2)%5][xs[y-2][nx]][d] + (r[xs[y][x]][y] + r[xs[y-2][nx]][y-2]) * abs(xs[y][x] - xs[y-2][nx]));
			}
		}

		ll res = INF;
		rep(x, xs[n-1].size()) rep(d, m+1) chmin(res, dp[(n-1)%5][xs[n-1][x]][d]);
		rep(x, xs[n-2].size()) REP(d, 1, m+1) chmin(res, dp[(n-2)%5][xs[n-2][x]][d]);
		cout << res << endl;
	}
}

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

int main() {
  string s;cin>>s;
  vector<int> an(26,0);
  for(auto c:s) {
    int ci = c - 'a';
    if (an[ci]!=0) {
      cout << "no";
      return 0;
    } 
    an[ci]++;
  }
  cout << "yes";
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long 
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;

class UnionFind
{
private:
    vector<ll> data;
    vector<ll> tree_size;

public:
    UnionFind(ll n)
    {
        data = vector<ll>(n);
        tree_size = vector<ll>(n, 1);
        for (ll i = 0; i < n; ++i)
        {
            data[i] = i;
        }
    }

    ll root(ll a)
    {
        if (data[a] == a) return a;
        else return data[a] = root(data[a]);
    }

    void unite(ll a, ll b)
    {
        ll root_a = root(a);
        ll root_b = root(b);
        if (root_a == root_b)
            return;
        else
        {
            tree_size[root_b] += tree_size[root_a];
            tree_size[root_a] = 0;
            data[root_a] = root_b;
            return;
        }
        return;
    }
    ll get_tree_size(ll a)
    {
        return tree_size[root(a)];
    }
};

int main()
{
	std::ios::sync_with_stdio(false);
	ll N, M;
    cin >> N >> M;
    vll A(M), B(M);
    UnionFind uf = UnionFind(N);
    for(size_t i=0;i<M; i++)
    {
        cin >> A[i] >> B[i];
        uf.unite(A[i]-1, B[i]-1);
    }
    ll max_size=0;
    for(size_t i=0;i<N; i++)
    {
        max_size = max(max_size, (uf.get_tree_size(i)));
    }
    cout << max_size << endl;
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    int num[n];
    for (int i = 0; i < n; ++i) {
        cin>>num[i];
    }
    sort(num,num+n);
    cout<<max(0,num[n/2]-num[n/2-1]);
    return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;

const int mod = 924844033;

void add_self(int & a, int b) {
	a += b;
	if(a >= mod) a -= mod;
}

const int nax = 2005;
int n;
int old[2][nax], nowy[2][nax];
int cnt[2];

void add(int type) {
	for(int waiting : {0, 1}) for(int pairs = 0; pairs <= n; ++pairs) {
		int me = old[waiting][pairs];
		if(me == 0) continue;
		add_self(nowy[1][pairs], me);
		int ways = cnt[type^1] - pairs - waiting;
		if(ways <= 0) continue;
		add_self(nowy[0][pairs+1], (ll) me * ways % mod);
	}
	++cnt[type];
	for(int waiting : {0, 1}) for(int pairs = 0; pairs <= n; ++pairs) {
		old[waiting][pairs] = nowy[waiting][pairs];
		nowy[waiting][pairs] = 0;
	}
}

void czysc() {
	for(int pairs = 0; pairs <= n; ++pairs) {
		add_self(old[0][pairs], old[1][pairs]);
		old[1][pairs] = 0;
	}
}

int main() {
	int k;
	cin >> n >> k;
	old[0][0] = 1;
	for(int side : {0, 1}) for(int startowy = 1; startowy <= k; ++startowy) {
		int i = side, j = startowy;
		while(j <= n) {
			add(i);
			i ^= 1;
			j += k;
		}
		czysc();
	}
	printf("%d\n", old[0][n]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;

vector<bool> seen;
vector<int> d;
vector<int> f;
#define pi 3.141592653589793


int main(int argc,char **argv){
  int n; cin>>n;
  string s,t; cin>>s>>t;

  int kyou=0;
  rep(i,0,n){
    if(s.substr(i,n)==t.substr(0,n-i)) {
      int nd=s.substr(i,n).size();
      cout<<nd+(n-nd)*2<<endl;
      return 0;
    }
  }

  cout<<2*n<<endl;
  }

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;


int main() {
    int n;
    scanf("%d", &n);
    int ans = 0;

    for (int i=1; i<=n; i++) {
        int k = i;
        int keta = 0;
        while(k > 0) {
            keta++;
            k = k / 10;
        }
        if (keta % 2 == 1) {
            ans++;
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> A = new ArrayList<Integer>();

        for (;;) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                for (int i=0; i<A.size(); i=i+2) {
                    for (int j=0; j<A.get(i); j++) {
                        for (int k=0; k<A.get(i+1); k++) {
                            System.out.print("#");
                        }
                        System.out.println();
                    }
                    System.out.println();
                }
                break;
            }
            else {
                A.add(H);
                A.add(W);
            }
        }

    }
}


Measured memory_bytes: 37772
#include <iostream>

using namespace std;
/** Problem0063 : Palindrome **/
int main()
{
	string s;
	int len, ans=0;
	
	while (cin >> s) {
		len = (int)s.length();
		for (int i=0; i<len/2; i++) {
			if (s[i] != s[len-i-1]) {
				goto end;
			}
		}
		ans++;
	end: ;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=2e5+5;
const ll INF=1e18+7;
ll a[maxn],b[maxn];
int main()
{
   int n,m,t;

   scanf("%d%d%d",&n,&m,&t);

   for (int q=0;q<n;q++)
       scanf("%lld",&a[q]);
   
   for (int q=0;q<m;q++) scanf("%lld",&b[q]);

    ll x,s;
    while (t--)
    {
        scanf("%lld",&x);
        
        int t1=lower_bound(a,a+n,x)-a;
        int t2=lower_bound(b,b+m,x)-b;

        s=INF;
        if (t1!=0)
        {
            if (t2!=0)
            {
                s=min(s,abs(x-b[t2-1])+abs(b[t2-1]-a[t1-1]));
                s=min(s,abs(x-a[t1-1])+abs(a[t1-1]-b[t2-1]));
            }
            if (t2!=m)
            {
                
                s=min(s,abs(x-b[t2])+abs(b[t2]-a[t1-1]));
                s=min(s,abs(x-a[t1-1])+abs(a[t1-1]-b[t2]));
            }
        }
        if (t1!=n)
        {
            if (t2!=0)
            {
                s=min(s,abs(x-b[t2-1])+abs(b[t2-1]-a[t1]));
                s=min(s,abs(x-a[t1])+abs(a[t1]-b[t2-1]));
            }
            if (t2!=m)
            {   
                s=min(s,abs(x-b[t2])+abs(b[t2]-a[t1]));
                s=min(s,abs(x-a[t1])+abs(a[t1]-b[t2]));
            }
        }

        printf("%lld\n",s);
    }

    return 0;
}

Measured memory_bytes: 2944
N = int(input())
N_List = str(input())
C_Ans = N_List[1:].count("E")
Ans = C_Ans
for i in range(1,N):
    C_Ans = C_Ans + (0,1)[N_List[i-1] == "W"] - (0,1)[N_List[i] == "E"]
    if C_Ans < Ans:
        Ans = C_Ans

print(Ans)

Measured memory_bytes: 9644
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    string key = "keyence";
    REP(i,7){
        string a = s.substr(0,7-i);
        string b = s.substr(s.length()-i,i);
        if(a+b==key){
            cout << "YES" << endl;
            return 0; 
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl weight(n), value(n);
    rep(i, n) {
        cin >> weight[i] >> value[i];
    }

    const ll MAX_SUMVALUE = 100010;
    
    vvl dp(n+1, vl(MAX_SUMVALUE, INF));  // dp[i+1][j] : i番目までの品物で価値の総和がjのときの重さの総和の最小値
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, MAX_SUMVALUE) {
            chmin(dp[i+1][j], dp[i][j]);
            if(j >= value[i]) {
                chmin(dp[i+1][j], dp[i][j - value[i]] + weight[i]);
            }
        }
    }

    ll ans = 0;
    rep(j, MAX_SUMVALUE) {
        if(dp[n][j] <= W) {
            ans = j;
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 80256
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int n,ans[101][101]={};
    scanf("%d",&n);
    int x[n],y[n],h[n];
    for (int i=0; i<n; i++){
        scanf("%d%d%d",&x[i],&y[i],&h[i]);
    }
    for (int k=0; k<n; k++){
        if (h[k]!=0){
            for (int i=0; i<101; i++){
                for (int j=0; j<101; j++){
                    ans[i][j]=h[k]+abs(i-x[k])+abs(j-y[k]);{
                    }
                }
            }
        break;
        }
    }
    for (int k=0; k<n; k++){
        if (h[k]!=0){
            for (int i=0; i<101; i++){
                for (int j=0; j<101; j++){
                    if (ans[i][j]!= h[k]+abs(i-x[k])+abs(j-y[k]) ){
                        ans[i][j]=-5;
                    }
                }
            }   
        }
    }
    for (int i=0; i<101; i++){
        for (int j=0; j<101; j++){
            if (ans[i][j]!=-5){
                for (int k=0; k<n; k++){
                    if (h[k]==0){
                        if(ans[i][j]-abs(x[k]-i)-abs(y[k]-j)>0){
                            ans[i][j]=-5;
                        }
                    }
                }
            }
        }
    }
    for (int i=0; i<101; i++){
        for (int j=0; j<101; j++){
            if (ans[i][j]!=-5){
                printf("%d %d %d\n",i,j,ans[i][j]);
            }
        }
    }
	return 0 ;
}

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

signed main(void)
{
	string s;
	map<char, int> mp;
	bool ok;
	cin >> s;
	ok = true;
	if (s[0] != 'A') ok = false;
	mp['C'] = 0;
	if ('a' > s[1] || s[1] > 'z') ok = false;
	for(int i = 2; i < s.size() - 1; i++) mp[s[i]]++;
	for(auto p : mp)
	{
		if (p.first == 'C')
		{
			if(p.second != 1)
				ok = false;
		}
		else
		{
			if ('a' > p.first || p.first > 'z')
				ok = false;
		}
	}
	if ('a' > s[s.size() - 1] || s[s.size() - 1] > 'z') ok = false;
	if (ok)
		cout << "AC" << endl;
	else
		cout << "WA" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i=0;
    int n;
    cin >> n;
    int ret=0;
    long long int sum=0;
    for(i=1;ret<n;i++,ret++){
        if(i%3==0||i%5==0)
            continue;
        else
            sum+=i;
    }
    cout << sum;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    if(n%2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    for(int i=0;i<n/2;i++){
        if(s[i] != s[i+n/2]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>

using namespace std;
#define mod 1000000007
#define ll long long 


int n, k;
int dp[100009];
int arr[100009];
int solve(int idx) {
	if(idx == n - 1)
		return 0;

	if(dp[idx] != -1)
		return dp[idx];

	int ans = INT_MAX;

	
	for(int i = 1; i <= k; i++) {
		if(idx + i >= n) break;
		ans = min(ans, abs(arr[idx + i] - arr[idx]) + solve(idx + i));
	}

	return dp[idx] = ans;
		
}


int main() {
	
	
	cin>>n>>k;
	memset(dp, -1, sizeof(dp));
	for(int i = 0; i < n; i++)
		cin>>arr[i];

	cout<<solve(0)<<endl;
}


Measured memory_bytes: 5760
#include<stdio.h>
int main()
{
    int N,i,j,cnt=0,cnt1=0;
    scanf("%d",&N);
    for(i=1;i<=N;i+=2)
    {
        for(j=1;j<=i;j++)
        {
            if(i%j==0)
            {
                cnt++;
            }

        }
        if(cnt==8)
            {
            cnt1++;
            }
            cnt=0;
    }
    printf("%d\n",cnt1);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL N, K, sum[300040], tmp[300050], b[300050], tree[300050], a[300050];
int cnt;
void insert(int x){
	for(;x <= cnt; x += -x & x){
		tree[x]++;
	}
}
LL ask(int x){
	LL ans = 0;
	for(;x > 0; x -= -x & x){
		ans += tree[x];
	}
	return ans;
}
int find(LL x){
	int l = 1, r = cnt;
	while(l <= r){
		int mid = (l + r) >> 1;
		
		if(b[mid] == x){
			return mid;
		}
		if(b[mid] > x)r = mid - 1;
		else l = mid + 1;
	}
	return -1;
}
int main(){
	cin>>N>>K;
	LL ans = 0;
	for(int i = 1;i <= N; i++){
		scanf("%lld", &a[i]);
		sum[i] = sum[i-1] + a[i] - K;
		if(sum[i] >= 0)ans++;
		tmp[i] = sum[i];
	}
	sort(tmp + 1, tmp + N + 1);
	b[++cnt] = tmp[1];
	for(int i = 2;i <= N; i++){
		if(tmp[i] == tmp[i-1])continue;
		b[++cnt] = tmp[i];
	}
	for(int i = 1;i <= N; i++){
//		printf("yuan=%d\n", sum[i]);
		sum[i] = find(sum[i]);
//		printf("sum[%d]=%lld\n", i, sum[i]);
	}
	for(int i = 1;i <= N; i++){
		ans += ask(sum[i]);
		insert(sum[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10752
const lines: string[] = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line: string) {
  lines.push(line);
});

reader.on("close", function () {
  const rule = lines.shift().split(" ").map(Number);
  const long = rule[0];
  const short = rule[1];
  const h = rule[2];
  const m = rule[3];

  let angle = 30 * h + m * 0.5 - 6 * m;
  if (angle >= 180) angle = 360 - angle;

  let res =
    Math.pow(long, 2) +
    Math.pow(short, 2) -
    2 * long * short * Math.cos(angle * (Math.PI / 180));

  res = Math.sqrt(res);
  console.log( res);
});


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

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 ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  int H,W,N;
  cin>>W>>H>>N;
  int xl=0,xr=W,yd=0,yu=H;
  for(int i = 0; i < N; i++){
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1) chmax(xl,x);
    if(a==2) chmin(xr,x);
    if(a==3) chmax(yd,y);
    if(a==4) chmin(yu,y);
  }
  cout<<max(xr-xl,0)*max(yu-yd,0)<<endl;
}
  
  

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

using int64 = long long;
using PII = pair<int64, int64>;  // X, H

int main() {
  int64 n, d, a;
  cin >> n >> d >> a;
  vector<PII> XH(n);
  for (auto& xh : XH)
    cin >> xh.first >> xh.second;
  sort(XH.begin(), XH.end());

  vector<PII> attacks;
  int64 ret = 0;
  int64 attack = 0;
  for (int64 i = 0, j = 0; i < n; ++i) {
    int64 x = XH[i].first;
    for (; j < attacks.size() && attacks[j].first < x; ++j)
      attack -= attacks[j].second;
    int64 k = max<int64>(0, (XH[i].second - attack + a - 1) / a);
    attack += k * a;
    attacks.emplace_back(XH[i].first + 2 * d, a * k);
    ret += k;
  }
  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 9200
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dirx[8]={1,0,-1,0,1,-1,-1,1};
int diry[8]={0,1,0,-1,1,1,-1,-1};

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b));
	return 0;
}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    int N,M;
    cin >> N >> M;
    vector<ll>X(M);
    for (int i = 0; i < M; i++) {
        cin >> X[i];
    }
    sort(all(X));
    vector<ll> sub(M-1);
    for (int i = 0; i < M-1; i++) {
        sub[i] = abs(X[i+1] - X[i]);
    }
    sort(all(sub));

    ll sum = 0;
    for (int i = 0; i < (int)sub.size() - N + 1; i++) {
        sum += sub[i];
    }
    cout << sum << endl;



    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define Rep(i,N) for(int i = 0;i < N;i++)
using namespace std;
int main(){
  int h,w,a,b=0,c=0;
  cin >> h >> w >> a;
  char m[h][w];
  Rep(i,h){
    Rep(j,w) cin >> m[i][j];
  }
  Rep(i,h){
    Rep(j,w){
      if(m[i][j] == '.' && i+a <= h){
	Rep(k,a){
	  if(m[i+k][j] != '.') break;
	  c++;
	}
	if(c == a) b++;
	c = 0;
      }
      if(m[i][j] == '.' && j+a <= w){
	Rep(k,a){
	  if(m[i][j+k] != '.') break;
	  c++;
	}
	if(c == a) b++;
	c = 0;
      }
    }
  }
  cout << b << endl;
  return(0);
}

Measured memory_bytes: 3036
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(void){
	int N;
	int tmp;
	vector<int> input;

	cin >> N;

	for(int i=0;i<N;i++){
		cin >> tmp;
		input.push_back(tmp);
	}

	sort(input.begin(),input.end());

	cout << input[N/2]-input[N/2-1] << endl;


	return 0;
}


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

int main(void){
    int n,m,l;
    cin >> n >> m >> l;
    int gyoretsu1[100][100] = {{}};
    int gyoretsu2[100][100] = {{}};
    long long int C[100][100] = {};
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> gyoretsu1[i][j];
        }
    }
    for (int i = 0; i < m; i++){
        for (int j = 0; j < l; j++){
            cin >> gyoretsu2[i][j];
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            for (int k = 0; k < l; k++){
                 C[i][k] += gyoretsu1[i][j] * gyoretsu2[j][k];
            }
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < l; j++){
            if (j == 0){
               cout << C[i][j];
            }
            else {
               cout << " " << C[i][j];
            }
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
 
//#define int long long
#define F first
#define S second

int main() {
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if (a * 500 >= b)
		cout << "Yes";
	else
		cout << "No";

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int K, X;

int main() {
	cin >> K >> X;
	for (int i = X - K + 1; i <= X + K - 1; ++i) {
		cout << i << sp;
	}
	cout << endl;
}

Measured memory_bytes: 256
module Main where

import Data.List
import Control.Monad

solve :: Int -> Int -> Int -> Int -> Int
solve h w h2 w2 = h * w - h2 * w - w2 * h + h2 * w2

main = do
    [h, w] <- fmap read . words <$> getLine
    [h2, w2] <- fmap read . words <$> getLine
    print $ solve h w h2 w2




Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
string s="";
string out(char c, int x){
    for(int i=0; i<x; i++){
        s += c;
    }
    return s;
}
int main(){
    int a, b;
    cin>>a>>b;
    if(a>b){
        cout<<out((char)b+48, a);
        return 0;
    }
    if(a <= b){
        cout<<out((char)a+48, b);
        return 0;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#define N 1000070

using namespace std;

inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}

struct Node{
	int l,r,num;
}q[N];
int n,m,a[N],block,ans,res[N],cnt[N];

bool cmp(Node a,Node b){
	return (a.l/block)^(b.l/block)?a.l<b.l:(((a.l/block)&1)?a.r<b.r:a.r>b.r);
}

void add(int x){
	cnt[x]++;
	if(cnt[x]==1) ans++;
}

void del(int x){
	cnt[x]--;
	if(cnt[x]==0) ans--;
}

int main(void){
	n=read();m=read();
	for(int i=1;i<=n;++i)
		a[i]=read();
	block=n/sqrt(m*2/3);
	for(int i=1;i<=m;++i){
		q[i].l=read();
		q[i].r=read();
		q[i].num=i; 
	}
	std::sort(q+1,q+m+1,cmp);
	int l=0,r=0;
	for(int i=1;i<=m;++i){
		while(l>q[i].l) add(a[--l]);
		while(l<q[i].l) del(a[l++]);
		while(r>q[i].r) del(a[r--]);
		while(r<q[i].r) add(a[++r]);
		res[q[i].num]=ans;
	}
	for(int i=1;i<=m;++i)
		printf("%d\n",res[i]);
}

Measured memory_bytes: 15336
#include <stdio.h>
int main(void){
    // Your code here!

    int H,W;
    
    while(1){
      scanf("%d %d",&H,&W);
      if( (H+W)==0 )break;
      for(int j=0; j<H; j++){
        for(int i=0; i<W; i++){
          printf("#");
        }  printf("\n");
      }  printf("\n");
    }
    
}



Measured memory_bytes: 1928
/**/
#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compile and get accepted.
 *      ____________
 *     /         __ \
 *    /   __    |  | \
 *   /   |__|   |  |  \
 *  (           |__|   )
 *   \                /
 *    \      ___     /
 *     \____________/
 *
 *
 */
const long long mod = 1000000007;

long long dp[301][301];
long long diff[301][301][301];

string grid[301];

long long W,H;
long long ind;

long long bt(long long a,long long b){
	if(min(a,b) == 0){
		return 0;
	}

	long long & ref = dp[a][b];
	if(ref != -1)
		return ref;
	ref = diff[ind][a][b] + min(bt(a-1,b),bt(a,b-1));
	return ref;
}

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

	
	cin>>H>>W;
//	H = W = 300;
	for(long long i = 0;i < H;i++){
		cin>>grid[i];
//		grid[i] = string(W,'a');
	}
	long long res = 0;
	for(ind = 0;ind+1 < W;ind++){
		for(int i = 1;i <= H;i++){
			for(int j = 1;j <= H;j++){
				diff[ind][i][j] = diff[ind][i-1][j-1] + (bool)(grid[i-1][ind] == grid[j-1][ind+1]);
			}
		}
		memset(dp,-1,sizeof dp);
		res += bt(H,H);
	}
	cout<<res<<'\n';
	return 0;
}
/**/


Measured memory_bytes: 212736
def l_in(type_): return list(map(type_, input().split()))
def i_in(): return int(input())
def m_in(type_): return map(type_, input().split())
def r_in(n, type_): return [type_(input()) for _ in range(n)]
const = 1000000007
ans = 0

n = i_in()
a = l_in(int)

ins = 0
for i in range(1, n):
    ins += a[i-1]
    ans += ins * a[i]

print(ans%const)


Measured memory_bytes: 105148
#include <iostream>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int e,y;
    cin>>e>>y;
    if(e==0){
        if(y<=1911){
            cout<<"M"<<y-1867<<"\n";
        }
        if(y>=1912 && y<=1925){
            cout<<"T"<<y-1911<<"\n";
        }
        if(y>=1926 && y<=1988){
            cout<<"S"<<y-1925<<"\n";
        }
        if(y>=1989){
            cout<<"H"<<y-1988<<"\n";
        }
    }
    if(e==1){
        cout<<y+1867<<"\n";
    }
    if(e==2){
        cout<<y+1911<<"\n";
    }
    if(e==3){
        cout<<y+1925<<"\n";
    }
    if(e==4){
        cout<<y+1988<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

ll n,k,sum;
ll a[1000000];

bool search(){
  ll m = k;
  rep(i,n){
    ll s = a[(i+1)%n]-a[i];
    while(s!=k){
      s+=n;
      m--;
      if(m<0) return true;
    }
  }
  if(m!=0){
    return true;
  }

  cout<<"YES"<<endl;

  return false;
}


int main(){
  cin>>n;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }

  k = sum/((n*(n+1))/2);

  if(sum%((n*(n+1))/2)||search()){
    cout<<"NO"<<endl;
  }

  return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
struct P{
    double x, y;
};
int main(){
    P p1, p2;
    double d;
    cin >> p1.x >> p1.y >> p2.x >> p2.y;
    d = sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
    printf("%.8f\n", d);
}



Measured memory_bytes: 3292
#include<stdio.h>
int main()
{
  int N, R;
  scanf("%d %d", &N, &R);
  if(N>=10)
    printf("%d", R);
  else
    //100*(10-N) = R ;
    //n = 10 - R/100
    printf("%d", R + 100*(10 - N));
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{
	int a, b, c;
	scanf("%d %d", &a, &b);
	c = a%b;
	if (c == 0)
		printf("%d\n", a / b);
	else
		printf("%d\n", a / b + c);
	return 0;
}

Measured memory_bytes: 596
alphabets = Array.new(26, 0)
while line = gets
  chars = line.chomp.downcase.chars
  chars.each do |c|
    i = c.ord - 97
    alphabets[i] += 1 if i >= 0 && i <= 25    
  end
end

alphabets.each_with_index do |n, i|
  puts "#{(i + 97).chr} : #{n}"
end



Measured memory_bytes: 6868
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int ans = gcd(a);

		System.out.println(ans);

	}

	static int gcd(int... array) {
		int gcd = 0;
		for (int i = 0; i < array.length; i++) {
			gcd = gcd(gcd, array[i]);
		}
		return gcd;
	}

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

}

Measured memory_bytes: 59560
a[1<<20];
n=1<<20;
main(i,c) {
	a[0]=a[1]=1;
	for(i=2;i<=n;i++)
		if(!a[i])
			for(c=2*i;c<=n;c+=i)
				a[c]=1;
	for(;scanf("%d",&n),n;){
		c=0;
		for(i=n+1;i<=2*n;i++)
			if(!a[i])
				c++;
		printf("%d\n",c);
	}
	exit(0);
}

Measured memory_bytes: 0
n = int(input())
inf = 10**9
dp = [inf for i in range(n+1)]
dp[0] = 0
for i in range(n):
    if dp[i] != inf:
        #1円引き出す場合
        dp[i+1] = min(dp[i] + 1, dp[i+1])
        num = 6
        while i + num <= n:
            dp[i + num] = min(dp[i] + 1, dp[i+num])
            num *= 6
        num = 9
        while i + num <= n:
            dp[i + num] = min(dp[i] + 1, dp[i+num])
            num *= 9

print(dp[n])


Measured memory_bytes: 45040
#include<cmath>
#include <stdio.h>
#include <cstdio>
#include<string.h>
using namespace std;
int main()
{
char s;
int a[26];
int i;
memset(a,0,sizeof(a));
while(scanf("%c",&s)!=EOF)
{
    i=s-'a';
    a[i]++;
}
int m=26;
for (int j=0;j<=25;j++)
{
    if (a[j]==0)
    {m=j;break;}
}

if (m!=26)
{s='a'+m;
printf("%c",s);}
else
printf("None");
return 0;
}



Measured memory_bytes: 128
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        int ans = 0;
        for (int i = 0; i < 2; i++) {
            if (a < b) {
                ans += b;
                b--;
            }
            else {
                ans += a;
                a--;
            }
        }
        System.out.println(ans);
        inp.close();
    }
}


Measured memory_bytes: 23892
use std::io::Read;
use std::str::SplitWhitespace;
use std::str::FromStr;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse<T> {
    fn parse(&mut self) -> T;
}

impl<'a, T> Parse<T> for SplitWhitespace<'a>
where
    T: FromStr,
{
    fn parse(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n: usize = iter.parse();
    let m: u64 = iter.parse();
    let mut v: Vec<(u64, u64)> = (0..n).map(|_| (iter.parse(), iter.parse())).collect();
    v.sort();

    let mut c = 0;
    let mut ans = 0;
    for (a, b) in v {
        let min = std::cmp::min(m - c, b);
        ans += a * min;
        c += min;
        if c == m {
            break;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 8444
// LHiC氏.
// https://atcoder.jp/contests/code-festival-2017-qualb/submissions/2148089
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int ans = 0, n;
int dp[1000000], pr[1000000];
char s[505050];

int main(){
    scanf("%d %s", &n, s);
    dp[0] = 0;
    int lst = -1;
    rep(i, n){
        pr[i] = lst;
        if(s[i] == '0'){
            lst = i;
            dp[i + 1] = dp[i];
        }else{
            dp[i + 1] = dp[i];
            if(lst == i - 1 && lst >= 0){
                int x = pr[lst];
                dp[i + 1] = max(dp[i + 1], dp[x + 1] + (lst - x - 1));
                if(lst - x - 2 >= 0) dp[i + 1] = max(dp[i + 1], dp[x + 2] + (lst - x - 2));
            }
            if(lst >= 1 && pr[lst] != lst - 1) dp[i + 1] = max(dp[i + 1], dp[lst - 1] + i - lst);
        }
    }
    printf("%d\n", dp[n]);
    return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b;
    cin >> a >> b;
    cout << a * b << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int N;
  long long K;
  cin>>N>>K;
  long long A[200000];
  for(int i=0;i<N;i++) cin>>A[i];
  sort(A,A+N);
  long long notan=0;
  long long answer=A[N-1];
  while(notan!=answer-1){
    long long med=(notan+answer)/2;
    int judge=0;
    for(int i=0;i<N;i++){
      if(A[i]>med){
        judge+=A[i]/med-1;
        if(A[i]%med!=0) judge++;
      }
    }
    if(judge>K) notan=med;
    else answer=med;
  }
  cout<<answer<<endl;
  
  return 0;
}

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

const static int MAX = 25;

class Node {
public:
    int parent, left, right;
    Node(int parent = -1, int left = -1, int right = -1) : parent(parent), left(left), right(right) {}
};

Node T[MAX];
int H[MAX], D[MAX];


void setDepth(int node, int d) {
    if (node == -1) return;
    D[node] = d;
    setDepth(T[node].left, d+1);
    setDepth(T[node].right, d+1);
}

int setHeight(int node) {
    int hl = 0, hr = 0;
    if (T[node].left != -1) {
        hl = setHeight(T[node].left) +1;
    }
    if (T[node].right != -1) {
        hr = setHeight(T[node].right) + 1;
    }
    H[node] = std::max(hl, hr);
    return H[node];
}

int getSibling(const int &node) {
    if (T[node].parent == -1) return -1;
    if (T[T[node].parent].left == node) return T[T[node].parent].right;
    return T[T[node].parent].left;
}

int getDegree(const int &node) {
    if (T[node].left == -1 && T[node].right == -1) return 0;
    if (T[node].left != -1 && T[node].right != -1) return 2;
    return 1;
}


int main()
{
    int N, node, left, right, root = 0;
    std::scanf("%d", &N);

    for (int i = 0; i < N; i++) {
        std::scanf("%d %d %d", &node, &left, &right);
        if (left != -1) T[left].parent = node;
        if (right != -1) T[right].parent = node;
        T[node].left = left; T[node].right = right;
    }

    for (int i = 0; i < N; i++) {
        if (T[i].parent == -1) {
            root = i;
            break;
        }
    }
    setDepth(root, 0);
    setHeight(root);
    for (int i = 0; i < N; i++) {
        std::printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
                    i, T[i].parent, getSibling(i), getDegree(i), D[i], H[i]);

        if (i == root) std::printf("root\n");
        else if (H[i] == 0) std::printf("leaf\n");
        else std::printf("internal node\n");
    }

    return 0;
}



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

/**
 * UnionFind(重みなし)
 */
class UnionFind
{
    private:
        vector<long long> parents;

    public:
        UnionFind(long long N)
        {
            this->parents = vector<long long>(N, -1);
        }

        long long size(long long A)
        {
            return -1 * this->root(A);
        }

        long long root(long long A)
        {
            if (this->parents[A] < 0) return A;

            this->parents[A] = this->root(this->parents[A]);
            return this->parents[A];
        }

        bool unite(long long A, long long B)
        {
            long long ra = this->root(A);
            long long rb = this->root(B);

            if (ra == rb) return false;

            if (this->size(ra) > this->size(rb)) {
                this->parents[ra] += this->parents[rb];
                this->parents[rb] = ra;
            } else {
                this->parents[rb] += this->parents[ra];
                this->parents[ra] = rb;
            }
            return true;
        }

        bool isUnite(long long A, long long B)
        {
            return this->root(A) == this->root(B);
        }

        void show()
        {
            for (int i = 0; i < this->parents.size(); i++) {
                this->root(i); // 親の更新を行う
                cout << "i: " << i << ", parents[i]: " << this->parents[i] << endl;
            }
        }
};


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

    vi P(N);
    rep(i, N) {
        cin >> P[i];
        P[i]--;
    }
    vi X(M), Y(M);
    rep(i, M) {
        cin >> X[i] >> Y[i];
        X[i]--;
        Y[i]--;
    }

    UnionFind u(N);
    rep(i, M) {
        u.unite(P[X[i]], P[Y[i]]);
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (u.isUnite(i, P[i])) cnt++;
    }
    cout << cnt << endl;
}

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

int main() {
    int N = 0, X = 0, T = 0;
    cin >> N >> X >> T;
    int A = N / X;
    int B = N % X;

    if (A == 0) {
        cout << T << endl;
    }

    else if (A >= 1 && B == 0) {
        cout << A * T << endl;
    }

    else if (A >= 1 && B >= 1) {
        cout << (A + 1) * T << endl;
    }
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] HWM = br.readLine().split(" ");
		
		int H = Integer.parseInt(HWM[0]);
		int W = Integer.parseInt(HWM[1]);
		int M = Integer.parseInt(HWM[2]);
		
		HashSet<Long> Bakuha = new HashSet<Long>();
		long MaxH = 3*100000;
		int[]sumH = new int[H];
		int[]sumW = new int[W];
		int SH = 0;
		int SW = 0;
		
		for(int i = 0; i<M; i++) {
			String[] HW = br.readLine().split(" ");
			int inH = Integer.parseInt(HW[0])-1;
			int inW = Integer.parseInt(HW[1])-1;
			Bakuha.add((inH*MaxH)+inW); 
			sumH[inH] ++;
			sumW[inW] ++;
			if(sumH[inH]>= SH) {
				SH = sumH[inH];
			} 
			if(sumW[inW]>= SW) {
				SW = sumW[inW];
			}
		}
		
		ArrayList<Integer> SHindex = new ArrayList<Integer>();
		ArrayList<Integer> SWindex = new ArrayList<Integer>();
		
		for(int h=0; h<H; h++) {
			if(sumH[h] == SH) {
				SHindex.add(h);
			}
		}	
		for(int w=0; w<W; w++) {
			if(sumW[w] == SW) {
				SWindex.add(w);
			}	
		}
		
		int ans = SH+SW-1;//最低の爆破可能数、鳩の巣に被っている
		int I = SHindex.size();
		int J = SWindex.size();
		
		if((long)SHindex.size()*SWindex.size() > M) {//鳩の巣Mより交点の数が大きいとき
			ans = SH+SW;
		}else {//鳩の巣Mより交点の数が小さいとき、交点は鳩の巣に被っているかもしれない
			for(int i=0; i<I; i++) {
				long SHnakami = SHindex.get(i)*MaxH;
				for(int j=0; j<J; j++) {
					if (!Bakuha.contains(SHnakami+SWindex.get(j))) { //HashMapに既にキーがないとき、鳩の巣に被っていない
						ans = SH+SW;
					}
				}
			}
		}
		
		System.out.print(ans);
	}
}

Measured memory_bytes: 89436
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n,k;cin >> n >> k;
	int ans=1;
	rep(i,n-1)
	{
		ans*=k-1;
	}	
	ans*=k;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();

		boolean[] start=new boolean[N+1];
		boolean[] goal=new boolean[N+1];

		for(int i=0; i<N+1; i++) {
			start[i]=false;
			goal[i]=false;
		}

		int tmp1=0;
		int tmp2=0;
		for(int i=0; i<M; i++) {
			tmp1=sc.nextInt();
			tmp2=sc.nextInt();
			if(tmp1==1) {
				start[tmp2]=true;
			}

			else if(tmp2==N) {
				goal[tmp1]=true;
			}
		}

		for(int i=2; i<=N-1; i++) {
			if(start[i]==true && goal[i]==true) {
				System.out.println("POSSIBLE");
				System.exit(0);
			}
		}
		System.out.println("IMPOSSIBLE");
	}
}

Measured memory_bytes: 96200
#include <bits/stdc++.h>
#define x real()
#define y imag()
#define EPS (1e-10)
using namespace std;
typedef complex<double> point;
//vector <point> pl;

namespace std {
  bool operator < (const point& a, const point& b){
    return fabs(real(a)-real(b)) < EPS ? imag(a) < imag(b) : real(a) < real(b);
  }
  bool operator == (const point& a, const point& b){
    return fabs(real(a) - real(b)) < EPS && fabs(imag(a) - imag(b)) < EPS;
  }
  bool operator != (const point& a, const point& b){
    return !(a == b);
  }
  point operator+(const point& a, const point& b){
    point res;
    res.x = a.x + b.x;
    res.y = a.y + b.y;
    return res;
  }
}
 
double dot(point a,point b){return a.x*b.x+a.y*b.y;}
double cross(point a,point b){return a.x*b.y-a.y*b.x;}
int ccw(point a,point b,point c){
  point d = b-a,e = c-a;
  if(cross(d,e)>0) return 1;//"COUNTER_CLOCKWISE"
  if(cross(d,e)<0) return -1;//"CLOCKWISE"
  if(dot(d,e)<0) return 2;//"ONLINE_BACK"
  if(abs(d) < abs(e)) return -2;//"ONLINE_FRONT"
  return 0;//"ON_SEGMENT"
}
 
point crosspoint(point a,point b,point c,point d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
 
bool intersection(point a,point b,point c,point d){
  return (ccw(a,b,c)*ccw(a,b,d)<=0&&ccw(c,d,a)*ccw(c,d,b)<=0);
}

bool eq(double a,double b){
  return abs(a-b) < EPS;
}

int func(set< point > &s){
  vector< point > res;
  set< point> :: iterator I;
  for( I = s.begin(); I!=s.end(); I++){

    point p = *I;

    if( eq(p.real(), -100 ) )continue;
    if( eq(p.real(), 100 ) )continue;
    if( eq(p.imag(), -100 ) )continue;
    if( eq(p.imag(), 100 ) )continue;

    bool flag=true;
    for(int i=0;i<(int)res.size();i++){
      if( res[i]==p )flag=false;
    }

    
    if(flag)res.push_back(p);
  }
  return res.size();
}

int main(void){
  int N;

  /*   vect.insert( make_pair(point(-100, -100), point(-100, 100)) );
       vect.insert( make_pair(point(-100, -100), point(100, -100)) );
       vect.insert( make_pair(point(100, 100), point(-100, 100)) );
       vect.insert( make_pair(point(100, 100), point(100, -100)) );
      */

  while(cin >> N, N){
    int ans = 1;
    set<point> inj;
    set< pair<point, point> > vect;
    for(int i = 0; i < N; i++){
      inj.clear();

      
      ans += 1;
      point p1, p2;
      cin >> p1.x >> p1.y >> p2.x >> p2.y;
      
      for(set< pair<point, point> >::iterator it = vect.begin(); it != vect.end(); it++){
	//cout << it->first << " " << it->second << endl;

	if(intersection(p1, p2, it->first, it->second)){

	  inj.insert( crosspoint(p1, p2, it->first, it->second) );
	  //	  if(inj.find( crosspoint(p1, p2, it->first, it->second)) == inj.end() ){
	  //	    ans += 1;
	  //	    inj.insert( crosspoint(p1, p2, it->first, it->second) );
	  //	  }
	}
      }

      ans+= func( inj );

      vect.insert( make_pair(p1, p2) );
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3148
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var grade = new List<char>();
        int m, f, r;
        string str;
        string[] strer = new string[3];

        while (true)
        {
            str = Console.ReadLine();
            if (str == "-1 -1 -1")
            {
                break;
            }
            strer = str.Split(' ');

            m = int.Parse(strer[0]);
            f = int.Parse(strer[1]);
            r = int.Parse(strer[2]);

            if (m == -1 || f == -1)
            {
                grade.Add('F');
            }
            else if (m + f >= 80)
            {
                grade.Add('A');
            }
            else if (m + f >= 65)
            {
                grade.Add('B');
            }
            else if (m + f >= 50)
            {
                grade.Add('C');
            }
            else if (m + f >= 30 && r >= 50)
            {
                grade.Add('C');
            }
            else if (m + f >= 30)
            {
                grade.Add('D');
            }
            else if (m + f < 30)
            {
                grade.Add('F');
            }
        }

        foreach (var c in grade)
        {
            Console.WriteLine(c);
        }

    }
}


Measured memory_bytes: 17972
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
char s[100010];
int n,ans;
int main(){
	scanf("%s",s);
	n=strlen(s);
	ans=n;
	for(int i=1;i<n;i++){
		if(s[i]!=s[i-1]){
			ans=min(ans,max(i,n-i));
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384