akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define mod 1000000007
using namespace std;
typedef long long int LL;

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

    if (N == 1 and M == 1) {
        cout << 1 << endl;
    } else if (N == 1) {
        cout << (M - 2) << endl;
    } else if (M == 1) {
        cout << (N - 2) << endl;
    }  else {
        cout << (N - 2) * (M - 2) << endl;
    }

    return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int A, B, K;
  int count = 0;
  vector<int> G;
  cin >> A >> B >> K;

  for (int i = 1; i <= 100; i++) {
    if (A % i == 0 && B % i == 0) {
      G.insert(G.begin(),i);
    }
  }
  cout << G[K-1] << endl;

  return 0;
}


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

ll gcd(ll c, ll d) {
  ll r, l;
  ll a = c;
  ll b = d;
  if (a < b) swap(a, b);
  r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = gcd(a, b);
  int ans = 0;
  ll c = g;
  for (int p = 2; p <= sqrt(c); p++) {
    if (g % p == 0) {
      g /= p;
      ans++;
    }
    while (g % p == 0) {
      g /= p;
    }
  }
  if (g > sqrt(c)) ans++;
  ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>

static const int drawPoint = 1;
static const int winPoint = 3;

enum Result
{
	WINNER_A,
	DRAW,
	WINNER_B,
};

Result game(const std::string a, const std::string b);

int main(void)
{
	int n;
	std::cin >> n;
	int point_a = 0;
	int point_b = 0;
	std::string a, b;
	for (int i = 0; i < n; i++)
	{
		std::cin >> a >> b;
		switch (game(a, b))
		{
		case WINNER_A:
			point_a += winPoint;
			break;
		case DRAW:
			point_a += drawPoint;
			point_b += drawPoint;
			break;
		case WINNER_B:
			point_b += winPoint;
			break;
		default:
			break;
		}
	}
	printf("%d %d\n", point_a, point_b);
	return 0;
}

Result game(const std::string a,const std::string b)
{
	
	if (a[0] > b[0])
	{
		return WINNER_A;
	}
	else if (a[0] < b[0])
	{
		return WINNER_B;
	}
	else
	{
		std::string a_sub, b_sub;
		a_sub = a.substr(1);
		b_sub = b.substr(1);
		if (a_sub.size() > 0 && b_sub.size() == 0)
		{
			return WINNER_A;
		}
		else if (a_sub.size() == 0 && b_sub.size() > 0)
		{
			return WINNER_B;
		}
		else if (a_sub.size() == 0 && b_sub.size() == 0)
		{
			return DRAW;
		}
		else
		{
			return game(a_sub, b_sub);
		}
	}
}

Measured memory_bytes: 3260
using System;

class AOJ{
  public static void Main(string[] args)
  {
    string s;

    while((s = Console.ReadLine()) != null){
      string[] n = s.Split(' ');

      int sum = int.Parse(n[0]) + int.Parse(n[1]);

      Console.WriteLine(sum.ToString().Length);
    }
  }
}

Measured memory_bytes: 9020
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]
sall = lambda: sys.stdin.readlines()

def main():
    h, w = na()
    a = sall()

    hs = []
    for i in range(h):
        if not [v for v in a[i] if v == '#']:
            hs.append(i)

    ws = []
    for i in range(w):
        if not [a[j][i] for j in range(h) if a[j][i] == '#']:
            ws.append(i)

    for i in range(h):
        p = False
        for j in range(w):
            if i in hs or j in ws:
                continue
            print(a[i][j], end='')
            p = True

        if p:
            print('')
            
main()


Measured memory_bytes: 43992
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;


Node root;



void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){

    y = x;
    if (z->key < x->key) x = x->left;
    else x = x->right;

}

  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

}

void inorder(Node u){

  if(u == NIL) return;
  else {
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
    
  }
}

void preorder(Node u){
  if(u == NIL) return;
  else{
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
    
  }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    /* if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");*/
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }/* else if ( com[0] == 'd' ){
	scanf("%d", &x);
	treeDelete(treeSearch(root, x));
	}*/
  }

  return 0;
}

Measured memory_bytes: 24040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, sum;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> sum;
	ll ans = -1, base;
	for(base = 2; base * base <= n; base++){
		ll tn = n;
		ll ts = 0;
		while(tn > 0)
			ts += tn % base, tn /= base;
		if(ts == sum){
			ans = base;
			break;
		}
	}
	if(ans != -1){
		cout << ans << "\n";
		return 0;
	}
	for(; base <= n; ){
		ll sang = n / base;
		ll nbase = n / sang;
		ll tmp = n - sum + sang;
		if(tmp % sang == 0){
			ll tbase = tmp / sang;
			if(tbase >= base && tbase <= nbase){
				ans = tbase;
				break;
			}
		}
		base = nbase + 1;
	}
	if(ans == -1){
		if(n == sum)
			ans = n + 1;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
//   PIGMEISTER™   //

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

#define ll long long
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define MAX 100005

int main()
{
    jaldi;
    
    ll n;
    cin >> n;
    ll a[n];
    sidha (i, 0, n) cin >> a[i];

    ll b[n] = {0}, ans = 0;
    sidha (i, 0, n) {
        if (i-a[i]+1 >= 0)
            ans += b[i-a[i]+1];
        if (i+a[i]+1 < n)
            b[i+a[i]+1]++;
    }

    cout << ans;
    
    return 0;
}


Measured memory_bytes: 6728
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e6 + 5;

int n, a[1111][1111];
int color[N], deg[N];
vector<int> g[N];

int idx(int i, int j) {
	if (i > j) swap(i, j);
	return (i - 1) * n + j;
}

bool found = 0;
void dfs(int v, int p){
  color[v] = 1;
  for(int w : g[v]){
    if(color[w] == 1){
      found = 1;
      return;
    }
    if(color[w] == 0) dfs(w, v);
  }
  color[v] = 2;
}

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

	cin >> n;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < n; j++) {
			cin >> a[i][j];
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 2; j < n; j++) {
			int u = idx(i, a[i][j - 1]), v = idx(i, a[i][j]);
			g[u].pb(v);
			deg[v]++;
		}
	}

	for (int i = 1; i <= n and !found; i++) {
		for (int j = i + 1; j <= n and !found; j++) {
			int node = idx(i, j);
			if (color[node] == 0) {
				dfs(node, -1);
			}
		}
	}

	//cout << "done dfs\n";

	if (found) {
		cout << "-1\n";
		return 0;
	}

	int ans = 0;
	set<pii> S;
	for (int i = 1; i <= idx(n, n - 1); i++) {
		S.insert({deg[i], i});
	}

	while (!S.empty()) {
		//cout << "S.size() = " << S.size() << "\n";
		vii curr;
		while (!S.empty() and S.begin() -> fi == 0) {
			curr.pb(*S.begin());
			S.erase(S.begin());
		}
		for (auto u: curr) {
			for (int v: g[u.se]) {
				S.erase(S.find({deg[v], v}));
				deg[v]--;
				S.insert({deg[v], v});
			}
		}
		ans++;
	}

	cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 136048
#include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<iostream>
    #include<string>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<map>
    #include<set>
    #include<algorithm>
    #include<numeric>
     
    #define rep(n) for(int i=0;i<n;i++)
    #define repp(j, n) for(int j=0;j<n;j++)
    #define reppp(i, m, n) for(int i=m;i<=n;i++)
    #define all(c) c.begin(), c.end()
    #define rall(c) c.rbegin(), c.rend()
    #define pb(x) push_back(x)
    #define eb(x,y) emplace_back(x,y)
    #define MOD 1000000007
    #define MAX 1000000001
    #define INF 1410065408
    #define EPS 1e-9
    #define DEBUG 0
    #define ll long long
    #define Pll pair<ll, ll>
    #define Pii pair<int, int>
    #define Pdd pair<double, double>
     
    using namespace std;
    struct edge{int from, to; ll cost;};
     
    signed main(){
        ios::sync_with_stdio(false); cin.tie(0);
        vector< Pdd > v;
        double n, tmp, second = 0.25;
        rep(4){
            cin >> tmp;
            v.pb(Pdd(tmp * (2.0/second), second));
            second *= 2;
        }
        cin >> n;
     
        sort(all(v));
        ll ans = 0;
        rep(4){
            Pdd p = v[i];
            double price = p.first * (p.second/2.0);
            ll tmp = n / p.second;
            n -= (double)tmp * p.second;
            ans += (ll)price * tmp;
            if(n == 0) break;
        }
        cout << ans;
    }

Measured memory_bytes: 256
n,k = map(int,input().split())
H = list(map(int,input().split()))
dp = [10**10]*(n+1)
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j],dp[i]+abs(H[i+j]-H[i]))
print(dp[n-1])

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H, W;
    cin >> H >> W;
    vector<int> A(H), B(H);
    for (int i = 0; i < H; ++i) {
        cin >> A[i] >> B[i];
    }
    set<pair<int, int>> S; // cur, start
    vector<int> difference_count(W, 0); // cur - start
    for (int i = 1; i <= W; ++i) {
        S.insert({i, i});
    }
    difference_count[0] = W;
    int min_difference = 0;
    for (int i = 0; i < H; ++i) {
        auto L = S.upper_bound({A[i], 0});
        auto R = S.upper_bound({B[i] + 2, 0});
        if (L != S.end() && L != R) {
            int max_start = 0;
            for (auto it = L; it != R; ++it) {
                int cur = it->first, start = it->second;
                --difference_count[cur - start];
                max_start = max(start, max_start);
            }
            S.erase(L, R);
            if (B[i] + 1 <= W) {
                S.insert({B[i] + 1, max_start});
                ++difference_count[B[i] + 1 - max_start];
            }
        }
        if (S.empty()) {
            cout << "-1\n";
        }
        else {
            while (difference_count[min_difference] == 0) {
                ++min_difference;
            }
            cout << i + 1 + min_difference << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 15060
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n;
vector<ll> a;

void solve(){
    cin >> n;
    a.resize(n,0);
    rep(i,n){
        cin >> a[i];
    }
    int l=0,r=1;
    ll x=a[0],ans=1;
    while (true){
        if (r==n) break;
        if ((x&a[r])==0) {
            r+=1;
            x|=a[r-1];
            ans+=r-l;
        }
        else {
            l+=1;
            x^=a[l-1];
        }
        if (r==n) break;
    }

    cout << ans << endl;
}

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

Measured memory_bytes: 1792
A,B,C = map(int, input().split())
K = int(input())
# A: aka < B: midori < C: ao
def F(d):
    for i in range(K):
        for j in range(K - i):
            for k in range(K - i - j+1):
                a = A*2**i
                b = B*2**j
                c = C*2**k
                #print("a:",a, ",b:",b, ",c:",c)
                if a<b and b<c:
                    d = 1
                    return "Yes"
    if d ==0:
        return "No"

print(F(0))

Measured memory_bytes: 9200
#include<iostream>
#include<complex>
#define EPS (1e-8)
#define EQ(a,b) (abs((a)-(b)) < EPS)
using namespace std;

typedef complex<double> P;
double cross(P x,P y){return imag(conj(x)*y);}
double area_tri(P a,P b,P c){return abs(cross(b-a,c-a)/2);}

int main(){
  P p[4];
  while(cin >> p[0].real() >> p[0].imag()){
    for(int i=1;i<4;i++)cin >> p[i].real() >> p[i].imag();
    double sum = 0;
    for(int i=0;i<3;i++)sum += area_tri(p[i],p[(i+1)%3],p[3]);
    if(EQ(sum,area_tri(p[0],p[1],p[2])))cout << "YES\n";
    else cout << "NO\n";
  }
}

Measured memory_bytes: 1192
#include <cstdio>
#include <cstring>

int main()
{
char str[1024];
int len;
int ab = 'Z' - 'A' + 1;

scanf("%s", str);
len = strlen(str);

for(int i = 0; i < len; ++i) {
char c = str[i];
c = (c - 'A' + ab - 3) % ab + 'A';
str[i] = c;
}

printf("%s\n", str);

return 0;
}

Measured memory_bytes: 948
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>
#include <math.h>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


template<typename T>
// return true:素数
bool isPrime(T num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (T i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }
    return true;
}


int main(){
    ll X;
    cin >> X;

    while(true)
    {
      if(isPrime(X))break;
      ++X;
    }

    cout << X << endl;

    return 0;    
}



Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#define mxn 100010
#define LL long long
using namespace std;
LL sum,ans,l[mxn],r[mxn],f[mxn];
int n,X,sl,fh,b[mxn],rk[mxn];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
bool cmp(const int &x,const int &y) {return f[x]>f[y];}
bool check(LL t)
{
	static LL S,nw;static LL x,y;
	nw=sum;x=t/X,y=t%X;if(x>=n) return 1;
	for(int i=1;i<=x;++i) nw+=f[rk[i]];
	for(int i=x+1;i<=n;++i)
	{
		S=nw;
		if(y<=b[rk[i]]) S+=y*l[rk[i]];
		else S+=b[rk[i]]*l[rk[i]]+(y-b[rk[i]])*r[rk[i]];
		if(S>=0) return 1;
	}
	nw+=f[rk[x+1]];
	for(int i=1;i<=x;++i)
	{
		S=nw-f[rk[i]];
		if(y<=b[rk[i]]) S+=y*l[rk[i]];
		else S+=b[rk[i]]*l[rk[i]]+(y-b[rk[i]])*r[rk[i]];
		if(S>=0) return 1;
	}
	return 0;
}
#define Mid ((L+R)>>1)
int main()
{
	n=rd();X=rd();LL L=0,R=0;
	for(int i=1;i<=n;++i)
	{
		b[i]=rd(),l[i]=rd(),r[i]=rd();R+=b[i];
		f[i]=r[i]*(X-b[i])+b[i]*l[i];rk[i]=i;sum-=b[i]*l[i];
	}
	sort(rk+1,rk+n+1,cmp);
	while(L<=R)
	{
		if(check(Mid)) ans=Mid,R=Mid-1;
		else L=Mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = ReadLine();
        var sum = N.Select(x => x - '0').Sum();
        var ans = (sum % 9 == 0) ? "Yes" : "No";

        WriteLine(ans);
    }
}


Measured memory_bytes: 27344
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int N = Integer.valueOf(s.next());
		
		int ret = 0;
		for(int i = 1; i <= N; i++) {
			int cur = Integer.valueOf(s.next());
			if(cur%2 == 1 && i % 2 == 1) {
				ret++;
			}
		}
		System.out.println(ret);
	}
}

Measured memory_bytes: 35560
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 998244353;

int main() {
    //constexpr int n = 15;
    //for (int k = 0; k < 1 << n; k++) {
    //    int l = k;
    //    for (int i = 1;; i++) {
    //        if (l & 1) {
    //            l /= 2;
    //        } else {
    //            l /= 2;
    //            l += 1 << (n - 1);
    //        }
    //        if (l == k) {
    //            if (i != n * 2) cout << bitset<n>(k) << ' ' << i << endl;
    //            break;
    //        }
    //    }
    //}

    int n;
    string x;
    cin >> n >> x;

    for (int i = n - 1; i >= 0; i--) {
        x[i] -= '0';
    }
    x.back()++;
    int g = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (x[i] == 2) {
            x[i] = 0;
            if (i > 0) x[i - 1]++; else g++;
        }
    }

    vector<int> y(n + 1);
    y[0] = 1;
    for (int i = 0; i < n; i++) {
        y[i + 1] = y[i] * 2 % P;
    }

    ll z = 0;
    //ll u = 0;
    vector<int> r(n + 1);
    for (int i = 1 + (n + 1) % 2; i <= n; i += 2) {
        if (n % i != 0 || n / i % 2 == 0) continue;
        ll t = r[i];
        int m = i + 1, f = 1;
        for (int j = -1; j < n; j++) {
            m--;
            int f2 = f;
            if (j >= i && x[j] != x[j - i]) f2 = 0;
            if (j >= i && x[j] == x[j - i]) f = 0;
            int x1 = j < 0 ? g : x[j];
            if (x1 == 0) continue;
            if (m < 0) {
                if (f2) t++;
            } else {
                t += y[m];
            }
        }
        t %= P;
        //u += t;
        z += t * (i * 2) % P;
        for (int h = i * 2; h <= n; h += i) {
            r[h] -= t;
            if (r[h] < 0) r[h] += P;
        }
    }

    //cout << u << endl;
    cout << z % P << endl;

    //B
    //どの経路でも距離が変わらない（ループあるから違った）
    //二部グラフであることが必要
    //二部グラフにすればk=2は達成できる
    //木だったら？直径 じゃあ偶閉路があったら？
    //V[i]の頂点からV[i-1]に行くかV[i+1]に行くかわからないから難しい

    //C
    //情報は欠落しない 反転してrotateしてる
    //0101 0010 Nが偶数のとき
    //基本N*2回で戻るが、N回以上N*2回未満で戻ることはあるか？ N回でnot
    //N=ブロック長*奇数 とできるとき ブロック長*2 で戻りそう ブロックが反転しながら繰り返されるやつ
    //ブロック長がMのものは2^M個あるが、その中にはMの約数のも含まれているかも
    //ブロック長とNの偶奇は一致する（奇数をかけてNになるので）
    //Nと偶奇が一致する約数を列挙 考えられるブロックの通り数を配列に入れる 小さい順に見てその個数を自分の倍数から引く
    //さて、N未満ではなくX+1未満なので難しい 約数は高々160個 確定が1ループぶん以上あるなら確認して1通り ないなら2^あまったbit数通り
    //NlogN*160？いや、約数毎にO(N)でカウントできるんじゃ 2^Nから2^0までN+1通りある？
    //サンプルが8多かったり少なかったりするが

    return 0;
}

Measured memory_bytes: 2180
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	cin >> N;
	VLL A(N);
	for (LL n = 0; n < N; n++) {
		cin >> A[n];
	}
	if (N == 2) {
		cout << max(A[0], A[1]) << "\n";
		return 0;
	}
	VLL sum(N,0);
	sum[0] = A[0];
	for (LL n = 2; n < N; n += 2) {
		sum[n] = sum[n - 2] + A[n];
	}
	VLL DP(N);
	DP[0] = 0;
	DP[1] = max(A[0], A[1]);
	DP[2] = max(A[0], max(A[1], A[2]));
	for (LL n = 3; n < N; n++) {
		if (n & 1) {
			DP[n] = DP[n - 2] + A[n];
			DP[n] = max(DP[n], sum[n-1]);
		}
		else {
			DP[n] = DP[n - 2] + A[n];
			DP[n] = max(DP[n], DP[n-3] + A[n - 1]);
			DP[n] = max(DP[n], sum[n - 2]);
		}
	}
	cout << DP[N-1] << "\n";
	return 0;
}


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

using namespace std;

#define MAX_H 20
#define MAX_W 20
#define MAX_N 5
#define MAX_S 40
#define INF 1e9

struct P{
    int x,y;
    P(){}
    P(int x,int y) : x(x),y(y) {}
};

struct State{
    int x,y,S,t;
    State(int x,int y,int S,int t) : x(x),y(y),S(S),t(t) {}
};

int H,W,N,L[MAX_N],b;
bool can[MAX_H][MAX_W];
bool dp[MAX_H][MAX_W][1<<MAX_N][MAX_S];
vector<P> path[MAX_N];
const int dx[9] = {-1,-1,-1,0,0,0,1,1,1};
const int dy[9] = {-1,0,1,-1,0,1,-1,0,1};

bool inField(int x,int y){
    return (0 <= x && x < W && 0 <= y && y < H);
}

int bfs(int sx,int sy){
    if(b == (1<<N)-1) return 0;
    queue<State> Q; Q.push(State(sx,sy,b,0));
    memset(dp,false,sizeof(dp));
    dp[sy][sx][b][0] = true;
    while(!Q.empty()){
        State s = Q.front(); Q.pop();
        int x = s.x,y = s.y,S = s.S;
        int t = s.t;
        bool ok = true;
        for(int i = 0 ; i < N ; i++){
            if(!(S >> i & 1) && L[i] <= t){
                ok = false;
                break;
            }
        }
        if(!ok) continue;
        if(S == (1<<N)-1) continue;
        for(int i = 0 ; i < 9 ; i++){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(!inField(nx,ny)) continue;
            if(!can[ny][nx]) continue;
            int nS = S;
            for(int j = 0 ; j < N ; j++){
                if(L[j] <= t+1) continue;
                P p = path[j][t+1];
                if(p.x == nx && p.y == ny){
                    nS |= 1<<j;
                }
            }
            if(!dp[ny][nx][nS][s.t+1]){
                dp[ny][nx][nS][s.t+1] = true;
                Q.push(State(nx,ny,nS,s.t+1));
            }
        }
    }
    int res = INF;
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            for(int k = 1 ; k < H+W ; k++){
                if(dp[i][j][(1<<N)-1][k]){
                    res = min(res,k);
                }
            }
        }
    }
    return (res == INF ? -1 : res);
}

int main(){
 int sx,sy,x,y;
    cin >> W >> H >> N >> sx >> sy; sx--; sy--;
    fill(can[0],can[0]+MAX_H*MAX_W,1); b = 0;
    for(int i = 0 ; i < N ; i++){
        cin >> L[i]; path[i].resize(L[i]);
        for(int j = 0 ; j < L[i] ; j++){
            cin >> x >> y; x--; y--;
            path[i][j] = P(x,y);
            if(j == L[i]-1) can[y][x] = 0;
            if(j == 0 && x == sx && y == sy){
                b |= 1<<i;
            }
        }
    }
    cout << bfs(sx,sy) << endl;
    return 0;
}

Measured memory_bytes: 1860
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007

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

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

#define N 14000

int main()
{
   FAST/**/
   
   ll n,m;
   cin>>n>>m;
   ll arr[n][m];
   for(ll i=0;i<n;i++)
        for(ll j=0;j<m;j++)
            cin>>arr[i][j];
        
   bool dp[n][m][N];
   for(ll i=0;i<n;i++)
        for(ll j=0;j<m;j++)
            for(ll i1=0;i1<N;i1++)
                dp[i][j][i1] = 0;
   
   
   ll arr1[n][m];
   for(ll i=0;i<n;i++)
        for(ll j=0;j<m;j++)
            cin>>arr1[i][j], arr[i][j] = arr[i][j] - arr1[i][j];
   
   dp[0][0][arr[0][0]+N/2] = 1;
   for(ll i=0;i<n;i++)
   {
       for(ll j=0;j<m;j++)
       {
           if(i+j == 0)
                continue;
           for(ll i1=0;i1<N;i1++)
           {
               ll d1 = i1+arr[i][j];
               ll d2 = i1-arr[i][j];
               
               if(i>0 && d1<N && d1>-1)
                    dp[i][j][d1]|=dp[i-1][j][i1];
               if(i>0 && d2<N && d2>-1)
                    dp[i][j][d2]|=dp[i-1][j][i1];        
               if(j>0 && d1<N && d1>-1)
                    dp[i][j][d1]|=dp[i][j-1][i1];
               if(j>0 && d2<N && d2>-1)
                    dp[i][j][d2]|=dp[i][j-1][i1];        
           }
       }
   }
   
   ll ans = 90;
   for(ll i=0;i<N;i++)
   {
       if(dp[n-1][m-1][i])
            ans = min(ans, (ll)abs(i-N/2));
   }
   
   cout<<ans;
           
}  
   

Measured memory_bytes: 87808
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int counter=1;
    cin>>n;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s,s+n);
    for(int i=1;i<n;i++){
	    if(s[i-1]!=s[i]){
            counter+=1;
        }
    }
    cout<<counter<<endl;
}

Measured memory_bytes: 9844
P = list(input())
xi = P.index('?')
Q =[6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2]

pqsum = 0
for i in range(11):
    if P[i]=='?':
        pass
    else:
        pqsum += int(P[i])*Q[i]

if xi<11:
    Pxi = []
    for i in range(10):
        PQS = pqsum + i*Q[xi]
        if PQS%11<=1:
            P0 = 0
        if 1<PQS%11:
            P0 = 11-(PQS%11)
        if P0==int(P[11]):
            Pxi.append(i)

    if len(Pxi)==1:
        print(Pxi[0])
    else:
        print('MULTIPLE')

if xi==11:
    if pqsum%11<=1:
        P0 = 0
    if 1<pqsum%11:
        P0 = 11-(pqsum%11)
    print(P0)


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

using namespace std;

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> a(n + 1), b(m + 1);
    a[0] = x;
    b[0] = y;
    for (int i = 0; i < n; i++) cin >> a[i + 1];
    for (int i = 0; i < m; i++) cin >> b[i + 1];

    bool x_is_ok;
    bool y_is_ok;
    for (int z = -100; z <= 100; z++){
        x_is_ok = true;
        y_is_ok = true;
        for (int i = 0; i < n + 1; i++){
            if (a[i] >= z) {
                x_is_ok = false;
            }
        }
        for (int i = 0; i < m + 1; i++){
            if (b[i] < z){
                y_is_ok = false;
            }
        }
        if (x_is_ok && y_is_ok) break;
    }

    if ((x_is_ok == true) && (y_is_ok == true))  cout << "No War" << endl;
    else    cout << "War" << endl;
    return 0;
}

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

public class Prime{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
         
        var primeFactors = PrimeFactors(n);
         
        string output = primeFactors.Count() == 0 
                        ? n.ToString() 
                        : string.Join(" ", primeFactors.Select (f => f.ToString()).ToArray()); //AOJ??¨
                        //:string.Join(" ", primeFactors);
        Console.WriteLine("{0}: {1}", n, output);
    }
     
    public static IEnumerable<int> PrimeFactors(int n)
    {
        int i = 2;
        int tmp = n;
         
        while (i <= tmp)
        {
            if(tmp % i == 0){
                tmp /= i;
                yield return i;
            }else if(i > Math.Sqrt(n)){
                i = int.MaxValue; //???????????????
                yield return tmp;
	    }else{
                i++;
            }
             
            //if(i > Math.Sqrt(n)){
            //}
        }
    }
}

Measured memory_bytes: 5996
#include<bits/stdc++.h>
using namespace std;
long long x[100001];//注意定ll，要不然会WA
int main()
{
    long long ans=0,n,a,b,i;
    cin>>n>>a>>b;
    for(i=1;i<=n;i++)
     cin>>x[i];
    for(i=2;i<=n;i++)//从第一座城市开始
     ans+=min((x[i]-x[i-1])*a,b);//取较小值
    cout<<ans<<endl;
}

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

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

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N, K;
  cin >> N >> K;
  K--; // 0-indexed
  string S;
  cin >> S;

  if (S[K] == 'A') {
    S[K] = 'a';
  } else if (S[K] == 'B') {
    S[K] = 'b';
  } else {
    S[K] = 'c';
  }

  cout << S << endl;

  return 0;
}


Measured memory_bytes: 256
object Main extends App{
  var n = scala.io.StdIn.readInt
  n.toString.last match{
    case '2'|'4'|'5'|'7'|'9' => printf("hon")
    case '0'|'1'|'6'|'8' =>printf("pon")
    case '3'=>printf("bon")
  }
}


Measured memory_bytes: 54480
#include <cstdio>
#include <cmath>
#include <algorithm>

#define ll long long
#define maxn 10000000000

ll nrcif(ll x) {
    ll rez = 0;
    while (x > 0) {
        rez++;
        x = x / 10;
    }
    return rez;
}

int main() {
    ll n;
    ll a, b;
    scanf("%lld", &n);
    ll rez = maxn + 1;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            a = nrcif(i);
            b = nrcif(n / i);
            rez = std::min(rez, std::max(a, b));
        }
    }
    printf("%lld", rez);
    return 0;
}


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

int main()
{
    string a, b;
    cin >> a >> b;
    a = a + b;
    int n = stoi(a);
    int n1 = sqrt(n);
    n1 = n1*n1;
    if (n1 == n)cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#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++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

bool IsPrime(int64_t i){
  int64_t j = 2;
  while(j * j <= i){
    if(i % j == 0){
      return false;
    }
    j++;
  }
  return true;
}

int main(){
  int64_t N, K, R, S, P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  int64_t ans = 0;
  vector<bool> chg(N, false);
  rep(i, sz(T)){
    if(i < K){
      if(T.at(i) == 'r'){
        ans += P;
      }
      else if(T.at(i) == 's'){
        ans += R;
      }
      else{
        ans += S;
      }
    }
    else{
      if(T.at(i) != T.at(i-K)){
        if(T.at(i) == 'r'){
          ans += P;
        }
        else if(T.at(i) == 's'){
          ans += R;
        }
        else{
          ans += S;
        }
      }
      else{
        if(chg.at(i-K)){
          if(T.at(i) == 'r'){
            ans += P;
          }
          else if(T.at(i) == 's'){
            ans += R;
          }
          else{
            ans += S;
          }
        }
        else{
          chg.at(i) = true;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

struct UnionFind{
	vector<int> elems;
	UnionFind(int n):elems(n){
		for(int i=0;i<n;i++){
			elems[i] = i;
		}
	}
	bool same(int a, int b){
		return parent(a) == parent(b);
	}
	void unite(int a, int b){
		elems[parent(a)] = parent(b);
	}
private:
	int parent(int a){
		if(a == elems[a]){
			return a;
		}
		return elems[a] = parent(elems[a]);
	}
};

int main(){
    int n; cin >> n;
    vector<pair<int, int>> xs(n), ys(n);
    for(int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        xs[i] = {x, i};
        ys[i] = {y, i};
    }
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
    struct Elem{
        int len, a, b;
        bool operator < (const Elem& e) const{
            return len < e.len;
        }
    };
    vector<Elem> ve;
    for(int i = 1; i < n; i++){
        ve.push_back({xs[i].first - xs[i - 1].first, xs[i].second, xs[i - 1].second});
        ve.push_back({ys[i].first - ys[i - 1].first, ys[i].second, ys[i - 1].second});
    }
    sort(ve.begin(), ve.end());
    UnionFind uf(n);
    ll ans = 0;
    for(auto e : ve){
        if(uf.same(e.a, e.b)){ continue; }
        ans += e.len;
        uf.unite(e.a, e.b);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 6516
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n+m){
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(a[i]+a[j]<=m)
	ans=max(ans,a[i]+a[j]);
    }
  }
  if(ans==0)
    cout<<"NONE"<<endl;
  else
    cout<<ans<<endl;
  }
  return 0;
}

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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;


int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   ll n; cin >> n;
   int sum = 0;
   for(int i =0; i < n; i++)
   {
      int x, y; cin >> x >> y;
      sum += y-x+1;
   }
   cout <<sum << nl;
   return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b;}
template<class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct InitIO{
  InitIO() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
  }
}init_io;

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  rep2(i, 1, n+1) {
    ll y = n / i;
    ans += y*(y+1)*ll(i)/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3656
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int MAX_N =2000010;
int heap[MAX_N];
int n;

int parent(int i){
	return i/2;
}
int rightchild(int i){
	return 2*i+1;
}
int leftchild(int i){
	return 2*i;
}
int sz = 1;
void push(int x){
	int i =sz++;
	while(i >1){
		int p =parent(i);
		//もし逆転していないなら抜ける
		if(heap[p] >=x)break;
		//親のノードの数字をおろして自分は上に
		heap[i]=heap[p];
		i = p;
	}
	heap[i] = x;
}
int pop(){
	//最大値取り出し
	int  ret =heap[1];
	//根に持ってくる値
	int x =heap[--sz];
	//根から下ろしていく
	int i = 1;
	while(leftchild(i) <sz){
		//子同士を比較
		int left =leftchild(i);
		int right =rightchild(i);
		if(leftchild(i) <sz&&heap[rightchild(i)] >heap[leftchild(i)]){
			left =right;
		}
		if(heap[left]<=x)break;

		heap[i]=heap[left];
		i =left;
	}
	heap[i]=x;
	return ret;
}
int main(){
	string str;
	while(cin>>str){
		if(str=="end")return 0;
		if(str=="insert"){
			int x;
			cin>>x;
			push(x);
		}else{
			cout <<pop()<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 5296
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;



int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n,z,w;
    cin>>n>>z>>w;
    vector<int> a(n), dpx(n,0), dpy(n,0);
    for(int& i:a){
        cin>>i;
    }
    if(n==1){
        cout<<abs(a[0]-w);
        return 0;
    }
    dpx[n-1]=abs(a[n-1]-a[n-2]);
    dpy[n-1]=abs(a[n-1]-a[n-2]);
    for(int i=n-2; i>=1; i--){
        dpx[i]=abs(a[n-1]-a[i-1]);
        dpy[i]=abs(a[n-1]-a[i-1]);
        for(int j=i+1; j<n; j++){
            dpx[i]=max(dpx[i],dpy[j]);
            dpy[i]=min(dpy[i],dpx[j]);
        }
    }
    int ans=abs(a[n-1]-w);
    for(int i=1; i<n; i++){
        ans=max(ans,dpy[i]);
    }
    cout<<ans;
    
    return 0;
    
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int N,X,Y,Z;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        long[,] dp = new long[N,1 << (X+Y+Z)];
        int l = 0;
        int g = 0;
        long count = 1;
        g += 1 << X+Y+Z-1;
        g += 1 << Y+Z-1;
        g += 1 << Z-1;
        for(int i=0;i<X+Y+Z;i++){
            l += 1 << i;
        }
        for(int i=0;i<N;i++){
            for(int j=0;j<1 << (X+Y+Z);j++){
                dp[i,j] = 0;
            }
        }
        for(int i=0;i<10;i++){
            dp[0,l & (1 << i)] ++;
        }
        for(int i=0;i<N-1;i++){
            for(int j=0;j<1 << (X+Y+Z);j++){
                for(int k = 1;k <= 10;k++){
                    int t = (j << k) + (1 << (k-1));
                    if((t & g) != g){
                        dp[i+1,t & l] = (dp[i+1,t & l] + dp[i,j]) % Define.mod; 
                    }
                }
            }
        }
        for(int i=0;i<N;i++){
            count = (count * 10) % Define.mod;
        }
        for(int i=0;i< 1 << (X+Y+Z);i++){
            count = (count - dp[N-1,i] + Define.mod) % Define.mod;
        }
        sb.Append(count+"\n");
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        X = int.Parse(str[1]);
        Y = int.Parse(str[2]);
        Z = int.Parse(str[3]);
    }    
}
public static class Define{
    public const long mod = 1000000007;
}

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

int main() {
	int n,k;
	cin >> n >> k;
	vector<int> p(n);
	rep(i,n) cin >> p[i];
	sort(p.begin(), p.end());
	int ans = 0;
	rep(i,k) ans += p[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3604
def solve():
    H, W = map(int, input().split())
    a = [list("."+input()+".") for _ in [0]*H]
    a.insert(0, list("."*(W+2)))
    a.append(list("."*(W+2)))
    result = []
 
    for y in range(1, H+1):
        for x in range(1, W+1):
            if a[y][x] == "#":
                result.append("#")
            else:
                result.append(str((a[y-1][x-1:x+2]+a[y][x-1:x+2]+a[y+1][x-1:x+2]).count("#")))
        result.append("\n")
 
    print("".join(result))
 
 
if __name__ == "__main__":
    solve()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
int a;
cin>>a;
vector<int> v(a),b(a);
int tmp;
for(int i=0; i<a; i++){
cin>>v[i];
b[i]=v[i];
}

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

if(v[a-1]==v[a-2]){
  for(int i=0; i<a; i++)
    cout<<v[a-1]<<endl;
} 
else{
  for(int i=0; i<a; i++){
    if(v[a-1]==b[i])
      tmp=i;
  } 
  for(int i=0; i<a; i++){
    if(tmp==i)
      cout<<v[a-2]<<endl;
    else
      cout<<v[a-1]<<endl;
  }
}
}


Measured memory_bytes: 3200
#include<cstdio>
int main(){
	int h,w;
	int a[26]={};
	scanf("%d %d",&h,&w);
	for(int i=0;i<h;i++){
		char s[w+10]={};
		scanf("%s",s);
		for(int j=0;j<w;j++){
			a[s[j]-97]++;
		}
	}
	int x=0;
	if(h%2==0 && w%2==0){
		int y=0;
		for(int i=0;i<26;i++){
			if(a[i]%4!=0)y=1;
		}
		if(y==0)x=1;
	}else if(h%2==0 && w%2==1){
		int y=0;
		int z=0;
		for(int i=0;i<26;i++){
			if(a[i]%4==2) z++;
			else if(a[i]%4!=0)y++;
		}
		if(y==0){
			if(z%2==(h/2)%2 && z<=h/2){
				x=1;
			}
		}
	}else if(h%2==1 && w%2==0){
		int y=0;
		int z=0;
		for(int i=0;i<26;i++){
			if(a[i]%4==2) z++;
			else if(a[i]%4!=0)y++;
		}
		if(y==0){
			if(z%2==(w/2)%2 && z<=w/2){
				x=1;
			}
		}
	}else{
		int y=0;
		int z=0;
		int q=0;
		for(int i=0;i<26;i++){
			if(a[i]%4==1)y++;
			else if(a[i]%4==2)z++;
			else if(a[i]%4==3)q++;
		}
		if(q==0){
			if(y==1){
				if(((h-1)/2+(w-1)/2)%2==z%2)x=1;
			}
		}
	}
	if(x==1)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

string grade(long long x, long long y, long long z)
{
    if (x == -1 || y == -1)
    {
        return "F";
    }
    else if (x + y >= 80)
    {
        return "A";
    }
    else if (x + y >= 65)
    {
        return "B";
    }
    else if (x + y >= 50)
    {
        return "C";
    }
    else if (x + y >= 30)
    {
        if (z >= 50)
        {
            return "C";
        }
        return "D";
    }
    else
    {
        return "F";
    }
}

int main()
{
    bool flag = true;
    while (flag)
    {
        long long x, y, z;
        cin >> x >> y >> z;
        if (x == -1 && y == -1 && z == -1)
        {
            break;
        }
        string result = grade(x, y, z);
        cout << result << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(x: u32, mut ms: Vec<u32>) -> u32 {
    let total = ms.iter().fold(0, |sum, m| sum+m);

    ms.sort();

    let remain = (x - total) / ms[0];

    ms.len() as u32 + remain
}

fn main() {
    let (n, x) = parse_line!(usize, u32);

    println!("{}", solve(x, (0..n).map(|_| parse_line!(u32)).collect()));
}

#[test]
fn solve_test() {
    assert_eq!(solve(1000, vec![120, 100,140]), 9);
    assert_eq!(solve(360, vec![90, 90, 90, 90]), 4);
    assert_eq!(solve(3000, vec![150,130,150,130,110]), 26);
}


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

int main() {
    int N;
    cin >> N;
    int A[N], B[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];

    ll bigA = 0, bigB = 0;
    for(int i = 0; i < N; i++) {
        if(A[i] > B[i])
            bigA += A[i] - B[i];
        else
            bigB += (B[i] - A[i]) / 2;
    }
    if(bigB >= bigA)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 384