akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static string Solve(long N)
        {
            if (N == 0) { return "0"; }
            var S = new List<char>();
            for (long mask = 1, digit = 1; N != 0; mask <<= 1, digit *= -2)
            {
                if ((N & mask) != 0)
                {
                    S.Add('1');
                    N -= digit;
                }
                else
                {
                    S.Add('0');
                }
            }
            S.Reverse();
            return new string(S.ToArray());
        }
        static void Main(string[] args)
        {
            Console.WriteLine(Solve(ReadInt()));
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

int X1[102], X2[102], Y1[102], Y2[102];
bool G[606][606];
int H, W, N;

int compress(int *x1, int *x2) {
  vector<int> xs;
  rep(i, N) REP(d, -1, 2) {
    xs.push_back(x1[i] + d), xs.push_back(x2[i] + d);
  }

  sort(all(xs));
  xs.erase(unique(all(xs)), xs.end());

  rep(i, N) {
    x1[i] = find(all(xs), x1[i]) - xs.begin();
    x2[i] = find(all(xs), x2[i]) - xs.begin();
  }

  return xs.size();
}

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

typedef pair<int, int> P;

void fill_bfs(vector<vector<bool>>& vis, int y, int x, queue<P>& online_q) {
  queue<P> q; q.emplace(y, x);
  while(!q.empty()) {
    int y, x; tie(y, x) = q.front(); q.pop();
    rep(i, 4) {
      int ny = y + dy[i], nx = x + dx[i];
      if(!in_range(ny, nx, H, W)) { continue; }
      if(vis[ny][nx]) { continue; }
      vis[ny][nx] = 1;
      if(G[ny][nx]) {
        online_q.emplace(ny, nx);
      }
      else {
        q.emplace(ny, nx);
      }
    }
  }
}

int count_the_regions() {

  int ret = 0;

  queue<P> q; q.emplace(0, 0);

  vector<vector<bool>> vis(H, vector<bool>(W));
  vis[0][0] = 1;
  if(!G[0][0]) {
    fill_bfs(vis, 0, 0, q); ret ++;
  }

  while(!q.empty()) {
    int y, x; tie(y, x) = q.front(); q.pop();
    rep(i, 4) {
      int ny = y + dy[i], nx = x + dx[i];
      if(!in_range(ny, nx, H, W)) { continue; }
      if(vis[ny][nx]) { continue; }
      vis[ny][nx] = 1;
      if(G[y][x] && !G[ny][nx]) {
        fill_bfs(vis, ny, nx, q);
        ret ++;
      } else {
        q.emplace(ny, nx);
      }
    }
  }

  return ret;
}

int main() {

  for(; cin >> N && N;) {
    zero(X1); zero(X2); zero(Y1); zero(Y2);
    rep(i, N) {
      int l, t, r, b; cin >> l >> t >> r >> b;
      X1[i] = (l + 1) * 2, X2[i] = (r + 1) * 2, Y1[i] = (b + 1) * 2, Y2[i] = (t + 1) * 2;
    }

    W = compress(X1, X2);
    H = compress(Y1, Y2);

    zero(G);
    rep(i, N) {
      REP(x, X1[i], X2[i]+1) {
        G[Y1[i]][x] = G[Y2[i]][x] = 1;
      }
      REP(y, Y1[i], Y2[i]+1) {
        G[y][X1[i]] = G[y][X2[i]] = 1;
      }
    }
//    rep(i, H) { rep(j, W) cout << G[i][j]; cout << endl; }
    cout << count_the_regions() << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3480
#include <bits/stdc++.h>
using namespace std;
int main(void){
    stack<bool> stk;
    string s;
    cin>>s;
    stk.push(false);
    for(int i=0;i<s.size();i++){
        if(s[i]=='S'){
            stk.push(true);
        }
        else{
            if(stk.top()==true){
                stk.pop();
            }
            else{
                stk.push(false);
            }
        }
    }
    cout<<stk.size()-1<<endl;
    
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int m, n;
  cin >> n;

  map<string, int> s;
  for (int i = 0; i < n; i++)
  {
    string a;
    cin >> a;
    s[a]++;
  }

  cin >> m;
  for (int i = 0; i < m; i++)
  {
    string b;
    cin >> b;
    s[b]--;
  }

  int res = 0;
  for (auto e : s)
  {
    res = max(res, e.second);
  }

  cout << res << endl;
}

Measured memory_bytes: 256
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
ll in(){ ll x; cin >> x; return x; }
vector<ll> in(size_t n){ vector<ll> v(n); each(x, v) cin >> x; return v; }
/* ]]] */

int n, l;
int a[100000];

int main(){
  cin >> n >> l;
  rep(i, n) cin >> a[i];
  
  int p = -1;
  rep(i, n - 1){
    if (a[i] + a[i + 1] >= l){
      p = i + 1;
    }
  }

  if (p == -1) cout << "Impossible\n";
  else {
    cout << "Possible\n";
    rep(i, 1, p) cout << i << endl;
    rrep(i, p + 1, n) cout << i << endl;
    cout << p << endl;
  }
}


Measured memory_bytes: 1280
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>

#define u first
#define v second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define debug
#define TRACE(x)

using namespace std;
using pii = pair<int, int>;

typedef long long llint;

const int MAXN = 100010;

int n, sz[MAXN], dad[MAXN], totm;
set<int> e[MAXN][2];
queue<pii> q;

int find(int x) {
  if (dad[x] == x) return x;
  return dad[x] = find(dad[x]);
}

void add_edge(int x, int y, int t) {
  if (x == find(y)) return;
  
  e[x][t].insert(y);
  if (e[x][t^1].count(y)) 
    q.push({x, y});
}

void change_edge(int x, int y1, int y2, int t) {
  if (x == find(y1)) return;

  e[x][t].insert(y2);

  if (e[x][t^1].count(y2))
    q.push({x, y2});
}

void merge(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return;

  ++totm;

  if (sz[v] > sz[u]) swap(u, v);
  dad[v] = u;
  sz[u] += sz[v];

  REP(t, 2)
    for (auto it = e[v][t].begin(); it != e[v][t].end(); ++it)
      change_edge(*it, v, u, t);

  REP(t, 2)
    for (auto it = e[v][t].begin(); it != e[v][t].end(); ++it)
      add_edge(u, *it, t);
}

int main(void) {
  scanf("%d",&n);
  REP(i, n) { dad[i] = i; sz[i] = 1; }
  REP(t, 2) {
    REP(i, n - 1) {
      int u, v;
      scanf("%d %d",&u,&v);
      --u;
      --v;
      add_edge(u, v, t);
      add_edge(v, u, t);
    }
  }

  while (!q.empty()) {
    pii x = q.front();
    q.pop();

    TRACE(x.u+1 _ x.v+1);

    merge(x.u, x.v);
  }

  printf(totm == n - 1 ? "YES\n" : "NO\n");
  
  return 0;
}


Measured memory_bytes: 67456
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int d=sc.nextInt();
			int dx=600/d;
			int s=0;
			for(int x=0;x<600;x=x+d){
				s=s+x*x*d;
			}
			System.out.println(s);
		}
	}
}

Measured memory_bytes: 17248
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long li;

const int maxn = 1e5;

int n, fa[maxn];
li D[maxn];
int size[maxn];

pair<li, int> ord[maxn];
map<li, int> id;
li dp[maxn];

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%lld", D + i);
  for (int i = 0; i < n; ++i) ord[i] = {D[i], i};
  for (int i = 0; i < n; ++i) id[D[i]] = i;
  sort(ord, ord + n);
  reverse(ord, ord + n);
  for (int i = 0; i < n; ++i) size[i] = 1;
  for (int i = 0; i < n; ++i) dp[i] = 0;

  for (int i = 0; i < n - 1; ++i) {
    int u = ord[i].second;
    li del = n - size[u] * 2;
    if (del <= 0 || !id.count(D[u] - del)) {
      puts("-1");
      return 0;
    }
    fa[u] = id[D[u] - del];
    size[fa[u]] += size[u];
    dp[fa[u]] += dp[u] + size[u];
  }

  if (dp[ord[n - 1].second] != D[ord[n - 1].second]) {
    puts("-1");
    return 0;
  }

  for (int i = 0; i < n - 1; ++i) {
    int u = ord[i].second;
    int v = fa[u];
    printf("%d %d\n", u + 1, v + 1);
  }
  return 0;
}


Measured memory_bytes: 11520
n = int(input())
a = []
b = 0
while n != 0:
    c = (-2) ** b
    if n % (c*(-2)) != 0:
        n -= c
        a.append("1")
    else:
        a.append("0")
    b += 1
ans = "".join(reversed(a))
if ans == "":
  ans = 0
print(ans)


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

INF = 10 ** 10

n = int(input())
# 貰うDPだと0へのアクセスが、配るDPだとn+1へのアクセスが必要になる
h = [INF] + list(map(int, input().split())) + [INF]
dp = [INF] + [INF] * n + [INF]
dp[1] = 0

def chmin(dp_table, index, value):
    if dp_table[index] > value:
        dp_table[index] = value

# 貰うDP(dp[i-1], dp[i-2]が計算済み)
#for i in range(2, n+1):
#    chmin(dp, i, dp[i-1] + abs(h[i] - h[i-1]))
#    chmin(dp, i, dp[i-2] + abs(h[i] - h[i-2]))

# 配るDB(dp[i]が計算済み)
for i in range(1, (n-1)+1):
    chmin(dp, i+1, dp[i] + abs(h[i] - h[i+1]))
    chmin(dp, i+2, dp[i] + abs(h[i] - h[i+2]))

print(dp[n])


Measured memory_bytes: 55316
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M, D;
    cin >> M >> D;
    int ans = 0;
    for (int m = 1; m <= M; m++)
    {
        for (int d = 1; d <= D; d++)
        {
            int d1 = d / 10;
            int d10 = d - (d / 10) * 10;
            if (d1 * d10 == m && d1 >= 2 && d10 >= 2)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
from collections import deque
import copy
class BIT:
    def __init__(self, node_size):
        self._node = node_size+1
        self.bit = [0]*self._node
 
    def add(self, index, add_val):
        while index < self._node:
            self.bit[index] += add_val
            index += index & -index
 
    def sum(self, index):
        res = 0
        while index > 0:
            res += self.bit[index]
            index -= index & -index
        return res
 
s = input()
n = len(s)
a = [ord(i) - ord("a") for i in s]
x = [0]*26
for i in a:
  x[i] += 1
flag = 1
ki = -1
for i in x:
  if i%2 == 1:
    if flag:
      flag = 0
    else:
      print(-1)
      exit()
c = []
x2 = [0]*26
for i in a:
  x2[i] += 1
  if x[i]//2 >= x2[i]:
    c.append(i)
for i in range(26):
  if x[i]%2 == 1:
    b = copy.deepcopy(c)
    c.append(i)
    b = b[::-1]
    c.extend(b)
    break
else:
  b = copy.deepcopy(c)
  b = b[::-1]
  c.extend(b) 
d = {}
for i in range(26):
  d[i] = deque([])
for i in range(n):
  d[c[i]].append(i+1)
for i in range(n):
  x = d[a[i]].popleft()
  a[i] = x
b = []
for i in range(n):
  b.append([a[i],i+1])
b.sort()
b = b[::-1]
bit = BIT(n)
ans = 0
for i,j in b:
  bit.add(j,1)
  ans += bit.sum(j-1)
print(ans)

Measured memory_bytes: 79352
// 2020-08-29 21:02:09
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
void answer() {
  string s, t;
  cin >> s >> t;
  int ans = 1e9;
  rep(i, s.size() - t.size() + 1) {
    int now = 0;
    rep(j, t.size()) {
      if (s[i + j] != t[j]) now++;
    }
    chmin(ans, now);
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3656
import heapq


def main():
    _ = int(input())
    A = list(input())
    R_inds = []
    W_inds = []
    for i in range(len(A)):
        if A[i] == "R":
            R_inds.append(i*(-1))
        else:
            W_inds.append(i)

    if len(R_inds) == 0 or len(W_inds) == 0:
        print(0)
        return

    heapq.heapify(R_inds)
    heapq.heapify(W_inds)
    cnt = 0
    r_i = abs(heapq.heappop(R_inds))
    w_i = heapq.heappop(W_inds)
    while r_i > w_i:
        cnt += 1
        r_i = abs(heapq.heappushpop(R_inds, w_i*(-1)))
        w_i = heapq.heappushpop(W_inds, r_i)

    print(cnt)


if __name__ == '__main__':
    main()


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


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

ll gcd(ll x,ll y){
    while(y > 0){
        ll tmp = y;
        y = x % y;
        x = tmp;
    }
    return x;
}

ll lcm(ll x, ll y){
    return x / gcd(x,y) * y;
}

int main(){
    ll N;
    cin>>N;
    v A(N);
    rep(i,0,N)cin>>A[i];
    ll ans = 1;
    rep(i,0,N){
        ans = lcm(ans,A[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int H,W;
  while(cin >>H>>W && !(H==0 && W==0)){
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout <<"#";}
    cout<<endl;}

  cout<<endl;}
  return 0;
  }

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

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast")

using namespace std;
using ll = long long;

// MACRO
// for loop
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)

// for vector
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(ALL(x), greater<int>())
#define RSORTS(x) sort(ALL(x), greater<string>())
#define FIND(x, n) find(ALL(x), n)
#define VFOR(e, x) for (auto &e : x)

// Constant
const ll INF = 1000000000000; // 10^12:  ∞
const int MOD = 1000000007;   // 10^9+7: Congruence ceremony MOD
const int MAXR = 100000;      // 10^5:   Array Max Range
const char EL = '\n';         // newline

// alias
#define EB emplace_back // push as last element
#define PP pop_back     // pop last element
#define MP make_pair    // pair constractor
#define F first         // first element of pair
#define S second        // second element of pair

// change max/min
template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return 1;
  }
  return 0;
}

// optimize in/out
#define OPTIMIZE_CIN_COUT() \
  cin.tie(0);               \
  ios::sync_with_stdio(false);

template <typename... Args>
void input(Args... args)
{
  for (int &e : {args...})
  {
    cin >> e;
  }
}
#define INPUT1(a) \
  string a = "";  \
  cin >> a;
#define INPUT2(a, b) \
  int a = 0;         \
  int b = 0;         \
  cin >> a >> b;
#define INPUT3(a, b, c) \
  int a = 0;            \
  int b = 0;            \
  int c = 0;            \
  cin >> a >> b >> c;
#define INPUTS(s) \
  string s = "";  \
  cin >> s;

#define INPUTA(n, a) \
  int n = 0;         \
  cin >> n;          \
  vector<int> a(n);  \
  REP(i, n)          \
  {                  \
    cin >> a[i];     \
  }
#define INPUTB(x, y, b)                     \
  int x = 0, y = 0;                         \
  cin >> x >> y;                            \
  vector<vector<int>> b(y, vector<int>(x)); \
  REP(i, y)                                 \
  {                                         \
    REP(j, x)                               \
    {                                       \
      cin >> b[i][j];                       \
    }                                       \
  }

int main()
{
  OPTIMIZE_CIN_COUT();

  INPUT1(N);
  // INPUT2(A, B);
  // INPUT3(A, B, C);
  // INPUTS(S);
  // INPUTA(N, A);
  // INPUTB(X, Y, B);

  int num = 0;
  REP(i, N.size())
  {
    num += N[i] - '0';
  }

  if (num % 9 == 0)
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }
}


Measured memory_bytes: 3756
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
  	cin>>a>>b>>c;
  	if(a!=b&&b!=c&&c!=a)cout<<"3"<<endl;
  	else if(a==b&&b==c)cout<<"1"<<endl;
  	else cout<<"2"<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long
#define pi pair<bool,int>
main(){
  int w,h,s=0,x=0,y=0;
  cin>>w>>h;
  vector<int> p(w),q(h);
  vector<pi> r(w+h);
  for(int i=0;i<w;++i){
    cin>>r[i].second;
    r[i].first=false;
  }
  for(int i=w;i<h+w;++i){
    cin>>r[i].second;
    r[i].first=true;
  }
  sort(r.begin(),r.end(),[](pi a,pi b){return a.second<b.second;});
  for(auto& d:r)s+=d.second*(d.first?(x++,w+1-y):(y++,h+1-x));
  cout<<s;
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	vector<int> a;
	inputVector(a, N);

	int maxNum = LLONG_MIN;
	int maxArg = 0;
	rep(i, N) {
		if (a[i] > maxNum) {
			maxArg = i;
			maxNum = a[i];
		}
	}
	if (maxNum <= 0) {
		cout << maxNum << endl;
		cout << N - 1 << endl;
		rep(i, N - maxArg - 1) printf("%lld\n", N - i);
		rep(i, maxArg) printf("1\n");
		cout << endl;
		return 0;
	}

	int sum[2];
	memset(sum, 0, sizeof sum);
	vector<int> ptstmp[2];
	rep(i, N) {
		if (a[i] > 0) {
			sum[i % 2] += a[i];
			ptstmp[i % 2].push_back(i + 1);
		}
	}

	vector<int> ret;
	vector<int> pts = sum[0] > sum[1] ? ptstmp[0] : ptstmp[1];
	cout << max(sum[0], sum[1]) << endl;
	int pt = N;
	while (pt > pts.back()) {
		ret.push_back(pt);
		pt--;
	}
	for (int i = (int)(pts.size()) - 1; i >= 1; i--) {
		int len = pts[i] - pts[i - 1];
		int mid = pts[i] - len / 2;
		rep(j, len / 2) {
			ret.push_back(mid);
			mid--;
		}
	}
	rep(i, pts.front() - 1) {
		ret.push_back(1);
	}

	cout << ret.size() << endl;
	rep(i, ret.size()) printf("%lld\n", ret[i]);

    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int h,w,m;cin>>h>>w>>m;
  vector<pi> t(m);
  rep(i, m){ cin>>t[i].first>>t[i].second; t[i].first--; t[i].second--; }

  // 各行と列にある対象の数を保存
  vector<int>ch(h), cw(w);
  map<pi, int> mm;
  rep(i, m){
    ch[t[i].first]++;
    cw[t[i].second]++;
    mm[t[i]]=1;
//    cout<<t[i].first<<' '<<t[i].second<<endl;
  }

  vector<pi> sorth(h),sortw(w);
  rep(i, h)sorth[i] = make_pair(ch[i], i);
  rep(i, w)sortw[i] = make_pair(cw[i], i);

  sort(sorth.rbegin(), sorth.rend());
  sort(sortw.rbegin(), sortw.rend());

  // 縦横の対象の個数をカウントして、最大の個数と同じものを持つ縦と横を全部列挙する。
  int mxh = sorth[0].first;
  int mxw = sortw[0].first;
  vector<int>maxh, maxw;
  rep(i, h)if(sorth[i].first==mxh)maxh.push_back(sorth[i].second);
  rep(i, w)if(sortw[i].first==mxw)maxw.push_back(sortw[i].second);

//  for(auto c: sorth)cout<<c.second<<' ';cout<<endl;
//  for(auto c: sortw)cout<<c.second<<' ';cout<<endl;
//  for(auto c: maxh)cout<<c<<' ';cout<<endl;
//  for(auto c: maxw)cout<<c<<' ';cout<<endl;
//  cout<<mxh<<' '<<mxw<<' '<<':'<<endl;
  
  if((int)(maxw.size())*(int)(maxh.size()) > m){
    cout << mxh + mxw << endl;
    return 0;
  }

  for(auto y:maxh)for(auto x :maxw){
    if(mm[{y, x}]==0){
      cout << mxh + mxw << endl;
      return 0;
    }
  }

  cout << mxh + mxw - 1 << endl;

  return 0;
  
  int result = 0;
  rep(i, m){
    int y=t[i].first;
    int x=t[i].second;
    result = max(result, ch[y]+cw[x]-mm[t[i]]);
  }
  cout << result << endl;

  return 0;
}



Measured memory_bytes: 35560
#include<iostream>
using namespace std;
int main (void)
{
  long long int i,j,k,l,a,b,n,ans;
  cin>>a>>b>>k;
  if(k<a){cout<<a-k<<" "<<b<<endl;}
  else if(k<a+b){cout<<"0 "<<a+b-k<<endl;}
  else {cout<<"0 0"<<endl;}

}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	string S;	
	cin>>S;
	int N = S.size();
	string T;
	rep(i,N){
		if(S[i] == 'A'){
			T.push_back('A');
		}
		else if(S[i] == 'B'){
			if(i+1 < N && S[i+1] == 'C'){
				T.push_back('D');
				i++;
			}
			else{
				T.push_back('X');
			}
		}
		else{
			T.push_back('X');
		}
	}
	cerr<<T<<endl;
	long long ans = 0;
	long long a = 0;
	int M = T.size();
	rep(i,M){
		if(T[i] == 'A'){
			a++;
		}
		else if(T[i] == 'D'){
			ans += a;
		}
		else{
			a = 0;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 776
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000
 
struct Card {
  char suit;
  int value;
};
 
struct Card L[MAX/2+2], R[MAX/2+2];
 
void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}
 
void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}
 
int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}
 
void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}
 
int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;
 
  scanf("%d", &n);
 
  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }
 
  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);
 
  for(i=0;i<n;i++) {
    // ????????????????????¨??????????????????????????????????????????
    if(A[i].suit != B[i].suit) stable = 0;
  }
 
  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }
 
  return 0;
}

Measured memory_bytes: 4068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,Z,W;
  cin >>N>>Z>>W;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  if(N==1){
    cout<<abs(a.at(0)-W)<<endl;
  }else{
    int kotae=max(abs(a.at(N-1)-W),abs(a.at(N-2)-a.at(N-1)));
    cout<<kotae<<endl;
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  int count = 0;
  int s, m, l;
  for (int i = 1; i < N - 1; i++) {
    s = min(p.at(i - 1), min(p.at(i), p.at(i + 1)));
    l = max(p.at(i - 1), max(p.at(i), p.at(i + 1)));
    if (p.at(i) != l && p.at(i) != s) {
      count++;
    }
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <queue>
using namespace std;
int main()
{
	int n,m,k;
	ios::sync_with_stdio(false);
	int flag=0;
	string s,s1;
	cin>>s>>s1;
	if(s1.size()!=s.size())
	{
		cout<<"No\n";
		return 0;
	}
	for(int i=0;i<s.size();i++)
	{
		int ff=1;
		for(int j=0;j<s.size();j++)
		{
			if(s[(i+j)%s.size()]!=s1[j])
			ff=0; 
		}
		if(ff==1) flag=1;
	}
	if(flag) cout<<"Yes\n";
	else cout<<"No\n";
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */



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

    string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string u; cin >> u;
    
    if(u == s) --a;
    else --b;

    cout << a << " " << b << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int par[114514], siz[114514];
void init(int x) {
	rep(i, x) {
		par[i] = i;
		siz[i] = 1;
	}
}
int find(int x) {
	if (par[x] == x)return x;
	return par[x] = find(par[x]);
}
bool same(int x, int y) {
	return find(x) == find(y);
}
void unite(int x, int y) {
	x = find(x); y = find(y);
	if (x == y)return;
	if (siz[x] < siz[y]) {
		par[x] = y;
		siz[y] += siz[x];
	}
	else {
		par[y] = x;
		siz[x] += siz[y];
	}
}
int get_size(int x) {
	return siz[find(x)];
}
int n, m;
signed main() {
	cin >> n >> m;
	init(n);
	rep(i, m) {
		int a, b; cin >> a >> b;
		unite(a - 1, b - 1);
	}
	int siz0 = get_size(0), siz1 = get_size(1);
	int memo = n - siz0 - siz1;
	int ans = 0;
	rep(i, memo + 1) {
		int si0 = siz0 + i, si1 = siz1 + (memo - i);
		ans = max(ans, si0*(si0 - 1) / 2 + si1 * (si1 - 1) / 2 - m);
	}
	cout << ans << endl;
}


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

int main(){
  int N,s;
  set<int>st;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> s;
    st.insert(s);
  }
  
  if(N != st.size()) cout << "NO" << endl;
  else cout << "YES" << endl;
  
  return 0;
}

Measured memory_bytes: 9600
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    def calc_cost(cur, prev):
        return abs(cur[0] - prev[0]) + abs(cur[1] - prev[1])

    h, w, d = map(int, readline().split())
    a = [list(map(int, readline().split())) for _ in range(h)]
    q = int(readline())
    coordinate = dict()

    for row in range(h):
        for col in range(w):
            num = a[row][col]
            coordinate[num] = (row, col)

    cost = dict()

    for rem in range(1, d + 1):
        cost[rem] = 0
        for num in range(rem + d, h * w + 1, d):
            cost[num] = cost[num - d] + calc_cost(coordinate[num], coordinate[num - d])

    for _ in range(q):
        l, r = map(int, readline().split())
        print(cost[r] - cost[l])


if __name__ == '__main__':
    main()


Measured memory_bytes: 73304
#include <iostream>
using namespace std;
int H,W; char**field; int res; 
bool flag=true;
void dfsApple(int h,int w){
  field[h][w]='$';
  if(field[h][w-1]=='@') dfsApple(h,w-1);
  if(field[h][w+1]=='@') dfsApple(h,w+1);
  if(field[h-1][w]=='@') dfsApple(h-1,w);
  if(field[h+1][w]=='@') dfsApple(h+1,w);
  return ;
  }
void dfsPsm(int h,int w){
  field[h][w]='%';
  if(field[h][w-1]=='#') dfsPsm(h,w-1);
  if(field[h][w+1]=='#') dfsPsm(h,w+1);
  if(field[h-1][w]=='#') dfsPsm(h-1,w);
  if(field[h+1][w]=='#') dfsPsm(h+1,w);
  return ;
  }
void dfsOrange(int h,int w){
  field[h][w]='^';
  if(field[h][w-1]=='*') dfsOrange(h,w-1);
  if(field[h][w+1]=='*') dfsOrange(h,w+1);
  if(field[h-1][w]=='*') dfsOrange(h-1,w);
  if(field[h+1][w]=='*') dfsOrange(h+1,w);
  return ;
  }
void solve(){
    cin >> H >> W;
    if(W==0) {flag=false; return ;}
    field = new char*[H + 2];
    for (int h = 0; h <= H + 1; h++) {
        field[h] = new char[W + 2];
    }
 for (int h = 1; h <= H; h++) {
  for (int w = 1; w <= W; w++) {
	  cin >> field[h][w]; 
   }
  }
 for(int w=0; w<=W+1; w++) {
   field[0][w]='.'; field[H+1][w]='.';
   }
 for(int h=0; h<=H+1; h++) {
   field[h][0]='.'; field[h][W+1]='.';
   }
for (int h = 1; h <= H; h++) {
 for (int w = 1; w <= W; w++) {
  if(field[h][w]=='@') {
        dfsApple(h,w); res++;
  }
  if(field[h][w]=='#') {
        dfsPsm(h,w); res++;
  }
  if(field[h][w]=='*') {
        dfsOrange(h,w); res++;
  }
 }
}
  cout<<res<<endl;
  return ;
  }
int main() {
   while(flag){
       res=0; solve();
       }
     return 0;
}

Measured memory_bytes: 1984
from collections import defaultdict

def main():
    dic = defaultdict(int)
    for _ in range(3):
        a,b = map(int,input().split())
        dic[a] += 1
        dic[b] += 1
    
    for i in range(1,5):
        if dic[i]==3:
            print("NO")
            exit()
    print("YES")
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
N = int(input())
q = [[int(i) for i in input().split()] for j in range(N)]
q = sorted(q, key=lambda x: x[1])

time = 0
for i in range(N):
    a, b = q[i]
    time += a
    if time > b:
        print("No")
        break
else:
    print("Yes")

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

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            if(i * (m - j) + j * (n - i) == k)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),sum=0,ave;
  	long var1=0,var2=0;
  	int[] x=new int[n];
  	for(int i=0;i<n;i++){
  		x[i]=sc.nextInt();
  		sum+=x[i];
  	}
  	ave=sum/n;
  	for(int i=0;i<n;i++){
  		var1+=(int)Math.pow(x[i]-ave,2);
  		var2+=(int)Math.pow(x[i]-ave-1,2);
  	}
  	System.out.print(Math.min(var1,var2));
  }
}

Measured memory_bytes: 25300
#include<stdio.h>
int main(void)
{
	int n,k,x,y,z;
	scanf("%d",&n);
	scanf("%d",&k);
	x=n/k;
	y=n%k;
	if(y!=0) {
		z=x+1-x;
	}
	else {
		z=x-x;
	}
	printf("%d\n",z);
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
inline void pc(char k,int n)
{
    for(int i=0;i<n;i++)
    {
        cout<<k;
    }
}
int main()
{
    int ax,ay,tx,ty;
    cin>>ax>>ay>>tx>>ty;
    pc('U',ty-ay);
    pc('R',tx-ax);
    pc('D',ty-ay);
    pc('L',tx-ax);
    pc('L',1);
    pc('U',ty-ay+1);
    pc('R',tx-ax+1);
    pc('D',1);
    pc('R',1);
    pc('D',ty-ay+1);
    pc('L',tx-ax+1);
    pc('U',1);
    cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i,n){
        int a;
        cin >> a;
        mp[a]++;
    }
    int hoge = 0;
    each(it,mp){
        hoge += it.se-1;
    }
    cout << n - (hoge+hoge%2) << "\n";
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int NUM = 2e5 + 5;

int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        string s; cin>>s;
        int n = s.size();
        ll dp[n+1][13];
        for(int i=0;i<=n;i++)
            for(int j=0;j<13;j++)
                dp[i][j]=0;
        dp[0][0]=1; 
        // dp[i][j] is the number of ways to create i-th digit having modulo j%13
        for(int i=0;i<n;i++){
            for(int j=0;j<10;j++){
                // j is the no of choices if s[i]=='?'
                int next = s[i]-'0'; // otherwise we will go with the given value
                if(s[i]=='?') next = j;
                for(int k=0;k<13;k++){
                    // dp[i][k] => remainder is k
                    // so if we append j next to i-th digit then the remainder will be (10*k+j)%13
                    int rem = (10*k + next)%13;
                    dp[i+1][rem] += dp[i][k];
                    dp[i+1][rem] = dp[i+1][rem]%mod;
                }
                if(s[i]!='?') break;
            }
        }
        cout<<dp[n][5];
    }   
}


Measured memory_bytes: 10604
import java.util.*;
public class Main {

	public static void main(String[] args) {
		int MOD = 1_000_000_007;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		Arrays.setAll(A, i -> sc.nextInt());
		long ans = 0;
		long[] s = new long[N+1];
		for(int i = 0; i < N; i++)
			s[i+1] = (s[i] + A[N-1-i]) % MOD;
		for(int i = 0; i < N; i++)
			ans = (ans + s[N-i-1]* A[i]) % MOD;
		System.out.println(ans);
	}

}


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

int main() {
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    a--;
    b--;
    c--;
    d--;
    string result = "Yes";
    if (c < d) {
        for (int i = a + 2; i < d; i++) {
            if (s[i] == '#' && s[i - 1] == '#') {
                result = "No";
            }
        }
    } else {
        bool flag = false;
        for (int i = a + 2; i < c; i++) {
            if (s[i] == '#' && s[i - 1] == '#') {
                result = "No";
            }
        }
        for (int i = b + 1; i <= d + 1; i++) {
            if (s[i] == '.' && s[i - 1] == '.' && s[i - 2] == '.') {
                flag = true;
            }
        }
        if (!flag) {
            result = "No";
        }
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 640
x,y=map(int,input().split())
A=[1,3,5,7,8,10,12]
B=[4,6,9,11]
C=[2]
if x in A and y in A:print('Yes')
elif x in B and y in B:print('Yes')
elif x in C and y in C:print('Yes')
else:print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <map>
using namespace std;
#define rep(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF 1e+8
typedef pair<string, int> P;
typedef long long ll;
typedef priority_queue<int> pq;

map<string, int> data;
int direc[4] = {1, -1, 4, -4};

void bfs(){
	queue<P> que;
	que.push(P("01234567", 0));

	while(!que.empty()){
		P p = que.front();
		que.pop();
		string panel = p.first;
		int now = p.second;

		rep(i, 4){
			if(now+direc[i] >= 0 && now+direc[i] < 8){
				if((now == 3 && direc[i] == 1) || (now == 4 && direc[i] == -1))continue;
				string next = panel;
				next[now] = panel[now+direc[i]];
				next[now+direc[i]] = panel[now];

				if(data[next] != 0)continue;
				que.push(P(next, now+direc[i]));
				data[next] = data[panel]+1;
			}
		}
	}
}



int main(void){
	data["01234567"] = 1;
	string a;
	bfs();
	while(cin >> a){
		string S, L;
		S += a;
		for(int i = 1; i <= 7; i++){
			cin >> L;
			S += L;
		}
		cout << data[S]-1 << endl;
	}


	return 0;	
}

Measured memory_bytes: 3452
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <set>
#include <map>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)

using namespace std;
typedef long long ll;

int main(){
    string S;
    int N;
    cin>>S;
    N=S.length();
    int ans = 0;
    int prev = -1;
    for(int i = 0;i < N;i++){
        if(S[i]=='A'||S[i]=='T'||S[i]=='G'||S[i]=='C'){
            ans = max(ans,i-prev);
        }else{
            prev = i;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int R,G,B,n,ans = 0;
    cin >> R >> G >> B >> n;
    for(int r = 0;r <= 3000;r++){
        for(int g = 0;g <= 3000;g++){
            int tmp = (n - R*r -G*g);
            if(tmp%B == 0 && tmp >= 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
				
int32_t main() {
	fast_cin();  
	int n; cin >> n;
	vector<int> a(n), b(n);
	set<pair<int, int> > st;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
		st.insert({b[i], i});
	}
	int ans = 0;
	while (!st.empty()) {
		int i = st.rbegin()->second;
		st.erase(--st.end());
		int step = b[(i + 1) % n] + b[(i - 1 + n) % n];
		if (b[i] < step and b[i] != a[i]) {
			return cout << -1, 0;
		}
		if ((b[i] - a[i]) % step == 0) {
			ans += (b[i] - a[i]) / step;
			b[i] = a[i];
			continue;
		}
		ans += (b[i] / step);
		b[i] %= step;
		if (b[i] < a[i]) {
			return cout << -1, 0;
		}
		st.insert({b[i], i});
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 18692
a = list(input())
b = list(input())


for j in range(len(a)+1-len(b)) :
    Same = True
    ans = j
    i = 0
    while i < len(b) :
        if b[i] == a[j] :
            i += 1
            j += 1
        else :
            Same = False
            break
    if Same == True :
        print(ans)


Measured memory_bytes: 5576
int main(){
    int a,b,c;
    int l,m,n;
    scanf ("%d%d%d",&a,&b,&c);
    if ( a > b)
    {
        l = a;
        a = b;
        b = l;
    }
    if ( b > c)
    {
        m = b;
        b = c;
        c = m;
    }
    if ( a > b)
    {
        n = a;
        a = b;
        b = n;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 2112
import sys
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))

if M == 1:
  print (0)
  sys.exit()
Y = []
for i in range(M-1):
  Y.append(X[i+1]-X[i])
Y = sorted(Y)
for i in range(N-1):
  if len(Y) == 0:
    print (0)
    sys.exit()
  Y.pop()
print (sum(Y))


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

int main()
{
	ll n;
	cin >> n;
	vector<ll> M(n + 1);
	cin >> M[0];
	for (int i = 1; i < n; i++) {
		cin >> M[i] >> M[i];
	}
	cin >> M[n];
	vector<vector<ll>> dp(n, vector<ll>(n, INF)), mon(n, vector<ll>(n));
	for (int i = 0; i < n; i++) {
		dp[i][i] = 0;
		mon[i][i] = i;
	}
	for (ll k = 1; k < n; k++) {
		for (ll i = 0; i + k < n; i++) {
			for (ll j = 0; j <= i + k - 1; j++) {
				ll cost = dp[i][j] + dp[j + 1][i + k] + M[i] * M[j + 1] * M[i + k + 1];
				if (cost < dp[i][i + k]) {
					dp[i][i + k] = cost;
					mon[i][i + k] = j;
				}
			}
		}
	}
	cout << dp[0][n - 1] << endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i=0;i<n;i++){
    cin  >> vec.at(i);
  }
  int ans = 0;
  for (int i=1;i<n-1;i++){
    
    if (vec.at(i-1) < vec.at(i) && vec.at(i) < vec.at(i+1)){
      ans++;
    }
    if (vec.at(i+1) < vec.at(i) && vec.at(i) < vec.at(i-1)){
      ans++;
    }
  }
        
        
    
    cout << ans << endl;
    
    return 0;
  
}
    

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

int main() {
  vector<vector<int> > a(3, vector<int>(3));
  int tmp;
  int n;

  rep(i, 3) {
    rep(j, 3) { cin >> a[i][j]; }
  }
  cin >> n;
  rep(i, n) {
    cin >> tmp;
    rep(i, 3) {
      rep(j, 3) {
        if (a[i][j] == tmp) {
          a[i][j] = -1;
        }
      }
    }
  }

  bool flag = false;
  rep(i, 3) {
    if ((a[i][0] == -1) && (a[i][1] == -1) && (a[i][2] == -1)) {
      flag = true;
      break;
    }
    if ((a[0][i] == -1) && (a[1][i] == -1) && (a[2][i] == -1)) {
      flag = true;
      break;
    }
  }
  if (!flag) {
    if ((a[0][0] == -1) && (a[1][1] == -1) && (a[2][2] == -1)) {
      flag = true;
    }
    if ((a[0][2] == -1) && (a[1][1] == -1) && (a[2][0] == -1)) {
      flag = true;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

void solve() {
    int N;
    cin >> N;
    bool is_odd=false;
    if(N&1) {
        is_odd=true;
        N--;
    }
    int k=0;
    stringstream s;
    for(int i=1;i<=N;i++) {    
        int c = 1+N-i;
        for(int j=i+1;j<=N;j++) {
            if(j!=c) {
                k++;
                s << i << " " << j << "\n";
            }
        }    
    }

    if(is_odd) {
        for(int i=1;i<=N;i++) {
            k++;
            s << i << " " << N+1 << "\n";
        }
    }

    cout << k << "\n";
    cout << s.str();


}

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

    solve();
    return 0;
}

Measured memory_bytes: 384