akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
using ll = long long;

int main() {
  ll h, w;
  cin >> h >> w;

  ll odd_num = w / 2 + w % 2;
  ll even_num = w / 2;
  bool is_odd = true;
  ll ans = 0;
  for (ll i = 0; i < h; ++i) {
    ans += is_odd ? odd_num : even_num;
    is_odd = not is_odd;
  }
  if (w == 1 || h == 1)
    cout << 1 << endl;
  else
    cout << ans << endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

double calc_mean(ll value) { return (double)(value + 1) / 2.0; }

int main() {
  ll N, K;
  cin >> N >> K;
  ll p[N];
  FOR(i, 0, N) { cin >> p[i]; }

  double max_mean = 0.0;
  double mean = 0.0;
  FOR(i, 0, K) {
    mean += calc_mean(p[i]);
    max_mean = mean;
  }
  FOR(i, K, N) {
    ll from_index = i - K + 1;
    ll to_index = i;
    mean -= calc_mean(p[from_index - 1]);
    mean += calc_mean(p[to_index]);
    if (mean > max_mean) {
      max_mean = mean;
    }
  }

  printf("%.12f", max_mean);
  return 0;
}

// int main() {
//   ll N, K;
//   cin >> N >> K;
//   ll p[N];
//   FOR(i, 0, N) { cin >> p[i]; }

//   ll max_index_from = 0;
//   ll max_total = 0;
//   FOR(i, 0, K) { max_total += p[i]; }
//   FOR(i, K, N) {
//     ll from_index = i - K + 1;
//     ll to_index = i;
//     ll total = max_total;
//     total += p[to_index];
//     total -= p[from_index - 1];
//     if (total > max_total) {
//       max_index_from = from_index;
//       max_total = total;
//     }
//   }

//   double mean = 0.0;
//   FOR(i, 0, K) {
//     ll index = max_index_from + i;
//     mean += (double)(p[index] + 1) / 2.0;
//   }
//   cout << mean << endl;
//   return 0;
// }

Measured memory_bytes: 1792
n, m = map(int, input().split())

gu = 1
ki = m - m%2 + 2

for i in range(1, m+1)[::-1]:
    if i % 2 == 0:
        print(gu, gu+i)
        gu += 1
    else:
        print(ki, ki+i)
        ki += 1

Measured memory_bytes: 69988
x,y=map(int,input().split())
x0=x
y0=y
X=[1,1,-1,-1]
Y=[1,-1,1,-1]
l=[]
for i in range(4):
    x=x*X[i]
    y=y*Y[i]
    q=10**10
    if y-x>=0:
      q=y-x
      if X[i]==-1:
        q+=1
      if Y[i]==-1:
        q+=1
    l.append(q)
    x=x0
    y=y0
    
print(min(l))

Measured memory_bytes: 38256
import Data.List
f :: Int -> [Int] -> [Int] -> Int -> Int -> Int
f a [] _ _ _ = 0
f a _ [] _ _ = 0
f a (x:xs) (y:ys) m n 
    | (a + x) > y = n - m + (f a (x:xs) ys m (n + 1))
    | m + 1  == n = (f a (x:xs) ys m (n + 1))
    | otherwise = f a xs (y:ys) (m + 1) n

g :: [Int] -> Int
g (a:(x:xs)) = (f a (x:xs) xs 0 1) + (g (x:xs))
g _ = 0

main = do
    getLine
    x <- getLine >>= return . sort . (map (read :: String -> Int)) . words
    putStrLn $ show $ g x

Measured memory_bytes: 2300
import sys
N = int(input())

alphabet = "0abcdefghijklmnopqrstuvwxyz"
name = []
if N == 0:
    print("a")
    sys.exit()

while N > 0:
    if N % 26 == 0:
        next = 26
    else:
        next = N % 26
    name += alphabet[next]
    N = (N - next) // 26
name.reverse()
print("".join(name))

Measured memory_bytes: 9096
n = gets.chomp.to_i
nums = gets.chomp.split(" ").map(&:to_i)
alice_sum, bob_sum = nums.sort.reverse.each_slice(2).reduce([0, 0]) do |(alice_sum, bob_sum), (alice_next, bob_next)|
  [alice_sum + alice_next.to_i, bob_sum + bob_next.to_i]
end
puts alice_sum - bob_sum

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int isprime[100001]={1,1,0},prime[100001],s[100001]={0};
int main()
{
	int n,i,j,c=0,t=0,a,b;
	scanf("%d",&n);
	for(i=2;i<=100000;i++)
	{
		if(isprime[i]==0)
		{
			prime[c++]=i;
			if(isprime[(i+1)/2]==0)
			{
				t++;
			}
		}
		s[i]=t;
		for(j=0;j<c&&i*prime[j]<=100000;j++)
		{
			isprime[i*prime[j]]=1;
			if(i%prime[j]==0)
			{
				break;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&a,&b);
		printf("%d\n",s[b]-s[a-1]);
	}
	return 0;
}

Measured memory_bytes: 1408
import math

N = int(input())
X = list(map(int, input().split()))

def f(P,X):
    if len(X)==1:
        return (P-X[0])**2
    else:
        return (P-X[0])**2 + f(P,X[1:])

avg = sum(X) / N
max = math.ceil(avg)
min  = math.floor(avg)

if max-avg < avg-min:
    print (f(max,X))
else:
    print (f(min,X))


Measured memory_bytes: 3064
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

const int maxn=100000;

int main(){
    
    int n;
    cin >> n;
    int digsum=0;
    int subn=n;
    while(subn>0){
        digsum+=subn%10;
        subn=subn/10;
    }
    if(n%digsum==0){
        Yes;
    }
    else {
        No;
    }
    
    return 0;
}


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

#define int long long

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k, x;
	cin >> k >> x;
	if (k * 500 >= x)
		cout << "Yes";
	else
		cout << "No";
}


Measured memory_bytes: 256
S = input()
K = int(input())
OK = True
for i in range(min(K, len(S))):
    if S[i] != '1':
        OK = False
if OK:
    print('1')
    exit()
for i in range(len(S)):
    if S[i] != '1':
        print(S[i])
        exit()


Measured memory_bytes: 9092
/*input
1 1
50
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a;
		a=a*a;
		
		b>>=1;
	}
	return res;
}

int main(){
	IOS;
	int n,p;
	cin>>n>>p;
	bool odd=0;
	REP(i,n){
		int tmp;
		cin>>tmp;
		if(tmp&1) odd=1;
	}
	if(!odd){
		if(p) cout<<0<<'\n';
		else cout<<mypow(2,n)<<'\n';
	}
	else cout<<mypow(2,n-1)<<'\n';
	return 0;
}


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

typedef long long int ll;

int main()
{
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll a,b;
        cin>>a>>b;
        ll ans = (a*b)/__gcd(a,b);
        std::cout << ans << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define rep(i, j) for(int i = 0; i < j; i++)

int retMax(int n){
	int ret = -1;
	for(int i = 10; n % i != n; i *= 10){
		int a = n / i, b = n % i;
		ret = max(ret, a * b);
	}
	return ret;
}

int main(){
	int q;
	cin >>q;
	for(int z = 0; z < q; z++){
		int n, ans = 0; cin >>n;
		while(n >= 10){
			int befn = n;
			n = retMax(n);
			ans++;
			if(befn < n){
				ans = -1;
				break;
			}
		}
		cout <<ans <<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
#include<stdlib.h>

void run(void){
  char *s=(char *)malloc(sizeof(char)*(100000+1));
  scanf("%s",s);
  int p=0;
  int cnt=0;
  int i;
  for(i=0;s[i]!='\0';i++){
    if(p>0){
      if(s[i]=='g') cnt++;
      p--;
    } else {
      if(s[i]=='p') cnt--;
      p++;
    }
  }
  printf("%d\n",cnt);
}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>

using namespace std;
using ll = long long;


int main(){
    int H,W; cin >> H >> W;
    int sx,sy;
    int gx,gy;
    cin >> sy >> sx;
    cin >> gy >> gx;
    sy--; sx--; gy--; gx--;
    string S;
    int iii=10101010;
    vector<vector<int> > c(H,vector<int>(W,iii));
    bool f=false;
    for(int i=0;i<H;i++){
        cin >> S;
        for(int j=0;j<W;j++){
            if(S[j]=='#') c[i][j]=-1;
        }
    }
    queue<pair<int,int>> q;
    q.push(make_pair(sy,sx));
    c[sy][sx]=0;
    while(!q.empty()){
        pair<int,int> now = q.front(); q.pop();
        int n=c[now.first][now.second];
        for(int i=-2;i<=2;i++){
            for(int j=-2;j<=2;j++){
                int dy = now.first+i;
                int dx = now.second+j;
                int ttt=0;
                if(dy<0 || dy>=H) continue;
                if(dx<0 || dx>=W) continue;
                int nn=n;
                int dd=c[dy][dx];
                if(abs(i)>1 || abs(j)>1){
                    nn++;
                }else if(abs(i)==1 && abs(j)==1){
                    nn++;
                }
                if(dd==-1){
                    continue;
                }else if(dd>nn){
                    c[dy][dx] = nn;
                    q.push(make_pair(dy,dx));
                }else{
                    continue;
                }   
            }
        }
        
    }
    if(c[gy][gx]!=iii){
        cout << c[gy][gx] << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 7716
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 TowerArray[] = new int[1000];
		TowerArray[0] = 0;

		for(int i = 1; i < 1000; i++ ) {
			TowerArray[i] = TowerArray[i-1] + i;
		}

		int n = b - a;

		System.out.println(TowerArray[n] - b);

	}

}

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

using namespace std;


int main()
{
    long long N, A, B;
	cin >> N >> A >> B;

	vector<bool> bools;
	bool flag = false;
	long long count = 0;
	long long size = 0;

	long long mltNum = N / (A + B);

	size = mltNum * (A + B);
	count = mltNum * A;



	while (flag == false)
	{

		if (!flag) {
			count += A;
			size += A;
		}

		if (size >= N) {
			flag = true;
			count = count - (size - N);
			break;
		}

		if (!flag) {
			size += B;
		}

		if (size >= N) {
			flag = true;

			break;
		}
	}


	cout << count << endl;


}

Measured memory_bytes: 256
N = int(input())

As = []
As = list(map(int,input().split()))
Bs = []
Bs = list(map(int,input().split()))
Cs = []
Cs = list(map(int,input().split()))

value = 0
before = As[0]
for i,a in enumerate(As):
	value += Bs[a-1]
	if before+1 == a-1:
		value += Cs[before]
	before = a-1
	
print(value)

Measured memory_bytes: 38384
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main()
{
    double x1, y1, x2, y2, d;
    cin >> x1 >> y1 >> x2 >> y2 ;
    d = sqrt((x1 - x2)* (x1 - x2) + (y1 - y2)*(y1 - y2));
    cout << fixed;
    cout << setprecision(6) << d << endl;
    return 0;
}


Measured memory_bytes: 3272
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}
namespace IO{
    char nc(){ static char bf[100000],*p1=bf,*p2=bf; return p1==p2&&(p2=(p1=bf)+ fread(bf,1,100000,stdin),p1==p2)?EOF:*p1++; }
    int rd(){ int res=0; char c=getchar(); while(!isdigit(c))c=getchar(); while(isdigit(c))res=res*10+c-'0',c=getchar(); return res; }
}/*}}}*/
/******************heading******************/

int n;

int calc(int x){
    x=x&-x;
    FOR(i,1,31)if((x>>i-1)&1)return i;
}

int main(){
    scanf("%d",&n);
    FOR(i,0,n-1){
        FOR(j,i+1,n-1){
            printf("%d%c",calc(i^j)," \n"[j==n-1]);
        }
    }
    return 0;
}


Measured memory_bytes: 512
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <vector>
#include <stdio.h>
#include <iostream>
#include <unordered_set>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <random>
#include <time.h>
#include <cassert>


#define prev askdnsajd
#define rank asasdmdnasd
#define next lsjndajbs
#define hash asmdklansd
#define index asdklnas
#define right sld
#define left sldl

using namespace std;

typedef long long ll;
typedef long double dbl;

template<class T>
void print(vector<T> s){
    for (T x : s)
        cout << x << " ";
    cout << endl;
}

mt19937 mrand(random_device{} ());
int rnd() {
    return mrand();
}

class SegmentTree{
private:
    int b;
    vector<ll> add, tree;

private:
    void push(int v, int vl, int vr){
        tree[v] += (vr - vl) * add[v];
        if (vr - vl > 1){
            add[v * 2 + 1] += add[v];
            add[v * 2 + 2] += add[v];
        }
        add[v] = 0;
    }

    void update(int v, int vl, int vr, int l, int r, int x){
        push(v, vl, vr);
        if (vl >= r || vr <= l)
            return;
        if (vl >= l && vr <= r){
            add[v] += x;
            push(v, vl, vr);
            return;
        }
        int vm = (vl + vr) / 2;
        update(v * 2 + 1, vl, vm, l, r, x);
        update(v * 2 + 2, vm, vr, l, r, x);
        tree[v] = tree[v * 2 + 1] + tree[v * 2 + 2];
    }

    ll get(int v, int vl, int vr, int l, int r){
        push(v, vl, vr);
        if (vl >= r || vr <= l)
            return 0;
        if (vl >= l && vr <= r)
            return tree[v];
        int vm = (vl + vr) / 2;
        return get(v * 2 + 1, vl, vm, l, r) + get(v * 2 + 2, vm, vr, l, r);
    }

public:
    SegmentTree(int n){
        b = 0;
        while ((1 << b) < n)
            b++;
        b = (1 << b);
        tree.resize(2 * b - 1);
        add.resize(2 * b - 1);
    }

    void update(int l, int r, int val){
        update(0, 0, b, l, r, val);
    }

    ll get(int l, int r){
        return get(0, 0, b, l, r);
    }
};

const int maxn = 2e5 + 7;

vector<int> s[maxn];
int color[maxn];
int cur = 0;
int tin[maxn], tout[maxn];

void dfs(int v){
    color[v] = 1;
    tin[v] = cur++;
    for (int u : s[v]){
        if (color[u] == 0)
            dfs(u);
    }   
    tout[v] = cur;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(77);
    int n, q;
    cin >> n >> q;
    for (int i = 1; i < n; i++){
        int a, b;
        cin >> a >> b;
        s[a - 1].push_back(b - 1);
        s[b - 1].push_back(a - 1);
    }
    dfs(0);
    SegmentTree tree(n);
    while (q-- > 0){
        int p, x;
        cin >> p >> x;
        tree.update(tin[p - 1], tout[p - 1], x);
    }
    for (int i = 0; i < n; i++)
        cout << tree.get(tin[i], tin[i] + 1) << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 30336
S = list(input())
ans1 = 0
ans2 = 0

for i in range(len(S)):
    if i % 2 == 0:
        if S[i] != '1':
            ans1 += 1
    elif i % 2 == 1:
        if S[i] != '0':
            ans1 += 1
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] != '0':
            ans2 += 1
    elif i % 2 == 1:
        if S[i] != '1':
            ans2 += 1
print(min(ans1, ans2))

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

using namespace std;

int main()
{
    int w,a,b,c;
    cin >> w >> a >> b;
    if(a<=b)
    {
        if(a+w>b) c=0;
        else c=b-a-w;
    }
    else
    {
        if(b+w>a) c=0;
        else c=a-b-w;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
import math
from collections import Counter
n,m=map(int,input().split())
e=[int(x) for x in input().split()]
di={}
for i in range(m):
	a,b=map(int,input().split())
	if a in di:
		di[a]+=[b]
	else: di[a]=[b]
	if b in di:
		di[b]+=[a]
	else: di[b]=[a]

c=0
for u,v in di.items():
	h=e[u-1]
	f=False
	for i in v:
		if h<=e[i-1]:
			f=True
			break
	if not f:
		c+=1

for i in range(1,len(e)+1):
	if i not in di:
		c+=1

print(c)



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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;


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

    rep(i,N){
        cin>>H[i];
    }

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

    reverse(H.begin(),H.end());
    long long ans=0;
    rep(i,N){
        if(i>=K){
            ans+=H[i];
        }
    }

    cout<<ans<<endl;
    
    return 0;

}
/*


*/


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


class comb{
	vector<ll> f,fr;
	ll MOD_;
	public:
	//a^(p-1) = 1 (mod p)(p->Prime numbers)
	//a^(p-2) = a^(-1)
	ll calc(ll a,ll b,ll p){//a^(b) mod p   
		if(b==0)return 1;
		ll y = calc(a,b/2,p);y=(y*y)%p;
		if(b & 1) y = (y * a) % p;
		return y;
	}
	void init(ll n,ll mod){//input max_n
		MOD_ = mod;
		f.resize(n+1);
		fr.resize(n+1);
		f[0]=fr[0]=1;
		for(ll i=1;i<n+1;i++){
			f[i] = (f[i-1] * i) % mod;
			fr[i] = calc(f[i],mod-2,mod);
		}
	}
	ll nCr(ll n,ll r){
		if(n<0||r<0||n<r)return 0;
		return f[n] * fr[r] % MOD_ * fr[n-r] % MOD_;
	}
};


int main(){

	ll N,K;
	cin >> N >> K;
	vector<ll> A(N);
	FOR(i,0,N) cin >> A[i];
	SORT(A);
	comb co;
	co.init(N+2,MOD);
	map<ll,ll> ma;
	FOR(i,0,N)ma[A[i]]++;
	vector<ll> num,a;
	for(auto x:ma){
		num.push_back(x.second);
		a.push_back(x.first);
	}


	ll ans = 0;


	//max count
	ll sum = 0;
	FOR(i,0,num.size()){
		//if(sum+num[i] < K)continue;
		FOR(j,1,min(K,num[i])+1){
			ans += co.nCr(sum,K-j) * co.nCr(num[i],j) % MOD * a[i] % MOD;
			ans %= MOD;
		}
		sum += num[i];
	}

	sum = 0;
	FORR(i,0,num.size()){
		//if(sum+num[i] < K)continue;
		FOR(j,1,min(K,num[i])+1){
			ans += MOD - (co.nCr(sum,K-j) * co.nCr(num[i],j) % MOD * a[i] % MOD);
			ans %= MOD;
		}
		sum += num[i];
	}

	cout << ans << endl;

}



Measured memory_bytes: 9972
def set_depth nodes, node_id, depth
  nodes[node_id][3] = depth
  set_depth nodes, nodes[node_id][1][0], depth + 1 if nodes[node_id][1][0] != -1
  set_depth nodes, nodes[node_id][1][1], depth + 1 if nodes[node_id][1][1] != -1
end

def set_height nodes, node_id, height
  nodes[node_id][4] = height if !nodes[node_id][4] || nodes[node_id][4] < height
  set_height nodes, nodes[node_id][0], height + 1 if nodes[node_id][0] != -1
end

n = gets.chomp.to_i
nodes = Array.new(n)
while l = gets
  node_id, *child_node_ids = l.chomp.split(' ').map(&:to_i)
  if nodes[node_id]
    nodes[node_id][1] = child_node_ids
  else
    nodes[node_id] = [-1, child_node_ids, -1, nil, nil] # u's parent, u's children, u's sibling, u's depth, u's height
  end
  child_node_ids.each_with_index do |child_node_id, i|
    if child_node_id != -1
       sibling_node_id = (i == 0) ? child_node_ids[1] : child_node_ids[0]
       if nodes[child_node_id]
         nodes[child_node_id][0] = node_id
         nodes[child_node_id][2] = sibling_node_id
       else
         nodes[child_node_id] = [node_id, [], sibling_node_id, nil, nil]
       end
    end
  end
end

root_node_id = nil
nodes.each_with_index do |node, i|
  if node[0] == -1
    root_node_id = i
    break
  end
end
set_depth nodes, root_node_id, 0
nodes.each_with_index do |node, i|
  degree = node[1].count{|c| c != -1}
  set_height nodes, i, 0 if degree == 0
end

nodes.each_with_index do |node, i|
  degree = node[1].count{|c| c != -1}
  node_type = if node[0] == -1
                'root'
              elsif degree == 0
                'leaf'
              else
                'internal node'
              end
  puts "node #{i}: parent = #{node[0]}, sibling = #{node[2]}, degree = #{degree}, depth = #{node[3]}, height = #{node[4]}, #{node_type}"
end


Measured memory_bytes: 8912
// #include <iostream>
// // g++ hello.cpp && ./a.out
// using namespace std;
// int reverse(int n) {
// 	int rev,ans = 0;
// 	while(n != 0) {
// 		rev = n % 10;
// 		ans = (ans * 10) + rev; 
// 		n = n / 10;
// 	}
// 	return ans;
// }

// int main() {
// 	int T;
// 	cin >> T;
// 	int N;
// 	while(T--) {
// 		cin >> N;
// 		 cout << reverse(N) << endl;
// 	}
// 	return 0;
// }


// #include <iostream>
// // g++ hello.cpp && ./a.out
// using namespace std;

// int max(int arr[], int a) {
// 	int lar = 0, ans = 0;
// 	for (int i = 0; i < n; i++) {
// 		lar += arr[i];
// 		if (lar < 0 || max < arr[i+1]) {
// 			lar = arr[i+1];
// 		}
// 		return lar;
// 	}
// }

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

// #include <iostream>
// // g++ hello.cpp && ./a.out
// using namespace std;

// int maxSpeed(int arr[], int n) {
// 	int ans = 0;
// 	for (int i = 0; i < n; i++) {
// 		if (arr[0] > arr[1]) {
// 			ans++;
// 		}
// 		if (arr[i+1] > arr[i]) {
// 			ans++;
// 		}
// 		return ans;
// 	}
// }

// int main() {
// 	int T;
// 	cin >> T;
// 	int N;
// 	int arr[N];
// 	while (T--) {
// 		// int arr[N]; 
// 		cin >> N;
// 		for(int i = 0; i < N; i++) {
// 			cin >> arr[i];		
// 		}
// 		int max = maxSpeed(arr, N);
// 		cout << max << endl;
// 	}
// 	return 0;
// }

// #include <iostream>
// // g++ hello.cpp && ./a.out
// using namespace std;


// int main() {
// 	int X, Y, Z, temp, temp1;
// 	cin >> X >> Y >> Z;
// 	temp = X;
// 	X = Z;
// 	temp1 = Y;
// 	Y = temp;
// 	Z = temp1;
// 	cout << X <<" " << Y <<" " << Z << endl;
// 	return 0;
// }

// #include <iostream>
// // g++ hello.cpp && ./a.out
// using namespace std;


// int main() {
// 	int N, K;
// 	cin >> N;
// 	cin >> K;
// 	int ans;
// 	ans = N;
// 	while (ans > 0) {
// 		// ans = N;
// 		ans -= K;
// 		if (ans < 0)
// 		ans *= -1; 
// 	}
// 	cout << ans;
// 	return 0;
// }
#include <iostream>
// g++ hello.cpp && ./a.out
using namespace std;


int main() {
	int N, M;
	int total = 0;
	cin >> N >> M;
	int arr[N];
	for (int i = 0; i < N; i++) {
		cin >> arr[i];
		total += arr[i];
	}
	// cout <<total <<" " << M <<endl;
	int ans = 0;
	float notless = total*(1.0/(4.0*M));
	for (int i = 0; i < N; i++) {
		// cout << notless;
		if (arr[i] >= notless){
			// int ans = 0;
			ans++;
		}
	}
	if (ans >= M) {
		cout << "Yes";
	}
	else {
		cout <<"No";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> A(N-1);
  for(int i =0;i <N-1;i++){
    cin >> A.at(i);
  }
  sort(A.begin(), A.end()); 
  int count =0;
  int c=0;
  for(int i=1;i<N+1;i++){
    count =0;
    for(int j=c;j<N-1;j++){
    if(A.at(j)==i){
      count++;
    }
      else{
        c=j;
        break;
      }
    }
    cout << count << endl;
  }
}


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


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

    ll tmp_min = 10000000000;
    for ( int i = 0; i < s.length() - 2; i++ ) {
        tmp_min = min(tmp_min, abs((ll)atoi(s.substr(i, 3).c_str()) - 753));
    }

    cout << tmp_min << endl;

    return 0;
}

Measured memory_bytes: 256
/*** ?????????????´??????° ***/

#include <bits/stdc++.h>
using namespace std;
#define SIZE 300001

int main(){
	int N;
	int i, j;
	int count=0;
	int ms_prime[SIZE];
	int ms_primef[SIZE];
	for(i=0; i<SIZE; ++i) ms_primef[i]=1;
	for(i=0; i<6; ++i) ms_primef[i]=0;
	for(i=6; i<SIZE; ++i){
		if(i%7==1 || i%7==6){
			if(ms_primef[i]==1){
				for(j=i+i; j<SIZE; j+=i){
					ms_primef[j]=0;
				}
			}
		}
		else ms_primef[i]=0;
	}
	for(i=0; i<SIZE; ++i){
		if(ms_primef[i]==1){
			ms_prime[count]=i;
			++count;
		}
	}
	
	cin >> N;
	while(N!=1){
		cout << N << ":";
		
		for(i=0; i<count; ++i){
			if(N%ms_prime[i]==0){
				cout << " " << ms_prime[i];
			}
		}
		
		cout << endl;
		cin >> N;
	}
	return 0;
}

Measured memory_bytes: 4300
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,ans=0ll,ab=0ll,a=0ll,b=0ll;
  cin>>N;
  vector<string> s(N);
  for(int i=0;i<N;i++){
    cin>>s[i];
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<s[i].length()-1;j++){
      if(s[i][j]=='A'&&s[i][j+1]=='B'){
        ans++;
      }
    }
    if(s[i][0]=='B' && s[i][s[i].length()-1]=='A'){
      ab++;
    }else{
      if(s[i][s[i].length()-1]=='A'){
        a++;
      }
      if(s[i][0]=='B'){
        b++;
      }
    }
  }

  if(ab==N){
    cout<<ans+N-1<<endl;
  }else if(ab==0){
    cout<<ans+min(a,b)<<endl;
  }else{
    ans+=ab-1;
    if(a>0){
      ans++;a--;
    }
    if(b>0){
      ans++;b--;
    }
    cout<<ans+min(a,b)<<endl;
  }

  
}



Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>

using namespace std;
typedef long long ll;
int main(){
ll n,x;
cin>>n>>x;
ll a[n];
for(ll i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
int count=0;
ll sum=0;
for(ll i=0;i<n;i++){
sum+=a[i];
  if(sum<=x)
    count++;
}
  if(sum<x)
    count=count-1;
cout<<count;
  return 0;
}



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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h, w, m = LI()
bomb = defaultdict(lambda : 0)
cnt_h = [0] * h
cnt_w = [0] * w
for _ in range(m):
    H, W = LI()
    bomb[(H-1, W-1)] = 1
    cnt_h[H-1] += 1
    cnt_w[W-1] += 1

m_h = max(cnt_h)
m_w = max(cnt_w)
H_l = []
W_l = []
for i in range(h):
    if cnt_h[i] == m_h:
        H_l.append(i)

for i in range(w):
    if cnt_w[i] == m_w:
        W_l.append(i)

ans = m_h + m_w

for i in H_l:
    for j in W_l:
        if not bomb[(i, j)]:
            print(ans)
            quit()
print(ans-1)
            

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

int main() {
  int A, B;
  cin >> A >> B;

  int ans = 0;

  if (A >= B) {
    ans += A;
    A -= 1;
  } 
  else {
    ans += B;
    B -= 1;
  } 

  if (A >= B) {
    ans += A;
    A -= 1;
  } 
  else {
    ans += B;
    B -= 1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFLL = 1LL<<60;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;  // 階乗と階乗の逆元
  combination(int n):fact(n+1),ifact(n+1) {  // 階乗と階乗の逆元を n まで求める
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

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

  ll n, k;
  cin >> n >> k;

  combination comb(k);
  mint ans = comb(k, n);

  cout << ans.x << endl;

  return 0;
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> x, y;
    for (int i = 1; i <= n; i++) {
        for (int j = i+1; j <= n; j++) {
            if (i+j != n+(n%2==0)) {
                x.push_back(i); y.push_back(j);
            }
        }
    }
    cout << x.size() << endl;
    for (int i = 0; i < x.size(); i++) {
       cout << x[i] << " " << y[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
class Dice

    attr_accessor :dice_pos_1,:dice_pos_2,:dice_pos_3,:dice_pos_4,:dice_pos_5,:dice_pos_6

    def initialize(dice_num:[])
        @dice_pos_1 = dice_num[0]
        @dice_pos_2 = dice_num[1]
        @dice_pos_3 = dice_num[2]
        @dice_pos_4 = dice_num[3]
        @dice_pos_5 = dice_num[4]
        @dice_pos_6 = dice_num[5]
    end
    def parse_spin(spin_directions:[])
        spin_directions.each do |spin|
            if spin == "N"
                turn_north()
            elsif spin == "S"
                turn_south()
            elsif spin == "W"
                turn_west()
            elsif spin == "E"
                turn_east()
            end
        end
        return self
    end
    def turn_north
        @dice_pos_1,@dice_pos_2,@dice_pos_5,@dice_pos_6 = @dice_pos_2,@dice_pos_6,@dice_pos_1,@dice_pos_5
        return self
    end
    def turn_south
        @dice_pos_1,@dice_pos_2,@dice_pos_5,@dice_pos_6 = @dice_pos_5,@dice_pos_1,@dice_pos_6,@dice_pos_2
        return self
    end
    def turn_west
        @dice_pos_1,@dice_pos_3,@dice_pos_4,@dice_pos_6 = @dice_pos_3,@dice_pos_6,@dice_pos_1,@dice_pos_4
        return self
    end
    def turn_east
        @dice_pos_1,@dice_pos_3,@dice_pos_4,@dice_pos_6 = @dice_pos_4,@dice_pos_1,@dice_pos_6,@dice_pos_3
        return self
    end
end
dice_info = gets.split.map(&:to_i)
answers = []
gets.to_i.times do
    answers.push(gets.split.map(&:to_i))
end

answers.each do |answer|
    dices = [Dice.new(dice_num:dice_info)]
    new_dices = []
    break_flag = true
    while break_flag
        dices.each do |dice|
            if answer[0] == dice.dice_pos_1 && answer[1] == dice.dice_pos_2
                puts dice.dice_pos_3
                break_flag = false
                break
            else
                new_dices.push(dice.clone.turn_north)
                new_dices.push(dice.clone.turn_south)
                new_dices.push(dice.clone.turn_east)
                new_dices.push(dice.clone.turn_west)
            end
        end
        dices = new_dices
    end
end

=begin
=end


Measured memory_bytes: 6980
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    string s;
    vector<char> t;
    cin >> s;
    for(int i=0; i<s.length(); i++){
        if(s[i]=='0')t.push_back('0');
        else if(s[i]=='1')t.push_back('1');
        else if(t.size())t.pop_back();
    }
    for(int i=0; i<t.size(); i++){
        cout << t[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n, Y = map(int, input().split())
a = Y//1000

for x in range(n+1):
  for y in range(n-x+1):
    if 9*x + 4*y == a-n and n-x-y>=0:
      print(x, y, n-x-y)
      exit()
print(-1, -1, -1)

Measured memory_bytes: 9132
n,k = map(lambda x:int(x),input().split())
hunter_list = list(map(lambda x:int(x),input().split()))

def sum(list,k):#最初からk個までの和
    s = 0
    for i in range(len(list)-k):
        s = s+ list[i]
    return s


hunter_list.sort()

print(sum(hunter_list,k))




Measured memory_bytes: 26024
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

// const int maxn = 
// const int mo = 1e9 + 7;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;

	if (s[k-1] >='A' && s[k-1] <= 'Z')
		s[k-1] = s[k-1] - 'A' + 'a';
	
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
#include <iomanip>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << ": " << arg1 << " |";
	__f(comma + 1, args...);
}
const int N = 22;

char s[N][N];
int n_, m_;
bool used[N][N];

int mstep;
int D[4][2] = { {0,1},{1,0},{0,-1},{-1,0} };

struct node {
	int x, y,step;
	node(int x, int y, int step) :x(x), y(y), step(step) {};
	node() {};
} ednode;

void bfs(int x, int y) {
	queue<node> q;

	q.push({ x,y,0 });
	used[x][y] = 1;
	while (!q.empty()) {
		auto now = q.front(); q.pop();
		//int xx = it.x, yy = it.y, dis = it.step;
		if (now.step > mstep) {
			mstep = now.step;
			ednode.x = now.x;
			ednode.y = now.y;
		}
		for (int i = 0; i < 4; i++) {
			int xx = now.x + D[i][0];
			int yy = now.y + D[i][1];

			if (xx >= 0 && xx <= n_ && yy >= 0 && yy < m_ && !used[xx][yy] && s[xx][yy] == '.') {
				node next({ xx,yy,now.step + 1 });
				used[xx][yy] = 1;
				q.push(next);
			}
		}
	}
}
int main() {
	cin >> n_ >> m_;
	for (int i = 0; i < n_; i++) {
		for (int j = 0; j < m_; j++) {
			cin >> s[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < n_; i++) {
		for (int j = 0; j < m_; j++) {
			if (s[i][j] == '.') {
				memset(used, 0, sizeof used);
				mstep = 0;
				bfs(i, j);
				
				mstep = 0;
				
				memset(used, 0, sizeof used);
				bfs(ednode.x, ednode.y);
				ans = max(ans, mstep);
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;


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


#define INF 		2000000007
#define MOD			998244353

#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;



#define FAVOR(N,M)	(((N)/(M))==((N)%(M)))

int main(){
	int N,K;cin >> N >> K;
	string str;	cin >> str;

	str[K-1] = tolower(str[K-1]);

	cout << str << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<functional>

using namespace std;

int main() {
	int n;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	if (n == 2) {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll N = 100;
const ll W = 1e5;
ll dp[N+1][W+1];

int main(){
	int n,w;
	cin >> n >> w;
	int weight[n],value[n];
	for(int i=0;i<n;i++) cin >> weight[i] >> value[i];

	for(int i=1;i<=n;i++){
		for(int j=1;j<=w;j++){
			if(j-weight[i-1] >= 0) dp[i][j] = max(dp[i-1][j],dp[i-1][j-weight[i-1]]+value[i-1]);
			else
				dp[i][j] = dp[i-1][j];
		}
	}

	cout << dp[n][w];

return 0;
}



Measured memory_bytes: 81720
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a == 5 && b == 5 && c == 7 || a == 5 && b == 7 && c == 5 || a == 7 && b == 5 && c == 5)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
using namespace std;
int a, b, pro;
int main(void){
    // Your code here!
    cin >> a >> b;
    if (b / 10 == 0) pro = a * 10 + b;
    else if (b / 10 == 10) pro = a * 1000 + b;
    else pro = a * 100 + b;
    int t;
    t = sqrt(pro);
    if (t * t == pro) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
n = int(input())
ans = int(((n+1)*n)/2)
ans -= int(((n-(n%3)+3)*(n//3))/2)
ans -= int(((n-(n%5)+5)*(n//5))/2)
ans += int(((n-(n%15)+15)*(n//15))/2)

print(ans)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
std::vector<int> a[3000];
int main() {

  int n ;
  cin >> n ;
  int cnt = 0 ;
  while ( ((cnt) * (cnt - 1 ) / 2)  < n )
    cnt++;

  if (  ((cnt) * (cnt - 1 ) / 2)  > n) {
    cout << "No";
    return 0 ;
  }
  int pnt = 1 ;
  for (int i = 0; i < cnt; ++i)
  {
    for (int j = i + 1; j < cnt; ++j)
    {
      a[i].push_back(pnt);
      a[j].push_back(pnt);
      pnt++;
    }
  }
  cout << "Yes\n";
  cout << cnt << endl;
  for (int i = 0; i < cnt; ++i)
  {
    cout << a[i].size() << " ";
    for (int j = 0; j < a[i].size(); ++j)
    {
      cout << a[i][j] << (( j == a[i].size() -1 )?  "": " ");
    } 
    cout << endl;
  }

}

Measured memory_bytes: 2432
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<utility>
#include<math.h>
#include<set>
#include<map>
#include<string.h>
#include<stack>
#define n 200000
#define loop(a, b) for(int i = a; i<=b; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long lli;
typedef double llf;
struct edge{
	int from, to, weight;
	bool operator < (const edge& thing) const
	{
		return thing.weight < weight;
	}
};
vector<edge> V[n + 50];
bool visit[n + 50];
int a, b, c, d, e;
string str1, str2;
void addedge(int a, int b, int c)
{
	edge temp;
	temp.from = a;
	temp.to = b;
	temp.weight = c;
	V[a].push_back(temp);
}


//////////////////////////////////////////


void solve()
{
	cin >> a >> b;
	string arr[a + 5];
	loop(0, a - 1) cin >> arr[i];
	bool choose[a + 50][b + 50];
	memset(choose, 0, sizeof(choose));
	for(int i=0; i<a; i++)
	{
		for(int j=0; j<b; j++)
		{
			if(arr[i][j] == '#')
			{
//				printf("%d %d\n",i ,j);
				if(j + 1 < b && arr[i][j + 1] == '#' && j + 1 < b)
				{
					choose[i][j] = true;
					choose[i][j + 1] = true;
				}
				else if(j - 1 >= 0 && arr[i][j - 1] == '#' && j - 1 >= 0)
				{
					choose[i][j] = true;
					choose[i][j - 1] = true;
				}
				else if(i - 1 >= 0 && arr[i - 1][j] == '#' && i - 1 >= 0)
				{
					choose[i][j] = true;
					choose[i - 1][j] = true;
				}
				else if(i + 1 < a && arr[i + 1][j] == '#' && i + 1 < a)
				{
					choose[i][j] = true;
					choose[i + 1][j] = true;
				}
			}
		}
	}
	int yes = true;
	for(int i=0; i<a; i++)
		for(int j=0; j<b; j++)
		{
			if(arr[i][j] == '#' && !choose[i][j])
			{
//				printf("%d %d\n",i ,j);
				yes = false;
				break;
			}
		}
	if(!yes) cout << "No";
	else     cout << "Yes";
}
int main()
{
	int times = 1;
//	cin << times;
	loop(1, times)
	{
		solve();
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 4992
n,t=map(int,input().split())
a=list(map(int,input().split()))
b=c=0
m=a[0]
for i in range(n):
  if a[i]<m:
    m=a[i]
    continue
    
  d=a[i]-m
  if b<d:
    b=d
    c=1
  elif b==d:
    c+=1
print(c)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ll n, m;
    cin>>n>>m;
    vl h(n);
    forr(i, n)  cin>>h[i];
    
    map<ll, ll> mp1;
    forr(i, n)  mp1[i]++;
    forr(i, m)
    {
        ll r1, r2;
        cin>>r1>>r2;
        --r1, --r2;
        if(h[r1]>h[r2])
        {
            if(mp1.find(r2)!=mp1.end())
            mp1.erase(r2);
        }
        else if(h[r1]<h[r2])
        {
            if(mp1.find(r1)!=mp1.end())
            mp1.erase(r1);
        }
        else if(h[r1]==h[r2])
        {
            if(mp1.find(r1)!=mp1.end())
            mp1.erase(r1);
            if(mp1.find(r2)!=mp1.end())
            mp1.erase(r2);
        }
    }
    cout<<mp1.size();
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 10284
#include<iostream>
using namespace std;
const int BUF = 1000005;


int mod;

void read() {
    cin >> mod;
}


void work() {
    bool visited[BUF] = {};
    int cnt = 1;
    int cur = 7 % mod;

    while (cur != 0) {
        if (visited[cur]) {
            cout << -1 << endl;
            return;
        }
        visited[cur] = true;
        cur = (cur * 10 + 7) % mod;
        ++cnt;
    }

    cout << cnt << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 4528
#include <cstdio>
#include <algorithm>
#include <queue>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1e3 + 5;

struct Triple {
    int x, y, val;
    Triple(int x = 0, int y = 0, int val = INF): x(x), y(y), val(val) {}
    bool operator == (const Triple &rhs) const {
        return (x == rhs.x && y == rhs.y && val == rhs.val);
    }

    void operator = (const Triple &rhs) {
        x = rhs.x;
        y = rhs.y;
        val = rhs.val;
    }
};

char ch[maxn][maxn];
int vis[maxn][maxn], res[maxn][maxn], n, m, p, q, r, s;
queue<Triple> t;

int main() {
    scanf("%d%d%d%d%d%d", &n, &m, &p, &q, &r, &s);
    for (int i = 1; i <= n; i++)
        scanf("%s", ch[i] + 1);
    
    t.push(Triple(p, q, 1));

    while (!t.empty()) {
        Triple u = t.front();
        t.pop();
        if (res[u.x][u.y]) continue;
        res[u.x][u.y] = u.val;

        queue<Triple> a1;
        a1.push(u);
        while (!a1.empty()) {
            Triple c = a1.front();
            a1.pop();
            int x = c.x;
            int y = c.y;

            for (int i = -2; i <= 2; i++) {
                if (x + i < 1 || x + i > n) continue;
                for (int j = -2; j <= 2; j++) {
                    if (y + j < 1 || y + j > m) continue;
                    if (abs(i) + abs(j) == 1 && !res[x + i][y + j] && ch[x + i][y + j] == '.') {
                        res[x + i][y + j] = res[x][y];
                        a1.push(Triple(x + i, y + j, res[x][y]));
                    }
                    else if (abs(i) + abs(j) >= 2 && !res[x + i][y + j] && ch[x + i][y + j] == '.') {
                        t.push(Triple(x + i, y + j, res[x][y] + 1));
                    }
                }
            }
        }

        if (res[r][s]) break;
    }

        // printf("x = %d, y = %d\n", x, y);
        // printf("res:\n");
        // for (int i = 1; i <= n; i++) {
        //     for (int j = 1; j <= m; j++)
        //         printf("%d ", res[i][j]);
        //     putchar('\n');
        // }
        // printf("vis:\n");
        // for (int i = 1; i <= n; i++) {
        //     for (int j = 1; j <= m; j++)
        //         printf("%d ", vis[i][j]);
        //     putchar('\n');
        // }
        // printf("--------\n");

    printf("%d\n", res[r][s] - 1);
    return 0;
}

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

int main()
{
	int a;
	cin >> a;
	int ar[2*a];
	for(int i=0;i<2*a;i++)
		cin >> ar[i];
		
	sort(ar,ar+2*a);
	
	int ans=0;
	for(int i=0;i<2*a;i+=2)
	ans+=min(ar[i],ar[i+1]);
	
	
	cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int X;
  cin>>X;
  int ans;
  for(int i=1;i<1000;++i) {
    if(i*X%360==0) {
      ans = i;
      break;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3624
import math

n = int(input())
x = [0] + list(map(int, input().split()))
mod = 10**9 + 7

s = [pow(i, mod-2, mod) for i in range(0,n+1)]
for i in range(n):
    s[i+1] = (s[i+1] + s[i]) % mod

ans = 0
for i in range(1,n):
    ans += ((x[i+1] - x[i]) * s[i]) % mod
ans = int(ans * math.factorial(n-1)) % mod
print(ans)

Measured memory_bytes: 64024
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

  int a[1000000];
int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int l = 0, r = a[n-1]+1;
  while (r - l >= 1) {
    int mid = (l + r) / 2;
    int x = 2 * mid;
    bool flag = false;
    for (int i = n-1; i >= 0; i--) {
      x = 2 * a[i] - x;
      if (x < 0) {
        if (i % 2 == 1) {
          l = mid + 1;
        } else {
          r = mid;
        }
        flag = true;
        break;
      }
    }
    if (flag) {
      continue;
    }
    if (x < 2*mid) {
      r = mid;
    } else if (x > 2*mid) {
      l = mid + 1;
    } else {
      break;
    }
  }
  int x = (l + r) / 2 * 2;
  for (int i = 0; i < n; i++) {
    cout << x << " ";
    x = 2 * a[i] - x;
  }
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<iostream>
using namespace std;
int main(){
  int money;
  int change;
  while(cin >> money,money){
  money=1000-money;
  change=0;
  while(money){
    if(money>=500){
      change++;
      money-=500;
    }
    else if(money>=100){
      change++;
      money-=100;
    }
    else if(money>=50){
      change++;
      money-=50;
    }
    else if(money>=10){
      change++;
      money-=10;
    }
    else if(money>=5){
      change++;
      money-=5;
    }else{
      change++;
      money-=1;
    }
  }
  cout << change << endl;
}
}

Measured memory_bytes: 1156