akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    for(int i=0; i<s.size()-1; ++i) {
        if(s[i] == s[i+1]) {
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
        if(i+2 < s.size() && s[i] == s[i+2]) {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
}


Measured memory_bytes: 512
s = input()
acgt = set({'A','C','G','T'})
s = s + 'Z' #dummy
ans = [-1]*(len(s))
def dfs(i):
    if ans[i] != -1:
        return ans[i]
    elif s[i] not in acgt:
        ans[i] = 0
        return 0
    else:
        ans[i] = dfs(i+1) + 1
        return ans[i]
for i in range(len(s)):
    dfs(i)
print(max(ans))

Measured memory_bytes: 38384
import heapq

n,m = map(int,input().split())
ab = [tuple(map(int,input().split())) for i in range(n)]
ab = sorted(ab,key=lambda x: x[0],reverse=True)
heap = []
ans = 0
for i in range(1,m+1):
    while True:
        if not ab:
            break
        elif ab[-1][0] <= i:
            x = ab.pop(-1)
            heapq.heappush(heap,x[1]*-1)
        else:
            break
    if heap:
        y = heapq.heappop(heap)
        ans += y*-1
print(ans)

Measured memory_bytes: 18952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll dp[100001], mdp[100001], odp[100001], omdp[100001], x[100000], v[100000], ox[100000];
int main() {
    ll c;
    scanf("%lld%lld", &n, &c);
    ll res = 0;
    ll now = 0;
    for (int i = 0; i < n; i++) {
        scanf("%lld%lld", &x[i], &v[i]);
        ox[i] = c - x[i];
    }
    // 順に回る時
    for (int i = 0; i < n; i++) {
        now += v[i];
        dp[i] = now - x[i];
        if (i == 0) mdp[i] = dp[i];
        else mdp[i] = max(mdp[i-1], dp[i]);
        res = max(res, now - x[i]);
    }
    now = 0;
    // 逆に回る時
    for (int i = n-1; i >= 0; i--) {
        now += v[i];
        odp[i] = now - ox[i];
        if (i == n-1) omdp[i] = odp[i];
        else omdp[i] = max(omdp[i+1], odp[i]);
        res = max(res, now - ox[i]);
    }
    // 往復する場合
    // 1 2 3 4 5 6 7 8 9 10
    now = 0;
    for (int i = n-1; i > 1; i--) {
        now += v[i];
        res = max(res, mdp[i-1] + now - 2 * ox[i]);
    }
    now = 0;
    for (int i = 0; i < n - 1; i++) {
        now += v[i];
        res = max(res, omdp[i+1] + now - 2 * x[i]);
    }
    printf("%lld\n", res);
}


Measured memory_bytes: 5760
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long k = sc.nextLong();
    long q = sc.nextLong();
    long[] p = new long[n];
    for(int i = 0; i < n; i++) {
      p[i] = k - q;
    }
    for(int i = 0; i < q; i++) {
      int a = sc.nextInt() - 1;
      p[a]++;
    }
    for(int i = 0; i < n; i++) {
      String ans = "Yes";
      if(p[i] <= 0) ans = "No";
      System.out.println(ans); 
    }
  }
}

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

int main() {
    llint N, K;
    cin >> N >> K;
    vector<pair<llint, llint>> dr(N);
    for(int i = 0; i < N; i++) {
        cin >> dr[i].first >> dr[i].second;
    }
    sort(dr.begin(), dr.end());
    int ind = 0;
    priority_queue<llint> pq;
    llint rez = 0;
    for(int i = 1; i <= K; i++) {
        for(; ind < dr.size(); ind++) {
            if(dr[ind].first <= i) {
                pq.push(dr[ind].second);
            }
            else 
                break;
        }
        if(!pq.empty()) {
            rez += pq.top();
            pq.pop();
        }
    }
    cout << rez;
}

Measured memory_bytes: 2936
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        
        if(n % ((2 * d) + 1) == 0) {
        	System.out.println(n / ((2 * d) + 1));
        } else {
        	System.out.println((n / ((2 * d) + 1)) + 1);
        }
    }
}


Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<functional>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	for (int i = 6; i >-1; i--) {
		if (1 << i <= n) {
			cout << (1 << i) << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

typedef long long LL;
typedef vector<int> VI;

int main() {
  int a;
  string S;
  cin >> a >> S;
  if (a >= 3200) {
    cout << S << endl;
  } else {
    cout << "red" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h[100001];
int main()
{
	int minv=INT_MAX,i,n,k;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
		scanf("%d",&h[i]);
	sort(h,h+n);
	for(i=n-1;i>=k-1;i--)
	{
		//printf("%d %d\n",i-k+1,i);
		minv=min(minv,abs(h[i-k+1]-h[i]));
	}
	printf("%d",minv);
	return 0;
}

Measured memory_bytes: 640
object Main extends App {

  val Array(n, a, b) = io.StdIn.readLine.split(" ").map(_.toInt)

  val ans = (1 to n).foldLeft(0)( (acc,i) => {
      val sum = String.valueOf(i).map(_.asDigit).sum
      if(a <= sum && sum <= b ) acc + i else acc
    })

  println(ans)
}

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

int main(){
int n;
cin >> n;
set <string> ss;
rep(i,n) {
    string s; cin >> s;
    ss.insert(s);
}
cout << ss.size() << endl;


}

Measured memory_bytes: 19148
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
int B[MAXN];
int C[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

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

    cin>>n>>k;

    for(int i=0;i<n;i++)
        A[i] = k+i;

    int mid = (n+1)>>1;

    for(int i=0;i<n;i++){
        B[(mid+i)%n] = k+n+i;
    }

    for(int i=0;i<mid;i++)
        C[i] = k+(n<<1)+(i<<1);

    for(int i=0;i<(n>>1);i++)
        C[i+mid] = k+(n<<1)+((i<<1)|1);

    for(int i=0;i<n;i++)
        if(C[i]<A[i]+B[i]){
            cout<<"-1\n";
            return 0;
        }

    for(int i=0;i<n;i++)
        cout<<A[i]<<" "<<B[i]<<" "<<C[i]<<"\n";

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int>a(n+2);
  vector<int>b(n+1);
  for(int i=0;i<n+1;i++) cin >> a.at(i);
  for(int i=0;i<n;i++) cin >> b.at(i);
  a.at(n+1)=0;
  b.at(n)=0;
  
  int64_t x=0;
  int tmp1=0,tmp2=0;
  
  tmp1=min(a.at(0),b.at(0));
  x+=tmp1;
  tmp2=min(a.at(1),b.at(0)-tmp1);
  x+=tmp2;

  for(int i=1;i<n+1;i++){
     tmp1=min(a.at(i)-tmp2,b.at(i));
     x+=tmp1;
     tmp2=min(a.at(i+1),b.at(i)-tmp1);
     x+=tmp2;
  }
  cout << x;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 200005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000000
#define mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    int n, k;
    cin>>n>>k;
    ll a[k+5];
    for(int i = 0; i < k; i++)
        cin>>a[i];
    a[k] = n + a[0];
    vector<ll>ans;
    for(int i = 1; i <= k; i++)
        ans.push_back(a[i]-a[i-1]);
    sort(ans.begin(), ans.end());
    ll sum = 0;
    for(int i = 0; i < ans.size()-1; i++)
        sum+=ans[i];
    cout<<sum<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 4980
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC127D
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] NM = CIN.LongArray();
            long N = NM[0];
            long M = NM[1];
            long[] A = CIN.LongArray();
            long[] B = new long[M];
            long[] C = new long[M];

            for (int i = 0; i < M; i++)
            {
                long[] BC = CIN.LongArray();
                B[i] = BC[0];
                C[i] = BC[1];
            }
            
            Array.Sort(A);
            Array.Reverse(A);

            var make = new SortedDictionary<long, long>(new SortRule());
            for (int i = 0; i < M; i++)
            {
                if (make.ContainsKey(C[i]))
                {
                    make[C[i]] += B[i];
                    continue;
                }

                make.Add(C[i], B[i]);
            }

            long Count = 0;
            long Score = 0;
            long Index = 0;
            foreach (var VARIABLE in make)
            {
                if (Index > N - 1 || Count >= N)
                {
                    break;
                }
                while(VARIABLE.Key <= A[Index])
                {
                    Score += A[Index];
                    Index++;
                    Count++;
                    if (Index > N - 1 || Count >= N)
                    {
                        break;
                    }
                }
                if (Index > N - 1 || Count >= N)
                {
                    break;
                }
                long rest = Math.Min(N - Index, N - Count);
                Count += Math.Min(VARIABLE.Value, rest);
                Score += VARIABLE.Key * Math.Min(VARIABLE.Value, rest);
            }
            long res = Math.Min(N - Index, N - Count);
            for (int i = 0; i < res; i++)
            {
                Score += A[Index];
                Index++;
                Count++;
                if (Index > N - 1 || Count >= N)
                {
                    break;
                }
            }
            
            Console.WriteLine(Score);
        }
    }

    public sealed class SortRule : IComparer<long>
    {
        public int Compare(long x, long y)
        {
            return (int)y - (int)x;
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 32608
#include <iostream>

using namespace std;

long long f(long long num){
  if(num%2)
    if((num+1)%4>=2)
      return 1;
  	else
      return 0;
  else
    if((num+1)%4>=2)
	  return num|1;
  	else
      return num&~1;
}

int main(){
 long long A,B;
  cin >> A >> B;
  cout << (f(A-1)^f(B)); 
  return 0;
}


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

int main()
{
  int n, tmp;
  cin >> n;
  
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) cout << " " << i;
    else {
      tmp = i;
      while (tmp > 0) {
        if (tmp % 10 == 3) { cout << " " << i; break; }
        tmp /= 10;
      }
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3096
n = int(input())
A = list(map(int, input().split()))

A_sum = sum(A)
cnt = 1
tmp = 1

for a in A:
    A_sum -= a
    tmp = min((tmp - a) * 2, A_sum)
    cnt += tmp
    if tmp < 0:
        break

if tmp < 0:
    print(-1)
else:
    print(cnt)
    

Measured memory_bytes: 20056
N = int(input())
h = list(map(int,input().split()))
s = [0]*(N)
cnt = 0
#i = n のとき区間の幅n
for i in range(N,0,-1):
    for j in range(N-i+1):
        a = [0]*(i)
        for k in range(i):
            a[k] = h[j+k] - s[j+k]
        if all (s > 0 for s in a):
            ok = min(a)
            cnt += ok
            for p in range(i):
                s[j+p] += ok


print(cnt)

Measured memory_bytes: 3064
cnt = 0
def merge(A, left, mid, right):
    global cnt
    L = A[left:mid]
    R = A[mid:right]
    L.append(float("inf"))
    R.append(float("inf"))
    i, j = 0, 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left+right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

def solve(A):
    left = 0
    right = len(A)
    mergeSort(A, left, right)

def resolve():
    n = int(input())
    A = [int(i) for i in input().split()]
    solve(A)
    print(*A)
    print(cnt)

resolve()



Measured memory_bytes: 61652
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LaL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;

int main(){
  ll A,B,C,K;
  cin>>A>>B>>C>>K;
  
  if(A>=K) cout<<K<<endl;
  else if(A+B>=K) cout<<A<<endl;
  else cout<<A-(K-A-B)<<endl;
}

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

signed main(){
  
  int n;
  cin>>n;
  
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if( a % 2 == 0 ){
      if( !( a % 3 == 0 || a % 5 == 0 ) ){
	cout<<"DENIED"<<endl;
	return 0;
      }
    }
  }
  
  cout<<"APPROVED"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
a1 ,a2 ,a3 = i2()
print("bust" if a1 + a2 + a3 >= 22 else "win")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000000+7;
ll rui(ll x,ll y){
    if(y==0)return 1;
    if(y%2==0)return rui(x*x%mod,y/2);
    else return x*rui(x,y-1)%mod;
}
int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll ka,kb,na,nb;
    ka=1;kb=1;na=1;nb=1;
    for(ll i=2;i<=a;i++)ka=ka*i%mod;
    for(ll i=2;i<=b;i++)kb=kb*i%mod;
    for(ll i=0;i<a;i++)na=na*(n-i)%mod;
    for(ll i=0;i<b;i++)nb=nb*(n-i)%mod;
    ll ans=rui((ll)2,n)-na*rui(ka,mod-2)%mod-nb*rui(kb,mod-2)%mod-1;
    ans%=mod;
    if(ans>=0)cout<<ans;
    else cout<<mod+ans;

}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  unordered_map<ll, ll> m;
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
    m[a[i]]++;
  }

  ll ans = 0;
  rep(i, 0, 100000) {
    ll count = m[i] + m[i - 1] + m[i + 1];
    chmax(ans, count);
  }
  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 5156
import sys

def read():
    return sys.stdin.readline().rstrip()

def main():
    n = int(read())
    xy = [list() for _ in range(n)]
    for i in range(n):
        a = int(read())
        xyi = [tuple() for _ in range(a)]
        for j in range(a):
            xyi[j] = tuple(map(int, read().split()))
        xy[i] = xyi
    p = sorted([[int(j) for j in "{:0{}b}".format(i, n)] for i in range(2**n)], key=sum, reverse=True)
    for pi in p:
        flag = True
        for a in range(n):
            if not flag:
                break
            if pi[a] == 0:
                continue
            for x, y in xy[a]:
                if y ^ pi[x - 1]:
                    flag = False
                    break
        if flag:
            print(sum(pi))
            break

if __name__ == '__main__':
    main()

Measured memory_bytes: 10736
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<62;
const double pi=acos(-1);
const long double eps=1e-7;
const ll mod=1e6+3;
const int dx[8]={0,1,0,-1,-1,-1,1,1},dy[8]={1,0,-1,0,-1,1,-1,1};

int n,k;

int main(){
	cin>>n>>k;
	int res=0;
	for(int i=0;i<n;i++){
		int A;
		cin>>A;
		res+=min(k-A,A);
	}
	cout<<res*2<<endl;
}

Measured memory_bytes: 256
from heapq import heappop, heappush
n, m = map(int, input().split())
l = [[] for i in range(n)]
for i in range(n):
    a,b = map(int, input().split())
    c = min(m-a, n-1)
    if c < 0:
        continue
    heappush(l[c], -b)
heap = []
ans = 0
for i in range(n)[::-1]:
    for b in l[i]:
        heappush(heap, b)
    if heap:
        b = heappop(heap)
        ans += -b
print(ans)

Measured memory_bytes: 73724
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  int n,m;
  cin>>n>>m;
  Graph G(n);
  int h[n];
  rep(i,n){
    cin>>h[i];
  }
  rep(i,m){
    int a,b;
    cin>>a>>b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }
  int ans=0;
  rep(i,n){
    int x=1;
    for(auto itr=G[i].begin();itr!=G[i].end();++itr){
      if(h[i]<=h[*itr]){
        x=0;
      }
    }
    ans+=x;
  }
  cout<<ans;
}


Measured memory_bytes: 8804
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll h,w;
    cin >> h >> w;
    ll ans=min(h,w);
    if (h%3==0 or w%3==0){
        ans=0;
    }
    if (h>=2){
        ll x=h/2,y=h/2+h%2;
        for (ll i=0;i<w;i++){
            ll a=x*i,b=y*i,c=(w-i)*h;
            ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
        }
    }
    if (w>=2){
        ll x=w/2,y=w/2+w%2;
        for (ll i=0;i<h;i++){
            ll a=x*i,b=y*i,c=(h-i)*w;
            ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3552
#include <iostream>

using namespace std;

char* s;
int p,q,r;

int formula()
{
	if(isdigit(*s) || isupper(*s)){
		char c=*s++;
		if(isdigit(c)) return c-'0';
		if(c=='P') return p;
		if(c=='Q') return q;
		if(c=='R') return r;
	}
	if(*s=='-'){
		s++;
		int v=formula();
		return 2-v;
	}
	if(*s=='('){
		s++;
		int a=formula();
		char op=*s++;
		int b=formula();
		s++;
		if(op=='*') return min(a,b);
		if(op=='+') return max(a,b);
	}
	return -1;
}

int main()
{
	for(char s[81];cin>>s,s[0]!='.';){
		int res=0;
		for(p=0;p<3;p++)
			for(q=0;q<3;q++)
				for(r=0;r<3;r++){
					::s=s;
					if(formula()==2)
						res++;
				}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#c
M = int(input())
s=''
a=['z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y']
while M>0:
    s+=a[M%26]
    if M%26==0:
        M=int((M-1)/26)
    else:
        M=int(M/26)
print(s[::-1])

Measured memory_bytes: 61656
import collections
n = int(input())
xy =[]
for i in range(n):
    x,y = map(int,input().split())
    xy.append((x,y))
xy2 = xy[:]
c = collections.Counter()
for x,y in xy:
    for w,z in xy2:
        c[(x-w,y-z)] +=1
if n==1:
    print(1)            
else:    
    print(n-c.most_common(2)[1][1])


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    rep(i,n){
        if(s[i] - '0' == i % 2)ans++;
    }
    cout << min(n-ans,ans) << endl;
}

Measured memory_bytes: 512
C = [list(map(int, input().split())) for _ in range(3)]
def check(C):
    D = [[c[1] - c[0], c[2] - c[1]] for c in C]
    if D[0] == D[1] == D[2]:
        return 0
    else:
        print('No')
        exit()
check(C)
C = [list(c) for c in zip(*C)]
check(C)
print('Yes')


Measured memory_bytes: 3060
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=get_nsp
N=S.size
T=get_nsp
M=T.size
ans=INF
(N-M+1).times do|i|
    cnt=0
    M.times do|j|
      k=i+j
      cnt+=1 unless S[k]==T[j]
    end
    ans=min(ans,cnt)
end
puts ans

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N), A(N * M);

  for (int i = 0; i < N; ++i) {
    cin >> C.at(i);
    for (int j = 0; j < M; ++j) {
      cin >> A.at(i * M + j);
    }
  }

  // ただ大きな数で初期化する
  const int INF = 2147483647;
  int ans = INF;
  // 部分集合の問題なのでビットに直してループを書く
  for (int s = 0; s < (1 << N); ++s) {
    int cost = 0;
    vector<int> D(M);
    for (int i = 0; i < N; ++i) {
      // i番目のビットが建っているかどうか
      if ((s >> i) & 1) {
        cost += C.at(i);
        // 合計を求める
        for (int j = 0; j < M; ++j) {
          D.at(j) += A.at(i * M + j);
        }
      }
    }
    bool OK = true;
    for (int j = 0; j < M; ++j) {
      // 1つでも条件を満たさなければfalse
      if (D.at(j) < X) OK = false;
    }
    // falseなら評価をしない
    if (OK) ans = min(ans, cost);
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N),y(M);
  for (int i=0;i<N;i++){
    cin >> x[i];
  }
  for (int i=0;i<M;i++){
    cin >> y[i];
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  int a=x[N-1],b=y[0];
  if (a<b&&a<Y&&X<b){
    cout << "No War" << endl;
  }
  else {
    cout << "War" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














//---------------------------------------------------------------------------------------------------
void _main() {
	set<int> s;
	rep(i, 0, 3) {
		int x; cin >> x;
		s.insert(x);
	}

	if (s.size() == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
}







Measured memory_bytes: 256
#include<stdio.h>

int count=100;
int min(int a,int b)
{
  if(a<b)return a;
  else return b;
}
int main()
{
  int i,j,k,l,num,A[count+1],M[count+1][count+1];
  scanf("%d",&num);
  for(i=1;i<=num;i++)scanf("%d %d",&A[i-1],&A[i]);
  for(i=1;i<=num;i++)M[i][i]=0;
  for(j=2;j<=num;j++)
    {
      for(i=1;i<=num-j+1;i++)
	{
	  k=i+j-1;
	  M[i][k]=(1<<21);
	    for(l=i;l<=k-1;l++)
	      {
		M[i][k]=min(M[i][k],M[i][l]+M[l+1][k]+A[i-1]*A[l]*A[k]);
	      }
	}
    }
  printf("%d\n",M[1][num]);
  return 0;
}
		  

Measured memory_bytes: 636
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  rep(i, n) cin >> a[i] >> b[i];
  sort(a, a + n);
  sort(b, b + n);
  if (n % 2 == 1)
    Cout(b[n / 2] - a[n / 2] + 1);
  else {
    ll st, en;
    st = (a[n / 2 - 1] + a[n / 2]) / 2;
    en = (b[n / 2 - 1] + b[n / 2]) / 2;
    if ((a[n / 2 - 1] + a[n / 2]) % 2 == 1) ans++, st++;
    if ((b[n / 2 - 1] + b[n / 2]) % 2 == 1) ans++;
    ans += (en - st + 1) * 2;
    ans--;
    Cout(ans);
  }
  return 0;
}

Measured memory_bytes: 6736
require 'prime'

Q = gets.to_i
nums = []
Q.times do
  nums << gets.split.map(&:to_i)
end
max = nums.flatten.max
sum = []
(1..max).each do |i|
  if i.odd? && i.prime? && ((i+1)/2).prime?
    sum << 1
  else
    sum << 0
  end
end
sums = [0]
a = 0
sum.each do |j|
  a += j
  sums << a
end
nums.each do |k|
  p sums[k[1]] - sums[k[0]-1]
end

Measured memory_bytes: 26216
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
long long dp[99];
int main()
{
	dp[0]=2;dp[1]=1;
	for (int i=2;i<=86;i++) dp[i]=dp[i-1]+dp[i-2];
	int n;
	cin>>n;cout<<dp[n];
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

class Dict{
public:
  string key;
  int num;
  Dict(string _k,int _n) : key(_k), num(_n) {}
  bool operator<(const Dict& d) const{
    if(key.size() != d.key.size()){
      return key.size() < d.key.size();
    }
    else{
      return key < d.key;
    }
  }
  bool operator>(const Dict& d) const{
    if(key.size() != d.key.size()){
      return key.size() > d.key.size();
    }
    else{
      return key > d.key;
    }
  }
};

int main(){
  int n;
  while(~scanf("%d",&n)){
    map<string,int> freq;
    for(int i=0;i<n;i++){
      string key;
      int num;
      cin >> key >> num;
      freq[key] += num;
    }
    vector<Dict> dict;
    for(map<string,int>::iterator it = freq.begin(); it != freq.end(); it++){
      dict.push_back(Dict(it->first,it->second));
    }
    sort(dict.begin(),dict.end());
    for(int i=0;i<dict.size();i++){
      printf("%s %d\n",dict[i].key.c_str(),dict[i].num);
    }
  }
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
#define int long long
const int mod=1e9+7;
const int N=2e5+5;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
int n,gs1,gs2,ans=1,vis[N][2];
char a[N];
map<int,int>dp[N];
int dfs(int x,int y)
{
	if(x>n*2)return y==0;
	if(dp[x].count(y))return dp[x][y];
	if(a[x]=='B')
	{
		if(y%2==0)return dp[x][y]=dfs(x+1,y+1);
		else return dp[x][y]=y*dfs(x+1,y-1)%mod;
	}
	else{
		if(y%2==0)return dp[x][y]=y*dfs(x+1,y-1)%mod;
		else return dp[x][y]=dfs(x+1,y+1);
	}
}
signed main()
{
	n=read();
	scanf("%s",a+1);
//	for(int i=1;i<=2*n;i++)
//		if(a[i]=='W')gs1++;
//		else gs2++;
//	if(gs1!=gs2){puts("0");return 0;}
	for(int i=1;i<=n;i++)ans=ans*i%mod;
	cout<<ans*dfs(1,0)%mod<<endl;
//	cout<<dp[4][1]<<endl;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, a);
  out(a + a * a + a * a * a);
}


Measured memory_bytes: 3620
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto ab = readln.split.to!(int[]);
    auto A = ab[0];
    auto B = ab[1];

    auto C = new char[][](100, 100);
    foreach (i; 0..50) C[i][] = '#';
    foreach (i; 50..100) C[i][] = '.';

    foreach (i; 0..A-1) {
        auto h = i/50 * 2;
        auto w = i%50 * 2;
        C[h][w] = '.';
    }
    foreach (i; 0..B-1) {
        auto h = 99 - i/50 * 2;
        auto w = i%50 * 2;
        C[h][w] = '#';
    }

    writeln("100 100");
    foreach (c; C) writeln(c);
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long n = inputLongArray[0];
            long m = inputLongArray[1];

            inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            var sum = inputLongArray.Sum(a => a);
            string result = sum > n? "-1": (n-sum).ToString();

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 29284
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  int n = readln.chomp.to!int;
  int a = readln.chomp.to!int;
  writeln = n * n - a;
}


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

using namespace std;

struct Store {
    int price;
    int quantity;
    bool operator< (const Store& o) const {
        return price < o.price;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<Store> stores(n);
    for (auto& store : stores) {
        cin >> store.price >> store.quantity;
    }
    sort(stores.begin(), stores.end());
    long long total_price = 0;
    int remaining = m;
    for (auto& store : stores) {
        if (remaining > 0) {
            int to_buy = min(remaining, store.quantity);
            remaining -= to_buy;
            total_price += (long long) store.price * to_buy;
        }
    }
    cout << total_price << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int H, W, A, B;
  cin >> H >> W >> A >> B;

  REP(i, H){
    REP(j, W){
      if(i < B && j < A) cout << 1;
      else if(i < B) cout << 0;
      else if(j < A) cout << 0;
      else cout << 1;
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = ip(br.readLine());
        int[] s = createListInt(br.readLine());
        int q = ip(br.readLine());
        int[] t = createListInt(br.readLine());
        int count = 0;
        for (int i = 0; i < q; i++) {
            int target = t[i];
            s = Arrays.copyOf(s, n + 1);
            s[n] = target;
            int j;
            for (j = 0; j < n + 1; j++) {
                if (s[j] == target) {
                    break;
                }
            }
            if (j != n) {
                count++;
            }
        }
        System.out.println(count);
    }

    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static long[] createListLong(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        long[] list = new long[n];
        while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        }
        return list;
    }

    static int ip(String s) {
        return Integer.parseInt(s);
    }

    static long lp(String s) {
        return Long.parseLong(s);
    }
}

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

int main(){
  string S; cin >> S;
  string A, B;
  int Q; cin >> Q;
  bool rev = false;
  rep(q, Q) {
    int x; cin >> x;
    if (x == 1) rev = !rev;
    else {
      int y; char c; cin >> y >> c;
      if ((y == 1) ^ rev) {
        A.push_back(c);
      } else {
        B.push_back(c);
      }
    }
  }
  reverse(A.begin(), A.end());
  S = A + S + B;
  if (rev) reverse(S.begin(), S.end());
  cout << S << endl;
}


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

typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 7654321
#define IINF 87654321987654321LL
#define MAXV 200500

ll mod = 1e9 + 7;
ll a[100500];
vector<ll> E[100500];
int N,M;
bool vis[100500];
multiset<ll> s[100500];

void dfs(int x, int k){
	vis[x] = true;
	s[k].insert(a[x]);
	for(auto e : E[x])if(!vis[e]) dfs(e,k);
}
class ComparisonClass {
public:
    bool operator() (Pll e1, Pll e2) {
        int a = e1.Se, b = e2.Se;
		auto it1 = s[a].begin(); auto it2 = s[b].begin();
		while( true ){
			if( it1 == s[a].end() ) return true;
			if( it2 == s[b].end() ) return false;
			if( *it1 < *it2 ) return false;
			if( *it1 > *it2 ) return true;
			it1++; it2++;
		}
		return false;
    }
};

priority_queue<Pll, vector<Pll>, ComparisonClass> pq;
int main(){
	geti(N,M);

	rep(i,N) scanf("%lld",a+i);
	repp(i,M){
		int a,b; geti(a,b); E[a].pb(b); E[b].pb(a);
	}
	ll cnt = 0;
	rep(i,N) if( !vis[i] ) dfs(i,cnt++);

	vector<ll> v1,v2;
	multiset<ll> s2;
	int c1 = 0, c2 = 0;
	rep(i,cnt){	
		if( sz(s[i]) == 1 ){
			v1.push_back(*s[i].begin());
			c1++;
		}
		else{
			c2++;
			auto it = s[i].begin();
			v2.push_back(*it);
			it++;
			while( it != s[i].end() ) s2.insert( *(it++) );
		}
	}

	if( c2 == 0 ){
		if( c1 == 1 ) printf("0\n");
		else if( c1 == 2 ) printf("%lld\n",v1[0]+v1[1]);
		else printf("Impossible\n");
		return 0;
	}
	ll ans = 0;
	if( c2 == 1 ){
		s2.insert(v2[0]);
		if( sz(v1) > sz(s2) ){
			printf("Impossible\n");
			return 0;
		}
		auto it = s2.begin();
		rep(i,sz(v1)){
			ans += v1[i];
			ans += *it;
			it++;
		}

		printf("%lld\n",ans);
		return 0;
	}

	for(auto e : v2) ans += e;

	rep(i,c2-2){
		if( sz(s2) == 0 ){
			printf("Impossible\n");
			return 0;
		}
		auto it = s2.begin();
		ans += *it;
		s2.erase(it);
	}

	if( sz(v1) > sz(s2) ){
		printf("Impossible\n");
		return 0;
	}
	auto it = s2.begin();
	rep(i,sz(v1)){
		ans += v1[i];
		ans += *it;
		it++;
	}

	printf("%lld\n",ans);
}


Measured memory_bytes: 21248