akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<set>
using namespace std;

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<int> a(n, 0), b(n, 0);
        while(m-- > 0){
            int s, k;
            cin >> s >> k;
            if(k == 1){
                int x;  cin >> x;
                x--;
                a[x] += s, b[x] += s;
                continue;
            }
            while(k-- > 0){
                int x;  cin >> x;
                x--;
                b[x] += s;
            }
        }
        int ans = 0;
        multiset<int> mins;
        for(int i = 0; i < n; i++)  mins.insert(a[i]);
        for(int i = 0; i < n; i++){
            mins.erase(mins.find(a[i]));
            ans = max(ans, b[i]-*mins.begin());
            mins.insert(a[i]);
        }
        cout << ans+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3292
X,N = map(int,input().split())
p = list(map(int, input().split()))
num=list(range(-99,201))
for i in range(N):
    num.remove(p[i])
min_=210
for i in range(len(num)):
    s=abs(X-num[i])
    if s<min_:
        min_=s
        min_list=[num[i]]
    elif s==min_:
        min_list.append(num[i])
print(min(min_list))

Measured memory_bytes: 61928
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,L; cin >> N >> L;
  vector<string> mojiretu(N);
  for(int i = 0; i < N; i++)
    cin >> mojiretu.at(i);
  
  sort(mojiretu.begin(),mojiretu.end());
  string ans;
  ans = mojiretu.at(0);
  for(int i = 1; i < N;i++)
    ans = ans + mojiretu.at(i);
  
  cout << ans <<endl;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<algorithm>

using namespace std;

int main()
{
   int a[5];
   scanf("%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4]);
   sort(a,a+5);
   for(int i=4;i>=0;i--)
   {
       printf("%d",a[i]);
       if(i>0) printf(" ");
       else printf("\n");
   }
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <pair<ll, ii> > pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



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

    int T=1;
    //cin >> T;
    while(T--){
        ll h,w,m,x,y;
        cin>>h>>w>>m;
        int r[h+1]={0}, c[w+1]={0};
        vector<ii> s;

        rep(i,m){
            cin>>x>>y;
            s.pb(mp(x,y));
            r[x]++;
            c[y]++;
        }
        sort(all(s));

        if(m<=2){
            cout<<m<<el;
            return 0;
        }

        vector<ii> r1, c1;
        rep_a(i,1,h+1){
            if(r[i]>0){
                r1.pb(mp(r[i], i));
            }
        }
        rep_a(i,1,w+1){
            if(c[i]>0){
                c1.pb(mp(c[i], i));
            }
        }

        sort(all(r1));
        sort(all(c1));

        x=r1.size();
        y=c1.size();

        ll mx=r1[x-1].ff+c1[y-1].ff-1;
        vi rs;
        rs.pb(r1[x-1].ss);
        rev(i, x-2){
            if(r1[i].ff==r1[i+1].ff){
                rs.pb(r1[i].ss);
            }
            else break;
        }

        rep(i,w+1) c[i]=0;
        c[c1[y-1].ss]=1;
        ll cnt=1;
        rev(i, y-2){
            if(c1[i].ff==c1[i+1].ff){
                c[c1[i].ss]=1;
                cnt++;
            }
            else break;
        }

        rep(i, rs.size()){
            int f=0;
            int pos = lower_bound(all(s), mp(rs[i],0ll))-s.begin();
            while(pos<m && s[pos].ff==rs[i]){
                f+=c[s[pos].ss];
                pos++;
            }
            if(f<cnt){
                cout<<mx+1<<el;
                return 0;
            }
        }
        cout<<mx<<el;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 27304
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
typedef long long ll;
using namespace std;
ll rek(ll a, ll b)
{
    if (a == b)
    {
        return a;
    }
    if (a < b)
    {
        swap(a, b);
    }
    return rek(a - b, b) + b * 2;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, x;
    cin >> n >> x;
    ll ans = n;
    ll a = n - x, b = x;
    while (a && b)
    {
        if (a < b)
        {
            swap(a, b);
        }
        ans += (a / b) * b * 2ll;
        a = a % b;
    }
    ans -= max(a, b);
    cout << ans << endl;
    //cout << rek(n - x, x) + n << "\n";
    return 0;
}

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  deque<char>deq;
  string s;cin>>s;
  ll n=s.size();
  rep(i,0,n)deq.PB(s[i]);
  ll q;cin>>q;
  ll now=0;
  while(q--){
    ll t;cin>>t;
    if(t==1)now^=1;
    else{
      ll f;cin>>f;f--;
      char c;cin>>c;
      //cout<<(f^now) spa c<<endl;
      if(f^now)deq.push_back(c);
      else deq.push_front(c);
    }
  }
  while(!deq.empty()){
    if(now==1){
      cout<<deq.back();
      deq.pop_back();
    }
    else {
      cout<<deq.front();
      deq.pop_front();
    }
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    string s; cin >> s;
    ll n = s.size();
    
    VL mods(2019,0);
    ll rem = 0, tens = 1;

    rep(i,n){
        ll d = s[n-1-i] - '0';
        rem = (rem + tens*d) % 2019;
        tens = (tens*10) % 2019;
        mods[rem]++;
    }

    mods[0]++;

    ll ans = 0;
    rep(i, 2019){
        ll m = mods[i];
        ans += m*(m-1)/2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string c;
  cin >> c;
  if(c == "a" || c == "i" || c == "u" || c == "e" || c == "o"){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;  
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int input_MAX=0,input_MIN=0,i,count=0;
  int data,data_rerv,data_rerv_save;
  scanf("%d",&input_MIN);
  scanf("%d",&input_MAX);

  for(i = input_MIN ; i <= input_MAX ; i++){
    data_rerv=0;
    data_rerv_save=0;
    data=i;
    //printf("*********\n");
    do{
      //printf("data = %d\n", data);
      data_rerv_save = data % 10;
      //printf("data_rerv_save = %d\n",data_rerv_save );
      data_rerv = data_rerv * 10 + data_rerv_save;
      //printf("data_rerv = %d\n",data_rerv);
      data = data / 10;
    }while(data!=0);
    //printf("%d %d\n",i,data_rerv );
    if(i== data_rerv){
      count++;
    }else{
      //printf("Not Match\n");
    }
  }
  printf("%d\n",count );
  return 0;
}


Measured memory_bytes: 128
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep(i,n) for(ll i=0; i<n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;
  ll ans = 0;
  ll minimam = min({a,b,c,d,e});
  cout << 4+(n+minimam-1)/minimam;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
long a=0;
long b=0;
long c=0;
long k=0;
long sum=0;
long tmp=0;
scanf("%ld %ld %ld %ld",&a,&b,&c,&k);
if(k>a){
    tmp=k-a;
    sum=a;
    if(tmp>b){
        tmp=tmp-b;
        sum=sum-tmp;
    }
}else{
    sum=k;
}



printf("%ld",sum);

return 0;

}

Measured memory_bytes: 1724
#include<stdio.h>

int main(void)
{
        int n,i,j,mojisu[100],k;
        char w[100][11];

        scanf("%d",&n);
        for(i=0;i<n;i++)
                scanf("%s",w[i]);


        for(i=0;w[n-1][i]!='\0';i++);
        mojisu[n-1] = i;

        for(i=1;i<n;i++){
                for(j=0;w[i-1][j]!='\0';j++);
                if(w[i-1][j-1]!=w[i][0]){
                        printf("No\n");
                        return 0;
                }
                mojisu[i-1] = j;
        }

        for(i=0;i<n-1;i++){
                for(j=i+1;j<n;j++){
                        if(mojisu[i]==mojisu[j]){
                                k=0;
                                while(w[i][k]!='\0'){
                                        if(w[i][k]!=w[j][k])
                                                break;
                                        k++;
                                }
                                if(k==mojisu[i]){
                                        printf("No\n");
                                        return 0;
                                }
                        }
                }
        }

        printf("Yes\n");
        return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

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

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

int a[5000];
int dp[5000];

int main(){
	ios::sync_with_stdio(false);

	int n;
	int smax;

	while(1){
		scanf("%d", &n);
		if(n==0) break;

		REP(i, n)	scanf("%d", &a[i]);

		dp[0]=a[0];
		smax =a[0];

		FOR(i, 1, n){
			dp[i]=max(dp[i-1]+a[i], a[i]);
		}

		REP(i, n){
				smax=max(dp[i], smax);
		}

		printf("%d\n", smax);
	}
}

Measured memory_bytes: 3236
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CSameIntegers solver = new CSameIntegers();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSameIntegers {
        static final int three = 3;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int[] x = new int[three];
            for (int i = 0; i < three; i++) {
                x[i] = in.nextInt();
            }

            Arrays.sort(x);
            int answer = 0;
            while (x[0] != x[2]) {
                if (x[2] == x[1]) {
                    x[0] += 2;
                } else {
                    x[0]++;
                    x[1]++;
                }
                answer++;
                Arrays.sort(x);
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main() {
	int N;
	cin >> N;
	string ans = "No";

	for (int k = 0; k <= 100; k++) {
		for (int d = 0; d <= 100; d++) {
			if (4 * k + 7 * d == N) ans = "Yes";
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 998244353;


     signed main(){
         cout << std::fixed << std::setprecision(15);
  int n;
  cin>>n;
  int a,ans=0;map<int,int>mp;
  for(int i=0;i<n;i++){
       cin>>a;
       mp[a]++;
  }
  for(auto i:mp){
       if(i.second>=i.first)ans+=i.second-i.first;
       else ans+=i.second;
  }
  cout<<ans<<endl;
 }

 


 






    





      

        


Measured memory_bytes: 6272
s = gets.chomp.to_i
int_dic = {}
i = 1
while true do
  if int_dic[s.to_s.to_sym]
    int_dic[s.to_s.to_sym] += 1
    break
  else
    int_dic[s.to_s.to_sym] = 1
  end
  if s%2 == 0
    s = s/2
  else
    s = s*3 + 1
  end
  i += 1
end

puts i

Measured memory_bytes: 1788
from heapq import heappush, heappop
S = input()
K = int(input())

H = []
D = {}
for i in range(len(S)):
    heappush(H, (S[i], i, 1))

while K:
    s, i, l = heappop(H)
    if s not in D:
        if K == 1:
            print(s)
            break
        K -= 1
        D[s] = 1
    ne = S[i:i+l+1]
    if ne not in D:
        heappush(H, (ne, i, l+1))

Measured memory_bytes: 49624
import sys
import heapq
input = sys.stdin.readline
heapify, push, pop = heapq.heapify, heapq.heappush, heapq.heappop

_n, _m = map(int, input().split())
_lrc = []
for _ in range(_m):
    l, r, c = map(int, input().split())
    _lrc.append((l - 1, r - 1, c))

_lrc.sort()


def chker(n, m, lrc):
    dst = [float('inf')] * n
    dst[0] = 0
    q = [(0, 0)]

    cnt = 0
    for i in range(n):
        while q:
            d, r = q[0]
            if i <= r:
                break
            pop(q)
        else:
            print(-1)
            return

        dst[i] = d
        while cnt < m and lrc[cnt][0] == i:
            l, r, c = lrc[cnt]
            push(q, (d + c, r))
            cnt += 1

    print(dst[-1])


chker(_n, _m, _lrc)


Measured memory_bytes: 30384
/*
Wai u read my code xD
*/
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;


void solve()
{
    ll a,b; cin >> a >> b;
    if (a<=0&&b>=0) nout("Zero");
    else if (b<0)
    {
        if ((abs(a)-abs(b)+1)%2!=0) nout("Negative");
        else nout("Positive");
    }
    else nout("Positive");
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    A, B = map(str, stdin.readline().rstrip().split())
    ans = 0
    ans = int(A) * int(B[-1])
    ans += int(A) * int(B[-2]) * 10
    ans = ans // 100
    ans += int(A) * int(B[-4])
    if len(B)==5:
        ans += int(A) * int(B[-5])
    print(ans)

main()


Measured memory_bytes: 9200
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int k = sc.nextInt();
			
			//77:    7 * 11
			//777:   7 * 3 * 37 (111)
			//7777:  7 * 11 * 101
			//77777: 7 * 11111
			// --> 扱いが難しい...
			
			// 7 * (10^i - 1) / (10-1)
			
			//9kが 7 * (10^i - 1)の倍数
			//9k + 1 = 10^i  ---> 扱いが簡単！
			
			int d = 9*k;
			if ( k % 7 == 0 ) {
				d = d / 7;
			}
			
			int i = 1;
			int res = 0; 
			while(i < 10000000) { //ここ適当
				
				if ( res == 0 ) {
					res = 10 % d;
				}
				else {
					res = (res * 10) % d;
				}
				if ( res == 1 ) {
					//bingo!
					System.out.println(i);
					return;
				}
				
				i++;
			}
			
			System.out.println("-1");
		}
	}

}

Measured memory_bytes: 36036
n, d, a = map(int, input().split())
l = [[0, 0] for _ in range(n)]
for i in range(n):
  x, h = map(int, input().split())
  l[i][0] = x
  l[i][1] = h
  
l.sort()
from collections import deque
d = 2*d
q = deque([])
total = 0

ans = 0
for i in range(n):
  x = l[i][0]
  h = l[i][1]
  if q:
    while q[0][0] < x:
      total -= q[0][1]
      q.popleft()
      if not q:
        break
  h -= total
  if h > 0:
    num = (h+a-1)//a
    ans += num
    damage = num*a
    total += damage
    q.append([x+d, damage])

print(ans)

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

long long greedy(vector<long long> a, long long x){
    long long cum = 0LL;
    cum += max(0LL, a[0] - x);
    a[0] = min(x, a[0]);
    for (int i = 1; i < a.size(); ++i){
        auto dif = a[i] + a[i - 1] - x;
        if (dif > 0LL){
            a[i] -= dif;
            cum += dif;
        }
    }
    return cum;
}

int main() {
    ios::sync_with_stdio(false);
    long long N, x;
    cin >> N >> x;
    vector<long long> a(N, 0);
    for (auto &ai : a) cin >> ai;

    auto ans0 = greedy(a, x);
    reverse(a.begin(), a.end());
    auto ans1 = greedy(a, x);
    cout << min(ans0, ans1) << endl;
    return 0;
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

lint n;
vector<lint> b;

int main() {
    cin >> n;
    b.resize(n-1);  for(auto& e : b)  cin >> e;
    b.push_back(LLONG_MAX);

    lint res = b[0];
    for(lint i = 0; i < n-1; i++) {
        res += min(b[i], b[i+1]);
    }

    cout << res << endl;
}

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

#define INFTY 1000000001

int count=0;

void merge(int [],int,int,int);
void mergeSort(int [],int,int);

int main(){
  int *S;
  int n, i;
  
  scanf("%d",&n);
  S = (int *)malloc(n * sizeof(int));
 
  for(i=0; i<n; i++)
    scanf("%d",&S[i]);

  mergeSort(S, 0, n);

  for(i=0; i<n; i++){
    printf("%d",S[i]);
    if(i<n-1)
      printf(" ");
  }
  printf("\n%d\n",count);
  
  free(S);
  return 0;
}

void merge(int A[],int l,int m,int r){
  int *L, *R;
  int n1, n2;
  int i, j, k;
  
  n1 = m-l;
  n2 = r-m;

  L = (int *)malloc((n1+1) * sizeof(int));
  R = (int *)malloc((n2+1) * sizeof(int));

  for(i=0; i<n1; i++)
    L[i] = A[l+i];

  for(i=0; i<n2; i++)
    R[i] = A[m+i];

  L[n1] = INFTY;
  R[n2] = INFTY;

  i = j = 0;
  for(k=l; k<r; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
      count++;
    }
    
    else{
      A[k] = R[j];
      j++;
      count++;
    }
  }
  
  free(L);
  free(R);
  return;
}

void mergeSort(int A[],int l,int r){
  int m;
  
  if(l+1 < r){
    m = (l+r)/2;
    mergeSort(A, l, m);
    mergeSort(A, m, r);
    merge(A, l, m, r);
  }
}



Measured memory_bytes: 5416
fun main(args: Array<String>) {
    val (n, m, d) = readLine()!!.split(' ').map(String::toLong)
    val sumBeauty = if (d != 0L) {
        (n - d) * 2 * (m - 1)
    } else {
        n * (m - 1)
    }
    val aveBeauty = sumBeauty.toDouble() / n / n
    println(aveBeauty)
}


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

using namespace std;

#define int long long

signed main(){
  const int MAX = 110000;
  int N, M;
  int res = 0;
  vector<int> X, con;
  vector<pair<int,int>> modM;

  cin>>N>>M;

  X.resize(N);
  con.resize(MAX);
  modM.resize(M);

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

  for(int i = 0; i < MAX; i++){
    modM[i%M].first += con[i]%2;
    modM[i%M].second += con[i]/2;
  }

  for(int i = 0; i * 2 <= M; i++){
    if(i == 0 || (M%2 == 0 && i == M/2)) {
      res += modM[i].second + modM[i].first / 2;
    } else {
      int mino = min(modM[i].first, modM[M-i].first);

      res += mino;

      modM[i].first -= mino;
      modM[M-i].first -= mino;

      //cout<<"A "<<mino<<endl;

      if(modM[i].first){
        mino = min(modM[i].first/2, modM[M-i].second);
        res += mino * 2;
        //cout<<"B "<<mino<<endl;
        modM[M-i].second -= mino;
      }
      if(modM[M-i].first) {
        mino = min(modM[M-i].first/2, modM[i].second);
        res += mino * 2;
        //cout<<"C "<<mino<<endl;
        modM[i].second -= mino;
      }

      res += modM[i].second + modM[M-i].second;
    }
    //cout<<"i = "<<i<<" res = "<<res<<endl;
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 3456
s = int(input())
s1 = s%100
s2 = int((s-s1)/100)
ans = 0
if 0 < s1 and s1 < 13:
	if 0 < s2 and s2 < 13:
		print("AMBIGUOUS")
		exit()
	else:
		print("YYMM")
		exit()
else:
	if 0 < s2 and s2 < 13:
		print("MMYY")
		exit()
	else:
		print("NA")
		exit()



Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;

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

	double ans = 0;

	for(int i=1;i<=n;i++){
		int x = i;
		double p = 1.0/static_cast<double>(n);
		while(x < k){
			p *= 0.5;
			x = x << 1;
		}
		ans += p;
	}

	cout << setprecision(12) << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while (b != 0):
        a, b = b, a % b
    return a

n, m = map(int, input().split())
s = input()
t = input()
lcm = (n * m) // gcd(n, m)
gcd = gcd(n, m)
ans = lcm
if gcd > 1:
    for i in range(gcd):
        if s[i * (n // gcd)] != t[i * (m // gcd)]:
            ans = -1
if s[0] != t[0]:
    ans = -1
print(ans)

Measured memory_bytes: 3316
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int ans = 0;

int n;
string s;

int dp[1000000];
int pr[1000000];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> s;
	n = s.size();
	dp[0] = 0;
	int lst = -1;
	for (int i = 0; i < n; ++i) {
		pr[i] = lst;
		if (s[i] == '0')
			lst = i;
		if (s[i] == '0') {
			dp[i + 1] = dp[i];
		}
		else {
			dp[i + 1] = dp[i];
			if (lst == i - 1 && lst >= 0) {
				int x = pr[lst];
				dp[i + 1] = max(dp[i + 1], dp[x + 1] + (lst - x - 1));
				if (lst - x - 2 >= 0)
					dp[i + 1] = max(dp[i + 1], dp[x + 2] + (lst - x - 2));
			}
			if (lst >= 1 && pr[lst] != lst - 1) {
				dp[i + 1] = max(dp[i + 1], dp[lst - 1] + i - lst);
			}
		}
	}
	cout << dp[n] << "\n";
	return 0;
}




Measured memory_bytes: 6940
#include <bits/stdc++.h>
using namespace std;
 
//Optimizations
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
//save time
#define endl '\n'
#define db(x) cerr << "> " << #x << ": " << x << endl
typedef long long ll;
 
//for sorting
#define all(a) a.begin(),a.end()
 
//Constants
#define PI   3.141592653593
#define MOD  1000000007LL
#define EPS  0.000000001
#define INF  0X3f3f3f3f
 
//loops
#define REP(i,n) 	    for(int i=0;i<(n);++i)
#define FOR(i,a,b)      for(int i=(a);i<(b);++i)
#define DFOR(i,a,b)     for(int i=(a);i>=(b);--i)
 
//vectors
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int,int>>
#define vlll vector<pair<ll,ll>>
#define pb 	push_back
 
//pairs
#define pi pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define F first
#define S second
 
//fast I/O
#ifndef _WIN32
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define gc getchar
#define pc putchar
 
//If using cin and cout
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(NULL);cout.tie(NULL)
 
//queue
#define di deque<int>
#define dll deque<ll>
#define qi queue<int>
#define PQ priority_queue
 
//general
#define E empty()
 
//Declare all variables and methods needed between this comment and the next one(OCD lol)
const int MAXN=0;
int main(){
    int n , w ; cin >> n >> w ; 

    vll dp(w+1 , 0);
   // pi ar[n];
    REP(i, n){
        int weight, value; cin >> weight >> value;
        for(int i = w - weight; i >=0 ; --i){
            dp[i+weight] = max(dp[i+weight],dp[i]+ value);
        }
    }
    ll res = 0;
    FOR(i, 0, w+1){
        res = max(res, dp[i]);
    }
    cout << res << endl;
   
}

Measured memory_bytes: 4052
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import Data.List

readIntLines :: IO [Int]
readIntLines = map (fst . fromJust . BC.readInt) . BC.lines <$> BC.getContents

main :: IO ()
main = do
  getLine
  length . filter (==True) . map (odd . length) . group . sort <$> readIntLines >>= print


Measured memory_bytes: 15612
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    string s;  cin >> s;
  	if(s.length() % 2 != 0){  cout << "No" << endl;  return 0;  }
    for(int i = 0 ; i < s.length() - 1; i += 2){
      if(s.substr(i, 2) != "hi"){  cout << "No" << endl;  return 0;  }
    }

    cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*

*/
int main(){
  ll N; cin>>N;
  string S; cin>>S;
  ll j=N-1, ans=0;
  for(ll i=0; i<j; i++){
    if(S[i] == 'W'){
      for(;j>i; j--){
        if(S[j]=='R'){
          S[i] = 'R';
          S[j] = 'W';
          ans++;
          break;
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3640
function Main(input) {
    input = input.split("");
    isloop_out = true;
    P = 0;
    while(true){
        isloop_out = true;
        for(i = 0; i < input.length; i++){
            if(input[i] === undefined) break;
            if( input[i] === "1" &&
                input[i+1] === "0"){
                    P++;
                    isloop_out = false;
                    input.splice(i,2);
                    i--;
                    i--;
                }
            if( input[i] === "0" &&
                input[i+1] === "1"){
                    P++;
                    isloop_out = false;
                    input.splice(i,2);
                    i--;
                    i--;
                }
        }
        if(isloop_out) break;
    }
    console.log(P*2)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 14412
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	for {
		if s == "" {
			fmt.Println("YES")
			break
		}
		if !strings.HasSuffix(s, "dream") && !strings.HasSuffix(s, "dreamer") && !strings.HasSuffix(s, "erase") && !strings.HasSuffix(s, "eraser") {
			fmt.Println("NO")
			break
		}

		for _, v := range []string{"dreamer", "dream", "eraser", "erase"} {
			s = cutSuffix(s, v)
		}
	}
}

func cutSuffix(s, target string) string {
	if strings.HasSuffix(s, target) {
		s = strings.TrimSuffix(s, target)
	}
	return s
}


Measured memory_bytes: 1280
using System;

namespace ITP1_9_A
{
	class Program
	{
		static void Main(string[] args)
		{
			string search = Console.ReadLine();
			string text;
			int cnt = 0;

			do {
				text = Console.ReadLine();
				text = text.Replace("\"", string.Empty);
				text = text.Replace(".", string.Empty);
				string[] kws = text.Split(' ');
				foreach(string kw in kws) {
					if(search.ToUpper() == kw.ToUpper()) {
						cnt++;
					}
				}
			}
			while(!text.EndsWith("END_OF_TEXT"));

			Console.WriteLine(cnt);
		}
	}
}



Measured memory_bytes: 18736
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define INF 100000000000ULL

size_t a[2][2019];

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

	memset(a, 0, sizeof(size_t)*2*2019);
	
	size_t i;
	size_t sum = 0;
	for (i = 0; ; ++i) {
		int c = getchar();
		if (c < '1' || c > '9') break;
		c -= '0';
		size_t cur = i % 2;
		size_t nxt = (i + 1) % 2;
		//printf("%d\n", c);
		a[nxt][c] = 1;
		REP(j, 2019) {
			size_t k = (j * 10 + c) % 2019;
			a[nxt][k] += a[cur][j];
		}
		sum += a[nxt][0];
		memset(a[cur], 0, sizeof(size_t) * 2019);
		//REP(j, 2019) {
		//	a[cur][j] = 0;
		//}
		//printf("---\n");
	}

	printf("%zu\n", sum);
	
	return 0;
}

Measured memory_bytes: 3812
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]
INF = 10 ** 12

def dfs(i, a, b, c):
    if i == N:
        if min(a, b, c) > 0:
            return abs(A - a) + abs(B - b) + abs(C - c) - 30
        else:
            return INF
    res0 = dfs(i + 1, a, b, c)
    res1 = dfs(i + 1, a + L[i], b, c) + 10
    res2 = dfs(i + 1, a, b + L[i], c) + 10
    res3 = dfs(i + 1, a, b, c + L[i]) + 10
    return min(res0, res1, res2, res3)

print(dfs(0, 0, 0, 0))

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

using namespace std;

typedef long long ll;

inline ll read(){
    char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
      	  ch=getchar();
    }
    while(ch<='9' && ch>='0') {
       x=x*10+ch-'0';
       ch=getchar();
    }
    return x*f;
}

int main(){
	int n=read();
	for(int i=1;i<=n;i++){
		printf("ACL");
	} 
	return 0;
}


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

int main() {
  int N;
  int sum = 0;
  cin >> N;

  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3592
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

var sc = newScanner()

func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

func min(a ...int) int {
	m := a[0]
	for i := 1; i < len(a); i++ {
		if m > a[i] {
			m = a[i]
		}
	}
	return m
}

func main() {
	n, x, y := scanInt(), scanInt(), scanInt()
	m := make(map[int]int)

	for i := 1; i <= n-1; i++ {
		for j := i + 1; j <= n; j++ {
			d := j - i
			d = min(d, abs(i-x)+1+abs(y-j))
			m[d]++
		}
	}

	for i := 1; i <= n-1; i++ {
		fmt.Println(m[i])
	}
}


Measured memory_bytes: 896
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int digg(int here, int N, int *map, int *been);

int digg(int here, int N, int *map, int *been) {
	int i;
	int sum;
	int paths;

	been[here] = 1;
	//if \sum been = N, vertex here is the end of path.
	sum = 0;
	for(i = 0; i < N; i += 1) {
		sum += been[i];
	}
	if(sum == N) {
		//printf("exit %d:endofpath\n", here);
		been[here] = 0;
		return 1;
	}

	paths= 0;
	for(i = 0; i < N; i += 1) {
		//Check if path vertex here to vertex i be open,
		//and also never been to vertex i.
		//If true, repeat digging from vertex i
		//else, check vertex i+1.
		//printf("now %d, check %d\n", here, i);
		if(map[here + N * i] == 0) {
			//printf("  %d closed\n", i);
			continue;
		}
		if(been[i] == 1) {
			//printf("  %d visited\n", i);
			continue;
		}
		//printf("  %d open\n", i);
		paths += digg(i, N, map, been);
	}
	been[here] = 0;
	//printf("exit %d\n", here);
	//paths is the number of paths whose end vertex is deeper than vertex 'here'
	return paths;
}

int main(void) {
	int N, M;//vertices, bonds
	int a, b;
	int *map;//map[i+n*j)]=0:i to j closed, =1:i to j open
	int *been;
	int ans;
	int i, j;
	char buf[128], *ch;


	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);
	ch = strtok(NULL, " ");
	M = atoi(ch);

	been = (int *)calloc(N, sizeof(int));
	map = (int *)calloc(N * N, sizeof(int));

	//make map
	for(i = 0; i < M; i += 1) {
		fgets(buf, sizeof(buf), stdin);
		ch = strtok(buf, " ");
		a = atoi(ch);
		ch = strtok(NULL, " ");
		b = atoi(ch);

		map[(a - 1) + (b - 1) * N] = 1;
		map[(b - 1) + (a - 1) * N] = 1;
	}

	//search path to the end
	ans = digg(0, N, map, been);
	printf("%d\n", ans);

	free(been);
	free(map);
	return 0;
}


Measured memory_bytes: 2080
N = int(input())
Xn = list(map(int, input().split()))

sXn = sorted(Xn)
m1 = sXn[N//2-1]
m2 = sXn[N//2]
m = (m1+m2) / 2

for X in Xn:
    print(m1 if X > m else m2)

Measured memory_bytes: 25620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long a = sc.NextLong();
        long b = sc.NextLong();
        long x = sc.NextLong();

        long answer = b / x - a / x;
        if (a % x == 0)
        {
            answer++;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
void main(){
	int a, b;
	readf("%d %d\n", &a, &b);
	writeln( (a*b)&1? "Yes": "No" );
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2796
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    int b[] = new int[n];
    
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
      b[i] = a[i];
    }
    
    int sum = 0;
    for(int i = 0; i < n; i++){
      for(int j = i+1; j < n; j++){
        sum += a[i] * b[j];
      }
    }

    System.out.println(sum);
    
    
  }
}

Measured memory_bytes: 22612
#include <cstdio>
#include <iostream>
#include <algorithm>

const int MAX_N = 100;
const int MAX_M = 100;

int main()
{
	int N, M;
	scanf("%d %d", &N, &M);
	
	int A[N];
	int l, i = 0;
	int sum = 0;
	while(std::cin >> l) {
		A[i] = l;
		sum += l;

		i++;
		if(i >= N) {
			break;
		}
	}

	std::sort(A, A + N, std::greater<int>());

	// // 選択可能票閾値を計算する
	// int limit = sum / (4 * M);
	// printf("%d", limit);

	bool flg = true;
	for(i = 0; i < M; i++) {
		// 閾値未満の場合の時点でループを終了する
		// if(A[i] < limit) {
		if(A[i] * 4 * M < sum) {
			flg = false;
			break;
		}
	}

	if(flg) {
		printf("Yes");
	} else {
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d=1;
	cin>>a>>b;
	c=a;
	while(1){
		if(b==1){ d=0; break; }
		if(b<=c) break;
		c+=a-1;
		d++;
	}
	cout<<d<<endl;
}

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

int n, u, v, m;
bool a[500][500], b[500][500];
int xa[1000000], ya[1000000], xb[1000000], yb[1000000];
int p(bool a[][500], int x, int y) {
	a[x][y] = 1;
	if (n == 1)return 1;
	int res = 0;
	bool ok = 1; rep(i, n)ok &= a[x][i];
	if (ok)res++;
	ok = 1; rep(i, n)ok &= a[i][y];
	if (ok)res++;
	if (x == y) {
		ok = 1;
		for (int i = 0, j = 0; i < n; i++, j++)ok &= a[i][j];
		if (ok)res++;
	}
	if (x + y == n - 1) {
		ok = 1;
		for (int i = 0, j = n - 1; i < n; i++, j--)ok &= a[i][j];
		if (ok)res++;
	}
	return res;
}
int main() {
	scanf("%d%d%d%d", &n, &u, &v, &m);
	memset(xa, -1, sizeof(xa)); memset(xb, -1, sizeof(xb));
	rep(i, n)rep(j, n) {
		int c; scanf("%d", &c); c--;
		xa[c] = i; ya[c] = j;
	}
	rep(i, n)rep(j, n) {
		int c; scanf("%d", &c); c--;
		xb[c] = i; yb[c] = j;
	}
	int c1 = 0, c2 = 0;
	rep(i, m) {
		int c; scanf("%d", &c); c--;
		if (~xa[c])c1 += p(a, xa[c], ya[c]);
		if (~xb[c])c2 += p(b, xb[c], yb[c]);
		if (c1 >= u) {
			if (c2 >= v)puts("DRAW");
			else puts("USAGI");
			return 0;
		}
		else if (c2 >= v) {
			puts("NEKO"); return 0;
		}
	}
	puts("DRAW");
}

Measured memory_bytes: 19136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//using T = tuple<string, int, int>;

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    if (to_string(i).size() % 2 == 1) {
      ans++; 
    }
  }

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

// https://github.com/atcoder/live_library

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	vector<string>vec(2);
	rep(i, 0, 2)cin >> vec[i];
	bool ans = true;
	rep(i, 0, 2) {
		rep(j, 0, 3) {
			if (vec[i][j] != vec[1 - i][2 - j])ans = false;
		}
	}
	cout << (ans ? "YES" : "NO") << "\n";

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> V(N);
    vector<int> C(N);
    for (int i=0; i<N; i++) cin >> V.at(i);
    for (int i=0; i<N; i++) cin >> C.at(i);
    int sum = 0;
    for (int i=0; i<N; i++) {
        if (V.at(i) - C.at(i) > 0) sum += V.at(i) - C.at(i);
    }
    cout << sum << endl;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a + b > c + d) cout << "Left";
  else if(a + b < c + d) cout << "Right";
  else cout << "Balanced";
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
   int n,k;cin>>n>>k;
   map<ll,ll> mp;
   priority_queue<pair<ll,ll>> que;
   priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>> > que2;
   rep(i,n){
       ll x,t;cin>>x>>t;
       que.push({t,x});
   }
   ll res1=0,st=0;
   rep(i,k){
       auto p=que.top();que.pop();
       ll t=p.second,d=p.first;
       res1+=d;
       if(mp[t]!=0){
           mp[t]++;
           que2.push({d,t});
       }else{
           mp[t]++;
       }
   }
   st=mp.size();
   //cout<<res1<<" "<<st<<endl;
   ll res=res1+st*st;
   while(que.size()&&que2.size()){
       auto p=que.top();que.pop();
       ll t=p.second,d=p.first;
       if(mp[t]!=0)continue;
       auto p2=que2.top();que2.pop();
       ll t2=p2.second,d2=p2.first;
       //cout<<res1+(d-d2)+(st+1)*(st+1)<<endl;
        st++;
        mp[t]--;
        mp[t2]++;
        res1+=(d-d2);
        res=max(res,res1+st*st);
   }
   //cout<<res1<<" "<<st<<endl;
   cout<<res<<endl;
}

Measured memory_bytes: 6640
panels = input().split()
panels = [int(panel) for panel in panels]

N,M,X,Y = panels[:]
domain = set(range(X+1,Y+1))

x_enp = input().split()
x_enp = [int(place) for place in x_enp]
y_enp = input().split()
y_enp = [int(place) for place in y_enp]

x_max = max(x_enp)
y_min = min(y_enp)

if y_min <= x_max:
    print("War")
else:
    evaluation = set(range(x_max+1,y_min+1))
    
    if evaluation & domain:
        print("No War")
    else:
        print("War")

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

int a[20000];
int sum[20000];
int n,s;
int main() {
	a[0] = 2;
	sum[0] = 2;
	cin >> n;
	while(n!=0) {
		for(int i=1 ; i<n; ++i) {
			int k = a[i-1] + 1;
			while(a[i]==0) {
				while(k%a[s]!=0) {
					if(a[s]*a[s] > k) {
						a[i] = k;
						//cout << i+1 << "th prime is" << a[i] << endl;
						sum[i] = sum[i-1] + a[i];
						break;
					}
					++s;
				}
				s = 0;
				++k;
			}
		}
		cout << sum[n-1] << endl;
		cin >> n;
	}
}
		

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

ll dp [105][100100];
 
int main() {

    int n,W;
    int v[105];
    int w[105];

    cin>>n>>W;
    rep(i,n)    cin>>w[i]>>v[i];

    rep(i,n) {
        for(int sum_w=0;sum_w<=W;++sum_w) {
            if(sum_w>=w[i]) dp[i+1][sum_w]=max(dp[i][sum_w-w[i]]+v[i],dp[i][sum_w]);
            else dp[i+1][sum_w]=dp[i][sum_w];
        }
    }

    cout<<dp[n][W]<<endl;

 return 0;
}

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

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

	vector<int> a( N+1 );
	for( int i = 1; i <= N; ++i ) {
		cin >> a.at( i );
	}

	vector<int> b( N+1 );
	vector<int> result;

	for( int i = N; i >= 1; --i ) {
		int x = 0;

		for( int j = i+i; j <= N; j += i ) {
			x += b.at( j );
		}

		if( (x & 1) != a.at(i) ) {
			b.at( i ) = 1;
			result.push_back( i );
		}
	}

	cout << result.size() << endl;

	for( int i = 0; i < result.size(); ++i ) {
		cout << result.at( i );

		if( i < result.size()-1 ) {
			cout << " ";
		}
	}

	cout << endl;
}


Measured memory_bytes: 3064
def AUN(x):
    a = 0
    un = 0
    for i in range(len(x)):
        if x[i] == 'A':
            a += 1
        else:
            un += 1
    if a >= un:
        return True
def p(x):
    a = 0
    un = 0
    for i in range(len(x)):
        if x[i] == 'A':
            a += 1
        else:
            un += 1
    if a == un:
        return True
N = int(input())
b = []
d = []
e = []
for i in range(N):
    b.append(input())
if p(b):
    for i in range(N):
        d.append(b[i])
        e.append(AUN(d))
    if all(e) :
        print("YES")
    else:
        print("NO")
else:
    print("NO")


Measured memory_bytes: 5600