akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    string s; int x, y; cin >> s >> x >> y;
    vector<int> mX, mY;
    
    int cnt = 0; int cx = 0, cy = 0;
    for(char c: s){
        if(c == 'F') cnt%2 ? cy++ : cx++;
        else{
            if(cnt%2==0){
                mX.push_back(cx);
                cx = 0;
            }else{
                mY.push_back(cy);
                cy = 0;
            }
            cnt++;
        }
    }
    if(cnt%2==0) mX.push_back(cx);
    else mY.push_back(cy);
    
    map<int, bool> dpx, dpy;
    dpx[0] = true, dpy[0] = true; bool fir = true;
    for(int num: mX){
        vector<int> key;
        for(auto m: dpx)key.push_back(m.first);
        dpx.clear();
        for(int m: key){
            dpx[m+num] = true;
            if(!fir) dpx[m-num] = true;
        }
        fir = false;
    }
    for(int num: mY){
        vector<int> key;
        for(auto m: dpy)key.push_back(m.first);
        dpy.clear();
        for(int m: key){
            dpy[m+num] = true;
            dpy[m-num] = true; 
        }  
    }

    if(dpx[x] && dpy[y]) cout << "Yes" << ln;
    else cout << "No" << ln;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
# C

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

import math
a, b, c = map(int, input().split())

a1 = a + b - c
if a1 >0:
    print('No')
    sys.exit()

if a1**2 - 4 * a * b > 0:
    print('Yes')
else:
    print('No')

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

constexpr int P = 1000000007;

ll powmod(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}
ll inv(ll n) {
    return powmod(n, P - 2);
}

vector<int> f0, f1;
void init(int n) {
    f0.resize(n + 1);
    f0[0] = 1;
    for (int i = 1; i <= n; i++) {
        f0[i] = (ll)f0[i - 1] * i % P;
    }
    f1.resize(n + 1);
    f1[n] = inv(f0[n]);
    for (int i = n; i > 0; i--) {
        f1[i - 1] = (ll)f1[i] * i % P;
    }
}
ll fact(int k) {
    return f0[k];
}
ll comb(int n, int k) {
    if (n < k || k < 0) return 0;
    return (ll)f0[n] * f1[k] % P * f1[n - k] % P;
}

struct Graph {
    struct Sub {
        Sub() : r(1), k(0) {}
        Sub &operator+=(const Sub &s) {
            k += s.k;
            r = (ll)r * s.r % P * comb(k, s.k) % P;
            return *this;
        }
        Sub &add_root() {
            k++;
            return *this;
        }
        int r, k;
    };
    struct Vertex { int n; Sub s; };
    struct Edge { int i, n; Sub s; };
    Graph(int n, int m) : v(n, { -1, {} }), e(m), r(m), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n, {} };
        v[i].n = m;
        m++;
    }
    Sub dfs0(int i, int p) {
        Sub s;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            if (o.i == p) continue;

            s += o.s = dfs0(o.i, i);
        }
        return s.add_root();
    }
    void dfs1(int i, int p, Sub *r, Sub s0) {
        int l = 0;
        Sub x;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            if (o.i == p) o.s = s0;
            r[l++] = o.s;
            x += o.s;
        }
        for (int k = l - 1; k > 0; k--) {
            r[k - 1] += r[k];
        }
        v[i].s = r[0].add_root();

        Sub s;
        int k = 0;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            k++;
            if (o.i != p) {
                Sub t = s;
                if (k < l) t += r[k];
                dfs1(o.i, i, r + l, t.add_root());
            }
            s += o.s;
        }
    }
    void solve() {
        dfs1(0, -1, &r[0], dfs0(0, -1));

        for (int i = 0; i < n; i++) {
            cout << v[i].s.r << '\n';
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    vector<Sub> r;
    int n, m;
};

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

    int n;
    cin >> n;

    init(n);

    Graph g(n, (n - 1) * 2);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    g.solve();

    return 0;
}

Measured memory_bytes: 15616
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        List<Character> al = new ArrayList<>();
        for (char i = 'a'; i <= 'z'; i++) {
            al.add(i);
        }

        while (sc.hasNextLine()) {
            String S = sc.nextLine();

            String ans = "";
            for (int i = 0; i < 27; i++) {
                StringBuilder tmp = new StringBuilder();

                for (int j = 0; j < S.length(); j++) {
                    if (Character.isLetter(S.charAt(j))) {
                        int index = al.indexOf(S.charAt(j)) + i;

                        if (index >= al.size()) {
                            index %= al.size();
                        }
                        tmp.append(al.get(index));
                    } else {
                        tmp.append(S.charAt(j));
                    }
                }

                if (tmp.toString().contains("the") || tmp.toString().contains("this") || tmp.toString().contains("that")){
                    ans = tmp.toString();
                    break;
                }
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 26388
from math import hypot
N = int(input())
P = [tuple(int(x) for x in input().split()) for _ in range(N)]
term = 0
for i in range(N):
    for j in range(i + 1, N):
        x0, y0 = P[i]
        x1, y1 = P[j]
        term += hypot(x1 - x0, y1 - y0)
term /= N*(N - 1)//2
print((N - 1)*term)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;

// a と b の最大公約数を返す
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}


ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}



// 素数判定
bool is_prime(ll N) {
    if (N == 1) return false;
    for (ll i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}


// 約数列挙
vector<ll> enum_divisors(ll N) {
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll N){
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= N; i++){
        if(N % i != 0)  continue;
        ll ex = 0;

        while(N % i == 0){
            ex++;
            N /= i;
        }

        res.push_back({i, ex});
    }

    if(N != 1)  res.push_back({N, 1});
    return res;
};


int main(){
    ll n;   cin >> n;
    vector<P> prime_list = prime_factorize(n);
    int res = 0;
    for(auto x: prime_list){
        ll num = x.sc;
        int count = 1;
        while(num >= count){
            num -= count;
            count++;
            res++;
        }
    }
    cout << res << endl;


    return 0;
}


Measured memory_bytes: 3616
// #include <cstdio>
// #include <string>
// #include <iostream>
// #include <unordered_map>

// using namespace std;
// string s[200000];

// int main(){
//     unordered_map<string, long long> mp;
//     int n, i, l, j;
//     scanf("%d", &n);
//     int m = n;
//     long long ans = 0;
//     while(n--){
//         cin >> s[n];
//         l = s[n].length();
//         int d[26] = {0};
//         for(i = 0; i < 26; ++i)
//             d[i] = -1;
//         for(i = l - 1; i >= 0; --i)
//             d[s[n][i] - 'a'] = i;
//         //ans += mp[s];
//         string str;
//         for(i = 0; i < 26; ++i)
//             if(~d[i]){
//                 str = "a";
//                 str[0] += i;
//                 ++mp[str];
//         }
//         for(i = l - 1; i >= 1; --i){
//             str = s[n].substr(i, l - i);
//             for(j = 0; j < 26; ++j){
//                 if(d[j] < i && ~d[j]){
//                     string pstr = "a";
//                     pstr[0] += j;
//                     pstr.append(str);
//                     ++mp[pstr];
//                 }
//             }
//         }
//     }
//     while(m--)
//         ans += mp[s[m]] - 1;
//     printf("%lld\n", ans);
//     return 0;
// }

#include <cstdio>
#include <cstring>
#include <set>

struct Trie{
    Trie* children[26];
    int is_end;
    int num[26];

    Trie(){
        for(int i = 0; i < 26; ++i){
            children[i] = NULL;
            num[i] = 0;
        }
        is_end = 0;
    }
    Trie* upsert(char ch){
        if(children[ch - 'a'] == NULL)
            children[ch - 'a'] = new Trie();
        return children[ch - 'a'];
    }
    Trie* find(char ch){
        return children[ch - 'a'];
    }
};

int main(){
    int n;
    scanf("%d", &n);
    char s[1000005];
    Trie *root = new Trie();
    Trie *p, *q;
    int len;
    int i, j;
    int d[26];
    int t;
    long long ans = 0;
    while(n--){
        scanf("%s", s);
        len = strlen(s);
        for(i = 0; i < 26; ++i)
            d[i] = 0x7FFFFFFF;
        //std::set<char> se;
        for(i = len - 1; i >= 0; --i)
            d[s[i] - 'a'] = i; 
        for(i = 0; i < 26; ++i)
            if(d[i] < len){
                ++root->num[i];
                q = root->find('a' + i);
                if(q)
                    ans += (long long)q->is_end;
                //printf("%c%d ", 'a' + i, ans);
            }
        p = root;
        //printf("%lld ", ans);
        for(i = len - 1; i >= 1; --i){
            p = p->upsert(s[i]);
            for(j = 0; j < 26; ++j)
                if(d[j] < i){
                    ++p->num[j];
                    q = p->find('a' + j);
                    if(q)
                        ans += q->is_end;
                }
        }
        ans += (long long)(p->num[s[0] - 'a'] - 1);
        p = p->upsert(s[0]);
        ++p->is_end;
        //printf("%lld ", ans);
        //++p->num;
        //printf("%lld\n", ans);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 330896
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
    int n;
    scanf("%d", &n);

    int a[n];
    for(int i = 0 ; i < n; i++) {
        scanf("%d", &a[i]);
    }

    int count = 0;
    while(true) {
        bool result = true;
        for (int i = 0; i < n; i++) {
            if (a[i] % 2 == 1) {
                result = false;
                break;
            }
            a[i] = a[i] / 2;
        }
        if(!result) {
            break;
        }
        count++;
    }

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

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

using namespace std;

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

#define INF 4294967295

unsigned int dp[2][62][62][4000];


signed main()
{
	int nn, kk;
	cin >> nn >> kk;
	vi data(nn);
	rep(i, nn) {
		cin >> data[i];
	}
	vi red(kk), black(kk);
	int RED = 0, BLACK = 0;
	rep(i, kk) {
		cin >> red[i];
		RED += red[i];
	}
	rep(i, kk) {
		cin >> black[i];
		BLACK += black[i];
	}


	sort(all(data));
	reverse(all(data));
	sort(all(red));
	reverse(all(red));
	sort(all(black));
	reverse(all(black));
	vi ruiseki(nn + 1, 0);
	rep(i, nn) {
		ruiseki[i + 1] = ruiseki[i] + data[i];
	}

	//cout << "hoge " << endl;

	//rep(j, kk + 1) {
	//	rep(k, kk + 1) {
	//		rep(l, RED + 1) {
	//			dp[0][j][k][l] = INF;
	//		}
	//	}
	//}
	memset(dp[0], -1, sizeof(dp[0]));

	dp[0][0][0][0] = 0;
	

	//cout << "hoge " << endl;

	int ura = 0;
	int omote = 1;
	rep(i, data.size()) {

		int rr = ruiseki[i];
		int dd = data[i];
		//rep(j, kk + 1) {
		//	rep(k, kk + 1) {
		//		rep(l, RED + 1) {
		//			dp[omote][j][k][l] = INF;
		//		}
		//	}
		//}
		memset(dp[omote], -1, sizeof(dp[omote]));
		rep(j, kk + 1) {
			
			rep(k, kk + 1) {
				for (int l = 0; l <= rr && l + dd <= RED; l++)
				{
					if (dp[ura][j][k][l] ==  INF || j == kk)continue;
						dp[omote][j + 1][k][l + dd] =
							min(dp[omote][j + 1][k][l + dd],
								dp[ura][j][k][l] + max(0, dd - red[j]));
					
				}
				for (int l = rr; 0 <= l && rr - l + dd <= BLACK; l--)
				{
					if (dp[ura][j][k][l] == INF || k == kk)continue;
						dp[omote][j][k + 1][l] =
							min(dp[omote][j][k + 1][l],
								dp[ura][j][k][l] + max(0, dd - black[k]));
					
				}
				
			}
		}
		swap(omote, ura);
	
	}
	unsigned int ans = INF;
	rep(j, kk + 1) {
		rep(k, kk + 1) {
			rep(l, RED + 1) {
				
				ans = min(ans, dp[ura][j][k][l]);
			}
		}
	}
	if (ans == INF) {
		cout << -1 << endl;
	}
	else {

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




Measured memory_bytes: 123276
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
int aa[503][503];
map<int, int> mp;


bool comp(const P &a, const P &b){
  if(a.first != b.first)return a.first < b.first;
  else{
    if(mp[a.first] % 2 == 0){
      return a.second < b.second;
    }else{
      return a.second > b.second;
    }
  }
}

int main(int argc, char const* argv[])
{
  int h, w;
  cin >> h >> w;
  vector<P> vec;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> aa[i][j];
      if(aa[i][j] % 2 == 1){
        vec.pb(mk(i, j));
        if(mp.find(i) == mp.end())mp[i] = mp.size();
      }
    }
  }
  sort(vec.begin(), vec.end(), comp);

  vector<pair<P, P> > pvec;
  for(int i = 0; i + 1 < vec.size(); i+=2){
    int x1 = vec[i].first;
    int y1 = vec[i].second;
    int x2 = vec[i + 1].first;
    int y2 = vec[i + 1].second;
    if(mp[x1] % 2 == 0){
      int j;
      for(j = y1; j < y2; j++){
        pvec.pb(mk(mk(x1 + 1, j + 1), mk(x1 + 1, j + 2)));
      }
      for(int k = x1; k < x2; k++)pvec.pb(mk(mk(k + 1, j + 1), mk(k + 2, j + 1)));
      for(; j > y2; j--){
        pvec.pb(mk(mk(x2 + 1, j + 1), mk(x2 + 1, j)));
      }
    }else{
      int j;
      for(j = y1; j > y2; j--){
        pvec.pb(mk(mk(x1 + 1, j + 1), mk(x1 + 1, j)));
      }
      for(int k = x1; k < x2; k++)pvec.pb(mk(mk(k + 1, j + 1), mk(k + 2, j + 1)));
      for(; j < y2; j++){
        pvec.pb(mk(mk(x2 + 1, j + 1), mk(x2 + 1, j + 2)));
      }
    }
  }
  cout << pvec.size() << endl;
  for(pair<P, P> pp: pvec){
    cout << pp.first.first << " " << pp.first.second << " " << pp.second.first << " " << pp.second.second << endl;
  }
	return 0;
}


Measured memory_bytes: 7152
#include <stdio.h>
#define N 100000

int Partition(int *,int ,int );

main(){

  int i,n,a[N],p=0,v,j;

  scanf("%d",&n);

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

 v=Partition(a,p,n);
 
 for(i=0; i<v; i++)
   printf("%d ",a[i]);

 printf("[%d] ",a[v]);

 for(j=v+1; j<n-1; j++)
   printf("%d ",a[j]);

 printf("%d\n",a[j]);


 return 0;
}




  int Partition(int *a,int p,int r){
    int x,i,j,tmp,k;

  
    x=a[r-1];
    i=p-1;
    for(j=p; j<r-1; j++){
      if(a[j]<=x){
	i=i+1;
      tmp=a[i];
      a[i]=a[j];
      a[j]=tmp;
      }
    }

    tmp=a[i+1];
    a[i+1]=a[r-1];
    a[r-1]=tmp;

    return i+1;
  }

Measured memory_bytes: 988
[r,c] = map(int,raw_input().split()) 
D = [[0 for i in range(c+1)] for j in range(r+1)] 
for y in range(r):
    v = map(int,raw_input().split())
    for x in range(c):
        D[y][x] = v[x]
        D[y][c] = D[y][c] + v[x]
        D[r][x] = D[r][x] + v[x]
        D[r][c] = D[r][c] + v[x] 
        
for y in range(r+1):
    s = ''
    for x in range(c+1):
        if x == 0:
            s = str(D[y][x])
        else: s = s + ' ' + str(D[y][x])
    print s

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

const int MAXN=4005;
typedef long long ll;
ll n,MOD,C[MAXN][MAXN],f[MAXN][MAXN],p[MAXN];

ll qpow(ll a,ll b){
	ll ans=1,base=a;
	while(b){
		if(b&1)(ans*=base)%=MOD;
		(base*=base)%=MOD;
		b>>=1;
	}
	return ans;
}

ll qpowt(ll a,ll b){
	ll ans=1,base=a;
	while(b){
		if(b&1)(ans*=base)%=(MOD-1);
		(base*=base)%=(MOD-1);
		b>>=1;
	}
	return ans;
}


void get(){
	for(ll i=0;i<=n;i++)C[i][0]=1;
	for(ll i=1;i<=n;i++){
		    //c[i][0]=1;  
       // c[i][i]=1;  
		for(ll j=1;j<=i;j++){
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;
		}
	}
	for(ll i=0;i<=n;i++){
		f[i][0]=1;
		for(ll j=1;j<=i;j++){
			f[i][j]=f[i-1][j-1]+((f[i-1][j]*(j+1))%MOD);
			f[i][j]%=MOD;
		}
	}
	for(ll i=0;i<=n;i++){
		ll B=qpow(2,1ll*(n-i));
		ll mul=1;
		for(ll j=0;j<=i;j++){
			p[i]+=f[i][j]*mul;	
			p[i]%=MOD;
			mul*=B;mul%=MOD;
		}
		p[i]*=qpow(2,qpowt(2,n-i));
		p[i]%=MOD;
	}
}

//ans=sigma (-1)^i * C(n,i)*f[i];

inline void add(ll &a,ll b){
	a+=b;if(a>=b)a-=b;
}

int main(){
	scanf("%lld%lld",&n,&MOD);
	get();
	ll ans=0;
	for(ll i=0;i<=n;i++){
		ans+=((qpow(-1,i)*C[n][i])%MOD)*p[i];
		ans%=MOD;add(ans,MOD);
	} 
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 189056
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {

    ll n,m; cin >>n>>m;

    ll res = 0;
    if(n > 2 && m > 2) {
        res = n*m - (n*m - (n-2)*(m-2));
    } else if(n == 2 || m == 2) {
        res = 0; 
    } else if (n == 1 && m > 2) {
        res = m - 2;
    } else if (m == 1 && n > 2) {
        res = n - 2;
    } else if (n == 1 && m == 1){
        res = 1;
    }

    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(input().split())
    return li

# --------------------------------------------

dp = None

def main():
    Sp = input()
    T = input()

    is_restorable = False
    replace_start_idx = None
    replace_end_idx = None

    for start_idx in range(len(Sp) - len(T) + 1):
        target_idx = 0
        while target_idx < len(T):
            if T[target_idx] == Sp[start_idx + target_idx] or Sp[start_idx + target_idx] == "?":
                target_idx += 1

                if target_idx == len(T):
                    is_restorable = True
                    replace_start_idx = start_idx
                    replace_end_idx = start_idx + target_idx
            else:
                break

    if not is_restorable:
        print("UNRESTORABLE")
    else:
        idx = 0
        while idx < len(Sp):
            if replace_start_idx <= idx < replace_end_idx:
                for t in T:
                    print(t, end="")
                idx += len(T)
            elif Sp[idx] == "?":
                print("a", end="")
                idx += 1
            else:
                print(Sp[idx], end="")
                idx += 1


main()


Measured memory_bytes: 4620
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
pl = [I() for _ in range(N)]
pl.sort(reverse=True)
ans = 0
for i in range(N):
    if i == 0:
        ans += pl[i]//2
    else:
        ans += pl[i]
print(ans)

Measured memory_bytes: 73924
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# import re
# import array
# import copy
# import functools
# import operator

# import collections
# import itertools
# import bisect
# import heapq

# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace

# from queue import PriorityQueue as pq

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )
# # from itertools import accumulate
# # from collections import deque

# from operator import mul
# from functools import reduce

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random
# import time


def reverse_range(a, b):  # b < a ,  get [b, a)
    return range(b, a, -1)  # range(a, b+1, -1)


def main():
    n, m, x, y = map(int, input().strip().split())
    l_x = list(map(int, input().strip().split()))
    l_x.sort(reverse=True)
    l_y = list(map(int, input().strip().split()))
    l_y.sort()

    eprint("range ", end=": ")
    eprint([i for i in reverse_range(x, y)[::-1]])

    for i in reverse_range(x, y)[::-1]:
        if l_x[0] < i <= l_y[0]:
            print("No War")
            return
    print("War")
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
/*
解法が分からなかった（アイデアが分からなかった）

*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, start, n) for (int i = start; i < (int)(n); i++)
typedef long long ll;
int N, A;
int x[50];
ll dp[51][51][3010];

int main() {
	cin >> N >> A;
	rep(i, 0, N) cin >> x[i];
 
	dp[0][0][0] = 1;
	rep(i, 0, N) rep(j, 0, N) rep(k, 0, 2500) if(dp[i][j][k]){
		dp[i + 1][j][k] += dp[i][j][k];
		dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
	}
 
	ll ans = 0;
	rep(i, 1, N + 1) ans += dp[N][i][i*A];
	cout << ans << endl;
}

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

const ll INF = 1001001001;

const double PI=3.141592653;

const ll sosu = 1000000007;//大きい素数

//提出のときに言語がc＋＋似合っていることを確認する

// lからrまでの和
ll sum(ll l,ll r){
  return ((l+r)*(r-l+1))/2;
}

int main(){
      ll n,k;
      cin>>n>>k;
      ll ans=0;
      for(ll i=k;i<=n+1;i++){
        ll l=sum(0,i-1);
        ll r=sum(n-i+1,n);
        ans+=r-l+1;
        ans=ans%sosu;
      }
      cout<<ans<<endl;
    
    
    return 0;
}       

       

Measured memory_bytes: 3640
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [map(int, input().split()) for _ in range(M)]
x, y, c = [list(x) for x in zip(*xyc)]

m = min(a)+min(b)
for i in range(M):
    tmp = a[x[i]-1]+b[y[i]-1]-c[i]
    m = min(m, tmp)

print(m)

Measured memory_bytes: 112364
# -*- coding: utf-8 -*-

a, b, c = map(int, input().split())

if a < -100 or a > 100:
   print('error')
   exit()
if b < -100 or b > 100:
   print('error')
   exit()
if c < -100 or c > 100:
   print('error')
   exit()

if a <= c and c <= b:
   print('Yes')
else:
   print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,m,s,c;
map<int,int> ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for (int i=0;i<m;i++){
        cin>>s>>c;
        if (ans.find(s)!=ans.end()){
            if (ans[s]!=c){
                cout<<-1;
                return 0;
            }
        }
        else {
            ans[s]=c;
        }
    }
    for (int i=1;i<=n;i++){
        if (ans.find(i)==ans.end()){
            if (i==1 && n>1) ans[i]=1;
            else ans[i]=0;
        }
    }
    if (n>1){
        if (ans[1]==0){
            cout<<-1;
            return 0;
        }
    }
    for (int i=1;i<=n;i++){
        cout<<ans[i];
    }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

count = [0]*(max(a)+1)
for i in a: count[i]+=1

if len(count) <= 2:
  print(sum(count))
  exit()
  
ans = 0
for i in range(2,max(a)):
  if count[i-1]+count[i]+count[i+1] > ans:
    ans = count[i-1]+count[i]+count[i+1]
print(ans)

Measured memory_bytes: 20896
import java.util.Scanner;
class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int n = sc.nextInt();
   boolean flag = true;

   for(int i=0;i<n;i++) {
	   int a = sc.nextInt();
	   if(a%2==0&&((a%3)!=0)&&((a%5)!=0)) {
		   flag=false;
	   }
   }
   	System.out.println(flag?"APPROVED":"DENIED");
 }
}

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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll r;
	cin>>r;
	cout<<pow(r,2)<<"\n";
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


Measured memory_bytes: 3784
// Equal Sum Sets
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][][] dp = new int[21][11][156];
		dp[0][0][0] = 1;
		for (int n = 1; n < 21; n++)
			for (int k = 0; k < 11; k++)
				for (int s = 0; s < 156; s++) {
					dp[n][k][s] += dp[n - 1][k][s];
					if (k > 0 && s >= n)
						dp[n][k][s] += dp[n - 1][k - 1][s - n];
				}
		while (true) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			int s = sc.nextInt();
			if ((n | k | s) == 0)
				break;
			System.out.println(dp[n][k][s]);
		}
		sc.close();
	}
}

Measured memory_bytes: 20988
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  char X,Y;cin>>X>>Y;
  
  if(X<Y){
    cout<<'<'<<endl;
  }
  else if(X==Y){
    cout<<'='<<endl;
  }
  else{
    cout<<'>'<<endl;
  }
}

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

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

	if (A == B && A != C && B != C) {
		cout << "Yes" << endl;
	} else if (C == B && B != A && C != A) {
		cout << "Yes" << endl;
	} else if (A == C && A != B && B != C) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<bool > vecbool;
typedef vector<string > vecstr;
typedef vector<vector<int > > vec2int;
typedef vector<vector<bool > > vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  int h, w;
  cin >> h >> w;
  vec2bool g(h,vecbool(w));
  char tmp;
  int numinit = 0;
  REP(i,h){
    REP(j,w){
      cin >> tmp;
      if(tmp == '.'){
	g[i][j] = true;
      }else{
	g[i][j] = false;
	numinit ++;
      }
    }
  }


  vec2int dist(h,vecint(w,0));
  queue<pair<int,int> > q;
  dist[0][0] = 1;
  q.push(make_pair(0,0));
  while(!q.empty()){
    int x0 = q.front().first;
    int y0 = q.front().second;
    q.pop();
    REP(i,4){
      int x = x0 + dx[i];
      int y = y0 + dy[i];
      if(0 <= x && x<= h - 1 && 0<= y && y<= w - 1){
	if(g[x][y]&&dist[x][y]==0){
	  q.push(make_pair(x, y));
	  dist[x][y] = dist[x0][y0] + 1;
	}
      }
    }
  }
  
  if(dist[h -1][w - 1] > 0){
    cout << h*w - numinit - dist[h - 1][w - 1] << endl;
  }else{
    cout << -1 << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define ll long long int
int main(void){
	ll n,x,i;
	scanf("%lld%lld",&n,&x);
	ll a[n],sum=0;
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	if(a[0]>x)a[0]=x;
	for(i=0;i<n;i++){
		ll y=a[i]+a[i+1];
		if(y>x)a[i+1]=x-a[i];
	}
	for(i=0;i<n;i++){
		sum-=a[i];
	}
	
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 896
N = int(input())
a = [1, 6, 6**2, 6**3, 6**4, 6**5, 6**6, 9, 9**2, 9**3, 9**4, 9**5]
a.sort()
dp = [10**6]*160000
for i in a:
    dp[i] = 1
for i in range(1, N+1):
    for j in a:
        dp[i+j] = min(dp[i]+1, dp[i+j])
print(dp[N])

Measured memory_bytes: 42092
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
int main(){
    int n,x,count=0,ans=0,a,b,c;
    string s;
    vector<int> v;
        cin>>n;
        for(int i=0;i<=n;i++)ans+=i;
        cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main(){
	int n, m, ans;
	int a[100], b[100], c[100], d[100];
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int j = 0; j < m; j++) {
		cin >> c[j] >> d[j];
	}
	for (int i = 0; i < n; i++) {
		int min = 1000000007;
		for (int j = m - 1; j >= 0; j--) {
			int co = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (co <= min) {
				ans = j + 1;
				min = co;
			}
		}
		cout << ans << endl;
	}
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        int[] seats = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0};
        int[] groupMembers = new int[] {2, 5, 2, 2, 2};
        int[] eatTimes = new int[] {19, 39, 25, 36, 22, 42};

        int headGroup = -1;
        int pastMinutes = 0;

        Scanner sc = new Scanner(System.in);

        List<Integer> inputted = new ArrayList<Integer>();
        int maxInputted = -1;
        while (sc.hasNext()) {
            int ni = sc.nextInt();
            maxInputted = maxInputted < ni ? ni : maxInputted;
            inputted.add(ni);
        }

        List<Integer> waitTime = new ArrayList<Integer>();

        while (waitTime.size() <= maxInputted) {
            // たべおわる
            for (int i = 0; i < seats.length; i++) {
                seats[i] = seats[i] == 0 ? 0 : seats[i] - 1;
            }

            // 来店
            if (headGroup == -1 && pastMinutes % 5 == 0) {
                headGroup = pastMinutes / 5;
            }

            // ちゃくせき
            while (headGroup != -1) {
                int needsSequencialSeats = groupMembers[headGroup % 5];
                int sequencialSeats = 0;
                int startIndex = -1;
                for (int i = 0; i < seats.length; i++) {
                    sequencialSeats = seats[i] == 0 ? sequencialSeats + 1 : 0;

                    if (sequencialSeats == needsSequencialSeats) {
                        startIndex = i - (needsSequencialSeats - 1);
                        break;
                    }
                }

                if (startIndex != -1) {
                    // すわれたみたい
                    waitTime.add(headGroup, pastMinutes - (headGroup * 5));
                    for (int i = startIndex; i < (startIndex + needsSequencialSeats); i++) {
                        seats[i] = eatTimes[headGroup % 6];
                    }

                    headGroup = (((headGroup + 1) * 5) <= pastMinutes) ? headGroup + 1
                            : -1;
                } else {
                    // すわれなかったみたい
                    break;
                }

            }

            pastMinutes++;

        }

        for (int input : inputted) {
            System.out.println(waitTime.get(input));
        }

    }
}

Measured memory_bytes: 17180
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n,m;
int a[14][14];
int x;
int c[14];
int d[14];

int main(){
  cin >> n >> m >> x;
  rep(i,0,n){
    cin >> c[i];
    rep(j,0,m){
      cin >> a[i][j];
    }
  }
  int ans=INF;
  for(int S=0;S<1<<n;S++){
    fill(d,d+14,0);
    int u=0;
    rep(i,0,n){
      if(S>>i & 1){
        u += c[i];
        rep(j,0,m){
          d[j] += a[i][j];
        }
      }
    }
    bool t=true;
    rep(i,0,m){
      if(d[i] < x)t=false;
    }
    if(t){
      ans = min(ans,u);
    }
  }
  if(ans >= INF)ans = -1;
  cout << ans << endl;

  return 0;
}


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

int main() {
    
    /* Input */
    int N;
    cin >> N;

    string s;
    cin >> s;

    /* Main Logic */
    int trial = 0;
    int r2wCnt = 0, w2rCnt = 0;

    /* とりあえず全部Wの文字列と比較 */
    for (int i = 0; i < N; i++) {
        if (s[i] == 'R') r2wCnt++;
    }
    trial = r2wCnt;

    /* 左からWをRに変化 */
    for (int i = 0; i < N; i++) {
        if (s[i] == 'R') r2wCnt--;
        else w2rCnt++;
        trial = min(trial, max(r2wCnt, w2rCnt));
    }

    /* Output */
    cout << trial << endl;
    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
string S;

void solve() {
	cin >> S;
	N = sz(S);

	vector<pi> vec;

	ll res = 0;
	ll zero = 0;
	rep(i, 0, N) {
		if(i == 0 || vec.back().fst != (S[i] == '1')) {
			vec.pb(pi(S[i] == '1', 1));
		}
		else vec.back().sec++;
		zero += (S[i] == '0');
	}
	// debug(vec);
	int zat = 0;
	int at = 0;
	rep(i, 0, sz(vec)) {
		if(vec[i].fst == 0) {
			zat += vec[i].sec;
			at += vec[i].sec;
		}
		else {
			if(vec[i].sec % 2 == 0) {
				res += (zero * (vec[i].sec / 2));
			}
			else {
				res += (zero * (vec[i].sec / 2)) + (zat + (at % 2 == 0)) / 2 + (zero - zat);
				at++;
			}
		}
	}
	ll one = N - zero;
	while(one) {
		res += (one + 1) / 2;
		one--;
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 5448
package main

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

type long int64
type float float32
type double float64

// io
type Scanner struct {
    reader *bufio.Reader
    buffer []string
    pointer int
}

func NewScanner() *Scanner {
    return &Scanner{
        reader: bufio.NewReaderSize(os.Stdin,4096),
        pointer: 0,
    }
}

func (self *Scanner) NextLine () string {
    var buffer []byte
    for {
        line,isPrefix,_ := self.reader.ReadLine()

        buffer = append(buffer, line...)
        if !isPrefix {
            break
        }
    }
    return string(buffer)
} 

func (self *Scanner) Next () string {
    if self.pointer >= len(self.buffer) {
        line := self.NextLine()
        self.buffer = strings.Fields(line)
        self.pointer = 0
    }
    self.pointer++
    return self.buffer[self.pointer-1]
}

func (self *Scanner) NextInt () int {
    s := self.Next()
    i,_ := strconv.ParseInt(s,10,32)
    return int(i)
}

func (self *Scanner) NextLong () long {
    s := self.Next()
    l,_ := strconv.ParseInt(s,10,64)
    return long(l)
}

func (self *Scanner) NextFloat () float {
    s := self.Next()
    f,_ := strconv.ParseFloat(s,32)
    return float(f)
}

func (self *Scanner) NextDouble () double {
    s := self.Next()
    d,_ := strconv.ParseFloat(s,64)
    return double(d)
}
// math
// func Max (a,b int) int { if a < b { return b } else { return a } }
// func Max (a,b long) long { if a < b { return b } else { return a } }
func Min (a,b int) int { if a < b { return a } else { return b } }

func main () {
    cin := NewScanner()

    N := cin.NextInt()
    K := cin.NextInt()

    ans := 1
    for i := 0; i < N; i++ {
        ans = Min(ans * 2, ans + K)
    }

    fmt.Println(ans)
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int i,j,n,prime[2000000],ans,list[1000000];

int main(){
	for(i=2;i<=1000000;i++)prime[i]=1;
	for(i=2,n=0;i<=1000000;i++){
		if(prime[i]==1){
			list[n]=i;n++;
			if(i<=1000)for(j=i*i;j<=1000000;j+=i)prime[j]=0;
		}
	}
	while(scanf("%d",&n)*n){
		ans=0;
		for(i=1;list[i]<=n/2;i++){
			if(prime[n-list[i]]==1)ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 7052
import sys
sys.setrecursionlimit(10**9)
N, M, Q = map(int, input().split())
A = []
B = []
C = []
D = []
ans = 0
for i in range(Q):
    a, b, c, d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

def dfs(n):
    if len(n) == N+1:
        global ans
        tmp = 0
        for i in range(Q):
            if n[B[i]] - n[A[i]] == C[i]:
                tmp += D[i]
        ans = max(ans, tmp)
    else:
        for i in range(n[-1], M+1):
            tmp2 = n[:]
            tmp2.append(i)
            dfs(tmp2)
dfs([1])
print(ans)


Measured memory_bytes: 9172
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	ll h, w, a, b;
	ll ans, M, m, X, Y, Z;
	cin >> h >> w;
	if (h*w % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	ans = min(h, w);
	for (int k = 0; k < 2; ++k) {
		for (int i = 0; i <= 1; ++i) {
			for (int j = 0; j <= 1; ++j) {
				a = w / 3 + i; b = h / 2 + j;
				X = a * h;
				Y = b * (w - a);
				Z = (w - a)*(h - b);
				M = max(X, Y);
				M = max(M, Z);
				m = min(X, Y);
				m = min(m, Z);
				ans = min(ans, M - m);
			}
		}
		swap(h, w);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define I(x) cin >> x;
#define D(x) cerr << (x) << " ";
#define BR cerr << "\n";
#define P(x) cout << (x) << endl;
#define FIX cout << fixed << setprecision(10);

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;

int main(void){
  string s;
  I(N);
  I(s);
  if (s.size() <= N) {
    P(s);
  } else {
    cout << s.substr(0, N) << "..." << endl;
  }

}


Measured memory_bytes: 3592
N,M = map(int,input().split())

ab = []

for i in range(N):

    a,b = map(int,input().split())

    ab.append([a,b])

cd = []

for i in range(M):

    c,d = map(int,input().split())

    cd.append([c,d])



for i in ab:

    pno = 0
    now = float("inf")

    for j in range(M):

        if now > abs( i[0] - cd[j][0] ) + abs( i[1] - cd[j][1] ):
            
             pno = j+1
             now = abs( i[0] - cd[j][0] ) + abs( i[1] - cd[j][1] )

    print (pno)


Measured memory_bytes: 3064
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  ll n, k, q; cin >> n >> k >> q;
  vector<ll> A(q), B(n);
  loop(i,0,q) cin >> A[i];
  loop(i,0,q) A[i]--;
  loop(i,0,n) B[i] = k-q;
  loop(i,0,q) B[A[i]] += 1;
  loop(i,0,n) {
    if (B[i]<=0) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 4820
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, A[303030];
i64 hi[303030], lo[303030];

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < 3 * N; ++i) scanf("%d", A + i);

	{
		priority_queue<int> Q;
		i64 sum = 0;
		for (int i = 0; i < 3 * N; ++i) {
			Q.push(-A[i]);
			sum += A[i];
			if (Q.size() > N) {
				sum += Q.top();
				Q.pop();
			}
			hi[i] = sum;
		}
	}
	{
		priority_queue<int> Q;
		i64 sum = 0;
		for (int i = 3 * N - 1; i >= 0; --i) {
			Q.push(A[i]);
			sum += A[i];
			if (Q.size() > N) {
				sum -= Q.top();
				Q.pop();
			}
			lo[i] = sum;
		}
	}
	i64 ret = -(1LL << 60LL);
	for (int i = N - 1; i <= 2 * N - 1; ++i) {
		ret = max(ret, hi[i] - lo[i + 1]);
	}
	printf("%lld\n", ret);
	return 0;
}


Measured memory_bytes: 7028
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>
#include <complex>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
typedef long long int ll;
#define iceil(x,y) (x+y-1)/y
#define min(x,y)(x<y?x:y)
 
using namespace std;
typedef pair<int, int> P;

int main() {
	FAST;

	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	rep(i, A.size()) cin >> A[i];
	
	map<int, int> m;
	vector<int> SUM(N+1);
	SUM[0]=0;
	rep(i,N) {
		SUM[i+1] = (SUM[i] + A[i]) % M;
	}

	ll ans=0;

	rep(i, SUM.size()) {
		ans += m[SUM[i]];
		m[SUM[i]]++;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3968
S = input()
n = len(S)
A = [0] * n
p = 0
for i in range(n-1):
    if S[i] == 'R' and S[i+1] == 'L':
        for j in range(p, i+1):
            if S[j] == 'R':
                if (i+1-j)%2==0:
                    A[i+1]+=1
                else:
                    A[i]+=1
        p = i + 1
p = n - 1
for i in range(n-1, 0, -1):
    if S[i-1] == 'R' and S[i] == 'L':
        for j in range(p, i-1, -1):
            if S[j] == 'L':
                if (i-1-j)%2==0:
                    A[i-1]+=1
                else:
                    A[i]+=1
        p = i - 1
print(*A)


Measured memory_bytes: 78988
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int n; cin >> n;
	for (int ix=0;ix<n;ix++) {
		string num; cin >> num;
		sort(num.begin(),num.end());
		stringstream os;
		os.str(num);
		int min; os >> min;
		reverse(num.begin(),num.end());
		stringstream oss;
		oss.str(num);
		int max; oss >> max;
		cout << max-min << endl;
	}
}

Measured memory_bytes: 0
import qualified Data.ByteString.Char8 as B
import Data.Maybe

solve [_] [] = 0
solve (a:b:as) (x:xs)
    | a >= x = x + solve (b:as) xs
    | otherwise = (a + rest') + solve (b':as) xs
    where
        rest = x - a
        rest' = min b rest
        b' = max 0 (b - rest')


main = do
    n <- readLn :: IO Int
    as <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    bs <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    print $ solve as bs

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

int main() {
  int N,M; cin >> N >> M;
  vector<int> k(M);
  vector<vector<int>> s(M);
  for (int i =0; i<M; i++) {
    cin >> k.at(i);
    for (int j =0; j<k.at(i); j++) {
      int a; cin >> a;
      s.at(i).push_back(a);
    }
  }
  vector<int> p(M);
  for (int i =0; i<M; i++) cin >> p.at(i);
  
  int count =0;
  for (int tmp =0; tmp< (1 << N); tmp++) {
    bitset<10> bit(tmp);
    int countK =0;
    for (int i =0; i<M; i++) {
      int countSwitch =0;
      int S = k.at(i);
      for (int j =0; j<S; j++) {
        if (bit[s.at(i).at(j)-1] == 1) countSwitch++;
      }
      if (countSwitch % 2 == p.at(i)) countK++;
    }
    if (countK == M) count++;
  } 
  cout << count << endl;  
}
  
  

Measured memory_bytes: 3620