akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 

using namespace std; 
const int MAX_N = 3005; 
double dp[MAX_N][MAX_N]; 
double p[MAX_N]; 
int n; 

int main () {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n; 
	for (int i = 1; i <= n; i++) {
		cin >> p[i]; 
	}

	dp[0][0] = 1.0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {
			if (dp[i][j] != 0.0) {
				dp[i + 1][j + 1] += dp[i][j] * p[i + 1]; 
				dp[i + 1][j] += dp[i][j] * (1.0 - p[i + 1]); 
			}
		}
	}

	double res = 0.0; 
	for (int i = (n + 1) / 2; i <= n; i++) {
		res += dp[n][i]; 
	}

	cout << fixed << setprecision(10) << res; 
	return 0; 
}

Measured memory_bytes: 68864
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n;
  string s;

  cin >> n >> s;

  rep(i,sz(s))
  {
    s[i] += n;
    if(s[i] > 90)
      s[i] -= 26;
  }

  cout << s;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
from collections import Counter
s = input()
t = input()


s_pattern = Counter(s)
t_pattern = Counter(t)


def check(string, original):
    n = len(string)
    flag = False
    for i in range(n):
        if original == string[i:] + s[:i]:
            flag = True
            break
    return flag


if s_pattern != t_pattern:
    print('No')
else:
    if check(s, t):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3316
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n, i, j, b, a[4][13];
    char c;
    
    scanf("%d", &n);
    
    for(i=0; i<4; i++){
        for(j=0; j<13; j++){
            a[i][j] = 1;
        }
    }
    
    for(i=0; i<n*2; i++){
        scanf("%c %d", &c, &b);
        if(c == 'S'){
            a[0][b-1] = 0;
        }else if(c == 'H'){
            a[1][b-1] = 0;
        }else if (c == 'C'){
            a[2][b-1] = 0;
        }else if (c == 'D'){
            a[3][b-1] = 0;
        }
    }
    for(i=0; i<4; i++){
        for(j=0; j<13; j++){
            if(a[i][j] == 1){
                if(i == 0){
                    printf("S ");
                }else if (i == 1){
                    printf("H ");
                }else if (i == 2){
                    printf("C ");
                }else if (i == 3){
                    printf("D ");
                }
                printf("%d\n", j+1);
            }
        }
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int A, B, C, D; cin >> A >> B >> C >> D;
  while (A>0&&C>0) {
    A -= D;
    C -= B;
  }
  string result = C<=0 ? "Yes" : "No";
  cout << result << endl;
  return 0;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0;i < n;i++){
    cin >> h[i];
  }
  int ans = 0;
  
  for (int i = 0;i < n;i++){
    if (h[i] >= k){
     ans++;
    }
  }
  
  cout << ans << endl;
}



Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.begin()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

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

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

  int n; cin >> n;

  ll a[20];
  rep(i, n) {
    cin >> a[i];
  }

  ll tmpl = a[0];
  ll ans;
  for (int i = 1; i < n; ++i) {
    ans = lcm(tmpl, a[i]);
    tmpl = lcm(ans, a[i]);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3192
#include <stdio.h>
int main(void){
  int a,b,c,t;
  scanf("%d%d%d",&a,&b,&c);
  t=a;
  a=b;
  b=t;
  t=a;
  a=c;
  c=t;
  printf("%d %d %d",a,b,c);
  return 0;
}


Measured memory_bytes: 1680
import sys
import collections as col
input=sys.stdin.readline

def main():
	#N,K=map(int,input().split())
	#N=input().rstrip()
	N=int(input())
	#vA=list(map(int,input().split()))
	vS=[input().rstrip() for _ in [0,]*N]
	cS=col.Counter(vS)
	
	mcS=cS.most_common()
	mc = mcS[0][1]
	res = sorted([s for s,c in mcS if c==mc])
	
	print(*res, sep="\n")


main()


Measured memory_bytes: 50208
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//string alp = "abcdefghijklmnopqrstuvwxyz";
using namespace std;
int main(){
  int n;
  cin >> n;
  cout << pow(2,floor(log(n)/log(2))) << endl;
  return 0;
}

Measured memory_bytes: 256
// AtCoder Grand Contest 019
// C - Fountain Walk

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


const int MAX_N = 200000;
const int INF = (int)1e9;
const long double PI_L = acos(-1.0L);

int X1, Y1, X2, Y2;
int N, K;
int inv_x, inv_y;
vector<pii> a;
int dp[MAX_N];

int main() {

    int x, y;
    long double ans;
    int cnt, arcs;

    cin >> X1 >> Y1 >> X2 >> Y2;
    cin >> N;
    inv_x = X1 > X2 ? -1 : 1;
    inv_y = Y1 > Y2 ? -1 : 1;
    X1 *= inv_x; X2 *= inv_x;
    Y1 *= inv_y; Y2 *= inv_y;

    for (int i = 0; i < N; i++) {
        cin >> x >> y;
        x *= inv_x; y *= inv_y;
        if (X1 <= x && x <= X2 && Y1 <= y && y <= Y2) {
            a.push_back(pii(x, y));
        }
    }
    sort(a.begin(), a.end());
    K = a.size();

    fill(dp, dp + K, INF);
    for (int j = 0; j < K; j++) {
        *lower_bound(dp, dp + K, a[j].second) = a[j].second;
    }
    cnt = lower_bound(dp, dp + K, INF) - dp;
    arcs = (cnt == (min(X2 - X1, Y2 - Y1) + 1)) ? cnt + 1 : cnt;

    ans = 100.0L * ((X2 - X1) + (Y2 - Y1)) - 20.0L * cnt + 5.0L * arcs * PI_L;

    cout << fixed << setprecision(20) << ans << endl;

    return 0;

}



Measured memory_bytes: 2672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b) cout<<c<<endl;
  else if(b==c) cout<<a<<endl;
  else cout<<b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
using P = pair<int, int>;
int N;
vector<vector<P>> V;
bool judge(int bit) {
    for (int i = 0; i < N; ++i) {
        if (!(bit & (1 << i))) continue;
        for (P xy : V[i]) {
            int x = xy.first;
            int y = xy.second;
            if (y == 1 && !(bit & (1 << x))) return false;
            if (y == 0 && (bit & (1 << x))) return false;
        }
    }
    return true;
}
int main() {
    cin >> N;
    V.resize(N);
    for (int i = 0; i < N; ++i) {
        int A; cin >> A;
        V[i].resize(A);
        for (int j = 0; j < A; ++j) {
            cin >> V[i][j].first >> V[i][j].second;
            V[i][j].first--;
        }
    }
    int cnt = 0;
    for (int i = 0; i < (1 << N); ++i) {
        if (judge(i)) {
            int count = 0;

            for (int j = 0; j < N; ++j) if (i & (1 << j)) count++;

            cnt = max(cnt, count);
        }
    }
    cout << cnt << endl;
}

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

#define sz(x) (int)x.size()
const int _ = 1e5 + 7 , P = 1e9 + 7;
vector < int > nxt1[_] , nxt2[_]; int N;

bool vis[_] , incirc[_];

int dfs1(int x , vector < int > &pot){
	vis[x] = 1; int r = 0;
	for(auto t : nxt1[x])
		if(!vis[t]){int v = dfs1(t , pot); if(v){pot.push_back(x); incirc[x] = 1; r = v;}}
		else if(vis[t] && !incirc[t]){r = t; pot.push_back(x); incirc[x] = 1;}
	return r == x ? 0 : r;
}

int dfs2(int x){
	int len = 0; vis[x] = 1;
	for(auto t : nxt2[x])
		if(!incirc[t]) if(!len) len = dfs2(t) + 1; else len = -1e9;
	return len;
}

int main(){
	scanf("%d" , &N); for(int i = 1 ; i <= N ; ++i){int x; scanf("%d" , &x); nxt1[i].push_back(x); nxt2[x].push_back(i);}
	int ans = 1; static int num[_];
	for(int i = 1 ; i <= N ; ++i)
		if(!vis[i]){
			vector < int > pot; dfs1(i , pot); vector < pair < int , int > > link;
			for(int i = 0 ; i < sz(pot) ; ++i){
				int p = dfs2(pot[i]); if(p < 0) ans = 0; else if(p > 0) link.push_back(make_pair(i , p));
			}
			if(link.empty()){++num[sz(pot)]; continue;}
			
			for(int i = 1 ; i < sz(link) ; ++i)
				if(link[i].first < link[i - 1].first + link[i - 1].second) ans = 0;
				else if(link[i].first > link[i - 1].first + link[i - 1].second) ans = 2 * ans % P;

			if(link.back().first + link.back().second > link.front().first + sz(pot)) ans = 0;
			else if(link.back().first + link.back().second < link.front().first + sz(pot)) ans = 2 * ans % P;
		}
	
	for(int i = 1 ; i <= N ; ++i)
		if(num[i]){
			static int dp[_]; dp[0] = 1;
			for(int j = 1 ; j <= num[i] ; ++j)
				dp[j] = ((i > 1 && (i & 1) ? 2 : 1) * dp[j - 1] + (j > 1 ? 1ll * dp[j - 2] * (j - 1) % P * i : 0)) % P;
			ans = 1ll * ans * dp[num[i]] % P;
		}
	printf("%d\n" , ans);
	return 0;
}


Measured memory_bytes: 18304
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;

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

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<char>>a(h+2, vector<char>(w+2, '0'));
  for(int i=1; i<=h; i++)for(int j=1; j<=w; j++)cin >> a[i][j];
  queue<pair<int, int>>Q;
  for(int i=1; i<=h; i++)for(int j=1; j<=w; j++)if(a[i][j]=='#')Q.push(make_pair(i, j));
  Q.push(make_pair(-1, -1));
  int ret=0;
  while(Q.size()>1){
    pair<int, int>p=Q.front();
    Q.pop();
    if(p==make_pair(-1, -1)){
      ret++;
      Q.push(make_pair(-1, -1));
      continue;
    }
    for(int i=0; i<4; i++){
      pair<int, int>pn=make_pair(p.first+dx[i], p.second+dy[i]);
      if(a[pn.first][pn.second]=='.'){
        a[pn.first][pn.second]='#';
        Q.push(pn);
      }
    }
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 9488
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int dp[1145140][2],last[1145140],zc[1145140];
signed main(){
	int n;
	cin>>n;
	vector<int> a;
	int xorall = 0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a.pb(x);
	}
	vector<int> b;
	b.pb(0);
	for(int i=1;i<=n;i++){
		b.pb(b[i-1]^a[i-1]);
	}
	zc[0]=1;
	for(int i=1;i<=n;i++){
		if( b[i] == 0 )zc[i] = zc[i-1]+1;
		else zc[i] = zc[i-1];
	}
	for(int i=0;i<(1<<20);i++){
		dp[i][0]=1;
	}
	for(int i=1;i<=n;i++){
		int c = b[i];
		if( c != 0 ){
			if( last[ c ] == 0 ){
				dp[c][1] = 1;
				last[c] = i;
			}
			else{
				int n0 = dp[c][0] + dp[c][1] * ( zc[i] - zc[last[c]] );
				n0 %= inf;
				int n1 = dp[c][1] + n0;
				n1 %= inf;
				last[c] = i;
				dp[c][0] = n0;
				dp[c][1] = n1;
			}
		}
		else if( i != n ){
			dp[0][0] *= 2;
			dp[0][0] %= inf;
		}
	}
	if( b[n] == 0 ){
		int ans = 0;
		for(int i=1;i<(1<<20);i++){
			ans += dp[i][1];
			ans %= inf;
		}
		ans += dp[0][0];
		ans %= inf;
		cout<<ans<<endl;
		return 0;
	}
	else{
		cout<<dp[b[n]][0]<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 39020
#include <cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
#define LL long long
#define INF 1e18
#define MAXN 100002
int n,m,s,t,u,v;
LL a,b,f=1e15,ans[MAXN];
struct Graph
{
	int cnt,head[MAXN],vis[MAXN];
	LL dis[MAXN];
	struct Edge{int next,to;LL dis;}edge[MAXN*2];
	queue<int> q;
	void add(int from,int to,LL dis)//在struct定义本质不变
	{
		edge[++cnt].next=head[from];
		edge[cnt].to=to;
		edge[cnt].dis=dis;
		head[from]=cnt;
	}
	void spfa(int s)
	{
		for(int i=1;i<=n;i++)
			dis[i]=INF;
		memset(vis,0,sizeof(vis));
		q.push(s);
		vis[s]=1;
		dis[s]=0;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			vis[x]=0;
			for(int i=head[x];i!=0;i=edge[i].next)
			{
				int to=edge[i].to;
				if(dis[to]>(dis[x]+edge[i].dis))
				{
					dis[to]=dis[x]+edge[i].dis;
					if(!vis[to])
						q.push(to),vis[to]=1;
				}
			}
		}
	}
}g1,g2;
int main()
{
	scanf("%d%d%d%d",&n,&m,&s,&t);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%lld%lld",&u,&v,&a,&b);
		g1.add(u,v,a);g1.add(v,u,a);
		g2.add(v,u,b);g2.add(u,v,b);
	}
	g1.spfa(s);
	g2.spfa(t);
	ans[n+1]=INF;
	for(int i=n;i>=1;i--)
		ans[i]=min(ans[i+1],g1.dis[i]+g2.dis[i]);
	for(int i=1;i<=n;i++)
		printf("%lld\n",f-ans[i]);
}

Measured memory_bytes: 12032
def main(n, l_r):
    ans = 0

    for l, r in l_r:
        ans += r - (l - 1)

    print(ans)


if __name__ == "__main__":
    n = int(input())
    l_r = [list(map(int, input().split())) for _ in range(n)]

    main(n, l_r)


Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int a, b;

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

    int x;

    if(b < 10){
        x = 10 * a + b;
    }else if(b < 100){
        x = 100 * a + b;
    }else{
        x = 1000 * a + b;
    }

    int y = (int)sqrt(x);

    if(y * y == x){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 2088
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>

using namespace std;

int main(){
	while(1){
		int e; cin >> e;
		if (e == 0) break;

		int min = 1000000;
		for (int z = 0; z <= 100; z++){
			for (int y = 0; y <= 1000; y++){
				int x = e - (z *z * z) - (y * y);
				if (x >=  0 and min > x + y + z){
					min = x + y + z;
				}
				
			}
		}
		cout << min<< endl;
	}
return 0;
}

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

int fall(vector<vector<int>>&field, vector<vector<int>>&pino,int l) {
	int y = 0;
	for ( y = 0; y < field.size() - pino.size(); ++y) {
		bool ok = true;
		for (int i = 0; i < pino.size(); ++i) {
			for (int j = 0; j < pino[i].size(); ++j) {
				if (pino[i][j]) {
					if (field[y + i+1][l + j])ok = false;
				}
			}
		}
		if (!ok) {
			break;
		}
	}
	for (int i = 0; i < pino.size(); ++i) {
		for (int j = 0; j < pino[i].size(); ++j) {
			if (pino[i][j]) {
				assert(!field[y + i][l + j]);
				field[y + i][l + j] = true;
			}
		}
	}
	int delline = 0;
	for (int i = y + pino.size() - 1; i >= y; --i) {
		while (all_of(field[i].begin(), field[i].end(), [](const int a) {return a == 1; })) {
			transform(field[i].begin(), field[i].end(), field[i].begin(), [](const int a) {return false; });
			for (int j = i- 1; j >= 0; --j) {
				swap(field[j], field[j + 1]);
			}
			delline += 1;
		}
	}
	return delline;
}

int main() {
	int N;
	while (cin>>N,N) {
		int sum = 0;
		vector<vector<int>>field(5*N+1, vector<int>(5));
		while(N--){
			int d, p, q; cin >> d >> p >> q; q--;
			sum += p;
			vector<vector<int>>pino(d == 1 ? 1 : p, vector<int>(d == 2 ? 1 : p, 1));
			sum -= fall(field, pino, q) * 5;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3136
#Union-Find木の構築
import sys
def 解():
    iN,iK,iL = [int(_) for _ in input().split()]
    aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

    def buildTree(a):
        aT = [0]*(iN+1)
        for p,q in a:
            rp = getRoot(aT,p)
            rq = getRoot(aT,q)
            thisRoot = max(rp,rq,q)
            aT[p] = thisRoot
            aT[q] = thisRoot
            aT[rp] = thisRoot #これで Union してるつもり
            aT[rq] = thisRoot
        return aT
    def getRoot(a,i): #find みんな小さい方に合わせるならデカい方に合わせてみよう
        if a[i] == i or a[i] == 0:
            if a[i] == 0 : a[i] = i
            return i
        elif i < a[i] :
            a[i] = getRoot(a,a[i])
            return a[i]
    #   else:
    #       print("! ",i,a[i])

    aT道 = buildTree(aD[0:iK])
    aT鉄道 = buildTree(aD[iK:])
    aRet = []
    dRet = {}
    for i in range(1,iN+1):
        # いやはやこんなもんもキーになるのか。
        Comb = (getRoot(aT道,i), getRoot(aT鉄道,i))
        aRet.append(Comb)
        if Comb in dRet:
            dRet[Comb] += 1
        else:
            dRet[Comb] = 1
    print(" ".join([str(dRet[_]) for _ in aRet]))

解()


Measured memory_bytes: 84652
#include <bits/stdc++.h>
using namespace std;
 
const int inf = 0x3f3f3f3f;
 
struct edge {
	int to, cap;
	char flag; // 0: r -> l   1: u -> d
	edge(): flag(-1) {}
	edge(const int &t, const int &c, const char &f): to(t), cap(c), flag(f) {}
} ge[60000];
int n, m;
vector <int> gl[10010];
int depth[10010], q[10010];
int iter[10010];
 
int N, M;
char a[110][110];
char dir[4][2] = { 1, 0, 0, 1, -1, 0, 0, -1 };
char chr[4][2] = { 'v', '^', '>' , '<', '^', 'v', '<', '>' };
void AddEdge(const int &from, const int &to, const int &cap, const char &flag);
int MaxFlow(const int &from, const int &to);
int dfs(const int &from, const int &to, const int &flow);
void GetAns(int from, int to, char flag);
 
int main() {
	scanf("%d%d", &N, &M);
	const int s = N * M, t = N * M + 1;
	for (int i = 0; i < N; ++i)
		scanf("%s", a[i]);
 
	for (int i = 0; i < N; ++i)
		for (int j = i & 1; j < M; j += 2)
			if (a[i][j] == '.') {
				if (i + 1 < N && a[i + 1][j] == '.')
					AddEdge(i * M + j, (i + 1) * M + j, 1, 0);
				if (j + 1 < M && a[i][j + 1] == '.')
					AddEdge(i * M + j, i * M + j + 1, 1, 1);
				if (i > 0 && a[i - 1][j] == '.')
					AddEdge(i * M + j, (i - 1) * M + j, 1, 2);
				if (j > 0 && a[i][j - 1] == '.')
					AddEdge(i * M + j, i * M + j - 1, 1, 3);
			}
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < M; ++j)
			if (a[i][j] == '.')
				if (i + j & 1)
					AddEdge(i * M + j, t, a[i][j] == '.', -1);
				else
					AddEdge(s, i * M + j, a[i][j] == '.', -1);
	printf("%d\n", MaxFlow(s, t));
 
	for (int i = 0; ge[i].flag != -1; i += 2)
		if (!ge[i].cap)
			GetAns(ge[i ^ 1].to, ge[i].to, ge[i].flag);
	for (int i = 0; i < N; ++i)
		printf("%s\n", a[i]);
	return 0;
}
 
void GetAns(int from, int to, char flag) {
	a[from / M][from % M] = chr[flag][0], a[to / M][to % M] = chr[flag][1];
}
 
void AddEdge(const int &from, const int &to, const int &cap, const char &flag) {
	ge[m] = edge(to, cap, flag);
	gl[from].push_back(m++);
	ge[m] = edge(from, 0, -1);
	gl[to].push_back(m++);
}
 
int MaxFlow(const int &from, const int &to) {
	int flow = 0;
	while (true) {
		memset(depth, -1, sizeof(depth));
		depth[from] = 0;
		int h = 0, t = 1; q[h] = from;
		while (h < t) {
			int u = q[h++];
			for (int i = 0; i < gl[u].size(); ++i) {
				edge &e = ge[gl[u][i]];
				if (e.cap > 0 && depth[e.to] == -1)
					q[t++] = e.to, depth[e.to] = depth[u] + 1;
			}
		}
		if (depth[to] == -1)
			return flow;
 
		memset(iter, 0, sizeof(iter));
		int f;
		while (f = dfs(from, to, inf))
			flow += f;
	}
}
 
int dfs(const int &from, const int &to, const int &flow) {
	if (from == to)
		return flow;
	for (int &i = iter[from]; i < gl[from].size(); ++i) {
		edge &e = ge[gl[from][i]], &e1 = ge[gl[from][i] ^ 1];
		if (e.cap > 0 && depth[e.to] == depth[from] + 1) {
			int f = dfs(e.to, to, min(flow, e.cap));
			if (f) {
				e.cap -= f;
				e1.cap += f;
				return f;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 5316
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;



void solve() {
	ll n, k;
	cin >> n >> k;
	ll health[n], sum = 0;
	for(int i = 0; i < n; ++i) {
		cin >> health[i];
		}
		sort(health, health + n);
		for(int i = 0; i < n - k; ++i) {
			sum += health[i];
			}
			cout << sum << endl;
}


int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	solve();
	return 0;
}
 
 
 


Measured memory_bytes: 5164
/* in the name of Anton */

/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;


const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
#ifdef ARYANC403
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s,t;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>s;
    string t="";

    for(auto x:s)
    {
        if(x=='?')
            t+='D';
        else
            t+=x;
    }

    cout<<t<<endl;

}   aryanc403();
    return 0;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int n;
int a[10];

signed main() {
  cin >> n;
  int Min = 1e18;
  rep (i, 5) {
    cin >> a[i];
    chmin(Min, a[i]);
  }

  // dbg((n + Min - 1))
  int ans = ((n + Min - 1) / Min) + 4;

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main(){
	char n;
	int	counter[26]={0};
	while(cin>>n){
		if(isalpha(n)){
		n=tolower(n);
		counter[n-'a']+=1;
		}
	}
	for(int i=0;i<26;i++){
		printf("%c : %d\n",'a'+i,counter[i]);
	}
}


Measured memory_bytes: 3184
#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__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
        int n; cin >> n;
        vector<int> a(n), b(n);
        forn(i, n)
        {
                cin >> a[i];
                b[i] = a[i];
        }
        sort(all(a));
        for (int i = 0; i < n; ++i)
        {
                if (b[i] == a[n - 1]) cout << a[n - 2] << endl;
                else cout << a[n - 1] << endl;
        }
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


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

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final String[] line = in.nextLine().split(" ");
        final int n = Integer.parseInt(line[0]);
        final int k = Integer.parseInt(line[1]);
        for (int i = 0; i < n; i++) {
            in.nextInt();
        }
        in.nextLine();
        System.out.println((int) Math.ceil((double) (n - 1) / (k - 1)));
    }
}


Measured memory_bytes: 58728
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			List<Integer> list = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				char str = in.nextString().toCharArray()[0];
				if (str == 'M' || str == 'A' || str == 'R' || str == 'C' || str == 'H') {
					list.add((int)str);
				}
			}
			Integer[] s = list.toArray(new Integer[list.size()]);
			Map<Integer, Integer> map = ArrayUtils.getCountMap(s);

			long ans = 0;
			long count77 = 0;
			long count65 = 0;
			long count82 = 0;
			long count67 = 0;
			long count72 = 0;
			if (map.get(77) != null) count77 = map.get(77);
			if (map.get(65) != null) count65 = map.get(65);
			if (map.get(82) != null) count82 = map.get(82);
			if (map.get(67) != null) count67 = map.get(67);
			if (map.get(72) != null) count72 = map.get(72);

			ans += (count77*count67*count72);
			ans += (count77*count65*count82);
			ans += (count77*count65*count67);
			ans += (count77*count65*count72);
			ans += (count77*count82*count67);
			ans += (count77*count82*count72);

			ans += (count65*count82*count67);
			ans += (count65*count82*count72);
			ans += (count65*count67*count72);

			ans += (count82*count67*count72);

			System.out.println(ans);

		}
	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(Integer[] s) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : s)
				map.merge(x, 1, Integer::sum);
			return map;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	ll H, n=0;
	cin >> H;
	while(H > 0){
		H >>= 1;
		n = (n << 1) | 1;
	}
	cout << n << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll k = n / (a + b);
  ll d = n % (a + b);
  ll ans = k * a + min(a, d);
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
vector<int> A;
vector<int> bucket;
int bs;

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

void update(int i, int x) {
    bucket[i / bs] = gcd(bucket[i / bs], x);
}

// get gcd(A[0], A[1], ..., A[j - 1], A[j + 1], ..., A[N - 1])
int get(int j) {
    int ret = 0;
    int l = 0;
    int r = A.size();
    for(int i = l; i < r; ) {
        if (i == j) {i++; continue;}
        int bi = i / bs;
        if (i / bs != j / bs && l <= bs * bi && bs * (bi + 1) <= r) {
            ret = gcd(ret, bucket[bi]);
            i += bs;
        } else {
            ret = gcd(ret, A[i]);
            i++;
        }
    }
    return ret;
}



int main() {
    int N;
    cin >> N;
    A.resize(N);
    bs = (int)sqrt(N);
    bucket.resize(bs);
    
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        update(i, A[i]);
    }
    
    int ans = 0;
    for(int i = 0; i < N; i++) {
        ans = max(ans, get(i));
    }
    
    cout << ans << endl;
    
    return 0;
}

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

int main() {
  int N, K;cin >> N >> K;
  long long sum=0;
  vector<int> H(N);

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

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

  for (int i = 0;i < N-K;i++) {
    sum += H[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 1024
N = int(input())
k = [0] * 1010
p = 0
counter = 2
ans = 1

for i in range(1,N + 1):
    p = i
    counter = 2
    
    while p != 1:
        if p % counter == 0:
            k[counter] += 1
            p /= counter
        else:
            counter += 1
for i in range(1,N + 1):
    ans = ans * (k[i] + 1) % 1000000007
print(ans)

Measured memory_bytes: 3064
def ma():
    return map(int,input().split())

def main():
    n,k=ma()
    b=input()
    left=0
    for i in range(n-1):
        if b[i]==b[i+1]:
            left+=1
    ans=min(left+2*k, n-1)
    print(ans)

if __name__=='__main__':
    main()    

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

int main()
{
	int64_t x,y;
	cin >> x >> y;

	int64_t m=y/x;
	int maxbit=0;

	for (int i=0;i<63;++i)
	{
		if ((m&1)!=0)
		{
			maxbit=i;
		}
		m>>=1;
	}
	cout << maxbit+1 << endl;
}







Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n,mini;
  cin >> n;
  vector <string> data1(n),data2(n);
  for(int i=0;i<n;i++){
    cin >> data1[i];
    data2[i] = data1[i];
  }
  for(int i=0;i<n-1;i++){
    for(int j=n-1;j>i;j--){
      if(data1[j][1]<data1[j-1][1]) swap(data1[j],data1[j-1]);
    }
  }
  for(int i=0;i<n;i++){
    mini = i;
    for(int j=i;j<n;j++){
      if(data2[j][1]<data2[mini][1]) mini = j;
    }
    if(mini != i) swap(data2[i],data2[mini]);
  }
  for(int i=0;i<n;i++) cout << (i!=0?" ":"") << data1[i];
  cout << endl << "Stable" << endl;
  for(int i=0;i<n;i++) cout << (i!=0?" ":"") << data2[i];
  if(data1==data2) cout << endl << "Stable" << endl;
  else cout << endl << "Not stable" << endl;
}



Measured memory_bytes: 3224
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l1=[LI() for _ in range(n)]
  l1.sort()
  l2=[LI() for _ in range(n)]
  l2.sort()

  check=[False for _ in range(n)]

  ans=0
  ans_list=[]
  for c,d in l2:
    _i=inf
    _b=-inf
    for i,[a,b] in enumerate(l1):
      if check[i]:
        continue

      if a<c and b<d:
        if _b<b:
          _i=i
          _b=b

    if _i!=inf:
      check[_i]=True
      ans+=1

  return ans

# main()
print(main())


Measured memory_bytes: 5464
#include<stdio.h>

int main(void)
{
	long long n, sum = 0, T, max, min;
	scanf("%lld", &T);
	for (int i = 1; i <= T; i++)
	{
		scanf("%lld ", &n);
		if (i == 1){
			max = min = n;
		}
		if (max<n){
			max = n;
		}
		else if (min>n){
			min = n;
		}
		sum = sum + n;
	}
	printf("%d %d %lld\n", min, max, sum);
	return 0;
}


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

class Program
{
    #region library
    static int n = 0;
    static int r = 0;
    static int c = 0;
    static int x = 0;
    static int y = 0;
    static string s = "";
    static string[] ss;
    static long sum = 0;
    static long cnt = 0;
    static long max = -1;
    static long min = 2147483647;
    static bool flg = false;
    static bool flg2 = false;
    static string alpha = "abcdefghijklmnopqrstuvwxyz";
    static int[] arr;
    static char[,] map;
    static int[,] imap;
    static string rl()
    {
        return Console.ReadLine();
    }
    static string[] rls()
    {
        return Console.ReadLine().Split();
    }
    static void wl(object obj = null)
    {
        Console.WriteLine(obj);
    }
    static void w(object obj)
    {
        Console.Write(obj);
    }
    static int Int(string s)
    {
        return int.Parse(s);
    }
    static void yes()
    {
        wl("YES");
    }
    static void no()
    {
        wl("NO");
    }
    static void Sum()
    {
        wl(sum);
    }
    static void Cnt()
    {
        wl(cnt);
    }
    static void setarray(int num = -1)
    {
        if (n == 0)
        {
            n = Int(rl());
        }
        arr = new int[n];
        if (num == -1) ss = rls();
        for (int i = 0; i < n; i++)
        {
            if (num == -1)
                arr[i] = Int(ss[i]);
            else
                arr[i] = num;
        }
    }
    static void setmap(char def = '@')
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        map = new char[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == '@') s = rl();
            for (int j = 0; j < c; j++)
            {
                map[i, j] = (def == '@') ? s[j] : def;
            }
        }
    }
    static void setimap(int def = -1)
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        imap = new int[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == -1) s = rl();
            for (int j = 0; j < c; j++)
            {
                imap[i, j] = (def == -1) ? Int(s[j].ToString()) : def;
            }
        }
    }
    #endregion

    static void Main(string[] args)
    {
        n = Int(rl());
        wl(n * n);

    }
}



Measured memory_bytes: 11220
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;
const int INF = 1000100100;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 100005;

int dp[MAX_N];
int flag[MAX_N];

vector<int> to[MAX_N];

int f(int x){
    if(flag[x]) return dp[x];
    flag[x] = 1;
    int fans = 0;
    for(int y: to[x]){
        fans = max(fans, f(y)+1);
    }
    return dp[x]=fans;
}

int main()
{
    int n, m; cin >> n >> m;
    rep(i,m){
        int xi, yi; cin >> xi >> yi; --xi, --yi;
        to[xi].push_back(yi);
    }
    int ans = 0;
    rep(i,n) ans = max(ans, f(i));
    cout << ans << endl;
}

Measured memory_bytes: 11856
import java.util.Scanner;

public class Main{
  static int h, w;
  static char[][] grid;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    h = sc.nextInt();
    w = sc.nextInt();
    grid = new char[h][w];
    for(int i = 0; i < h; i++){
      grid[i] = sc.next().toCharArray();
    }

    int[] dx = {0, -1, -1, -1, 0, 1, 1, 1};
    int[] dy = {-1, -1, 0, 1, 1, 1, 0, -1};
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        if(grid[i][j] != '.'){
          continue;
        }
        int count = 0;
        for(int k = 0; k < 8; k++){
          int ni = i + dx[k];
          int nj = j + dy[k];
          if(0 <= ni && ni < h && 0 <= nj && nj < w
              && grid[ni][nj] == '#'){
            ++count;
          }
        }
        grid[i][j] = (char)(count + '0');
      }
    }

    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < h; i++){
      sb.append(grid[i]);
      sb.append(System.lineSeparator());
    }

    System.out.print(sb);
  }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
  	int n,i,j,k;
    cin>>n;
    int sum=0;
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=n;++j)
        {
            for(k=1;k<=n;++k)
                sum+=__gcd(i,__gcd(j,k));
        }
    }
    cout<<sum;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,M;
  cin>>N>>M;
  VI S(N),T(N),C(N);
  rep(i,N) cin>>S[i]>>T[i]>>C[i];
  int X[M][100100]={};
  rep(i,N){
    X[C[i]-1][S[i]]++;
    X[C[i]-1][T[i]+1]--;
  }
  rep(i,M) rep(j,100100) X[i][j+1]+=X[i][j];
  rep(i,M) rep(j,100100) if(X[i][100099-j]==0 and X[i][100099-j]==1) X[i][100099-j]=1;
  int ans=0;
  rep(i,100100){
    int tmp=0;
    rep(j,M) if(X[j][i]) tmp++;
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 13184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool isPalindrome(string a) 
{ 
  int len=a.size();
  bool ans=true;
  for(int i=0,j=len-1;i<len/2;++i,--j)
  {
    if(a[j]!=a[i])
    ans=false;
  }
  return ans;
}
int main()
{
  string s;
  cin>>s;
  int n=s.size();
  string t="";
  for(int i=0;i<(n-1)/2;i++)
  {
    t+=s[i];
  }
  string y="";
  for(int i=((n+3)/2)-1;i<n;i++)
  {
    y+=s[i];
  }
  // cout<<y<<" "<<t<<endl;
  bool ans=false;
  if(isPalindrome(s))
  {
    if(isPalindrome(y) && isPalindrome(t))
      ans=true;
  }
  if(ans)
  {
    cout<<"Yes";
  }
  else
  {
    cout<<"No";
  }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

ll a , b;
ll w , v;
ll t;

int main(){
    migmig
    cin >> a >> v;
    cin >> b >> w >> t;
    bool ok = 0;
    if(a > b){
        a -= t*v;
        b-=w*t;
        if(a<=b)ok = 1;
    }
    else{
        a+=t*v;
        b+=w*t;
        if(a>=b)ok=1;
    }
    cout << ((ok)?"YES":"NO");

    return(0);
}

Measured memory_bytes: 3656
N = int(input())
c = 'AGC'
p = ['A', 'C', 'G', 'T']
s = 'XXX'
memo = [{} for _ in range(N)]
MOD = 10 ** 9 + 7


def agc_check(t):
    t1 = t[1] + t[0] + t[2] + t[3]
    t2 = t[0] + t[2] + t[1] + t[3]
    t3 = t[0] + t[1] + t[3] + t[2]
    if (c in t) or (c in t1) or (c in t2) or (c in t3):
        return 0
    else:
        return 1


def agc_plus(t, cur):
    if cur == N:
        return 1
    if t in memo[cur]:
        return memo[cur][t]
    r = 0
    for tt in p:
        if agc_check(t + tt):
            r += agc_plus(t[1:] + tt, cur + 1)
    memo[cur][t] = r % MOD
    return memo[cur][t]


ans = agc_plus(s, 0)
print(ans)

Measured memory_bytes: 3804
#include "cstdio"
#include "iostream"
#include "string"
using namespace std;
string s;int i,j,ss,k;
int main(){
	cin>>s;
	i=s.size()-1;
	while(j<=i){
		if(s[j]==s[i]){
			j++,i--;continue;
		}
		else if(s[j]=='x'){
			j++,ss++;continue;
		}
		else if(s[i]=='x'){
			i--,ss++;continue;
		}
		else{
			printf("-1\n");return 0;
		}
	}
	printf("%d\n",ss);
}

Measured memory_bytes: 512
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;

    string str;
    cin >> str;

    if (str[k - 1] == 'A') str[k - 1] = 'a';
    else if (str[k - 1] == 'B') str[k - 1] = 'b';
    else if (str[k - 1] == 'C') str[k - 1] = 'c';

    cout << str << endl;
}


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

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

    int ans=0;
    for(int i=0;i<S.length();i++){
        int count=0;
        for(int j=i;j<S.length();j++){
            if(S[j]=='A'||S[j]=='C'||S[j]=='G'||S[j]=='T'){
                count++;
                ans=max(ans,count);
            }else count=0;
        }
    }
    cout<<ans<<endl;
}

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

constexpr long long LLINF = 1LL << 62;

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int main() {
  long long n, m; cin>>n>>m;
  vector<long long> a(n);
  rep(i, n) cin>>a[i];
  sort(a.begin(), a.end());

  vector<long long> acc(n+1, 0);
  rep(i, n) acc[i+1] = a[i] + acc[i];

  long long ok = 0, ng = LLINF;
  while (ok + 1 < ng) {
    long long mid = (ok + ng) / 2;
    long long cnt = 0;
    rep(i, n) {
      cnt += a.end() - lower_bound(a.begin(), a.end(), mid - a[i]);
    }
    if (cnt < m) ng = mid;
    else ok = mid;
  }

  long long ans = 0;
  long long cnt = 0;
  rep(i, n) {
    int idx = lower_bound(a.begin(), a.end(), ok - a[i]) - a.begin();
    cnt += n - idx;
    if (idx < n) ans += a[i] * (n-idx) + (acc[n] - acc[idx]);
  }
  if (cnt > m) ans -= ok * (cnt - m);
  print(ans);

  return 0;
}

Measured memory_bytes: 1792