akhauriyash/Code-Regression huggingface dataset:
import sys
from itertools import chain

n, k, *a = map(int, sys.stdin.read().split())
*a, = map(lambda x: min(k, x), a)
a.sort()

mask = (1 << k) - 1
def is_needed(i):
    if a[i] == k:
        return True
    res = 1
    for j in chain(a[:i], a[i+1:]):
        res |= (res << j)
        res &= mask
    return res >> (k - a[i]) 

def main():
    lo = -1
    hi = n
    while lo + 1 < hi:
        i = (lo + hi) // 2
        if is_needed(i):
            hi = i
        else:
            lo = i
    
    return hi
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <string>
#include <queue>
using namespace std;

int j, y;

void dfs(int x1, int x2, string s){
	if(x1 == j && x2 == y){
		cout << s << endl;
		return;
	}
	if(x1 == 5 && x2 <= 3) return;
	if(x1 <= 3 && x2 == 5) return;
	if(x1 == 5 && x2 == 5) return;
	if(x1 == 6 && x2 <= 4) return;
	if(x1 <= 4 && x2 == 6) return;
	dfs(x1 + 1, x2, s + "A");
	dfs(x1, x2+1, s + "B");

}

int main(void){
	cin >> j >> y;

	string s{};
	dfs(0, 0, s);

	return 0;
}

Measured memory_bytes: 1196
#include <iostream>

#define MAX_N 200000

using namespace std;

int main(void){

  int n;
  int a;
  int n_even = 0;
  int n_odd = 0;

  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a;
    if(a % 2 == 0) n_even++;
    else n_odd++;
  }

  if(n_odd == 1 && n_even == 0) cout << "YES" << endl;
  else if(n_odd % 2 == 1) cout << "NO" << endl;
  else cout << "YES" << endl;

  return 0;

}


Measured memory_bytes: 256
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber
// 29 06 2020

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);

// defines...
#define MP make_pair
#define PB push_back
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

int gcd(int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a*b/gcd(a, b));
}
ll comb(ll a, ll b)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans;
}


void bruce()
{
    cout << "\nExpected answer:\n";
    cout << "\nAnswer recieved:\n";
}

void task()
{
    //code here...

    int n, a=0, b=0;

    cin >> n;
    vi ara(n);
    for(int K=0; K<n; K++) cin >> ara[K];

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

    for(int K=n-1; K>0; K--){
        if(a==0 && ara[K]==ara[K-1]){
            a = ara[K];
            K--;
        }
        else if(b==0 && ara[K]==ara[K-1]){
            b = ara[K];
            K--;
        }
        if(a!=0 && b!=0) break;
    }

    cout << (ll)a*b << "\n";
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    task();

    return 0;
}




Measured memory_bytes: 3796
#include <stdio.h>

int main(void) {
	int A, B, C, D;
	scanf("%d%d%d%d", &A, &B, &C, &D);

	if (A + B > C + D) {
		printf("Left\n");
	}
	else if (A + B < C + D) {
		printf("Right\n");
	}
	else {
		printf("Balanced\n");
	}

	return 0;

}

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

const long long INF = 1LL << 60;

int main() {
    int N, K; cin >> N >> K;
    vector<long long> h(N);
    for(int i = 0; i < N; ++i) cin >> h[i];
    
    vector<long long> dp(N, INF);
    dp[0] = 0;
    for(int i = 0; i < N; ++i) {
        for(int k = 1; k <= K; ++k) {
            dp[i+k] = min(dp[i+k], dp[i] + abs(h[i+k] - h[i]));
        }
    }
    
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int inf=1e9+7;
const ll longinf=1LL<<60;

const int mx=200010;
const ll mod=1e9+7;

int n,q;
ll ans[mx];
vector<int> v[mx];

void dfs(int x,int p){
  for(auto to : v[x]){
    if(to == p){continue;}
    ans[to] += ans[x];					//ko += oya
    dfs(to,x);
  }
}

int main() {
  cin >> n >> q;
  for(int i=1,a,b; i<n; i++){ 
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  
  for(int i=1,p,x; i<=q; i++){ 
    cin >> p >> x;
    ans[p] += x;
  }
  dfs(1,-1);

  for(int i=1; i<=n; i++){ 
    cout << ans[i] << " ";
  }
  
  cout << endl; 
  return 0;
}  


Measured memory_bytes: 24320
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d=0,n=0,x,y;
    string s,s1,s2;
    cin >> n;
    VI m(n);
    rep(i,n) cin >> m[i];
    sort(ALL(m));

    cout << m[n/2] - m[n/2-1] << endl;
    return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i)
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
    ~debug() { cerr << endl; }
eni(!=) { cerr << boolalpha << i; ris; }
eni(==) { ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << &", " [ 2 * (it == d.b)] << *it;
  ris << "]";
}
#else
    sim dor(const c&) { ris; }
#endif
};
#define imie(...) "" << #__VA_ARGS__ " = " << (__VA_ARGS__) << ""
#define arr array
using ll = long long;
const int INF = 1e9 + 5;
const int N = 1e6 + 5;


int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	for(int& x:h) {
		cin >> x;
	}
	vector<int> dp(n+1,INF);
	dp[0] = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 1; j <= 2; j++) {
			if(i+j < n) {
				dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
			}
		}
	}
	cout << dp[n-1] << "\n";

    return 0;
}




Measured memory_bytes: 4000
import bisect
n = int(input())
h = list(map(int, input().split()))
ans = 0
i = 0
lmax = 0
while i < n:
    if i+1 < n and h[i] >= h[i+1]:
        lmax+=1
        ans = max(ans, lmax)
    else:
        lmax = 0
    i+=1
print(ans)


Measured memory_bytes: 14484
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] b = Console.ReadLine().Split();
            int a, A, B;
            A = int.Parse(b[0]); B = int.Parse(b[1]);
            if (B % A == 0) { a = A + B; }
            else { a = B - A; }
            Console.Write(a);
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#define F(i,n) for(int i=0;i<n;i++)
#define lli long long int
// #define vi vector<int>
// #define vpb(x) v.push_back(x)
// #define spb(x) s.push_back(x)
using namespace std;

int main()
{
    int n; cin>>n;
    if(n>=30)
    cout<<"Yes";
    else
    {
        cout<<"No";
    }
    
    return 0;
}

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

using namespace std;

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

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


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

int main() {
	int N, M, X;
	cin >> N >> M >> X;
	int c_left = 0;
	int c_rigth = 0;
	int cost;
	REP(i, 0, M){
		cin >> cost;
		if(cost > X) ++c_rigth;
		else if(cost < X) ++c_left;
	}
	cout << min(c_rigth, c_left);

}


Measured memory_bytes: 256
my $N=<>;
my $s=<>;chomp $s;
my @dat = split(/\s+/, $s);
my $max=1;
my @mrow;
my $sum=0;
for(my $i=0;$i<=$#dat;$i++){
   push (@mrow,$max);
   my $a =$dat[$i];
   $max = $max - $a;
   if($max <0){ print "-1";exit}
   $max = $max *2;
}
my $leaf=0;
for(my $i=0;$i<=$#dat;$i++){
   my $a =$dat[$N-$i];
   if($mrow[$N-$i] < ($leaf+$a)  ){
     $leaf = ($mrow[$N-$i]);
   }else{
      $leaf = $a+$leaf;
   }
   $sum = $sum + $leaf;
}
print "$sum";

Measured memory_bytes: 19724
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int i)
{
	for(int d=3; d<=sqrt(i); d=(d+2))
	{
		if(i % d == 0)
			return false;
	}
	return true;
}
int main()
{
	int n;
	cin>>n;
	
	if(n <= 2)
		cout<<2;
	else
	{
		for(int i=n;;i++)
		{	
			if(i%2 != 0)
			{
				if(isPrime(i))
				{
					cout<<i;
					break;
				}
			}
		}
	}	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

	      
int main(){
  int i, n, m, count = 0;
  scanf("%d", &n);
  int A[n];
  for(i = 0 ; i < n ; i++){
    scanf("%d", &A[i]);
  }
  scanf("%d", &m);
  int B[m];
  for(i = 0 ; i < m ; i++){
    scanf("%d", &B[i]);
  }
  i = 0;
  for(i = 0 ; i < m ; i++){
    int j;
    for(j = 0 ; j < n ; j++){
      if(A[j] == B[i]){
	count++;
	break;
      }
    }
  }
  printf("%d\n", count);
}



Measured memory_bytes: 2044
#include <stdio.h>
int main() {
	int n, t=0, x=0, y=0;
	
	for (scanf("%d", &n); n--; ) {
		int x0, y0, t0;
		scanf("%d %d %d", &t0, &x0, &y0);
      {
		int dt = t0 - t, dx = x0 - x, dy = y0 - y;
        
		if (dx + dy > dt || (dt - dx - dy) % 2 ) {
			printf("No");
			return 0;
		}
      }
		t = t0;
		x = x0;
		y = y0;
	}
	
		
		
	
	printf("Yes");
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
int main(){
  int K, N, m = 0;
  int *A, *D;
  scanf("%d %d", &K, &N);
  A = (int *)malloc(sizeof(int) * N);
  D = (int *)malloc(sizeof(int) * (N+1));
  for(int i=0; i<N; i++){
    scanf("%d ", &A[i]);
    if(i > 0 && m < A[i] - A[i-1]) m = A[i] - A[i-1];
  }
  if(m < A[0] + K - A[N-1]) m = A[0] + K - A[N-1];
  
  printf("%d\n", K - m);
  
  free(A);
  free(D);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
double h,m,a,b;
double t1,t2;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>a>>b>>h>>m;
    t1=h*30+m*1.0/60*30;
    t2=m*1.0/60*360;
    double delta=fabs(t1-t2);
    if(delta>180.0) delta=360.0-delta;
    cout<<fixed<<setprecision(9)<<sqrt(a*a+b*b-2*a*b*cos(delta/180.0*acos(-1.0)));
    return 0;
}


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

int main()
{
  int N;cin>>N;
  vector<int> h(N+1);
  for (int i=1;i<=N;i++)
    cin>>h[i];
  vector<int> dp(N+1);
  //dp[i]=足場i番目にいる時の最小コスト
  dp[0]=0;
  dp[1]=0;
  dp[2]=abs(h[2]-h[1]);
  for (int i=3;i<=N;i++)
  {
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])); 
  }
  
  //for(int i=0;i<=N;i++)
    //cout<<"dp["<<i<<"]="<<dp[i]<<endl;
  
  cout<<dp[N]<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

void print(int i){
	if(i==0)cout<<"Monday"<<endl;
	if(i==1)cout<<"Tuesday"<<endl;
	if(i==2)cout<<"Wednesday"<<endl;
	if(i==3)cout<<"Thursday"<<endl;
	if(i==4)cout<<"Friday"<<endl;
	if(i==5)cout<<"Saturday"<<endl;
	if(i==6)cout<<"Sunday"<<endl;
	return;
}

int main(){
	int m,d,num=3;
	int season[12]={31,29,31,30,31,30,31,31,30,31,30,31};
	while(cin>>m>>d,m){
		num=3;
		rep(i,m-1)num+=season[i];
		num+=d-1;
		num%=7;
		print(num);
	}
	return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll int t,n,x,k,d,b;
	cin>>x>>k>>d;
	x=abs(x);
	b=x/d;
	if(b==0)
	{
		if(k%2==0)
		{
			cout<<x<<endl;
		}
		else {
			cout<<abs(x-d)<<endl;
		}
	}
	else
	{
		if(b>=k)
		{
			cout<<x-(d*k)<<endl;
		}
		else
		{
			int c=k-b;
			if(c%2==0)
			{
				cout<<x-(d*b)<<endl;
			}
			else cout<<abs(x-(d*b)-d)<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	char ans[10];
	int j = 0;
	rep(i, n) {
		if(s[i] == 'B' && j > 0) j--;
		else if(s[i] != 'B') {
			ans[j] = s[i];
			j++;
		}
	}
	rep(i, j) {
		cout << ans[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] a) {
    Scanner scan = new Scanner(System.in);
    String[] nums = scan.nextLine().split("\\s");
    Integer h = Integer.valueOf(nums[0]);
    Integer w = Integer.valueOf(nums[1]);
    
    System.out.println((h * w) + " " + (h *2 + w * 2));
    
  }   
}


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

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vector<int> H(N);

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

    int ans = 0;

    int cnt = 0;
    for(int i = 0; i < N-1; i++){
        if(H[i] >= H[i+1]){
            cnt++;
        } else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }

    if(cnt !=  0) ans = max(ans, cnt);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    string s,t,u;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    cin>>u;
    if(s==u){
        cout<<a-1<<" "<<b<<endl;
    }else{
        cout<<a<<" "<<b-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,k,c = map(int,input().split())
c += 1
a = input()
b = a[::-1]
form = [0]
lat = [0]
for i in range(n):
  if a[i] == 'x':
    form.append(form[-1])
  else:
    try:
      form.append(max(form[-c]+1,form[-1]))
    except:
      form.append(1)
  if b[i] == 'x':
    lat.append(lat[-1])
  else:
    try:
      lat.append(max(lat[-c]+1,lat[-1]))
    except:
      lat.append(1)
form.append(form[-1])
lat.append(lat[-1])
lat.reverse()
#print(form)
#print(lat)
#print(len(form))
for i in range(n):
  if form[i] + lat[i+2] == k-1:
    print(i+1)

Measured memory_bytes: 70992
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200200;
const int MOD = 1e9+7;
template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

struct Combination {
    vector<ModInt<MOD>> fact;
    Combination(int n) : fact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= n; i++) {
            fact[i] = (fact[i-1] * i);
        }
    }
    ModInt<MOD> operator() (int n, int r) {
        if (r < 0 || r > n) return 0;
        return fact[n]/(fact[n-r]*fact[r]);
    }
};

map<int, int> prime_factor(int n) {
    map<int, int> ret;
    for (int i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n]++;
    return ret;
}

int main() {
    int n, m;
    cin >> n >> m;
    map<int, int> mp = prime_factor(m);
    Combination com(MAX);
    
    ModInt<MOD> ans = 1;
    for (auto& e : mp) {
        int r = e.second;
        ans *= com(n+r-1, r);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#########################ABC解説実装#########################
import heapq
N=int(input())
A=list(map(int, input().split()))

left, right = A[:N], [-1 * i for i in A[2*N:]]
sum_left, sum_right = sum(left), sum(right)

results = [0] * (N+1)
results[0] = sum_left
results[N] = sum_right

heapq.heapify(left)
heapq.heapify(right)

for i in range(N, 2*N):
    v = A[i]
    p = heapq.heappushpop(left, v)
    sum_left += v - p
    results[i-N+1] += sum_left
    
for i in range(2*N-1, N-1, -1):
    v = -1 * A[i]
    p = heapq.heappushpop(right, v)
    sum_right += v - p
    results[i-N] += sum_right
print(max(results))

Measured memory_bytes: 117012
def solve():
    n = int(input())
    k = int(input())
    x = list(map(int, input().split()))
    ans = 0
    for i in x:
        cost = min(i*2, abs(k-i)*2)
        ans += cost
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

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

template<class T> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<T> diff_weight;

    UnionFind(int n = 1, T SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, T SUM_UNITY = 0) {
        par.resize(n);
        rank.resize(n);
        diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) return x;
        int r = root(par[x]);
        diff_weight[x] += diff_weight[par[x]];
        return par[x] = r;
    }

    T weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool isSame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, T w) {
        w += weight(x);
        w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    T diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind<int> uf(N);
    for (int i = 0; i < M; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        if (uf.isSame(l, r)) {
            int diff = uf.diff(l, r);
            if (diff != d) {
                cout << "No" << endl;
                return 0;
            }
        }else{
            uf.merge(l, r, d);
        }
    }
    cout << "Yes" << endl;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> L(M), R(M);
  for(int i = 0; i < M; i++){
    cin >> L.at(i) >> R.at(i);
  }
  int l = L.at(0), r = R.at(0);
  for(int i = 0; i < M; i++){
    l = max(l, L.at(i));
    r = min(r, R.at(i));
  }
  if(l <= r)cout << r - l + 1 << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <unordered_map>

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

using namespace std;

int main()
{
  int n, a, b;
  int p[100];

  cin >> n >> a >> b;
  REP(i, n)
  {
    cin >> p[i];
  }

  sort(p, p + n);

  int ca = 0, cb = 0, cc = 0;
  REP(i, n)
  {
    if (p[i] <= a)
    {
      ca++;
      continue;
    }
    if (a < p[i] && p[i] <= b)
    {
      cb++;
      continue;
    }
    if (b < p[i])
    {
      cc++;
      continue;
    }
  }

  cout << min(ca, min(cb, cc)) << endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
using ll=int_fast64_t;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,m,l,a,b,c,q,s,t;
    in>>n>>m>>l;
    ll inf=LLONG_MAX/2;
    vector<vector<ll>> d(n,vector<ll>(n,inf));
    fr(i,m) in>>a>>b>>c,--a,--b,d[a][b]=d[b][a]=c;
    fr(i,n) d[i][i]=0;
    fr(k,n) fr(i,n) fr(j,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    fr(i,n) fr(j,n) d[i][j]=d[i][j]?(d[i][j]>l?inf:1):0;
    fr(k,n) fr(i,n) fr(j,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    in>>q;
    fr(i,q){
        in>>s>>t;
        --s,--t;
        cout<<(d[s][t]<inf?d[s][t]-1:-1)<<endl;
    }
}

Measured memory_bytes: 1280
#include <iostream>

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int r;

    cin >> r;
    cout << 3 * r * r << endl;

    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

a1 = (a + 9) // 10 * 10
b1 = (b + 9) // 10 * 10
c1 = (c + 9) // 10 * 10
d1 = (d + 9) // 10 * 10
e1 = (e + 9) // 10 * 10

tmax = 0
if tmax < a1 - a:
	tmax = a1 - a
if tmax < b1 - b:
	tmax = b1 - b
if tmax < c1 - c:
	tmax = c1 - c
if tmax < d1 - d:
	tmax = d1 - d
if tmax < e1 - e:
	tmax = e1 - e

print(a1+b1+c1+d1+e1-tmax)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define int int64_t
#define double long double
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
#define all(v) v.begin(),v.end() 
using namespace std;
//using pr = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

//プロトタイプ宣言
bool has_divisor(int, int);

//グローバル変数
//const int MAX_N;
//const int MAX_M;
//vvec data(N, vec(M));
//const int INF = ;

//関数：
/* yにxをn回乗じmodで割った余りを返す。
（素数pに対して x**p = x (mod p) が成り立つ。）*/
const int mod = 1000000007;
int mod_pow(int y, int x, int n, int mod) {
	//base case.
	int ans = y;
	if(n == 0) return ans;
	
	if(n%2 == 0) {
		int d = mod_pow(1, x, n/2, mod);
		rep(i, 2) ans = (ans * d) % mod;
	} else {
		ans = (ans * x) % mod;
		ans = (ans * mod_pow(1, x, n-1, mod)) % mod;
	}
	return ans;
}

/* yにmの階乗（からn-1の階乗を除したもの）を乗じmodで割った余りを返す（m > n）。 */
//const int mod = ;
int mod_factorial(int y, int m, int n, int mod) {
	int ans = y;
	for(int i=m; i>=n; --i) {
		ans *= i;
		ans %= mod;
	}
	return ans;
}

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

	int x, y; cin >> x >> y;
	
	if((x+y)%3 != 0) {
		cout << 0 << endl;
		return 0;
	}
	
	/* X+Yが3の倍数のとき、(+1,+2)の移動の回数をn、(+2,+1)の移動の回数をmとすると、n+2m=X,2n+m=Yという連立方程式が得られ、n,mが求まります。n<0またはm<0のとき答えは0です。そうでないときは、(m+n)Cnです。 */ 
	int n = (2*y-x)/3;
	int m = (x+y)/3 - n;
	if(n < 0 || m < 0) {
		cout << 0 << endl;
		return 0;
	}
	
	int mm = max(m, n); int nn = min(m, n);
	int ans = mod_factorial(1, mm+nn, mm+1, mod);
	for(int i=1; i<=nn; i++) {
		ans = ans * mod_pow(1, i, mod-2, mod) % mod;
	}
	
	cout << ans << endl;
	return 0;
}

//std::string str;
//str = std::to_string(int i);
//bitset<3> s(N);
//int ans = (char)grid - '0';
//int id = lower_bound(all(arr), x) - arr.begin();

/*struct data {
	char *name;
	int age;
	int height;
	double weight;
};*/

/*string ans = w;
string &ref = ans;
rep(i, N) {
	ref[i] = arr[i];
}*/

/*map<int,int> mp;
for(auto p : mp) {
	ct += p.second*(p.second-1); }

map<int,int>::iterator itr;
for(itr = mp.begin(); itr != mp.end(); itr++) {
	ans += itr->second * (itr->second-1);
}*/


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

typedef pair <int, int> ii;

const int Maxn = 100005;

int n, m;
string s;
int par[Maxn];
int val[Maxn];
deque <ii> D;

int main()
{
    cin >> n >> m;
    cin >> s;
    D.push_back(ii(0, n));
    for (int i = n - 1; i >= 0; i--) {
        while (!D.empty() && i + m < D.front().second) D.pop_front();
        if (D.empty()) { printf("-1\n"); return 0; }
        if (s[i] == '0') {
            par[i] = D.front().second;
            val[i] = val[D.front().second] + 1;
            while (!D.empty() && val[i] <= D.back().first) D.pop_back();
            D.push_back(ii(val[i], i));
        }
    }
    int v = 0;
    bool was = false;
    while (v < n) {
        if (was) printf(" ");
        else was = true;
        printf("%d", par[v] - v);
        v = par[v];
    }
    printf("\n");
    return 0;
}


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

#define deb(x) cerr<<"["#x<<" : "<<x<<" ]\n";
// abc084 B
int main()
{
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	
	if((int)s.length() != a+b+1) {
		puts("No");
		return 0;
	}
	
	bool ok = true;
	
	for(int i = 0; i < a+b+1; i++) {
		if(i == a and s[i] != '-') {
			ok = false;
			break;
		}
		
		if(i != a and (s[i] < '0' or s[i] > '9')) {
			ok = false;
			break;
		}
	}
	
	puts(ok ? "Yes" : "No");
}



Measured memory_bytes: 3616
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <random>

using namespace std;

long long N;
vector<string> s;

int cnt_ab(const string& sen) {
    int count = 0;
    string word = "AB";
    for (string::size_type pos = 0; (pos = sen.find(word, pos)) != string::npos; pos += word.size()) 
    {
        ++count;
    }
    return count;
}

int main()
{
    cin >> N;
    s.resize(N);
    long long ans = 0;
    long long acnt = 0, bcnt = 0, abcnt = 0;
    for(int i = 0;i < N;i++)
    {
        cin >> s[i];
        long long num = cnt_ab(s[i]);
        ans += num;
        if(s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A')
        {
            abcnt++;
        }
        else if(s[i][0] == 'B')
        {
            bcnt++;
        }
        else if(s[i][s[i].length() - 1] == 'A')
        {
            acnt++;
        }
    }
    if(abcnt == 0)
    {
        ans += min(acnt, bcnt);
    }
    else
    {
        ans += (abcnt - 1);
        if(acnt != 0)
        {
            ans++;
            acnt--;
        }
        if(bcnt != 0)
        {
            ans++;
            bcnt--;
        }
        ans += min(acnt, bcnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N, A;
    cin >> N;
    int res = 0;
    REP(i, N) {
        cin >> A;
        res += A - 1;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,i,sum1,x=0,sum2,j;
    scanf("%d",&n);

    for(i=1;i<=10;i++){
            for(j=1;j<=10;j++){
            sum1=0;
            sum2=0;
            sum1=(4*i)+(7*j);
            sum2=(4*j)+(7*i);
            if(sum1==n){
            x=1;
            break;
            }
            if(sum2==n){
            x=1;
            break;
            }
    }
    }
    if(x==1)
        printf("Yes\n");
    else if(n%4==0)
        printf("Yes\n");
    else if(n%7==0)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

using namespace std;
 
//#define int long long
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=0;i<=n;i++)

ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
 
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

ll modm(ll val, ll m) {
  ll res = val % m;
  if (res < 0) res += m;
  return res;
}

int main(){
    ios_base::sync_with_stdio(false);
    ll n,m,k,a,ans=0;
    cin >> n >> m;
    vector<ll> s(m,0);
    rep(i,n){
      cin >> k;
      rep(j,k){
        cin >> a;
        a--;
        s[a]++;
      }
    }
    rep(c,m){
      if(s[c]==n){
        ans++;
      }
    }

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


Measured memory_bytes: 3612
N = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

ans = 0
n = a.size()
0.upto(n-1).each do |i|
  if ((i+1)%2 == 1) && (a[i]%2 == 1)
    ans += 1
  end
end

p ans

    

Measured memory_bytes: 14364
#include <stdio.h>

int main(){
  int N,N1,N2,N3;
    scanf("%d",&N);
  
  N1=N%10;
  N2=(N/10)%10;
  N3=N/100;
  if(N1==7 || N2==7 || N3==7){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1588
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <list>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (1ll<<32);
static const int MAX = 100001;

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    int n;
    cin >> n;
    
    double res = n/2;
    if(n%2==1)res++;
    
    res/=n;
    
    printf("%.9f\n", res);
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
ll a[200005];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	ll sum = 0;
	FOR(i, n) {
		cin >> a[i];
		a[i] += sum;
		sum = a[i];
	}
	ll mi = 3000000007;
	FOR(i, n-1) {
		mi = min(mi, abs(a[n-1]-2*a[i]));
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
long long n, a[105] = { 0 }, dp[105][105] = { 0 };
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	dp[0][a[0]] = 1;
	for (int i = 1; i <= n - 2; i++) {
		for (int j = 0; j <= 20; j++) {
			if (j + a[i] <= 20 && j - a[i] >= 0) dp[i][j] = dp[i - 1][j + a[i]] + dp[i - 1][j - a[i]];
			else if (j + a[i] <= 20) dp[i][j] = dp[i - 1][j + a[i]];
			else dp[i][j] = dp[i - 1][j - a[i]];
		}
	}
	cout << dp[n - 2][a[n - 1]] << endl;
	return 0;
}

Measured memory_bytes: 3176
#include <stdio.h>

int main()
{
  int h,w;
  int i,j;
  scanf("%d",&h);
  scanf("%d",&w);
  while(!((h==0) && (w==0))){
    for(i=0;i<w;i++){
      printf("#");
    }
    printf("\n");

    for(i=0;i<h-2;i++){
      printf("#");
      for(j=0;j<w-2;j++){
        printf(".");
      }
      printf("#\n");
    }
    for(i=0;i<w;i++){
      printf("#");
    }
    printf("\n\n");
    scanf("%d",&h);
    scanf("%d",&w);
  }


  return 0;
}

Measured memory_bytes: 588
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> str = Arrays.asList(sc.next().split(""));
        Integer ans1 = 0;
        Integer ans2 = 0;
        for (int i = 0; i < str.size(); i++) {
            if (i % 2 == 0) {
                // 101010...
                if ("0".equals(str.get(i))) {
                    ans1++;
                }
                // 010101...
                if ("1".equals(str.get(i))) {
                    ans2++;
                }

            } else {
                // 101010...
                if ("1".equals(str.get(i))) {
                    ans1++;
                }
                // 010101...
                if ("0".equals(str.get(i))) {
                    ans2++;
                }

            }
        }
        System.out.println(Math.min(ans1, ans2));

    }
}

Measured memory_bytes: 32840
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        st: [(String, i64); n],
        x: String,
    }

    let mut ans = 0;
    let mut sleep = false;

    for (s, t) in st.into_iter() {
        if s == x {
            sleep = true;
        } else if sleep {
            ans += t;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
//#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0)
#define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0)
#else
#define DEBUG_PRINT(...)do{}while(0);
#define DEBUG_VAL(a, b)do{}while(0);
#endif

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
    ll a, b, c, d;
    cin >>  a >> b >> c >> d;
    vl ans(4);
    ans[0] = a*c;
    ans[1] = a*d;
    ans[2] = b*c;
    ans[3] = b*d;
    sort(ans.begin(), ans.end());
    cout << ans[3] << endl;
}

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

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


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

int main() {
	vector<string> s; int h, w; cin >> h >> w;

	for (int i = 0; i < h; i++) {
		string sdash; cin >> sdash;
		s.push_back(sdash);
	}

	for (int i = 0; i < h; i++) {
		cout << s[i] << endl; cout << s[i] << endl;
	}

	return 0;
}


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

long long int dp[1002][1002];     //dp[?????\???][???]
const int INF = 1145141919;

int main()
{
  int n, m, kyori[1002] = {};
  int tenki[1002] = {};
  long long int ans=INF;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> kyori[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> tenki[j];
  }
  for (int i = 0; i <= 1001; i++) {
    for (int j = 0; j <= 1001; j++) {
      dp[i][j] = INF;
    }
  }
  for (int i = 0; i < m; i++) {
    dp[i][0] = 0;
  }
  for (int i = 1; i <= m; i++) {      //??\??°
    for (int j = 1; j <= n; j++) {    //???
      dp[i][j] = min(dp[i - 1][j - 1] + kyori[j - 1] * tenki[i - 1], dp[i-1][j]);
    }
  }
  cout << dp[m][n] << endl;
  return 0;
}

Measured memory_bytes: 9008
n = int(input())
F = [list(map(int,input().split())) for i in range(n)]
P = [list(map(int,input().split())) for i in range(n)]

max_Profit = -10**12
for i in range(1,2**10):
  C = [0]*n
  for j in range(10):
    for k in range(n):
        if F[k][j] == ((i >> j) & 1) == 1:
          C[k] += 1
  profit = 0
  for l in range(n):
    profit += P[l][C[l]]
  max_Profit = max(max_Profit,profit)
  
print(max_Profit)

Measured memory_bytes: 42220
import java.util.*;

public class Main {
    static Scanner sc;
    public static void main(String[] args) {
        sc=new Scanner(System.in);
        a();
        //b();
        //c();
        //d();
    }
    public static void a(){
        int a=sc.nextInt();int b=sc.nextInt();
        System.out.println((a>9||b>9)?-1:a*b);
    }
    public static void b(){
        int n=sc.nextInt();
        int po[]=new int[81];
        boolean b=false;
        for(int i=0;i<9;i++)
        for(int j=0;j<9;j++)if((i+1)*(j+1)==n)b=true;
        System.out.println(b?"Yes":"No");
    }
    public static void c(){
        long n=sc.nextLong();
        long q=(long)Math.sqrt(n);
        long index=n;
        for(int i=2;i<=q;i++){
            if(n%i==0)index=i;
        }
        System.out.println(index+(n/index)-2);
    }
    public static void d(){
        int a=sc.nextInt();
        int b=sc.nextInt();
        int x=sc.nextInt();
        if((double)2*x/(a*a)-b>=0){
            double bb=((double)2*x)/(a*a)-b;
            System.out.println(Math.atan((-bb+b)/a)*180/Math.PI);
        }
        else{
            double aa=((double)2*x)/(a*b);
            System.out.println(Math.atan(((double)b)/aa)*180/Math.PI);
        }
        
    }
}


Measured memory_bytes: 23636
import std.stdio, std.string, std.conv;

void main() {
    int n = readln.chomp.to!int;
    int[] a = readln.split.to!(int[]);
    int[] rain = new int[n];
    foreach (i; 0 .. n) {
        rain[0] += (-1) ^^ i * a[i];
    }
    foreach (i; 1 .. n) {
        rain[i] = 2 * a[i-1] - rain[i-1];
    }
    rain.to!(string[]).join(" ").writeln;
}

Measured memory_bytes: 13208
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN = 305;
int g[MAXN][MAXN], pro[MAXN];
bool be_deleted[MAXN];

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (register int i = 1; i <= n; i++)
		for (register int j = 1; j <= m; j++)
			scanf("%d", &g[i][j]);
	int ans = n;
	for (register int i = 1; i <= m; i++) {
		memset(pro, 0, sizeof(pro));
		for (register int j = 1; j <= n; j++)
			for (register int k = 1; k <= m; k++) {
				int temp = g[j][k];
				if (!be_deleted[temp]) {
					pro[temp]++;
					break;
				}
			}
		int pos = int(max_element(pro+1, pro+1+m) - pro);
		ans = min(ans, pro[pos]);
		be_deleted[pos] = true;
	}
	printf("%d", ans);
	return 0;
}

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

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

	int X[105],min = 101,max = -1;

	for (int i = 0; i < N; i++) {
		cin >> X[i];
		if (X[i] < min) min = X[i];
		if (X[i] > max) max = X[i];
	}

	long long sum_min = 1000000000;

	for (int i = min; i <= max; i++) {
		long long sum = 0;
		for (int j = 0; j < N; j++) {
			sum += (X[j] - i)*(X[j] - i);
		}
		if (sum < sum_min) sum_min = sum;
	}

	cout << sum_min << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    int l;
    cin >> l;
    //等差数列
    //初稿aはl
    int sum = n * (2 * l + (n - 1)) / 2;
    int min = 200;
    bool isminus = false;
    for(int i = 1; i < n+1; i++){
        if(min > abs(l+i-1)){
            min = abs(l+i-1);
            isminus = l+i-1 < 0;
        }
    }

    if(isminus){
        cout << sum + min << endl;
    }else{
        cout << sum - min << endl;
    }
    
    

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < p.length; ++i) {
            p[i] = sc.nextInt() - 1;
        }
        int[] x = new int[M];
        int[] y = new int[M];
        for (int i = 0; i < M; ++i) {
            x[i] = sc.nextInt() - 1;
            y[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(p, x, y));

        sc.close();
    }

    static int solve(int[] p, int[] x, int[] y) {
        int N = p.length;

        int[] parents = new int[N];
        Arrays.fill(parents, -1);

        for (int i = 0; i < x.length; ++i) {
            int rootX = findRoot(parents, x[i]);
            int rootY = findRoot(parents, y[i]);

            if (rootX != rootY) {
                parents[rootY] = rootX;
            }
        }

        Map<Integer, Set<Integer>> rootToIndices = new HashMap<>();
        for (int i = 0; i < N; ++i) {
            int root = findRoot(parents, i);
            if (!rootToIndices.containsKey(root)) {
                rootToIndices.put(root, new HashSet<>());
            }

            rootToIndices.get(root).add(i);
        }

        return rootToIndices.values().stream()
                .mapToInt(indices -> (int) indices.stream().filter(index -> indices.contains(p[index])).count()).sum();
    }

    static int findRoot(int[] parents, int node) {
        int root = node;
        while (parents[root] != -1) {
            root = parents[root];
        }

        int p = node;
        while (p != root) {
            int next = parents[p];
            parents[p] = root;

            p = next;
        }

        return root;
    }
}

Measured memory_bytes: 116524
#include <bits/stdc++.h>
using namespace std;
int main(){
	int h, w;
	while(cin >> h >> w){
		if(h==0 && w==0)
			break;
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++)
				cout << '#';
			cout << endl; 
		}
		cout << endl;
	}
	return 0;
} 


Measured memory_bytes: 3100