akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int n;
int dp[5000][5000];
string s;
int f(int x, int y){
    if(x < 0 || x >= y || y >= n)return 0;
    if(dp[x][y] != -1)return dp[x][y];
    int res = 1;
    if(s[x] != s[y])res = 0;
    else{
        res = f(x+1, y+1) + 1;
        res = min(res, y-x);
    }
    //cout << x << " " << y << " " << res << endl;
    return dp[x][y] = res;
}
int main(void){
    int ans = 0;
    cin >> n >> s;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dp[i][j] = -1;
        }
    }
    //f(0, 2);
    //return 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int v = f(i, j);
            ans = max(ans, v);
        }
    }
    cout << ans << endl;
}


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

 //2項係数（コピペ）
 ll nCr(int n, int r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

int main() {
   int n;
   cin>>n;
   map<string,int> S;
   rep(i,n){
       string s;
       cin>>s;
       sort(s.begin(),s.end());
       S[s]++;
   }
   ll ans=0;
   for(auto p:S){
       ans+=nCr(p.second,2);
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 11136
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),m=sc.nextInt(),x=sc.nextInt();
		List<Integer> a = new ArrayList<>();
		for(int i=0; i<m; i++) {
			a.add(sc.nextInt());
		}
		int cost1=0,cost2=0;
		for(int i=x; i<n; i++) {
			if(a.indexOf(i) != -1) cost1++;
		}
		for(int i=x; i>0; i--) {
			if(a.indexOf(i) != -1) cost2++;
		}
		System.out.println(cost1 < cost2 ? cost1:cost2);
	}
}


Measured memory_bytes: 21844
N=int(input())
H=list(map(int,input().split()))
for i in range(N-1):
    if H[i]>H[i+1]+1:
        print("No")
        break
    elif H[i]==H[i+1]+1:
        H[i]-=1
        H[i+1]+=1
else:
    print("Yes")


Measured memory_bytes: 20488
import collections
a = list(input())
b = list(input())
A = collections.Counter(a)
B = collections.Counter(b)
Alist = list(A.values())
Blist = list(B.values())
Asort = sorted(Alist)
Bsort = sorted(Blist)
if Asort == Bsort:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 12428
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define r(i,a,b) for(register int i=a;i<=b;i++)
#define ID(c) ('0'<=(c)&&(c)<='9')
#define pb push_back
using namespace std;
const ll xl=-10000000000;
const ll yl=-10000000000;
const ll xr=10000000000;
const ll yr=-10000000000;
inline int qr()
{
	int x=0,f=1;char c=getchar();
	for(;!ID(c);c=getchar()) if(c=='-') f=-1;
	for(; ID(c);c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
	return x*f;
}
int n;
int main()
{
	ll Max1=-40000000000, Max2=-40000000000;
        ll Min1=40000000000, Min2=40000000000;
        ll n;
        scanf("%lld", &n);
        ll x, y;
        for(int i=1;i<=n;i++)
		{
            x=qr();y=qr() ;
            Max1=max(abs(x-xl)+abs(y-yl), Max1);
            Min1=min(abs(x-xl)+abs(y-yl), Min1);
            Max2=max(abs(x-xr)+abs(y-yr), Max2);
            Min2=min(abs(x-xr)+abs(y-yr), Min2);
        }
        ll ans=max(Max1-Min1, Max2-Min2);
        printf("%lld\n", ans);

	return 0;
} 
	

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

int main() {   
    int x, y;
    while (true) {
        cin >> x >> y;
        if (x == 0 && y == 0) break;

        if (x > y) {
            cout << y << " " << x << endl;
        } else {
            cout << x << " " << y << endl;
        }
    }
}


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

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

int main() {
  int N,M,Z=0;
  cin>>N>>M;
  vector<int> h(N);
  for(int i=0;i<N;i++){
    cin>>h.at(i);
  }
  vector<vector<int>> G(N);
  
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  for(int i=0;i<N;i++){
    int A=0;
    for(int x:G.at(i)){
      if(h.at(x)>=h.at(i)){
        A++;
        break;
      }
    }
    if(A==0){
      Z++;
    }
  }
  cout<<Z<<endl;
}



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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int a,b; cin >> a >> b;
  cout << (a>8||b>8 ? ":(" : "Yay!") << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string>
#include <cmath>
#include <set>
using namespace std;



void solve()
{
	long long n;
	cin >> n;

	long long ans = n - 1;
	for (long long i = 1; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			long long k = n / i;

			long long temp = abs(1 - i) + abs(1 - k);
			ans = min(ans, temp);
		}
	}

	cout << ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD ll(1e9+7)
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

template< int mod >
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int) (1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

void solve() {
    using modint = ModInt<MOD>;
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    REP(i,N) cin >> A[i];

    sort(ALL(A),greater<int>());

    // 全要素が負の場合
    if (A[0] <= 0) {
        // 偶数を選ぶ場合は絶対値が最大になる様に再度reverse
        if(K%2==0) reverse(ALL(A));
        modint ans(1);
        REP(i,K) ans*=(modint(A[i]));
        cout << ans << endl;
        return;
    }

    modint now(1);

    int il = 0, ir = N-2;

    if(K%2==1) {
        now *= modint (A[0]);
        K--;
        il++;
    }

    // ここでAは偶数になる。
    REP (i,K/2) {
        ll a = ll(A[il])*ll(A[il+1]);
        ll b = ll(A[ir])*ll(A[ir+1]);
        now *= modint(max(a,b)%MOD);
        if(max(a,b) == a) il+=2;
        else ir-=2;
    }

    cout << now << endl;
}

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

Measured memory_bytes: 4008
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	long long ans=0;
	long long k=sqrt(n);
	for(int i=k;i>=1;i--)
	{
		if(n%i==0)
		{
			ans=i+n/i;
			break;
		}
	}
	ans-=2;
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 1000000000000000005
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
int main(){
	int n,k;
	while(~getII(n,k)){
		F(i,0,n){
			int aa;
			getI(aa);
		}
		n--,k--;
		if(n%k==0) printf("%d\n",n/k);
		else printf("%d\n",n/k+1);
	}
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

G g(500);

int main(){

    map<ll, ll>mp;
    for(ll i = 1, j = 0; j < NUM;){
        mp[j] = i;
        j += i;
        i++;
    }
    ll N;
    cin >> N;
    N = mp[N];
    if(N == 0){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    cout << N << endl;
    ll nxt = 1;
    rep1(i, N){
        for(ll j = i + 1; j <= N; j++){
            g_undir(g, i, j, nxt);
            nxt++;
        }
    }
    rep1(i, N){
        cout << g[i].size() << " ";
        rep(j, g[i].size()){
            cout << g[i][j].second;
            if(j + 1 == g[i].size())cout << endl;
            else cout << " ";
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 5120
#include<iostream> 
using namespace std;
int main(){
	long long  a,b;
  	cin >> a >> b;
  	int dem = 0;
  	for(int i=1; i<=a; ++i){
    	long long x,y;
      	cin >> x >> y;
      	if(x*x + y*y <= b*b){
          dem++;
        }  
    }
  	cout<<dem;
}  


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	vector<int>c[100001];
	bool e[100001]={0};
	int x=n;
	int y[100001];
	vector<int>z;
	int a,b;
	for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        c[a].push_back(b);
        c[b].push_back(a);
    }
    z.push_back(1);
    e[1]=1;
    x--;
    for(int o=0;o<z.size();o++)
    {
        for(int i=0;i<c[z[o]].size();i++)
        {
            if(!e[c[z[o]][i]])
            {
                e[c[z[o]][i]]=1;
                y[c[z[o]][i]]=z[o];
                z.push_back(c[z[o]][i]);
                x--;
            }
        }
    }
    if(x)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
        for(int i=2;i<=n;i++)
        {
            cout<<y[i]<<endl;
        }
    }
	return 0;
}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

    ll n,a[3001],ans=0;
    cin >> n;
    rep(i,n){
        cin >> a[i];
        ans += a[i] - 1;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
from functools import reduce

def main():
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10

    # 一文字のみを読み込み
    # s = input().rstrip().split(' ')
    
    # スペース区切りで標準入力を配列として読み込み
    # s = input().rstrip().split(' ')

    # 位置文字ずつ標準入力を配列として読み込み
    # s = list(input().rstrip())
    N = int(input().rstrip())
    K = int(input().rstrip())
    X = int(input().rstrip())
    Y = int(input().rstrip())
    ans = 0
    if(N>K):
        ans = K*X + (N-K)*Y
    else:
        ans = N*X
    print(ans)   
   
if __name__ == '__main__':
    main()


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

#define int long long
typedef pair<int, int> P;

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

/*
#define cin ifs
#define cout ofs
ifstream ifs("in.txt");
ofstream ofs("out.txt");
//*/

int N, L, Q;
int x[110000], a[110000], b[110000];
int dp[110000][30];

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    x[N] = 1e11;
    cin >> L >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < N; i++) {
        dp[i][0] = upper_bound(x, x + N, x[i] + L) - x - 1;
    }
    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < N; j++) {
            dp[j][i + 1] = dp[dp[j][i]][i];
        }
    }
    for (int i = 0; i < Q; i++) {
        if (a[i] > b[i]) swap(a[i], b[i]);
        a[i]--; b[i]--;
        if (a[i] == b[i]) {
            cout << 0 << endl;
            continue;
        }
        int ans = 0;
        for (int j = 20; j >= 0; j--) {
            if (dp[a[i]][j] < b[i]) {
                ans += 1 << j;
                a[i] = dp[a[i]][j];
            }
        }
        if (a[i] < b[i]) ans++;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 29056
#include <iostream>
#include <string>
#include <cstring>
#include <cctype>
#include <map>
using namespace std;

int def['z'];
typedef pair<char, int> VAR;
map<VAR, int> list;
string s;


typedef string::const_iterator State;
class ParseError {};
class NotDefined {};

// beginがexpectedを指していたらbeginを一つ進める。
void consume(State &begin, char expected) {
	if (*begin == expected) {
		begin++;
	} else {
		cerr << "Expected '" << expected << "' but got '" << *begin << "'" << endl;
		cerr << "Rest string is '";
		while (*begin) {
			cerr << *begin++;
		}
		cerr << "'" << endl;
		throw ParseError();
	}
}

int number(State &begin) {
	int ret = 0;
	while (isdigit(*begin)) ret = ret*10 + *begin++ - '0';
	return ret;
}

int expression(State &begin) {
	if(isdigit(*begin)) return number(begin);
	VAR ret;
	ret.first = *begin++;
	consume(begin, '[');
	ret.second = expression(begin);
	consume(begin, ']');
	if(def[ret.first] <= ret.second) throw NotDefined();
	if(list.find(ret) == list.end()) throw NotDefined();
	return list[ret];
}

void assignment(State &begin){
	VAR ret;
	ret.first = *begin++;
	consume(begin, '[');
	ret.second = expression(begin);
	consume(begin, ']');
	if(def[ret.first] <= ret.second) throw NotDefined();
	consume(begin, '=');
	int ret2 = expression(begin);
	list[ret] = ret2;
}

void declaration(State &begin){
	char name = *begin++;
	consume(begin, '[');
	int ret = number(begin);
	consume(begin, ']');
	def[name] = ret;
}

void program(State &begin){
	if(s.find('=') != string::npos) assignment(begin);
	else declaration(begin);
}

int main(void) {
	while(getline(cin, s), s != ".") {
		int l = 1, f = 0;
		list.clear();
		memset(def, 0, sizeof(def));
		do{
			if(f) continue;
			State begin = s.begin();
			try{
				program(begin);
			}catch(NotDefined a){
				cout << l << endl;
				f = 1;
			}
			l ++;
		}while(getline(cin, s), s != ".");
		if(!f) cout << "0" << endl;
	}
	return 0;
}

Measured memory_bytes: 1304
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,k;
  cin>>n>>k;
  long long a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  long long dp[n+1];
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(long int i=2;i<n;i++)
  {
    dp[i]=INT_MAX;
    for(long int j=1;j<=k;j++)
    {
      if((i-j)>=0)
      {
        dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
      }
    }
   }
     cout<<dp[n-1]<<"\n";
        
  
}


Measured memory_bytes: 1792
fn pop_count(mut n: usize) -> usize {
    let mut res = 0;
    while n > 0 {
        res += 1 & n;
        n >>= 1;
    }
    res
}

fn solve() {
    let mut n = read();
    let origin = n;
    let mut ps = vec![];
    let mut d = 2;
    while d * d <= n {
        if n % d == 0 {
            ps.push(d);
            while n % d == 0 {
                n /= d;
            }
        }
        d += 1;
    }
    if n != 1 {
        ps.push(n);
    }
    let s = ps.len();
    let mut ans = 0;
    for b in 1..(1 << s) {
        let c = pop_count(b);
        let mut mul = 1;
        for i in 0..s {
            if (b >> i) & 1 == 1 {
                mul *= ps[i];
            }
        }
        if c % 2 == 0 {
            ans -= origin / mul;
        } else {
            ans += origin / mul;
        }
    }
    ans = origin - ans;
    println!("{}", ans);
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Ord, Ordering, PartialOrd};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;
const INF: usize = 100_000_000_000;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========



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

int main()
{
    int a,b;
    cin >> a >> b;
    if(a == b){
        cout << "Draw" << endl;
    }else if(b !=1 && (a == 1 || a > b)){
        cout << "Alice" << endl;
    }else{
        cout << "Bob" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,dp[1000005][2];
int a[10000005];
bool dfs(int k,int t){
	if(dp[k][t]>=0)return dp[k][t] ;
	int ans=0;
	for(int i=1;i<=n;i++)
		if(k>=a[i])ans|=!dfs(k-a[i],!t);
	return dp[k][t]=ans;
}
int main(){
	memset(dp,-1,sizeof(dp));
	scanf("%d%d",&n,&k);
	for(int i=1;i<= n;i++)
		scanf("%d",&a[i]);
	if(dfs(k,0))puts("First");
	else puts("Second");
}

Measured memory_bytes: 12928
s = input()
q = int(input())
for i in range(q):
    m = list(map(str,input().split()))
    if m[0] == "print":
        print(s[int(m[1]):int(m[2])+1])
    elif m[0] == "reverse":
        sr = s[int(m[1]):int(m[2])+1]
        sr = sr[::-1]
        s1 = s[:int(m[1])]
        s2 = s[int(m[2])+1:]
        s = s1 + sr + s2
        #print(s,s1,sr,s2)
    elif m[0] == "replace":
        s1 = s[:int(m[1])]
        s2 = s[int(m[2])+1:]
        s = s1 + m[3] + s2
        #print(s)


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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2]) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> l(N);
  for(int i=0;i<N;i++){
    cin >> l.at(i);
  }
  sort(l.begin(),l.end(),greater<int>());
  int ans=0;
  for(int i=0;i<K;i++){
    ans+=l.at(i);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define minus(a) memset(a, -1, sizeof a)
template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

typedef pair<int, int> pii;

int N, C;
int S[11][11];

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

set<pii> vis;
bool has_zero;

int dfs(int i, int j, int x) {
  int ret = 1;
  rep(k, 6) {
    int ni = i + dy[k], nj = j + dx[k];
    if(!in_range(ni, nj, N, N)) continue;
    if(S[ni][nj] == 0) has_zero = 1;
    if(S[ni][nj] != x) continue;
    if(vis.count({ni, nj})) continue;
    vis.insert({ni, nj});
    ret += dfs(ni, nj, x);
  }
  return ret;
}

int main() {

  for(;cin >> N >> C && (N | C);) {
    minus(S);
    rep(i, N) rep(j, i+1) cin >> S[i][j];
    vector<pii> zpos;
    rep(i, N) rep(j, N) {
      if(S[i][j] == 0)
        zpos.push_back({i, j});
    }

    int ans = std::numeric_limits<int>::min();

    rep(k, zpos.size()) {
      int zy = zpos[k].first, zx = zpos[k].second;
      S[zy][zx] = C;
      vis.clear();
      vis.insert({zy, zx});
      int r = 0;

      has_zero = 0;
      int rr = dfs(zy, zx, C);
      if(!has_zero) r -= rr;

      rep(i, N) rep(j, N) {
        if(S[i][j] == -1) continue;
        if(S[i][j] == 0) continue;
        if(vis.count({i, j})) continue;
        vis.insert({i, j});
        has_zero = 0;
        int rr = dfs(i, j, S[i][j]);
        if(!has_zero) r += rr;
      }

      ans = max(r, ans);
      S[zy][zx] = 0;
    }
    cout << ans << endl;
  }

  return 0;
}

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


int main(){
    int N, M, H[100010];
    bool isNice[100010];
    cin >> N >> M;
    for (int i = 0; i < N; ++i){
        cin >> H[i];
        isNice[i] = true;
    }

    for (int j = 0; j < M; ++j){
        int a,b;
        cin >> a >> b;
        if (H[a-1] > H[b-1]){
            isNice[b-1] = false;
        }else if(H[a-1] == H[b-1]){
            isNice[a-1] = false;
            isNice[b-1] = false;
        }else{
            isNice[a-1] = false;
        }
    }
    
    int res = N;
    for (int i = 0; i < N; ++i){
        if (!isNice[i]) res--;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4096
#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(){
    ll n;
    cin >> n;
    vector <int> w(n),r(n);
    ll ww,rr;
    string s,s2;
    cin >> s;
    rep(i,n){
        s2=s[i];
        if(i==0){
            if(s2=="R"){
                r[0]=1;
                w[0]=0;
            }
            else{
                r[0]=0;
                w[0]=1;
            }
        }
        else{
            if(s2=="R"){
                r[i]=r[i-1]+1;
                w[i]=w[i-1];
            }
            else{
                r[i]=r[i-1];
                w[i]=w[i-1]+1;
            }
        }
    }

    /*rep(i,n){
        cout << w[i] << " " << r[i] << endl;
    }*/

    ll ans=n,ans2;

    rep(i,n){
        ans2=max(w[i],r[n-1]-r[i]);
        ans=min(ans,ans2);
    }

    if(w[n-1]==n){
        ans=0;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> list(n);
  for (int i=0; i<n; i++) {
    cin >> list.at(i);
  }
  sort(list.begin(),list.end());
  int ans = list.at(list.size()-1)-list.at(0);
  cout << ans << endl;
}

Measured memory_bytes: 256
program prob5
    implicit none
    integer(8)::K,S,i,j,ans
    read(*,*) K,S

    ans = 0
    do i = 0, K
        if(i <= S .and. S-i <= 2*K) then
            if(S-i <= K)then
                ans = ans + (S-i) + 1
            else
                ans = ans + 2*K - (S-i) + 1
            end if
        end if
    end do
    write(*,*) ans
    stop
end program

Measured memory_bytes: 2716
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

// ll dp[100][3000];

// int main()
// {
// 	int n, a;
// 	scanf("%d%d", &n, &a);
// 	dp[0][0] = 1;
// 	for (int i = 1; i <= n; ++i)
// 	{
// 		ll x;
// 		scanf("%lld", &x);
// 		for (int j = i; j > 0; --j)
// 			for (int k = a*n; k >= x; --k)
// 				dp[j][k] += dp[j-1][k-x];
// 	}
// 	ll ans = 0;
// 	for (int i = 1; i <= n; ++i)
// 		ans += dp[i][i*a];
// 	printf("%lld\n", ans);
// 	return 0;
// }

ll f(ll b, ll n)
{
	ll t = 0;
	while (n)
	{
		t += n%b;
		n /= b;
	}
	return t;
}

int main()
{
	ll n, s;
	scanf("%lld%lld", &n, &s);
	if (n < s)
	{
		printf("-1\n");
		return 0;
	}
	if (n == s)
	{
		printf("%lld\n", n+1);
		return 0;
	}
	ll k = sqrt(n);
	ll ans = -1;
	for (ll i = 2; i <= k; ++i)
		if (f(i, n) == s)
		{
			ans = i;
			break;
		}  
	if (ans != -1)
	{
		printf("%lld\n", ans);
		return 0;
	}
	ll t = n - s;
	for (ll a = sqrt(n-s); a >= 1; --a)
	{
		if (t % a == 0)
		{
			ll b = t / a + 1;
			if (b >= k && s-a < b && a <= s)
			{
				ans = b;
				break;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
09min 20sec WA
17min 25sec WA
"""
# 偶文字列の長さは必ず偶数。
# len(S) == 2nのとき、2i文字取り去った後が、
# (n-i)文字を二つ並べたものかどうかを調べる。
# break を入れ忘れてWAした。
# print()を消し忘れてWAした。

def main():
    S = input()
    n = len(S)//2
    answer = int()
    for i in range(1, n):
        #print(S[:(n-i)], S[(n-i):2*(n-i)])
        if S[:(n-i)] == S[(n-i):2*(n-i)]:
            answer = 2*(n-i)
            break
    print(answer)

if __name__ == "__main__":
    main()



Measured memory_bytes: 3060
import java.util.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int tako[] = new int[n];
        for (int i = 0; i < n; i++) {
            tako[i] = sc.nextInt();
        }

        int sum = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                sum += tako[i] * tako[j];
            }
        }

        System.out.println(sum);
	}
}


Measured memory_bytes: 21716
# http://tsutaj.hatenablog.com/entry/2017/03/29/204841

from fractions import gcd


class SegmentTree:
    def __init__(self, v):
        sz = len(v)

        self.n = 1
        while self.n < sz:
            self.n *= 2

        self.node = [0 for _ in range(2 * self.n - 1)]
        # 元配列 v をセグメント木で表現する
        # 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
        # セグメント木全体で必要なノード数は 2n - 1 個である

        for i in range(sz):
            self.node[i + self.n - 1] = v[i]
        # 最下段に値を入れたあとに、下の段から順番に値を入れる

        for i in range(self.n - 2, -1, -1):
            self.node[i] = gcd(self.node[2 * i + 1], self.node[2 * i + 2])
        # 値を入れるには、自分の子の 2 値を参照すれば良い

    def update(self, x, val):
        x += self.n - 1
        # 最下段のノードにアクセスする

        self.node[x] = val
        while x > 0:
            x = (x - 1) // 2
            self.node[x] = gcd(self.node[2 * x + 1], self.node[2 * x + 2])
        # 最下段のノードを更新したら、あとは親に上って更新していく

    # 要求区間 [a, b) 中の要素の最小値を答える
    # k := 自分がいるノードのインデックス
    # 対象区間は [l, r) にあたる

    def get_val(self, a, b, k, l, r):
        if r <= a or b <= l: return 0
        # 要求区間と対象区間が交わらない -> 適当に返す

        if a <= l and r <= b: return self.node[k]
        # 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う

        vl = self.get_val(a, b, 2 * k + 1, l, (l + r) // 2)
        vr = self.get_val(a, b, 2 * k + 2, (l + r) // 2, r)
        return gcd(vl, vr)
        # 要求区間が対象区間の一部を被覆 -> 子について探索を行う
        # 左側の子を vl ・ 右側の子を vr としている
        # 新しい対象区間は、現在の対象区間を半分に割ったもの


N = int(input())
a = tuple(map(int, input().split()))

st = SegmentTree(a)

g = max(
    gcd(
        st.get_val(0, drop_idx, 0, 0, st.n),
        st.get_val(drop_idx + 1, N, 0, 0, st.n)
    ) for drop_idx in range(N)
)
print(g)


Measured memory_bytes: 103520
# abc175_b.py
# https://atcoder.jp/contests/abc175

global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    # 長さごとのDictを構成
    dct = dict()
    for value in values:
        if value in dct.keys():
            dct[value] += 1
        else:
            dct[value] = 1

    log(dct)

    lengths = list(dct.keys())
    lengths.sort()

    log(f'lengths=[{lengths}]')

    # 種類の数 [4 5 4 3 3 5] -> [3 4 5] -> 3
    lenlen = len(lengths)

    # 種類数が不足する場合0をReturn
    if lenlen < 3:
        return [0]

    result = 0
    # 3つを選ぶ
    for a in range(lenlen-2):
        for b in range(a+1, lenlen-1):
            for c in range(b+1, lenlen):
                log(str(a) + ':' + str(b) + ':' + str(c))
                log('ABC')
                log(lengths[a])
                log(lengths[b])
                log(lengths[c])
                if lengths[a] + lengths[b] > lengths[c]:
                    result += dct[lengths[a]] * dct[lengths[b]] * dct[lengths[c]]

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['5', '4 4 9 7 5']
        lines_export = [5]
    if pattern == 2:
        lines_input = ['6', '4 5 4 3 3 5']
        lines_export = [8]
    if pattern == 3:
        lines_input = ['10', '9 4 6 1 9 6 10 6 6 8']
        lines_export = [39]
    if pattern == 4:
        lines_input = ['2', '1 1']
        lines_export = [0]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9240
#include<iostream>

using namespace std;

#define loop(i,a,n) for(int i = a; i < (n); i++)

int main(){

    int n;
    while(cin >> n, n){
        int ans = 0;
        loop(i,1,200){
            if(i*i > n)break;
            if(i*i == n){
                ans++;
                break;
            }
            loop(j,i,200){
                if(i*i + j*j > n)break;
                if(i*i + j*j == n){
                    ans++;
                    break;
                }
                loop(k,j,200){
                    if(i*i + j*j + k*k > n)break;
                    if(i*i + j*j + k*k == n){
                        ans++;
                        break;
                    }
                    loop(l,k,200){
                        if(i*i + j*j + k*k > n)break;
                        if(i*i + j*j + k*k + l*l == n){
                            ans++;
                            break;
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int h,w,cross;
		dowhile: do {
			h = sc.nextInt();
			if (h == 0) {
				break;
			}
			w = sc.nextInt();
			cross = h * h + w * w;

				for (int hi = h + 1; hi < 151; hi++) {
					for (int wi = hi+1; wi < 151; wi++) {
						int crossi = hi * hi + wi * wi;
						if (crossi == cross) {
							System.out.println(hi + " " + wi);
							continue dowhile;
						}
						if (crossi > cross) {
							break;
						}
					}
				} //for(hi)
			
				calc(cross);
		} while (true);
		sc.close();

	}
	
	//crossより1以上大きい対角線を持つ高さ最小の整長方形
	public static void calc(int cross) {
		int h;
		double w;
		double rootc = Math.sqrt(cross);
		for(h=1;h<=rootc;h++) {
			w = Math.sqrt(cross+1 - h*h);
			if(h<w && w%1==0) {
				System.out.println(h+" "+(int)w);
				return;
			}
		}
		calc(cross+1);
	}

}



Measured memory_bytes: 26128
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<char> d(k);
    for (int i = 0; i < k; i++) cin >> d[i];

    while (1) {
        string s = to_string(n);
        bool flag = false;
        for (int j = 0; j < s.size(); j++) {
            for (int l = 0; l < k; l++) {
                if (s[j] == d[l]) {
                    flag = true;
                    break;
                }
            }
            if (flag) break;
        }
        if (flag) n++;
        else break;
    }

    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	
	#define pii                 pair<int,int>
	#define vi                  vector<int>
	#define vii                 vector<std::vector<int>> v;
	#define mem(dp,a)           memset(dp,a,sizeof dp)
	#define sonic               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	#define pb(x)               push_back(x)
	#define mkp(x,y)             make_pair(x,y)
	#define all(c)              c.begin(), c.end()
	#define ff                  first
	#define ss                  second
	#define INF                 INT_MAX
	
	/* Bit Manipulation */
	
	#define isOn(S, j) (S & (1 << j))
	#define setBit(S, j) (S |= (1 << j))
	#define clearBit(S, j) (S &= ~(1 << j)) // to turn off
	#define toggleBit(S, j) (S ^= (1 << j))
	#define lowBit(S) (S & (-S)) // to get lsb
	#define setAll(S, n) (S = (1 << n) - 1)
	
	#define modulo(S, N) ((S) & (N - 1))   // returns S % N, where N is a power of 2
	#define isPowerOfTwo(S) (!(S & (S - 1)))
	#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
	#define turnOffLastBit(S) ((S) & (S - 1))
	#define turnOnLastZero(S) ((S) | (S + 1))
	#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
	#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
	
	void printSet(int vS) {                         // in binary representation
	  printf("S = %2d = ", vS);
	  stack<int> st;
	  while (vS)
	    st.push(vS % 2), vS /= 2;
	  while (!st.empty())                         // to reverse the print order
	    printf("%d", st.top()), st.pop();
	  printf("\n");
	}
		
	/* Bit Manipulation Ends. */
		
	// Global variables declared here...
	
	//*******User-Defined Functions*********//
	
	
	
	//*******Functions end here************//
	
	//*******Main func starts**************//
	int main()
	{
	    sonic;
		int h,w,k;
		cin >> h >> w >> k;
		vector<vector<char>> grid(h,vector<char>(w));
		for (int i=0;i<h;i++)
		{
			for (int j=0;j<w;j++)
			{
				char c;
				cin >> c;
				grid[i][j] = c;
			}
		}
		int ans = 0;
		for (int maskRo=0;maskRo<((1<<h)-1);maskRo++)
		{
			for (int maskCol=0;maskCol<((1<<w)-1);maskCol++)
			{
				int cnt = 0;
				for (int i=0;i<h;i++)
				{
					for (int j=0;j<w;j++)
					{
						if ((maskRo>>i)&1) continue;
						if ((maskCol>>j)&1) continue;
						if (grid[i][j] == '#')
							cnt++;
					}
				}
				if (cnt == k)
					ans++;
		    }
		}
		cout << ans << endl;
	}
	//******Main Ends here****************//
	
	
	


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        if(a+b>=c) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }

    }

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
char a[101],b[101],c[101];
int main()
{
	int n,i,ans=0;
	scanf("%d",&n);
	scanf("%s",a);
	scanf("%s",b);
	scanf("%s",c);
	for(i=0;i<n;i++)
	{
		if(a[i]!=b[i]&&a[i]!=c[i]&&b[i]!=c[i])
			ans+=2;
		else if(a[i]==b[i]&&b[i]==c[i])
			ans+=0;
		else
			ans+=1;
	}
	printf("%d",ans);
	return 0;
}

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


struct UnionFind{
	vector<int> par,gsize;
	int sz;
	
	UnionFind(int N) : par(N) ,gsize(N), sz(N) {
		for(int i=0;i<N;i++) {
			par[i]=i;
			gsize[i]=1;
		}
	}
	
    //root:子xの根を返す
	int root(int x){
		if(par[x]==x) return x;
		else{
			return par[x]=root(par[x]); 
		}
	}
	
    //unite:要素xとyを結ぶ
	void unite(int x,int y){
		int rx=root(x);
		int ry=root(y);
		if(rx==ry) return;
		else {
			if(gsi(rx)>gsi(ry))swap(rx,ry);
			par[ry]=rx; sz--; 
			gsize[rx]+=gsize[ry];
		}
	}
	
    //same:要素xとyの親が同じか判定する
	bool same(int x,int y){
		int rx=root(x);
		int ry=root(y);
		return rx==ry;
	}
	
    //size:全体のグループの数を返す
	int size() { return sz; }

	//gsize:要素xが属するグループの大きさを返す
	int gsi(int x) {return gsize[root(x)]; }
};
using graph=vector<vector<int>>;


signed main(){
    int N,M,K; cin>>N>>M>>K;
    UnionFind G(N);
    graph fri(N);
    graph blo(N);
    for(int i=0;i<M;i++){
        int a,b; cin>>a>>b; a--; b--;
        G.unite(a,b);
        fri[a].push_back(b);
        fri[b].push_back(a);
    }
    for(int j=0;j<K;j++){
        int a,b; cin>>a>>b; a--; b--;
        blo[a].push_back(b);
        blo[b].push_back(a);
    }
    for(int i=0;i<N;i++){
        int ans=G.gsi(i)-1;
        ans-=fri[i].size();
        if(blo[i].size()!=0){
            for(int j=0;j<blo[i].size();j++){
                int b=blo[i][j];
                if(G.same(i,b))ans--;
            }
        }
        
        cout<<max(0LL,ans)<<' ';
    }
    cout<<endl;
    return 0;

}

Measured memory_bytes: 15220
#include <iostream>

using namespace std;
void printRect(int H,int W){
  for(int i = 0; i < H ; i++){
    for(int j = 0; j < W; j++){
      cout<<"#";
    }
    cout<<endl;
  }
}
int main(){
  int h,w;
  cin>>h>>w;
  while(h!=0 || w!=0){
    printRect(h,w);
    cout<<endl;
    cin>>h>>w;
  }
}

Measured memory_bytes: 3080
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    string squre[50];
    int h,w;
    cin>>h>>w;
    for(int i=0; i<h; i++)
        cin>>squre[i];
    bool flag=true;
    if((h==1&&w==1)||(h==1&&w==2)||(h==2&&w==1))
    {
        cout<<"Yes\n";
        return 0;
    }
    if(h==2&&w==2)
    {
        int sum=0;
        for(int i=0; i<h; i++)
            for(int j=0; j<w; i++)
                if(squre[i][j]=='#') sum++;
        if(sum==1)
        {
            cout<<"No\n";
            return 0;
        }
        else if(sum==3||sum==4)
        {
            cout<<"Yes\n";
            return 0;
        }
        else if((squre[0][0]=='#'&&squre[0][1]=='.'&&squre[1][0]=='.'&&squre[1][1]=='#')||(squre[0][0]=='.'&&squre[0][1]=='#'&&squre[1][0]=='#'&&squre[1][1]=='.'))
        {
            cout<<"No\n";
            return 0;
        }
        else
        {
            cout<<"Yes\n";
            return 0;
        }
    }
    for(int i=0; i<h; i++)
        for(int j=0; j<w; j++)
        {
            if(squre[i][j]=='#')
            {

                if(i==0)
                {
                    if(j==0)
                    {
                        if(squre[i][j+1]!='#'&&squre[i+1][j]!='#') flag = false;
                    }
                    else if(j==w-1)
                    {
                        if(squre[i+1][j]!='#'&&squre[i][j-1]!='#') flag = false;
                    }
                    else
                    {
                        if(squre[i][j+1]!='#'&&squre[i+1][j]!='#'&&squre[i][j-1]!='#') flag = false;
                    }
                }
                else if(i==h-1)
                {
                    if(j==0)
                    {
                        if(squre[i][j+1]!='#'&&squre[i-1][j]!='#') flag = false;
                    }
                    else if(j==w-1)
                    {
                        if(squre[i-1][j]!='#'&&squre[i][j-1]!='#') flag = false;
                    }
                    else
                    {
                        if(squre[i][j+1]!='#'&&squre[i-1][j]!='#'&&squre[i][j-1]!='#') flag = false;
                    }
                }
                else if(j==0)
                {
                    if(i==0)if(squre[i][j+1]!='#'&&squre[i+1][j]!='#') flag = false;
                    else if(i==h-1)if(squre[i-1][j]!='#'&&squre[i][j+1]!='#') flag = false;
                    else if(squre[i][j+1]!='#'&&squre[i-1][j]!='#'&&squre[i+1][j]!='#') flag = false;
                }
                else if(j==w-1)
                {
                    if(i==0)if(squre[i][j-1]!='#'&&squre[i+1][j]!='#') flag = false;
                    else if(i==h-1)if(squre[i-1][j]!='#'&&squre[i][j-1]!='#') flag = false;

                    else if(squre[i][j-1]!='#'&&squre[i-1][j]!='#'&&squre[i+1][j]!='#') flag = false;
                }
                else if(squre[i+1][j]!='#'&&squre[i-1][j]!='#'&&squre[i][j-1]!='#'&&squre[i][j+1]!='#') flag = false;
            }
        }
    if(flag)
        cout<<"Yes\n";
    else cout<<"No\n";

}


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

int main(){
    int N,T,d;
    int tim[200001];
    cin>>N>>T;
    for(int t=0;t<N;t++)cin>>tim[t];
    int sum=0;

    for(int t=0;t<N;t++){
    if(t!=N-1){
        int g=tim[t+1]-tim[t];
        d=min(T,g);
        sum+=d;
    }else{
        sum+=T;
        }
    }

    cout<<sum<<"\n";
    
    return 0;
} 


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
     int n,k;
     cin>>n;
     k=n%10;
     if(k==3)cout<<"bon"<<endl;
     else if(k==0||k==1||k==6||k==8)cout<<"pon"<<endl;
     else cout<<"hon"<<endl;
}
   
    

   



Measured memory_bytes: 3596
fun main(args: Array<String>) {
  val (N, M) = readInts()

  var result = 0
  if (N > 1) {
    result += (N * (N - 1)) / 2
  }
  if (M > 1) {
    result += (M * (M - 1)) / 2
  }
  println(result)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }


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

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

  map<int,vector<vector<int>>> uvw;
  //uvw[u] = vector of {vertex v connected to u, weight w of the edge u-v }
  REP(i, N-1){
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--; //0-indexed
    uvw[u].push_back({v,w});
    uvw[v].push_back({u,w});
  }

  vector<bool> visited(N, false);
  vector<int> stack = {0};
  vector<ll> dist(N, 0);

  while(!stack.empty()){
    int from = stack.back();
    stack.pop_back();
    visited.at(from) = true;

    for(vector<int> v: uvw[from]){
      int to = v.at(0);
      int weight = v.at(1);
      if(visited.at(to)) continue;
      stack.push_back(to);
      dist.at(to) = dist.at(from) + weight;
    }
  }

  REP(i,N){
    cout << dist.at(i)%2 << endl;
  }
}


Measured memory_bytes: 21760
#include<stdio.h>
int num[3][1001][1001];
int main(){
	int m,n,k;
	int i,j,l;
	scanf("%d %d %d",&m,&n,&k);
	for(i=0;i<=m;i++)for(j=0;j<=n;j++)for(l=0;l<3;l++)num[l][i][j]=0;
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			char c;
			scanf(" %c",&c);
			if(c=='J')num[0][i][j]=1;
			if(c=='O')num[1][i][j]=1;
			if(c=='I')num[2][i][j]=1;
		}
	}
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			for(l=0;l<3;l++)num[l][i][j]+=num[l][i][j-1];
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			for(l=0;l<3;l++)num[l][j][i]+=num[l][j-1][i];
		}
	}
	for(i=0;i<k;i++){
		int x1,y1,x2,y2;
		scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
		for(j=0;j<3;j++){
			int ans=num[j][x2][y2]-num[j][x2][y1-1]-num[j][x1-1][y2]+num[j][x1-1][y1-1];
			printf("%d",ans);
			if(j!=2)printf(" ");
		}
		puts("");
	}
}

Measured memory_bytes: 12740
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) {rep(i,x.size()) cout << x[i] << " "; cout << endl;}
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 2e5;

int main() {
    int n; cin >> n;
    vint a(3*n);
    rep(i,3*n) cin >> a[i];
    sort(all(a));
    ll ans = 0;
    int id = 3*n-2;
    while (n--) {
        ans += a[id];
        id -= 2;
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  multiset<int> b;
  for(int i=0;i<n;i++) cin >> a[i];
  
  for(int i=0;i<n;i++) {
    b.insert(a[i]);
    auto itr=b.begin();
    if(*itr!=a[i]) {
      itr=b.lower_bound(a[i]);
      itr--;
      b.erase(itr);
    }
  }
  cout << b.size() << endl;
}

Measured memory_bytes: 5376