akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

const long long INF = 1e18;

void solve() {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    for (int i = 0; i < R; i++) {
        cin >> r.at(i);
        r.at(i)--;
    }
    vector<vector<long long>> d(N, vector<long long>(N, INF));
    for (int i = 0; i < N; i++) d.at(i).at(i) = 0;
    int a, b, c;
    for (int i = 0; i < M; i++) {
        cin >> a >> b >> c;
        d.at(a - 1).at(b - 1) = c;
        d.at(b - 1).at(a - 1) = c;
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                d.at(j).at(k) = min(d.at(j).at(k), d.at(j).at(i) + d.at(i).at(k));
            }
        }
    }
    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << i << " " << j << " " << d.at(i).at(j) << endl;
        }
    }
    */
    sort(r.begin(), r.end());
    long long ans = INF;
    do {
        long long s = 0;
        for (int i = 1; i < R; i++) {
            s += d.at(r.at(i - 1)).at(r.at(i));
            //cout << r.at(i) << " ";
        }
        //cout << endl;
        ans = min(ans, s);
    } while (next_permutation(r.begin(), r.end()));
    cout << ans << endl;
}

int main() {
    solve();
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main (){
  int a,s;
  cin >> a>>s;
  a=a%2;
  s=s%2;
  if(a==1&&s==1)
    cout << "Odd" << endl;
  else {
  cout << "Even" << endl;
  }
 
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long gcd(long long a, long long b){ return a%b ? gcd(b, a%b) : b; }
long long lcm(long long a, long long b){ return a/gcd(a, b)*b; }

int main(){
    int a, b;
    while(cin >> a >> b){
        cout << lcm(a, b) << endl;
    }
}

Measured memory_bytes: 256
/*-------enazuma11----------------*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(v) v.begin(),v.end()
#define inc(a,n) sort(a,a+n)
#define dec(a,n) sort(a,a+n,greater<int>() )
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define F first
#define S second
#define M 1000000007
 
/* int x[]={-1,-1,0,1,1,1,0,-1};
int y[]={0,1,1,1,0,-1,-1,-1};
*/
/* int x[]={-1,0,1,0};
int y[]={0,1,0,-1};
*/
const int N=3e5+5;
vector<ll> g[N];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		ll n,k,m;
		cin>>n>>k>>m;
		ll a[n+1]={};
		ll i,j,x;
		rep(i,0,m){
			cin>>x;
			a[x]++;
		}
		rep(i,1,n+1){
			a[i]+=k;
			a[i]-=m;
			if(a[i]<=0)
			cout<<"No"<<'\n';
			else
			cout<<"Yes"<<'\n';
		}
		
	}
	return 0;
}


Measured memory_bytes: 8448
n=int(input())
if n==1:
    print(1)
    exit()
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr
so=[]
ka=[]
for i in range(2,n+1):
    a=factorization(i)
    for j in a:
        if not j[0] in so:
            so.append(j[0])
            ka.append(j[1])
        else:
            ka[so.index(j[0])]+=j[1]
ans=1
for i in ka:
    ans*=(i+1)%1000000007
print(ans%1000000007)


Measured memory_bytes: 3064
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

h,w,k = lr()
a = [input() for i in range(h)]
ans = 0
for i in range(2**(h+w)):
    tmp = [[a[q][l] for l in range(w)] for q in range(h)]
    for j in range(h+w):
        if (j < h and ((i >> j) & 1)):
            for q in range(w):
                tmp[j][q] = '0'
        elif (j >= h and ((i >> j) & 1)):
            for q in range(h):
                tmp[q][j-h] = '0'
    pre = 0
    for q in range(h):
        for l in range(w):
            if tmp[q][l] == '#':
                pre+=1
    if pre == k:
        ans+=1
print(ans)

Measured memory_bytes: 74136
n = int(input())
ans = float("-INF")
f = [[0 for i in range(10)] for i in range(n)]
p = [[0 for i in range(11)] for i in range(n)]
for i in range(n):
  ft = list(map(int, input().split()))
  for j in range(10):
    f[i][j] = ft[j]
for i in range(n):
  pt = list(map(int, input().split()))
  for j in range(11):
    p[i][j] = pt[j]

for i in range(1, 2**10):
  t = 0
  for j in range(n):
    c = 0
    for k in range(10):
      if i>>k&1 and f[j][k]:
        c += 1
    t += p[j][c]
  ans = max(ans, t)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
struct edge{ll he,wi,d;};
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;
    cin>>h>>w;
    string s[h];
    ll dis[h][w][h][w];
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		for(int k=0;k<h;k++){
    			for(int x=0;x<w;x++){
    				if(i==k&&j==x)dis[i][j][k][x]=0;
    				else dis[i][j][k][x]=1e9;
    			}
    		}
    	}
    }
    for(int i=0;i<h;i++){
    	cin>>s[i];
    }
    ll ans=0;
    edge niko;
    queue<edge> q;
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		if(s[i][j]=='.')q.push({i,j,0});
    		bool maki[h][w];

    		memset(maki,0,sizeof(maki));
    		maki[i][j]=1;
    		while(!q.empty()){
    			niko=q.front();
    			q.pop();
    			dis[i][j][niko.he][niko.wi]=min(niko.d,dis[i][j][niko.he][niko.wi]);
    			if(niko.he!=h-1&&s[niko.he+1][niko.wi]=='.'&&maki[niko.he+1][niko.wi]==0){
    				maki[niko.he+1][niko.wi]=1;
    				q.push({niko.he+1,niko.wi,niko.d+1});
    			}
    			if(niko.he&&s[niko.he-1][niko.wi]=='.'&&maki[niko.he-1][niko.wi]==0){
    				maki[niko.he-1][niko.wi]=1;
    				q.push({niko.he-1,niko.wi,niko.d+1});
    			}
                if(niko.wi!=w-1&&s[niko.he][niko.wi+1]=='.'&&maki[niko.he][niko.wi+1]==0){
    				maki[niko.he][niko.wi+1]=1;
    				q.push({niko.he,niko.wi+1,niko.d+1});
    			}
    			if(niko.wi&&s[niko.he][niko.wi-1]=='.'&&maki[niko.he][niko.wi-1]==0){
    				maki[niko.he][niko.wi-1]=1;
    				q.push({niko.he,niko.wi-1,niko.d+1});
    			}
    		}
    	}
    }
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		for(int k=0;k<h;k++){
    			for(int x=0;x<w;x++){
    				if(s[i][j]=='.'&&s[k][x]=='.')ans=max(ans,dis[i][j][k][x]);
    				
    			}
    		}
    	}
    }
    cout << ans<<endl;
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  bool flag1=0,flag2=0;
  if(S.at(0)=='0'&&S.at(1)!='0')
    flag1=1;
  else if(S.at(0)=='1'){
    if('0'<=S.at(1)&&S.at(1)<='2')
      flag1=1;
    }
  if(S.at(2)=='0'&&S.at(3)!='0')
    flag2=1;
  else if(S.at(2)=='1'){
    if('0'<=S.at(3)&&S.at(3)<='2')
      flag2=1;
    }
  if(flag1&&flag2)
    cout<<"AMBIGUOUS"<<endl;
  else if(flag1&&!flag2)
    cout<<"MMYY"<<endl;
  else if(flag2)
    cout<<"YYMM"<<endl;
  else
    cout<<"NA"<<endl;
  }

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define N 310
typedef long long ll;
ll n, m, k;
class G {
public:
	ll g[N][N];
	void init() {
		for (int i = 0; i < N; i++)for (int j = 0; j < N; j++) {
			if (i == 0) { g[i][j] = 0; continue; }
			if (j == 0) { g[i][j] = 1; continue; }
			g[i][j] = g[i - 1][j] + g[i][j - 1]*i;
			g[i][j] %= m;
		}
	}
	ll qry(ll n, ll x) {
		return g[n][x];
	}
}; G g;
ll f[N][N];
int main() {
	cin >> n >> k >> m;
	g.init();
	for (int i = 0; i < N; i++)for (int j = 0; j < N; j++)f[i][j] = 0; f[0][0] = 1;
	for (int i = 0; i < N - 1; i++)for (int j = 0; j < N; j++) {
		for (int r = 0; r + j < N; r++) {
			f[i + 1][r + j] = (f[i + 1][r + j] + f[i][j] * g.qry(j+1, r))%m;
		}
	}
	cout << f[k][n] << endl;
	return 0;
}

Measured memory_bytes: 1792
# 2019/08/29

n,a,b,c,d=map(int,input().split())

s=input()
if c<d:
    flag=True
else:
    flag=False

if flag:
    for i in range(a,d-1):
        if s[i]==s[i+1]=='#':
            print('No')
            exit()
else:
    for i in range(b-1,d):
        if s[i-1]==s[i]==s[i+1]=='.':
            print('Yes')
            exit()

print('Yes' if flag else 'No')

Measured memory_bytes: 3572
S = list(input())
i, j = 0, len(S) - 1
ans = 0

while i < j:
    if S[i] == S[j]:
        i += 1
        j -= 1

    elif S[i] == 'x':
        i += 1
        ans += 1

    elif S[j] == 'x':
        j -= 1
        ans += 1

    else:
        print('-1')
        break

else:
    print(ans)


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

const int NUM = 1e6;

int main(){
    int n;
    ll sum=0, ans=0;
    
    cin>> n;

    map<int, ll> a;
    for(int i=0; i<n; i++){
        ll input;
        cin>>input;
        a[input]++;
        sum+=input;
    }
   // cout<<sum<<endl;
    int q;
    cin>>q;
    for(int i=0; i<q; i++){
        ll b, c;
        cin>> b >>c;

        sum-=a[b]*b;
        sum+=a[b]*c;
        if(c!=b){
            a[c]+=a[b];        
            a[b]=0;
        }

        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 9552
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define is insert
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
//set<int, Comparator> S;
int H,W;
vector<string> S;
bool road(int x,int y){
    return S[y][x]=='.';
}
int bfs(int x,int y,int p, int q) {
    if (!(road(x,y)&&road(p,q)))return 0;
    vector<int> V;
    V.resize(H*W,-1);
    V[x+y*W]=0;
    queue<int> Q;
    Q.push(x+y*W);
    int vx[]={0,0,1,-1},vy[]={1,-1,0,0};
    int m,n;
    while(!Q.empty()){
        int v=Q.front();Q.pop();
        int s=v%W,t=v/W;
        if (s==p&&t==q)break;
        for(int i=0;i<4;++i) {
            m=s+vx[i];n=t+vy[i];
            if (m>=0&&m<W&&n>=0&&n<H&&road(m,n)&&(V[m+n*W]==-1||V[m+n*W]>V[v]+1)) {
                V[m+n*W]=V[v]+1;
                Q.push(m+n*W);
            }
        }
    }
    return V[p+q*W];
}
int main() {
    cin >> H >> W;
    S.resize(H);
    REP(i,H)
        cin>>S[i];
    int ans=0;
    REP(x,W)
        REP(y,H)
            REP(p,W)
                REP(q,H)
                    ans=max(bfs(x,y,p,q),ans);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

#define SUMI(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SUMD(obj) accumulate((obj).begin(), (obj).end(), 0.)
#define SUML(obj) accumulate((obj).begin(), (obj).end(), 0LL)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll HMOD = (ll)1e9 + 7;
const ll LMOD = 998244353;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
const long double EPS = 1e-10;

void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

int main() {
	string S; cin >> S;
	int N = S.size();
	S = "2" + S;
	
	if(S[N] == '1' || S[1] != '1'){
		cout << -1 << endl;
		return 0;
	}

	for (int i = 1; i <= N / 2; ++i) {
		if(S[i] != S[N - i]){
			cout << -1 << endl;
			return 0;
		}
	}

	int u = 1, v = 1;
	for (; v < N; ++v) {
		if(S[v] == '1'){
			cout << u << " " << v + 1 << endl;
			u = v + 1;
		}
		else{
			cout << u << " " << v + 1 << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int h,w;
cin >> h >> w;
char a[h][w];
vector<int> h_co,w_co;
int h_count;
int w_count;
REP(i,h) {
  h_count = 0;
  REP(j,w) {
    cin >> a[i][j];
    if(a[i][j]=='.') h_count++;
  }
  if(h_count!=w) h_co.push_back(i);
}
REP(i,w) {
  w_count = 0;
  REP(j,h) {
    if(a[j][i]=='.') w_count++;
  }
  if(w_count!=h) w_co.push_back(i);
}
for(int i:h_co) {
  for(int j:w_co) {
    cout << a[i][j];
  }
  cout << endl;
}
return 0;
}


Measured memory_bytes: 256
// abc133_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, D;
    cin >> N >> D;
    vector<vector<int>> C;
    C.assign(N, vector<int>(D));
    REP(i, N) REP(j, D) cin >> C[i][j];

    int ans = 0;
    REP(i, N){
        REPN(j, i+1, N){
            double dd = 0;
            REP(k, D) dd += (C[i][k] - C[j][k]) * (C[i][k] - C[j][k]);
            double d = sqrt(dd);
            if (d == int(d)){
                ans++;
            }
        }
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>
#include <complex>

using int64 = long long;
using uint64 = unsigned long long;

using namespace std;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

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

    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;

    return 0;
}



Measured memory_bytes: 256
// Problem Link: 
// Tutorial Link: 

#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define repb(i,a,b) for(LL i=a;i>=b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

LL n, a[200005];

int main()
{
    FIO;
    LL x = 0;
    cin >> n;
    rep(i,1,n) cin >> a[i];
    rep(i,1,n) x = a[i] ^ x;
    rep(i,1,n) cout << (x ^ a[i]) << " ";
}

Measured memory_bytes: 5212
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 401;
const ll INF = 1e18;
ll dp[MAXN][MAXN], a[MAXN], sum[MAXN];
int main()
{
    int n; scanf("%d", &n); 
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            dp[i][j] = INF;
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), sum[i] = sum[i - 1] + a[i], dp[i][i] = 0;
    for (int len = 2; len <= n; len++)
        for (int i = 1; i + len - 1 <= n; i++)
        {
            int j = i + len - 1;
            for (int k = i; k + 1 <= j; k++) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum[j] - sum[i - 1]);
        }
    printf("%lld\n", dp[1][n]);
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

template <int mod>
struct ModInt {
  int x;
  ModInt(): x(0) {}
  ModInt(long long a) { x = a % mod; if (x < 0) x += mod; }
  ModInt &operator+=(ModInt that) { x = (x + that.x) % mod; return *this; }
  ModInt &operator-=(ModInt that) { x = (x + mod - that.x) % mod; return *this; }
  ModInt &operator*=(ModInt that) { x = (long long) x * that.x % mod; return *this; }
  ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
  ModInt inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return ModInt(u);
  }
  #define op(o, p) ModInt operator o(ModInt that) { return ModInt(*this) p that; }
    op(+, +=) op(-, -=) op(*, *=) op(/, /=)
  #undef op
  friend ostream& operator<<(ostream &os, ModInt m) { return os << m.x; }
};

using mint = ModInt<998244353>;

mint dp[3030][3030][2];

void solve() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  dp[a][b][0] = 1;
  repic(i, a, c) repic(j, b, d) rep(k, 2) {
    if (k == 0) {
      dp[i+1][j][1] += dp[i][j][k] * j;
      dp[i][j+1][0] += dp[i][j][k] * i;
    }
    if (k == 1) {
      dp[i+1][j][1] += dp[i][j][k] * j;
      dp[i][j+1][0] += dp[i][j][k];
    }
  }
  mint ans = 0;
  rep(k, 2) ans += dp[c][d][k];
  cout << ans << endl;
}


Measured memory_bytes: 75372
#include <stdio.h>
#include <string.h>

int main( void )
{
  int n, c;

  char S[100010];
  scanf("%s", S);

  n = strlen(S);

  for(int i = 0; i < n; i++)
  {
      if(i % 2 == 0)
      {
          if(S[i] != '0') c++;
      }
      else
      {
          if(S[i] != '1') c++;
      }
  }

  if(c > n - c) c = n - c;

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

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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


	int wc = 0;
	int lc = 0;
	for (int i = 0; i < x.size(); i++)
	{
		if (x[i] == 'o')
			wc++;
		else
			lc++;
	}

	if (wc >= 8)
	{
		cout << "YES" << endl;
	}
	else if (lc >= 8)
	{
		cout << "NO" << endl;
	}
	else
	{
		cout << "YES" << endl;
	}



	return 0;	
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		int n,m;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		if(n == m){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> W(N);
    rep (i, N) {
        cin >> W[i];
    }

    ll ans = INF;
    rep (i, N) {
        ll a = 0;
        ll b = 0;
        for (ll j = 0; j < i; j++) {
            a += W[j];
        }
        for (ll j = i; j < N; j++) {
            b += W[j];
        }
        ans = min(ans, abs(a-b));
    }

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

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
const int MAXN = 1E5+5;
const int LOGN = 18;
int array[MAXN]{ };
int    dp[MAXN]{ };
int spars[LOGN][MAXN]{ };
//  spars[I][J] = Farthest Child of [J] after [1<<I] days
int A, B, D, N, Q;

void solve()
{
	dp[1] = 0;
	int head=1, tail=1;
	while(head <= N)
	{	// Init Sparse Table
		if(tail < head)
			tail = head;
		bool end = (array[tail]-array[head] > D);
		spars[0][head] = tail-end;
		while((tail <= N) && (array[tail]-array[head] <= D))
		{
			dp[tail] = std::min(dp[head]+1, dp[tail]);
			spars[0][head] = tail;
			++tail;
		}
		++head;
	}
}

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i)
	{
		scanf("%d", &array[i]);
		dp[i] = MAXN;
	}
	scanf(" %d%d", &D, &Q);
	array[N+1] = array[N]+D+1;
	solve();
	for(int day = 1; day < LOGN; ++day) // f^(2^day)(x)
		for(int hot = 1; hot <= N; ++hot) // Hotel ID
			spars[day][hot] = spars[day-1][spars[day-1][hot]];
	while(Q --> 0)
	{
		scanf(" %d%d", &A, &B);
		if(A > B) std::swap(A, B);
		int cnt, ret=0;
		do {
			cnt = 0;
			while((cnt+1 < LOGN) && (spars[cnt+1][A] < B)) ++cnt;
			A = spars[cnt][A];
			ret += 1<<cnt;
		} while(A < B);
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define rep(i,m,n) for(int i=m; i<n; i++)
typedef long long ll;
const double PI = acos(-1);
int main() {
    double n; cin>>n;
    cout<<fixed<<setprecision(10)<<2*PI*n<<endl;
}

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

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

using namespace std;

int main(){
  int a,b; cin >> a >> b;
  int n; cin >> n;
  int s,f;
  int t[1005]={};
  t[a]++; t[b]--;
  for(int i=0;i<n;++i){
    cin >> s >> f;
    t[s]++; t[f]--;
  }
  int ans=0,flag=0;
  for(int i=0;i<=1000;++i) t[i+1]+=t[i];
  for(int i=a;i<=b;++i){
    if(t[i]>1)ans=1;
  }
  cout << ans << endl;
  
  return 0;
}



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

int main(){
	int n[100] = {};
	int t;
	while(cin >> t){
		n[t - 1]++;
	}
	int m = 0;
	for(int i = 0; i < 100; i++){
		m = max(m,n[i]);
	}
	for(int i = 0; i < 100; i++){
		if(n[i] == m){
			cout << i + 1 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3088
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	int ans = 0, n;
	string s;
	cin >> n >> s;
	int left = 0, right = s.size() - 1;
	while (left < right) {
		while (s[left] == 'R' && left < right)left++;
		while (s[right] == 'W' && left < right)right--;
		if (left >= right)break;
		ans++;
		//printf("l:%d r:%d\n", left, right);
		left++, right--;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3852
N, K, Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]

nes = Q-(K-1)

sanka = [0 for _ in range(N)]

for a in A:
	sanka[a-1] += 1

for i in range(N):
	if sanka[i] >= nes:
		print("Yes")
	else:
		print("No")

Measured memory_bytes: 8640
import java.util.Scanner;


public class Main {
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		int a= scanner.nextInt();
		int b= scanner.nextInt();
		System.out.println(Integer.toString(a*b)+" "+Integer.toString(a*2+b*2));
		scanner.close();
	}
}

Measured memory_bytes: 17160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = N / 2;
		if (N % 2 == 0) {
			ans--;
		}
		System.out.println(ans);
	}

}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[10005][10005];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  ll n=s.size();
  set<char> st;
  st.insert(s[0]);
  if(st.count(s[1])){
    cout<<1<<" "<<2<<endl;
    return 0;
  }
  st.insert(s[1]);
  irep(i,2,n){
    if(st.count(s[i])){
      cout<<i-1<<" "<<i+1<<endl;
      return 0;
    }
    st.insert(s[i]);
    st.erase(s[i-2]);
  }
  
  cout<<-1<<" "<<-1<<endl;
  
}

Measured memory_bytes: 512
using System;
using System.IO;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve());
        Console.Out.Flush();
    }
    static object Solve() {
        var N = int.Parse(Console.ReadLine());
        var a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = int.Parse(Console.ReadLine());
        }
        return a.Distinct().Count();
    }
}

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

using namespace std;

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

    int n;
    cin >> n;
    int grid[n][3], dp[n][3];
    for(int i = 0; i < n; i++)
        for(int j = 0; j < 3; j++)
            cin >> grid[i][j];
    
    for(int i = 0; i < 3; i++) dp[0][i] = grid[0][i];
    for(int i = 1; i < n; i++)
        for(int j = 0; j < 3; j++)
            dp[i][j] = grid[i][j] + max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]);

    cout << *max_element(dp[n - 1], dp[n - 1] + 3) << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string n;
  string m;
  cin >> n;
  cin >> m;
  int a=n.size();
  for(int i=0;i<100;i++){
    if(n==m){
      cout << "Yes";
      break;
    }
    int b=n.at(0);
    for(int j=0;j<a-1;j++){
      n.at(j)=n.at(j+1);
    }
    n.at(a-1)=b;
  }
  if(n!=m){
    cout << "No";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> have[1000010];
int arr[200010];
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i];
		have[arr[i]].push_back(i);
	}
	int answer = 0;
	for (int i = 1; i <= n; ++i) {
		bool ok = true;
		for (int j = 1; j * j <= arr[i]; ++j) {
			if (arr[i] % j == 0) {
				if (have[j].size() > 0) {
					//cout << j << '\n';
					if (j != arr[i]) {
						ok = false;
						break;
					} else if (j == arr[i] and have[j].size() >= 2) {
						ok = false;
						break;
					}
					
				}
				if (arr[i] % (arr[i] / j) == 0) {
					if (have[arr[i] / j].size() > 0) {
					//	cout << arr[i] / j << '\n';
						if (arr[i] / j != arr[i]) {
							ok = false;
							break;
						} else if (arr[i] / j == arr[i] and have[arr[i] / j].size() >= 2) {
							ok = false;
							break;
						}
						
					}
				}

			}
		}
		if (ok == true) {
			++answer;
		}
	}
	cout << answer;
}

Measured memory_bytes: 34044
#不備有
g=gets.split
x=[0,2,5,3]
y=[0,4,5,1]
n=gets.split
m=->r,d{r.map{|i|n[i]}.rotate(d).map.with_index{|v,i|n[r[i]]=v}}
m[rand(2)>0?x:y,rand(2)>0?1:-1]until g[0..1]==n[0..1]
puts g[2]==n[2]?:Yes: :No

Measured memory_bytes: 6140
#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define st first
#define nd second
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	ll d;
	cin>>n>>d;
	int cnt = 0;
	for(int i=0; i<n; ++i) {
		ll x, y;
		cin>>x>>y;
		ll dist = x*x + y*y;
		if(dist <= d*d) cnt++;
	}
	cout<<cnt;
}


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

int main() {
  string s;
  cin >> s;
  bool ok = false;
  if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ok = true;
  if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) ok = true;
  if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) ok = true;
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3552
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define allr(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

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

bool p(int n){
    return ((n&(n-1))==0);

}
void solve(){
    
    int a;
  	cin >> a;
    int ans = a+a*a+a*a*a;
    cout << ans << endl;
   
} 

signed main() 
{   
    IOS;
    int t = 1;
    // cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define __ <<' '<<
#define ___ <<' '
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {IoSetup() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout <<fixed<<setprecision(12);
    cerr <<fixed<<setprecision(12);
}}IoSetup;

using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int SMOD = 1000000007;
constexpr int NMOD = 998244353;
constexpr int dx[]={1,0,-1,0,1,1,-1,-1};
constexpr int dy[]={0,1,0,-1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a<b?a=b,true:false);}
template<class T>bool chmin(T &a, const T &b){return(a>b?a=b,true:false);}
inline int qp(int a,ll b,int mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}



signed main() {

    int n, k;
    cin >> n >> k;
    double ans = 0.0;

    for(int i = 1; i <= n; i++) {
        double t = 1.0/n;
        int s = i;
        while(s < k) {
            s *= 2;
            t /= 2;
        }
        ans += t;
    }

    cout << ans << endl;

  
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int H, N;

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

  cin >> H >> N;
  int sm = 0;
  int a;
  rep(i, N) {
    cin >> a;
    sm+=a;
  }
  string ans = H<=sm?"Yes":"No";
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
while True:

    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for k in range(W):
            if i == 0 or i == H-1 or k == 0 or k == W-1:
                print("#",end = "")
            else:
                print(".",end = "")
        print()

    print() 


Measured memory_bytes: 7004
// cpp219 - the 712534
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define fs first
#define sc second
#define mp make_pair
using namespace std;
const ll base = 7;
const ll N = 2e3 + 9;
const ll mod = 1e9 + 7;
typedef pair<ll,ll> LL;

ll i,j,l,ans,n;
int main(){
    ios_base::sync_with_stdio(false);
   	cin.tie(0); cout.tie(0);
    //freopen("test.inp", "r", stdin);
    cin>>n;
    for (i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(l=1;l<=n;l++) ans += __gcd(__gcd(i,j),l);
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef pair<int,int>pi;
vector<pi>adj[14];
int dd[14];
int dist[14];
#define inf 1000000000
int s_p(int st,int ed)
{
    for(int i=0;i<14;i++)dist[i]=inf;
    priority_queue<pi,vector<pi>,greater<pi> >q;
    q.push({0,st});
    dist[st]=0;
    while(!q.empty())
    {

        int top=q.top().second;
        int cost=q.top().first;
        q.pop();
        if(top==ed)break;
        for(int i=0;i<adj[top].size();i++)
        {
            int chi=adj[top][i].second;
            int ct=adj[top][i].first;
            if(ct+cost<dist[chi])
            {
                dist[chi]=ct+cost;
                q.push({dist[chi],chi});
            }
        }
    }
    return dist[ed];
}

int main()
{
    int n,m;cin>>n>>m;
    for(int i=0;i<10;i++)
    {
        for(int j=0;j<10;j++)
        {
            int a;cin>>a;
            adj[i].pb({a,j});
        }
    }
    for(int i=9;i>=0;i--)
    {
        int d=s_p(i,1);
        dd[i]=d;
//        cout<<"dis from "<<i<<" "<<dd[i]<<endl;
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            int a;cin>>a;
            if(a!=-1)ans+=dd[a];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            string[] input = Console.ReadLine().Split(' ');

            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            int d = int.Parse(input[3]);

            if (a + b == c + d)
            {
                Console.WriteLine("Balanced");
            }
            else if (a + b > c + d)
            {
                Console.WriteLine("Left");
            }
            else if (a + b < c + d)
            {
                Console.WriteLine("Right");
            }
        }
    }
}

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

using namespace std;

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


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

signed main()
{   
    gearup;
    int n; cin >> n;
    int n2 = (n/100);
    int n4 = n % 100;
    if(1 <= n2 && n2 <= 12){
        if(n4 <= 12 && n4 >= 1) cout <<"AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }else{
        if(n4 <= 12 && n4 >= 1) cout <<"YYMM" <<endl;
        else cout <<"NA"<< endl;
    }
    

}

Measured memory_bytes: 256
typedef long long ll;
#include <iostream>
#include <cstring>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <set>

using namespace std;

int memo[16][16];

int solve(int a, int b){
  if(memo[a][b] != -1) return memo[a][b];

  if(a < 2 && b < 2) {
    memo[a][b] = 0;
  } else{
    int win = 0;
    for(int i = 2; i <= a; i += 2){
      if(!solve(a - i, b + i / 2)) win = 1;
    }
    for(int i = 2; i <= b; i += 2){
      if(!solve(a + i / 2, b - i)) win = 1;
    }
    memo[a][b] = win;
  }

  return memo[a][b];
}


int main(){
  /*
  memset(memo, -1, sizeof(memo));
  REP(i,11){
    if(i == 0){ REP(j,11) printf("%2d ", j); puts(""); }
    REP(j,11) printf(" %c ", solve(i, j) == 1 ? 'A' : 'B');
    puts("");
  }
  */

  ll a, b; cin >> a >> b;
  puts(max(a, b) - min(a, b) <= 1 ? "Brown" : "Alice");
  return 0;
}


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

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<int>> a(H,vector<int>(W));
  for(int i=0;i<H;++i){
    for(int j=0;j<W;++j){
      cin>>a.at(i).at(j);
    }
  }
  vector<vector<int>> b(H,vector<int>(W));
  b=a;
  int sum=0;

  for(int i=0;i<H;++i){
    for(int j=0;j<W-1;++j){
      if(b.at(i).at(j)%2!=0 && b.at(i).at(j+1)%2!=0){
        --b.at(i).at(j);
        ++b.at(i).at(j+1);
        ++j;
        ++sum;
      }
      else if(b.at(i).at(j)%2!=0 && b.at(i).at(j+1)%2==0){
        --b.at(i).at(j);
        ++b.at(i).at(j+1);
        ++sum;
      }
    }
  }

  for(int i=0;i<H-1;++i){
    if(b.at(i).at(W-1)%2!=0 && b.at(i+1).at(W-1)%2!=0){
      --b.at(i).at(W-1);
      ++b.at(i+1).at(W-1);
      ++i;
      ++sum;
    }
    else if(b.at(i).at(W-1)%2!=0 && b.at(i+1).at(W-1)%2==0){
      --b.at(i).at(W-1);
      ++b.at(i+1).at(W-1);
      ++sum;
    }
  }

  cout<<sum<<endl;


  for(int i=0;i<H;++i){
    for(int j=0;j<W-1;++j){
      if(a.at(i).at(j)%2!=0 && a.at(i).at(j+1)%2!=0){
        --a.at(i).at(j);
        ++a.at(i).at(j+1);
        cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
        ++j;
      }
      else if(a.at(i).at(j)%2!=0 && a.at(i).at(j+1)%2==0){
        --a.at(i).at(j);
        ++a.at(i).at(j+1);
        cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
      }
    }
  }

  for(int i=0;i<H-1;++i){
    if(a.at(i).at(W-1)%2!=0 && a.at(i+1).at(W-1)%2!=0){
      --a.at(i).at(W-1);
      ++a.at(i+1).at(W-1);
      cout<<i+1<<" "<<W<<" "<<i+2<<" "<<W<<endl;
      ++i;
    }
    else if(a.at(i).at(W-1)%2!=0 && a.at(i+1).at(W-1)%2==0){
      --a.at(i).at(W-1);
      ++a.at(i+1).at(W-1);
      cout<<i+1<<" "<<W<<" "<<i+2<<" "<<W<<endl;
    }
  }

}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;
 
int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;

    vector<int> cnt(26);
    for(int i=0;i<N;i++){
        cnt[S[i] - 'a']++;
    }

    ll ans = 1;
    for(int i=0;i<26;i++){
        ans = (ans * (cnt[i] + 1)) % MOD;
    }
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<math.h>


int main() {
	int A, B;
	

	scanf("%d %d", &A, &B);

	
	if (A <= B) {
		for (int i = 0; i < B; i++) {
			printf("%d", A);
		}
	}
	else
	{
		for (int i = 0; i < A; i++) {
			printf("%d", B);
		}
	}

	return 0;
	
}

Measured memory_bytes: 128
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, A: "List[int]"):
    s = sum(A)
    cums = [0]
    for v in A:
        cums.append(cums[-1] + v)

    ret = float('inf')
    i, j, k = 1, 2, 3
    while j < N - 1:
        lm = cums[j]
        while i < j - 1 and cums[i] < lm // 2:
            i += 1
        if i > 2 and abs(lm - 2 * cums[i]) > abs(lm - 2 * cums[i - 1]):
            i -= 1

        rm = cums[N] - cums[j]
        while k < N - 1 and cums[k] - cums[j] < rm // 2:
            k += 1
        if k > j + 1 and abs(rm - 2 * (cums[k] - cums[j])) > abs(rm - 2 * (cums[k - 1] - cums[j])):
            k -= 1

        a, b, c, d = cums[i], cums[j] - cums[i], cums[k] - cums[j], cums[N] - cums[k]
        tmp = max(a, b, c, d) - min(a, b, c, d)
        #print(tmp, i, j, k, ':', a, b, c, d, '\n')
        ret = min(ret, tmp)
        j += 1
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 83576
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
int main()
{
	int n,d,sum;
	int ans=0;
	cin>>n>>d;
	int x[n][d];
	rep(i,n)
		rep(j,d)
			cin>>x[i][j];
	for(int i=0;i<n-1;i++)
	{
		for(int z=i+1;z<n;z++)
		{
			sum=0;
			rep(j,d)
			sum+=abs(x[i][j]-x[z][j])*abs(x[i][j]-x[z][j]);
			int sq=sqrt(sum);
			if(sq*sq==sum)
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256