akhauriyash/Code-Regression huggingface dataset:
using System;

namespace ALDS1_6_C
{
    public static class Sort
    {
        public delegate void SwapperAction<T>(ref T a, ref T b);
        public static void QuickSort<T>(this T[] a, SwapperAction<T> swapper) where T : IComparable
        {
            QuickSort(a, 0, a.Length - 1, swapper);
        }

        private static void QuickSort<T>(T[] a, int s, int t, SwapperAction<T> swapper) where T : IComparable
        {
            if (s < t)
            {
                int mid = Partition(a, s, t, swapper);
                QuickSort(a, s, mid - 1, swapper);
                QuickSort(a, mid + 1, t, swapper);
            }
        }
        private static int Partition<T>(T[] a, int s, int t, SwapperAction<T> swapper) where T : IComparable
        {
            int p = s;
            T x = a[t];
            for (int i = s; i < t; ++i)
            {
                if (a[i].CompareTo(x) <= 0) swapper.Invoke(ref a[p++], ref a[i]);
            }
            swapper.Invoke(ref a[p], ref a[t]);
            return p;
        }
    }
    class Program
    {
        class Card : IComparable
        {
            public int num;
            public char kind;
            public int oldPos;
            public int CompareTo(object obj)
            {
                return num.CompareTo((obj as Card).num);
            }
            public override string ToString()
            {
                return kind.ToString() + " " + num; 
            }

            public static Card Parse(string str)
            {
                var strs = str.Split(' ');
                return new Card() { kind = strs[0][0], num = int.Parse(strs[1]) };
            }

            public static void Swapper(ref Card a, ref Card b)
            {
                Card t = a;
                a = b;
                b = t;
            }
        }
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var cards = new Card[n];
            for (int i = 0; i < n; i++)
            {
                cards[i] = Card.Parse(Console.ReadLine());
                cards[i].oldPos = i;
            }
            cards.QuickSort(Card.Swapper);
            Console.WriteLine(IsStatble(cards) ? "Stable" : "Not stable");
            foreach (var card in cards) Console.WriteLine(card);
        }

        static bool IsStatble(Card[] cards)
        {
            Card pre = null;
            foreach (var card in cards)
            {
                if (pre == null) pre = card;
                else if (card.num == pre.num && card.oldPos < pre.oldPos) return false;
                else pre = card;
            }
            return true;
        }
    }
}

Measured memory_bytes: 15716
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;

LL n,m;
char ch;
LL blk[505][505] = {0};
LL vis[505][505] = {0};

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

struct node{
	LL x,y,stp;
}h,t;
queue <node> q;

LL bfs(LL x,LL y){
	LL ret = 0;
	for(LL i = 1;i <= n;i ++)
		for(LL j = 1;j <= m;j ++)
			vis[i][j] = 0;
	while(!q.empty()) q.pop();
	h.x = x; h.y = y; h.stp = 0; q.push(h); 
	vis[x][y] = 1;
	while(!q.empty()){
		h = q.front(); q.pop();
		ret = max(ret,h.stp);
		for(LL i = 0;i < 4;i ++){
			LL tx,ty;
			tx = h.x + dx[i]; ty = h.y + dy[i];
			if(blk[tx][ty] || vis[tx][ty] || tx < 1 || ty < 1 || tx > n || ty > m) continue;
			vis[tx][ty] = 1; t.x = tx; t.y = ty; t.stp = h.stp + 1;
			q.push(t);
		}
	}
	return ret;
}

int main(){
	cin >> n >> m;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 1;j <= m;j ++){
			cin >> ch;
			if(ch == '#') blk[i][j] = 1;
		}
	}
	
	LL ans = 0,mx = 0;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 1;j <= m;j ++){
			if(blk[i][j]) continue;
			mx = bfs(i,j);
			ans = max(ans,mx);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int k = stdIn.nextInt();
		
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
		}
		
		//System.out.println((n-2)/(k-1)+1);
		//System.out.println((n-k+1)/(k-1)+1);
		System.out.println((n+k-3)/(k-1));
		
		
	}

}


Measured memory_bytes: 50672
from itertools import accumulate
N=int(input())
A=list(map(int,input().split()))
p=10**9+7
ans=0
B=list(accumulate(A[::-1]))
for i,value in enumerate(A):
    if i==(N-1):
        break
    ans+=((value%p)*(B[-2-i]%p))%p
    ans=ans%p
print(ans)

Measured memory_bytes: 103364
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = long.Parse(Console.ReadLine());
            var route = (long)Math.Sqrt(input);
            for (long i = route; i >= 1; i--)
            {
                if (input % i == 0)
                {
                    Console.WriteLine(i + (input / i) - 2);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, d;
	cin >> n >> d;
	int ans = 0;
	if (n%(d*2+1) == 0) ans = n/(d*2+1);
	else ans = n/(d*2+1) + 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int knapsack(int n, int W, vi w, vi v){
    vvi dp(n + 1, vi (W + 1, 0));
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= W; j++) {
            if(j - w[i] >= 0) {
                chmax(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
            }
            chmax(dp[i][j], dp[i - 1][j]);
        }
    }
    int res=dp[n][W];
    for(int i=2;i<=n;i++){
        chmax(res,dp[i-1][W-1]+v[i]);
    }
    // rep(i,n+1){
    //     rep(j,W+1){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    return res;
}

int main() {
    
    int n,t;
    cin>>n>>t;
    vi v(n+1),w(n+1);
    vpii tmp(n+1);
    rep(i,n){
        cin>>tmp[i+1].first>>tmp[i+1].second;
    }
    Sort(tmp);
    rep(i,n){
        v[i+1]=tmp[i+1].second;
        w[i+1]=tmp[i+1].first;
    }
    fin(knapsack(n,t,w,v));
    
}

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

using namespace std;

vector<vector<int>> graph;
vector<int> label;

int dfs_init(int node, int par) {
    int mask = 0, beat = 0;
    for (auto vec : graph[node]) {
        if (vec == par) continue;
        int now = dfs_init(vec, node);
        beat |= (mask & now);
        mask |= now;
    }
    int need = 31 - __builtin_clz(beat);
    mask |= (1 << need) - 1;
    label[node] = __builtin_ctz(~mask);
    mask ^= (2 << label[node]) - 1;
    return mask;
}

int main() {
    int n; cin >> n;
    label.resize(n);
    graph.resize(n);
    for (int i = 1; i < n; ++i) {
        int a, b; cin >> a >> b;
        graph[a - 1].push_back(b - 1);
        graph[b - 1].push_back(a - 1);
    }
    dfs_init(0, -1);
    int res = 0;
    for (int i = 0; i < n; ++i) {
        res = max(res, label[i]);
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 11776
import Control.Monad

main :: IO ()
main = do
    n     <- readLn
    lines <- replicateM n getLine
    let cards = map ((\[s, r] -> (s, r)) . words) lines
    mapM_ (\t -> putStrLn (fst t ++ " " ++ snd t)) $ filter (\t -> elem t cards == False) [(s, show r) | s <- ["S", "H", "C", "D"], r <- [1 .. 13]]

Measured memory_bytes: 3716
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++)
			a[i] = sc.nextInt();
		int min = a[0];
		int max = a[0];
		for(int i = 1; i < n; i++) {
			if(a[i] < min)
				min = a[i];
			else if(a[i] > max)
				max = a[i];
		}
		boolean[] hash = new boolean[max - min + 1];
		for(int i = 0; i < hash.length; i++)
			hash[i] = false;
		int identity = 0;
		for(int i = 0; i < n; i++) {
			if(!hash[a[i] - min]) {
				identity++;
				hash[a[i] - min] = true;
			}
		}
		System.out.println(String.valueOf(identity - ((identity + 1)%2)));
	}
}

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

int main(){
    //input
    long long N,M,Q;
    cin >> N >> M >>Q;
    long long i,j;
    long long L[M+1], R[M+1];
    long long p[Q+1], q[Q+1];
    for(i=1; i<=M; i++){
        cin >> L[i] >> R[i];
    }
    for(i=1; i<=Q; i++){
        cin >> p[i] >> q[i];
    }

    //calc
    long long single_sum[N+1][N+1];
    for(i=0; i<=N; i++){
        for(j=0; j<=N; j++){
            single_sum[i][j]=0;
        }
    }
    for(i=1; i<=M; i++){
        single_sum[L[i]][R[i]]++;
    }
    long long col_sum[N+1][N+1];
    for(j=0; j<=N; j++){
        for(i=0; i<=N; i++){
            col_sum[i][j]=0;
        }
    }
    for(j=0; j<=N; j++){
        for(i=0; i<=N; i++){
            col_sum[i][j]=0;
        }
    }
    for(j=1; j<=N; j++){
        for(i=1; i<=N; i++){
            col_sum[i][j]=col_sum[i-1][j]+single_sum[i][j];
        }
    }
    long long sum[N+1][N+1];
    for(i=0; i<=N; i++){
        for(j=0; j<=N; j++){
            sum[i][j]=0;
        }
    }
    for(i=1; i<=N; i++){
        for(j=1; j<=N; j++){
            sum[i][j]=sum[i][j-1]+col_sum[i][j];
        }
    }
    //answer
    for(i=1; i<=Q; i++){
        cout << sum[N][q[i]] - sum[p[i]-1][q[i]] << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 11768
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>

#include<stack>

using namespace std;


int main() {

	int A, B, T;

	cin >> A >> B >> T;

	int resultNum = 0;
	for (int i = A; i <= T; i += A)
	{
		resultNum += B;
	}

	cout << resultNum << endl;
	return 0;
}


Measured memory_bytes: 256
A, B, C, D, E, F = list(map(int, input().split()))

water = set()
sugar = set()
res = {}
noudo = []

counter = max([int(F / A), int(F / B)])
A_counter = int(F / (A * 100))
B_counter = int(F / (B * 100))
for i in range(A_counter + 1):
    for j in range(B_counter + 1):
        tmp = A * i * 100 + B * 100 * j
        if tmp <= F:
            water.add(tmp)

C_counter = int(F / C)
D_counter = int(F / D)
for i in range(C_counter + 1):
    for j in range(D_counter + 1):
        tmp = i * C + D * j
        if tmp < F:
            sugar.add(tmp)

water.remove(0)
# sugar.remove(0)

for w in water:
    for s in sugar:
        if w + s <= F and s <= E * (w / 100):
            n = s / (w + s)
            noudo.append(n)
            res[n] = {"satoumizu": w + s, "sugar": s}
ans = res[max(noudo)]
# print(" ".join([str(ans["satoumizu"]), str(ans["sugar"])]))
print(str(ans["satoumizu"]) + " " + str(ans["sugar"]))


Measured memory_bytes: 5936
#include<stdio.h>
int main()
{
    
    int a,b,c;
   
    scanf("%d", &a);
    // スペース区切りの整数の入力
    scanf("%d ",&b);
  	scanf("%d", &c);
  
  
  	int count= 0;
  if(a == b){
	count++;
  }
  if(a==c){
    count++;
   
  }
  if(b==c){
	count++;
    
  }
  
  
  if(count == 1){
    printf("Yes");
  }else{
    printf("No");
  }
  
    return 0;
}

Measured memory_bytes: 128
// Problem : C - Repsept
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 100000005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	int n;
	cin >> n;
	int cur=0;
	rep(i,0,maxn)
	{
		cur = cur*10+7;
		cur%=n;
		if(cur == 0)
		{
			cout << i+1 <<"\n";
			return;
		}
	}
	cout << -1 <<"\n";
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


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

#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to));
#define sort(a) sort(a.begin(), a.end())

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;

  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, ans = 0;
    cin >> n;
    int mn = INF;
    for (int i = 0, x; i < n; i++) {
        cin >> x;
        if (x <= mn) {
            ++ans;
        }
        umin(mn, x);
    }
    cout << ans << '\n';
}


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

int main()
{
        int n;
        string str1, str2;
        int taro=0,hana=0;

        cin >> n;

        while(cin>>str1>>str2){
                if(str1.compare(str2)<0){hana+=3;}
                else if(str1.compare(str2)>0){taro+=3;}
                else{hana++, taro++;}
        }
        cout << taro << " " << hana << endl;
         
        return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <set>
#include <stdlib.h>
#include <cmath>
using namespace std;

int d, c[29], s[409][29], p[409], cp[29], rs;
set<int> st[29];

int cc()
{
	for (int i = 0; i < 26; i++)
		cp[i] = 0;
	int ans = 0;
	for (int i = 1; i <= d; i++) {
		for (int j = 0; j < 26; j++) {
			if (p[i] == j) {
				cp[j] = i;
				ans += s[i][j];
			}
			else
				ans -= (i - cp[j]) * c[j];
		}
	}
	return ans;
}

void rm(int n, int k)
{
	auto pi = st[k].find(n);
	auto l = pi; l--;
	auto r = pi; r++;
	int pl = (n - (*l) - 1), pr = ((*r) - n - 1), plr = ((*r) - (*l) - 1);
	st[k].erase(n);
	rs -= s[n][k];
	rs += pl * (pl + 1) / 2 * c[k]; rs += pr * (pr + 1) / 2 * c[k];
	rs -= plr * (plr + 1) / 2 * c[k];
}

void ins(int n, int k)
{
	auto r = st[k].lower_bound(n);
	auto l = r; l--;
	int pl = (n - (*l) - 1), pr = ((*r) - n - 1), plr = ((*r) - (*l) - 1);
	st[k].insert(n);
	rs += s[n][k];
	rs -= pl * (pl + 1) / 2 * c[k]; rs -= pr * (pr + 1) / 2 * c[k];
	rs += plr * (plr + 1) / 2 * c[k];
}

void up(int n, int k)
{
	rm(n, p[n]);
	p[n] = k;
	ins(n, p[n]);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> d;
	for (int i = 0; i < 26; i++) {
		cin >> c[i];
		st[i].insert(0); st[i].insert(d + 1);
	}
	for (int i = 1; i <= d; i++) {
		for (int j = 0; j < 26; j++)
			cin >> s[i][j];
		p[i] = rand() % 26;
		st[p[i]].insert(i);
	}
	rs = cc();
	double k = 100, sc = 350, kt = 0.99994;
	for (int i = 0; i < 4000000; i++) {
		double e1 = rs;
		int n = (rand() % d) + 1, kp = (rand() % 25) + 1;
		int hk = p[n], tk = (hk + kp) % 26;
		up(n, tk);
		int e2 = rs;
		double pb = exp((e2 - e1) / (k * sc));
		if (pb < rand() / (double)RAND_MAX)
			up(n, hk);
		k *= kt;
	}
	for (int i = 1; i <= d; i++)
		cout << p[i] + 1 << '\n';
	return 0;
}

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

using namespace std;
typedef long long ll;
int main()
{
    ll n ;
    cin >>  n ;
    ll arr[n+1];
    ll dp[n+1];
    for(int i = 1 ; i <=n ; i++)
    {
        cin >> arr[i];
    }
    ll ans = 1e10 , x;
    dp[2]=abs(arr[2]-arr[1]);
    dp[1]=0;
    for(int i = 3 ; i<= n ; i++)
    {
        //x=min(abs(arr[i-2]-arr[i] , abs(arr[i-1]-arr[i])) ;
        dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));
    }
    cout << dp[n]; ;
    return 0;
}


Measured memory_bytes: 5152
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(n), sorted(n);
    in_arr(int, a, n);
    copy(a.begin(), a.end(), sorted.begin());
    sort(sorted.begin(), sorted.end());
    ll ans = 10000000009;
    list<int> selected;
    for(vector<int>::iterator base = sorted.begin(); base != sorted.end(); base++){
        int limit = *base - 1;
        int start = 0, end = 0;
        rep(i, n){
            if(a[i] > limit)
                continue;
            end = i;
            if(end - start < k){
                start = end + 1;
                continue;
            }
            vector<int> seg(end - start);
            rep(i, end - start){
                seg[i] = a[i + start];
            }
            sort(seg.begin(), seg.end());
            rep(i, seg.size() - k + 1){
                selected.push_front(seg[i]);
            }
            start = end + 1;
        }
        end = n;
        if(end - start >= k){
            vector<int> seg(end - start);
            rep(i, end - start){
                seg[i] = a[i + start];
            }
            sort(seg.begin(), seg.end());
            rep(i, seg.size() - k + 1){
                selected.push_front(seg[i]);
            }
        }
        if(selected.size() < q){
            selected.clear();
            continue;
        }
        selected.sort();
        list<int>::iterator i = selected.begin();
        rep(j, q - 1){
            ++i;
        }
        ll prob_ans = *i - *(selected.begin());
        ans = min(ans, prob_ans);
        selected.clear();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
typedef struct Node{
    int key;
    struct Node *next;
    struct Node *prev;
}Node;
 
void insert(int);
void delete(Node *);
Node *search(int);

Node *nil;
main(){
    int n, tmpKey,i;
    char tmpStr[12];
    Node *p;
     
    nil = (Node *)malloc(sizeof(Node));
    nil -> next = nil -> prev = nil;
 
    scanf("%d", &n);
 
    for(i = 0;i < n;i++){
        scanf("%s",tmpStr);
        if(strcmp(tmpStr,"insert") == 0){
            scanf("%d",&tmpKey);
            insert(tmpKey);
        }
        else if(strcmp(tmpStr,"delete") == 0){
            scanf("%d",&tmpKey);
            delete(search(tmpKey));
        }
        else if(strcmp(tmpStr, "deleteFirst") == 0) delete(nil -> next);
        else if(strcmp(tmpStr, "deleteLast") == 0) delete(nil -> prev);
    }
 
    for (p = nil -> next;p -> next != nil;p = p -> next){
        printf("%d ",p -> key);
    }
    printf("%d\n",p -> key);
 
    return 0;
}
 
void insert(int key){
    Node *new;
 
    new = (Node *)malloc(sizeof(Node));
    new -> key = key;
    new -> next = nil -> next;
    new -> prev = nil;
    nil -> next = new;
    new -> next -> prev = new;
 
}
 
void delete(Node *ad){
    if (ad == NULL){
        return;
    }
    
    ad -> prev -> next = ad -> next;
    ad -> next -> prev = ad -> prev;
    free(ad);
}
 
Node *search(int key){
    Node *search;
    for (search = nil -> next;search != nil;search = search -> next){
        if (search -> key == key) return search;
    }
 
    return NULL;
}

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

using namespace std;

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

    vector< vector<int> > alist(N + 1, vector<int>());

    for (int i = 0; i < M; i ++) {
        long a, b;
        cin >> a >> b;

        alist.at(a).push_back(b);
        alist.at(b).push_back(a);
    }

    for (long city : alist[1]) {
        bool rc = false;
        for (long dest : alist.at(city)) {
            if (dest == N) {
                rc = true;
                break;
            }
        }

        if (rc) {
            cout << "POSSIBLE\n";
            return 0;
        }
    }

    cout << "IMPOSSIBLE\n";

    return 0;
}



Measured memory_bytes: 12016
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in=new Scanner(System.in);
long n=in.nextLong();
long x=in.nextLong();
long a,b,ans;
a=x;b=n-x;
ans=a+b;
if(a<b){
long temp;
temp=b;
b=a;
a=temp;
}
while(b!=0){
ans+=(a/b)*2*b;
a=a%b;
if(a<b){
long temp;
temp=b;
b=a;
a=temp;
}}
ans-=a;
System.out.println(ans);
}
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  rep(i, s.length())
    cout << static_cast<char>('A'+ ((s[i] - 'A' + n) % 26));
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 10000 + 10;
string a, b;

int main(){
    cin >> a >> b;
    bool flag = false;
    for(int i = 0; i < a.size(); i++){
        for(int j = 0; j < b.size(); j++){
            if(a[i] < b[j]) flag = true;
        }
    }
    if(a.size() < b.size()){
        bool flag1 = true;
        for(int i = 0; i < a.size(); i++){
                if(a[i] != b[i]){
                    flag1 = false;
                }
        }
        if(flag1) flag = true;
    }

    if(flag) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int main(int argc, const char *argv[]) {
  int K;
  long int res = 0;
  cin >> K;

  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      for (int c = 1; c <= K; c++) {
        res += gcd(gcd(a, b), c);
      }
    }
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;

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

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

    vector<long long> a(n);
    REP(i, n){
        long long ai;
        cin >> ai;
        a.push_back(ai);
    }

    sort(a.begin(), a.end(), greater<long long>());
    vector<long long> candidate(n);
    vector<long long> rect(n);
    while(!a.empty()){
        long long ai = a[a.size()-1];
        a.pop_back();
        if(ai == a[a.size()-1]){
            candidate.push_back(ai);
            a.pop_back();
            long long count = 2;
            while(ai ==a[a.size()-1]){
                a.pop_back();
                count += 1;
                if(count == 4){
                    rect.push_back(ai);
                }
            }
        }
    }

    if(candidate.size()>=2){
        sort(candidate.begin(), candidate.end(), greater< long long >());
        long long output = candidate[0] * candidate[1];
        if(rect.size()>=1){
            sort(rect.begin(), rect.end(), greater<long long>());
            output = max(output, rect[0]*rect[0]);
        }
        cout << output << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 4976
#include <stdio.h>

int main(void)
{
  int A,B,box,box1,box2;

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

  box = B % A;
  box1 = A + B;
  box2 = B - A;

  if (box == 0){
    printf("%d",box1);
  }

  else {
    printf("%d",box2);
  }

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int G[100][100], d[100], f[100], num[100];
int t = 1;

void depth(int u){
	int i;

	d[u] = t++;
	for (i = 1; i <= num[u]; i++){
		if (d[G[u][i]] == 0)
		{
			depth(G[u][i]);
		}
	}
	f[u] = t++;
}

int main(void)
{
	int i, j, n;
	int u, k;

	scanf("%d", &n);

	//?????????
	for (i = 1; i <= n; i++){
		d[i] = f[i] = 0;
		for (j = 1; j <= n; j++){
			G[i][j] = 0;
		}
	}

	//??£??\???????????¨???
	for (i = 1; i <= n; i++){
		scanf("%d", &u);
		scanf("%d", &num[u]);
		for (j = 1; j <= num[u]; j++){
			scanf("%d", &G[u][j]);
		}
	}

	for (i = 1; i <= n; i++){
		if (d[i] == 0)
		{
			depth(i);
		}
	}

	for (i = 1; i <= n; i++){
		printf("%d %d %d\n", i, d[i], f[i]);
	}

	return 0;
}

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

int main(){
	int n;
	cin>>n;
	vector<string> s(n);
	vector<int> p(n);

	vector<pair<string,pair<int,int>>> v(n);
	for(int i=0;i<n;i++){
		cin>>s[i]>>p[i];
		v[i]=make_pair(s[i],make_pair(-p[i],i+1));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++){
		cout<<v[i].second.second<<endl;
	}
}

Measured memory_bytes: 384
fn main() {
    let n: u32 = read();
    let reader: Box<Iterator<Item = i32>> = Box::new(ReadLines::new(n, 0));
    println!("{}", maximum_profit(reader));
}

fn maximum_profit(reader: Box<Iterator<Item = i32>>) -> i32 {
    let mut min    = i32::max_value();
    let mut profit = i32::min_value();
    for e in reader {
        let sub = e - min;
        if  sub > profit {
            profit = sub;
        }
        if e < min {
            min = e;
        }
    }
    profit
}

fn read<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().parse::<T>().ok().unwrap()
}

struct ReadLines<T: std::str::FromStr> {
    n: u32,
    cnt: u32,
    _d: T,
}
impl<T: std::str::FromStr> ReadLines<T> {
    fn new(n: u32, d: T) -> Self { ReadLines { n: n, cnt: 0, _d: d } }
}

impl<T: std::str::FromStr> Iterator for ReadLines<T> {
    type Item = T;
    fn next(&mut self) -> Option<T> {
        let ret = if self.cnt < self.n {
            let mut input = String::new();
            std::io::stdin().read_line(&mut input).unwrap();
            Some(input.trim().parse::<T>().ok().unwrap())
        } else {
            None
        };
        self.cnt += 1;
        ret
    }
}


Measured memory_bytes: 5052
#include <stdio.h>

#define MAX 100

void sort_reverse(int n, int arr1[], int arr2[]) {
    int i, j=n;

    for (i=0; i<n; i++) {
        arr2[i] = arr1[j-1];
	j--;
    }
}

void process(int n) {
    int array1[MAX], array2[MAX];
    int i, x;

    i = 0;
    while (i < n) {
        scanf("%d", &x);
	array1[i] = x;
	i++;
    }
    
    sort_reverse(n, array1, array2);

    i=0;
    while (i<n) {
        printf("%d", array2[i]);
	
	if (i == n-1) {
	    printf("\n");
	} else {
	    printf(" ");
	}
	i++;
    }
}

void scanner() {
    int n;
    scanf("%d", &n);
    process(n);
}

int main(void) {
    scanner();
    return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
const long long INF = 1LL << 60;


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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {//降順second
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {//降順first
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd


int main() {
	string s;
	int k;
	cin >> s >> k;
	map<string, int> ma;
	rep(i, k) {
		rep(j, s.size() - i) {
			ma[s.substr(j, i + 1)]++;
		}
	}
	int i = 0;
	for (auto itr : ma) {
		i++;
		if (i == k) {
			cout << itr.first;
		}
	}

	return 0;
}


Measured memory_bytes: 1920
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
/*---------------------------------------------------------------------*/
typedef vector<int> vi;
typedef vector<ll> vii;
const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    int n,m;
    cin>>n>>m;
    vii a(n);
    rep(i,n) cin>>a[i];
    double ans=accumulate(a.begin(),a.end(),0);
    ans/=(4.0*m);
    int cnt=0;
    rep(i,n)
    {
        if(a[i]>=ans)
        {
            cnt++;
        }
    }
    cout<<(cnt>=m?"Yes":"No")<<nl;
    return 0;
}


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

const int N = 1e5;

int n,m;
bool bisa[N+5];
int cnt[N+5];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		cnt[i] = 1;
	}
	bisa[1] = 1;
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		if(bisa[u]) bisa[v] = 1;
		cnt[u]--;
		cnt[v]++;
		if(cnt[u] == 0) bisa[u] = 0;
//		cout << cnt[u] << " AND " << cnt[v] << endl;
//		for(int j=1;j<=n;j++){
//			printf("%d ",bisa[j]);
//		}
//		printf("\n");
	}
	int ret = 0;
	for(int i=1;i<=n;i++){
		if(bisa[i]) ret++;
	}
	printf("%d\n",ret);
	return 0;
}

Measured memory_bytes: 768
n = int(input())
S = input()
dp = [[0]*n for _ in range(n)]
for i in range(n-1, -1, -1):
  for j in range(n-1, -1, -1):
    if i == n-1:
      dp[i][j] = int(S[i] == S[j])
    elif j == n-1:
      dp[i][j] = dp[j][i]
    else:
      if S[i] == S[j]:
        dp[i][j] = dp[i+1][j+1] + 1
ans = 0
for i in range(n):
  for j in range(n):
    ans = max(ans, min(dp[i][j], j-i))
print(ans)

Measured memory_bytes: 232072
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct DuLNode
{
	int data;
	struct DuLNode *prior,*next;	
}DuLNode;

DuLNode *InitDuLNode()
{
	DuLNode *h=(DuLNode*)malloc(sizeof(DuLNode));
	h->prior=h->next=h;
	return h;	
}

void insert(int key,DuLNode *h)
{
	DuLNode *p=(DuLNode*)malloc(sizeof(DuLNode));
	p->data=key;
	p->next=h->next;
	h->next->prior=p;
	h->next=p;
	p->prior=h;	
}
void Delete(int key,DuLNode *h)
{
	DuLNode *p=h->next; 
	if(h->prior==h)
	return;
	while(p!=h)
	if(p->data==key)
	{
		p->prior->next=p->next;
		p->next->prior=p->prior;
		free(p);
		break;
	}
	else
	p=p->next;			
}

void deleteFirst(int key,DuLNode *h)
{
	if(h->prior==h)
	return;
	DuLNode *p=h->next;
	h->next=p->next;
	p->next->prior=h;
	free(p);
} 

void deleteLast(int key,DuLNode *h)
{
	if(h->prior==h)
	return;
	DuLNode *p=h->prior;
	p->prior->next=h;
	h->prior=p->prior;
	free(p);
}
int main(int argc, char *argv[])
{
	DuLNode *h,*p;
	int n,i,key;
	char a[15];
	scanf("%d",&n);
	h=InitDuLNode();	
	for(i=0;i<n;i++)
	{
		scanf("%s%d",a,&key);
		if(strcmp(a,"insert")==0)
		insert(key,h);		
		else if(strcmp(a,"delete")==0)
		Delete(key,h);
		else if(strcmp(a,"deleteFirst")==0)
		deleteFirst(key,h);
		else
		deleteLast(key,h);
		
	}
	p=h->next;
	while(p!=h)
	{
		printf("%d",p->data);
		p=p->next;
		if(p!=h)
		printf(" ");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 32944
#include<bits/stdc++.h>
using namespace std;
bool debug;
#define all(x) (x).begin(), (x).end()
#define ll long long

#define db(x) if(debug)cout << " " << (x) <<" "
#define dbn(x) if(debug)cout << "\n" << (#x) << " is " << (x) << endl
#define endl "\n"
#define pb push_back
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>=1;i--)
// fill(all(vec), 1);
//vec.resize(unique(all(vec))-vec.begin())
const int N = 3e6;
void solve()
{
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = 4 * a * b - (a + b - c) * (a + b - c);
    ll z = c - a - b;
    cout << (ans <0 and z >= 0 ? "Yes" : "No");

}



int main()
{


    if(debug)
    {
#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
#endif
    }

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;


    while(t--)
    {
        solve();
        // cout << endl;
    }


}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

int main() {
    int ans = 0;
    int n,k;
    vi a;
    cin>>n>>k;

    a.resize(n);
    REP(i,n)cin>>a[i];

    ans = ceil(double(n-1) / (k-1));

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

Measured memory_bytes: 640
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.root = [-1]*(n+1)
		self.rank = [0]*(n+1)

	def find(self, x):
		if self.root[x] < 0:
			return x
		else:
			self.root[x] = self.find(self.root[x])
			return self.root[x]
			
	def unite(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return 0
		elif self.rank[x] > self.rank[y]:
			self.root[x] += self.root[y]
			self.root[y] = x
		else:
			self.root[y] += self.root[x]
			self.root[x] = y
			if self.rank[x] == self.rank[y]:
				self.rank[y] += 1

	def isSame(self, x, y):
		return self.find(x) == self.find(y) or x==y
		
def solve():
	n,_,*l=map(int,open(0).read().split())
	xy=l[n:]
	ids=[0]*(n+1)
	for i in range(n):ids[l[i]]=i+1
	uf=UnionFind(n)
	for x,y in zip(*[iter(xy)]*2):uf.unite(x,y)
	print(sum(uf.isSame(i,ids[i])for i in range(1,n+1)))
	
if __name__=="__main__":solve()

Measured memory_bytes: 35572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    ll ans = 2002002002;
    ll x = 0;
    rep(i, n) {
        x += a[i];
        if (i==n-1) continue;
        chmin(ans, abs(sum-x*2));
    }

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


Measured memory_bytes: 4728
use std::io;

fn input() -> (i64, i64) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let a: i64 = iter.next().unwrap().parse().unwrap();
    let b: i64 = iter.next().unwrap().parse().unwrap();
    (a, b)
}

fn main() {
    loop {
        let (H, M) = input();
        if H == 0 && M == 0 {
            break;
        }
        for i in 0..H{
            for j in 0..M{
                print!("#");
            }
            print!("\n")
        }
        print!("\n")
    }
}


Measured memory_bytes: 5020
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nums = br.readLine().split("");
        long sum = 0;
        String temp;
        String[] temp_split;
        
        for (int i = 0; i < (1<<nums.length-1); i++) {
            temp = nums[0];
            for (int j = 0; j < nums.length-1; j++) {
                if ((i & (1<<j)) >= 1) {
                    temp += "+" + nums[j+1];
                }
                else {
                    temp += nums[j+1];
                }
            }
            //System.out.println(temp);
            temp_split = temp.split("\\+");
            for (String x : temp_split) {
                sum += Long.parseLong(x);
            }
        }
        
        System.out.println(sum);
    }
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
int main(){
  int t[300000];
  memset(t,0,sizeof(t));
  int n,k,temp,cnt=0,sum=0;
  int b=0;
  cin>>n>>k;
  int a[n+1];
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  t[0]++;
  temp=a[0];
  for(int i=1;i<n;i++){
    //cout<<a[i]<<endl;
    if(temp!=a[i]){
      temp=a[i];
      b++;
    }
    t[b]++;
  }
  //for(int i=0;i<b+1;i++)cout<<t[i]<<' ';
  //cout<<endl;
  sort(t,t+b+1);
  for(int i=0;i<b+1-k;i++){
    sum+=t[i];
  }
  cout<<sum<<endl;
  return(0);
}

Measured memory_bytes: 2176
#include<stdio.h>
int main(){
  int n,f=1,a;
  scanf("%d",&n);
  while(n--){
    scanf("%d",&a);
    if(a%2==0&&a%3&&a%5)f=0;
  }
  printf("%s\n",f?"APPROVED":"DENIED");
  return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long int ll;
class edge
{
public:
	int source,target,cost;
	edge(int insource=0,int intarget=0,int incost=0):
	source(insource),target(intarget),cost(incost){}
	bool operator<(const edge &e)const{return cost<e.cost;}
};

class disjointset
{
public:
	vector<int> rank;
	vector<int> p;
	
	void makeset(int x)
	{
		p[x]=x;
		rank[x]=0;
		return;
	}
	disjointset(int s)
	{
		rank.resize(s);
		p.resize(s);
		for(int i=0;i<s;i++)makeset(i);
		return;
	}
	int findset(int x)
	{
		if(x!=p[x])p[x]=findset(p[x]);
		return p[x];
	}
	void link(int x,int y)
	{
		if(rank[x]>rank[y])p[y]=x;
		else
		{
			p[x]=y;
			if(rank[x]==rank[y])rank[y]++;
		}
		return;
	}
	bool same(int x,int y)
	{
		return findset(x)==findset(y);
	}
	void unite(int x,int y)
	{
		link(findset(x),findset(y));
		return;
	}
};

int n;

vector<edge> kruskal(vector<edge> e)
{
	sort(e.begin(),e.end());
	disjointset d=disjointset(n);
	edge ne;
	vector<edge> mst;
	
	for(int i=0;i<e.size();i++)
	{
		ne=e[i];
		if(!d.same(ne.source,ne.target))
		{
			mst.push_back(ne);
			d.unite(ne.source,ne.target);
		}
	}
	
	return mst;
}

int totalcostcal(vector<edge> e)
{
	int ans=0;
	for(int i=0;i<e.size();i++)ans+=e[i].cost;
	return ans;
}

int main()
{
	cin>>n;
	int m;cin>>m;
	int s,t,w;
	vector<edge> e;
	for(int i=0;i<m;i++)
	{
		cin>>s>>t>>w;
		e.push_back(edge(s,t,w));
		e.push_back(edge(t,s,w));
	}
	cout<<totalcostcal(kruskal(e))<<endl;
	return 0;
}

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


int main() {

    int x, y, z;
    cin >> x >> y >> z;
    int sum = 0;
    int cnt = 0;
    while (sum <= x - z) {
        sum += y + z;
        ++cnt;
    }
    cout << cnt - 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long 
#define MOD 1000000007
 
using namespace std;
 
signed main(){
 

    string s;

    cin >> s;

    int sum = 0;

    for(char x:s){
        if(x=='1'){
            sum++;
        }

        if(x=='0'){
            sum--;
        }
    }

    if(sum<0){
        cout <<s.size()+sum<<endl;
    }

    else{
        cout <<s.size()-sum<<endl;
    }

 	return 0;
 
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
        // TODO ?????????????????????????????????????????????
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        String[] strArray = br.readLine().split(" ");
        Stack<Integer> stack = new Stack<Integer>();
         
        for(int i = 0; i < strArray.length ; i++){
            char input = strArray[i].charAt(0);
            if(Character.isDigit(input)){
                stack.push(Integer.parseInt(strArray[i]));
            }
            else {
                int tmpResult = 0;
                if(input == '+'){
                    tmpResult = stack.pop() + stack.pop();
                }
                else if(input == '-'){
                    tmpResult = -(stack.pop() - stack.pop());
                }
                else if(input == '*'){
                    tmpResult = stack.pop() * stack.pop();
                }   
                //System.out.println(tmpResult);
                stack.push(tmpResult);
            }
        }
         
        System.out.println(stack.pop());
    }
 
}

Measured memory_bytes: 24452
/*
  Author: @yash_31
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#define ll long long int
#define eb emplace_back
#define fatafat ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define ft first
#define sd second
#define mkpr make_pair
#define deb(x) std::cout<<#x<<":"<<x<<endl;
#define whole(x) (x).begin(),(x).end()
#define revwhole(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define fbo find_by_order
#define ook order_of_key
#define init0(x) memset(x,0,sizeof(x));

using namespace std; 
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> gharKaSet;
 
const int maxlimit=2e5+2;
const ll inf=1e18;
//TTBDC

int main()
{
  fatafat
  int n;
  cin>>n;
  vector<ll> v(n);
  ll dp[n];
  for(int i=0;i<n;i++){cin>>v[i];dp[i]=inf;}
  dp[0]=0;
  for(int i=0;i<n;i++){
    if(i+1<n)dp[i+1]=min(dp[i+1],dp[i]+abs(v[i+1]-v[i]));
    if(i+2<n)dp[i+2]=min(dp[i+2],dp[i]+abs(v[i+2]-v[i]));
  }
  cout<<dp[n-1];
  return 0;
}

Measured memory_bytes: 4752
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	ll n;
	cin >> n;
	map<ll, ll> al;
	rep(i, n) {
		ll a;
		cin >> a;
		al[a]++;
	}
	ll ans = 0;
	for (auto i : al) {
		if (i.second % 2 != 0) {
			ans++;
		}
	}
	cout << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}



Measured memory_bytes: 9836