akhauriyash/Code-Regression huggingface dataset:
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

ll n, h = 20;
vvll to, par;
vll dep;

void dfs(ll x, ll p, ll d) {
  par[0][x] = p;
  dep[x] = d;
  for (auto& y : to[x])
    if (y != p) dfs(y, x, d + 1);
}

void build() {
  dep.resize(n);
  par.assign(h, vll(n, -1));
  dfs(0, -1, 0);
  rep(i, h - 1) {
    rep(j, n) {
      if (par[i][j] < 0)
        par[i + 1][j] = -1;
      else
        par[i + 1][j] = par[i][par[i][j]];
    }  // j
  }    // i
}

ll lca(ll u, ll v) {
  if (dep[u] > dep[v]) swap(u, v);
  rep(i, h) if ((dep[v] - dep[u]) >> i & 1) v = par[i][v];
  assert(dep[v] == dep[u]);
  if (u == v) return u;
  for (ll i = h - 1; i >= 0; i--) {
    if (par[i][u] != par[i][v]) {
      u = par[i][u];
      v = par[i][v];
    }
  }  // i
  return par[0][u];
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  cin >> n;
  to.resize(n);

  rep(i, n) {
    ll k;
    cin >> k;
    rep(j, k) {
      ll c;
      cin >> c;
      to[i].emplace_back(c);
      to[c].emplace_back(i);
    }
  }

  build();

  ll q;
  cin >> q;
  rep(i, q) { ll u, v;
    cin >> u >> v;
    cout << lca(u, v) << endl;
  }

  return 0;
}



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

int main() {

  int n;
  cin >> n;
  
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " <<  i;
    } else {
      string s = to_string(i);
      for (int j = 0; j < s.size(); j++){
        if (s[j] == '3') {
          cout << " " << i;
          break;
        }
      }
    }
  }
  cout << endl;

  return 0;

}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m,x;
  cin >> n >> m >> x;
  int sum1 = 0;
  int sum2 = 0;
  int a;
  for(int i = 0;i < m;i++) {
    cin >> a;
    if(a < x) {
      sum1++;
    }else {
      sum2++;
    }
  }
  cout << min(sum1,sum2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout<<'\n'
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n];
    ll k;
    cin>>k;
    ll count=0;
    for(int i=0;i<n;i++)
    {cin>>a[i];if(a[i]>=k)
    count++;}
    cout<<count;
}

Measured memory_bytes: 1024
#include <iostream>
#define MOD 1000000007
using namespace std;
int N;
string a,b;
int dp[60][4][4];
int rez;
void fix(int &val)
{
    if(val>=MOD)val-=MOD;
}
int main()
{
    cin>>N>>a>>b;
    a=" "+a;
    b=" "+b;
    if(a[1]==b[1])for(int j=1;j<4;j++)dp[1][j][j]=1;
    else          for(int j=1;j<4;j++)for(int k=1;k<4;k++)if(j!=k)dp[2][j][k]=1;
    for(int i=2+(a[1]!=b[1]);i<a.size();i++)
    {
        if(a[i]==b[i])
        {
            for(int j=1;j<4;j++)
            {
                for(int k=1;k<4;k++)
                {
                    if(k==j)continue;
                    for(int l=1;l<4;l++)
                    {
                        if(l==j)continue;
                        fix(dp[i][j][j]+=dp[i-1][k][l]);
                    }
                }
            }
        }
        else if(a[i-1]==a[i])
        {
            for(int j=1;j<4;j++)
            {
                for(int k=1;k<4;k++)
                {
                    if(j==k)continue;
                    for(int l=1;l<4;l++)
                    {
                        if(l==j)continue;
                        for(int m=1;m<4;m++)
                        {
                            if(m==k)continue;
                            fix(dp[i][j][k]+=dp[i-2][l][m]);
                        }
                    }
                }
            }
        }
    }
    for(int j=1;j<4;j++)for(int k=1;k<4;k++)fix(rez+=dp[N][j][k]);
    cout<<rez;
    return 0;
}


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

int main(){

  int n;
  vector<int> kushi;

  cin >> n;
  int a,b;
  for(int i=0; i < n; ++i){
	cin >> a>> b;
	kushi.push_back(a);
	kushi.push_back(b);
  }
  sort(kushi.begin(), kushi.end());
  
  int sum = 0;
  for(int i = 0; i < 2*n; i++){
	sum += min(kushi[i], kushi[i+1]);
	i++;
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC073A
{
    class Program
    {
        static void Main(string[] args)
        {
            string n;
            n = Console.ReadLine();

            if (n[0] == '9' || n[1] == '9')

                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

           Console.ReadKey();

        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
const int N = 200000 + 10;
int n, bit[N];
vector<int> v;
int id(int x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin() + 1;
}
void add(int pos, int x) {
    while (pos < N) {
        bit[pos] += x;
        pos += (pos&(-pos));
    }
}
int sum(int pos) {
    int ans = 0;
    while(pos) {
        ans = ans + bit[pos];
        pos -= pos & -pos;
    }
    return ans;
}
map<int, vector< pair<int,int> > > items;
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i ++) {
        int x1, y1, x2, y2;
        scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
        if (x1 == x2) {
            if (y1 > y2) swap(y1, y2);
            v.push_back(y1-1); v.push_back(y2);
            items[x1].push_back( make_pair(-2, y1-1) );
            items[x1].push_back( make_pair(+2, y2) );
        } else {
            if (x1 > x2) swap(x1, x2);
            v.push_back(y1);
            items[x1].push_back( make_pair(+1, y1) );
            items[x2+1].push_back( make_pair(-1, y1) );
            v.push_back(x1);
            v.push_back(x2+1);
        }
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    long long ans = 0;
    for (auto it: items) {
        vector< pair<int,int> > vec = it.second;
        for (auto p: vec) {
            if (p.first == +1)
                add(id(p.second), +1);
            if (p.first == -1)
                add(id(p.second), -1);
        }

        for (auto p: vec) {
            if (p.first == +2)
                ans = ans + sum(id(p.second));
            if (p.first == -2)
                ans = ans - sum(id(p.second));
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 11476
#include <iostream>
#include <cmath>
#include <algorithm>

#define SIZE 50

using namespace std;

int digitSum(int);

int main(int argc, char const *argv[])
{
    int N, K;
    int l[SIZE];
    cin >> N >> K;
    for(int i=0; i<N; i++){
        cin >> l[i];
    }
    sort(l, l+N, greater<int>());
    int max_l=0;
    for(int i=0; i<K; i++){
        max_l += l[i];
    }
    cout << max_l;
    return 0;
}

int digitSum(int a){
    if(a==0){
        return 0;
    }
    return a%10 +digitSum(a/10);
}

Measured memory_bytes: 256
def solve()
  n = gets.to_i
  s = []
  cnt = 0
  (0..n-1).each do |i|
    s.push(gets.to_s.chomp.chars.sort(&:casecmp).join)
  end
  new_s = s.group_by(&:itself).map{ |key, value| [key, value.count] }.to_h.values
  (new_s.length).times do |i|
    cnt += (new_s[i] * (new_s[i] - 1)) / 2
  end
  print(cnt)
end
solve()

Measured memory_bytes: 51196
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

const int MOD = 1e9 + 7;
int dp[100005][2];
signed main() {
    REP(i, 100005) REP(j, 2) dp[i][j] = -1;
    int N;
    cin >> N;
    vector<vector<int>> g(N);
    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    auto dfs = [&](auto f, int v, bool black, int p) -> int {
        auto &DP = dp[v][black];
        if (DP != -1) return DP;

        int ret = 1;
        FORE(w, g[v]) {
            if (p == w) continue;
            if (black) {
                ret *= f(f, w, false, v);
                ret %= MOD;
            } else {
                ret *= (f(f, w, true, v) + f(f, w, false, v)) % MOD;
                ret %= MOD;
            }
        }
        return DP = ret;
    };

    int ans = (dfs(dfs, 0, false, -1) + dfs(dfs, 0, true, -1)) % MOD;
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 55936
def make_num(N):
    ans = [2,]
    ans_3 = []
    now_num = 3
    while len(ans_3) < N:
        flag = True
        for i in ans:
            if now_num%i == 0:
                flag = False
                break
        if flag:
            if str(now_num)[-1] == '3':
                ans_3.append(now_num)
            ans.append(now_num)
        now_num += 2
    return ans_3


N = int(input())
ans = make_num(N)


print(' '.join(map(str,ans)))

Measured memory_bytes: 3064
void main()
{
    long[] tmp = rdRow;
    long n = tmp[0], m = tmp[1];

    auto tree = new UnionFind(n);
    foreach (i; 0 .. m)
    {
        long[] xyz = rdRow;
        long x = xyz[0] - 1, y = xyz[1] - 1, z = xyz[2];
        tree.unite(x, y);
    }

    long cnt;
    foreach (i; 0 .. n)
    {
        if (i == tree.par[i]) ++cnt;
    }

    cnt.writeln;
}

struct UnionFind
{
    long[] par;

    this(long n)
    {
        par = new long[n];
        foreach (i; 0 .. n)
        {
            par[i] = i;
        }
    }

    long root(long x)
    {
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    bool same(long x, long y)
    {
        return root(x) == root(y);
    }

    void unite(long x, long y)
    {
        x = root(x), y = root(y);
        if (x == y) return;
        par[x] = y;
    }
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 3708
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

int main()
{
	string str;
	string ref = "CODEFESTIVAL2016";
	
	cin >> str ;

	int cnt = 0;
	for (int i = 0; i < str.length(); i++)
	{
		if (str.at(i) != ref.at(i))
			cnt++;
	}


	cout << cnt << endl;

	//		sort(c, c + n, greater<int>()); //降順ソート

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

int main() {
  int x,y; cin >> x >> y;
  cout << x + y / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int N, H, W;

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

  cin >> N >> H >> W;

  cout << (N-H+1)*(N-W+1) << endl;

  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int> > field(h, vector<int>(w, 0));
    char c;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        cin >> c;
        if (c == '.') field[i][j] = 1;
    }

    vector<vector<int> > isWhite(h, vector<int>(w, 0));
    for (int i = 0; i < h; i++) {
        bool is = true;
        for (int j = 0; j < w; j++) {
            if (field[i][j] == 0) is = false;
        }
        if (is) for (int j = 0; j < w; j++) isWhite[i][j] = 1;
    }
    for (int i = 0; i < w; i++) {
        bool is = true;
        for (int j = 0; j < h; j++) {
            if (field[j][i] == 0) is = false;
        }
        if (is) for (int j = 0; j < h; j++) isWhite[j][i] = 1;
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (isWhite[i][j]) continue;
            if (field[i][j]) cout << '.';
            else cout << '#';
        }
        if (accumulate(isWhite[i].begin(), isWhite[i].end(), 0) != w) cout << '\n';
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <string>

int main() {

	int A, B, C, K;
	std::cin >> A >> B >> C >> K;

	bool finish = false;
	int cnt = 0;
	int sum = 0;

	while (finish == false && (cnt < A || cnt < K)) {
		if (cnt == K) {
			finish = true;
			break;
		}
		if (cnt == A) {
			break;
		}
		sum += 1;
		cnt += 1;
	}

	while ( finish == false && (cnt - A < B || cnt < K)) {
		if (cnt == K) {
			finish = true;
			break;
		}
		if (cnt - A == B) {
			break;
		}
		cnt += 1;
		sum += 0;
		
	}

	while ( finish == false && (cnt - A - B < C || cnt <= K)) {

		if (cnt == K) {
			finish = true;
			break;
		}
		if (cnt - A - B == C) {
			break;
		}

		cnt += 1;
		sum -= 1;
	}

	std::cout << sum << std::endl;

	return 0;
}

Measured memory_bytes: 3604
# abc124_a.py
# https://atcoder.jp/contests/abc124/tasks/abc124_a

# A - Buttons /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 2個のボタンがあり、大きさはそれぞれ A,Bです。
# 大きさ Xのボタンを押すと、X 枚のコインを獲得し、そのボタンの大きさが 1小さくなります。
# あなたは、いずれかのボタンを押すことを 2回行います。 同じボタンを 2回押しても構いません。
# 最大で何枚のコインを獲得できるでしょうか。

# 制約
#     入力は全て整数である。
#     3≤A,B≤20

# 入力
# 入力は以下の形式で標準入力から与えられる。
# A B

# 出力
# 獲得できるコインの枚数の最大値を出力せよ。

# 入力例 1
# 5 3

# 出力例 1
# 9

# 大きさ 5のボタンを 2 回押すと 5+4=9枚のコインが獲得でき、これが最大です。

# 入力例 2
# 3 4

# 出力例 2
# 7

# 入力例 3
# 6 6

# 出力例 3
# 12


def log(line):
    if False:
        print(line)


def calculation(lines):
    # line = lines[0]
    # N = int(lines[0])
    A, B = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(Q):
    #     valueses.append(list(map(int, lines[i+1].split())))

    if A == B:
        result = A*2
    else:
        result = max(A, B)*2-1

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['5 3']
        lines_export = [9]
    if pattern == 2:
        lines_input = ['3 4']
        lines_export = [7]
    if pattern == 3:
        lines_input = ['6 6']
        lines_export = [12]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i = 0;i < n;i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for(int i = 0;i < n - 1;i++) {
    if(vec.at(i) == vec.at(i+1)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

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

using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;

constexpr int INF = 1e9;

int main() {
    int N, K;
    cin >> N >> K;
    for(int i = 0; i < K; ++i) {
        int a, b; cin >> a >> b;
        int mi = min({a - 1, N - a, b - 1, N - b});
        cout << (mi % 3) + 1 << endl;
    }
}


Measured memory_bytes: 3120
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int c[210];
long long dp[210][110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",c+i);
	std::sort(c,c+a);
	reverse(c,c+a);
	dp[0][b]=1;
	for(int i=0;i<a;i++){
		for(int j=0;j<=b;j++){
			if(dp[i][j]==0)continue;
			dp[i+1][j]=(dp[i+1][j]+dp[i][j]*(a-i-1))%mod;
			dp[i+1][j%c[i]]=(dp[i+1][j%c[i]]+dp[i][j])%mod;
		}
	}
	long long ret=0;
	for(int i=0;i<=b;i++){
		ret=(ret+i*dp[a][i])%mod;
	}printf("%lld\n",ret);
}

Measured memory_bytes: 172160
#include<iostream>
#include<string>

using namespace std;

int dp[20][50001];
int main(){
	int n,m;
	int c[20];
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>c[i];
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<n+1;j++){
			if(i==0)
				dp[0][j]=j;
			else if(j<c[i])
				dp[i][j]=dp[i-1][j];
			else{
				if(dp[i-1][j]<dp[i][j-c[i]]+1)
					dp[i][j]=dp[i-1][j];
				if(dp[i][j-c[i]]+1<=dp[i-1][j])
					dp[i][j]=dp[i][j-c[i]]+1;
			}
		}
	}
	cout<<dp[m-1][n]<<endl;
	return 0;
}

Measured memory_bytes: 5064
#include<bits/stdc++.h>
#define for(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int read(){
	int res=0,f=1;
	char c=getchar();
	if(c=='-') f=-1;
	while(c>'9'||c<'0') c=getchar();
	while(c>='0'&&c<='9'){
		res=res*10+c-'0';
		c=getchar();
	}
	return res*f;
}
int main(){
	int n;
	n=read();
	string s;
	cin>>s;
	int cnt=0;
	for(i,0,n-3){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') cnt++;
	}
	cout<<cnt<<"\n";
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
int city[55]={};

int main() {
  int n,m;
  cin >> n >> m;
  for(int i=0;i<m;i++) {
    int a,b;
    cin >> a >> b;
    city[a]++;
    city[b]++;
  }
  for(int i=1;i<=n;i++){
    cout << city[i] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> mp(h, vector<int>(w));
    for(int i = 0; i < h; i++){
        string s;
        cin >> s;
        for(int j = 0; j < w; j++){
            if(s[j] == '#') mp[i][j] = 1;
        }
    }
    int ans = 0;
    for(int i = 0; i < (1 << h); i++){
        for(int j = 0; j < (1 << w); j++){
            vector<int> is, js;
            for(int k = 0; k < h; k++){
                if((i >> k) & 1) is.push_back(k);
            }
            for(int k = 0; k < w; k++){
                if((j >> k) & 1) js.push_back(k);
            }
            int total = 0;
            for(int k = 0; k < is.size(); k++){
                for(int l = 0; l < js.size(); l++){
                    total += mp[is[k]][js[l]];
                }
            }
            if(total == k) ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    ll q,h,s,d;
    ll n;
    cin >> q >> h >> s >> d;
    cin >> n;
    ll l1 = min({q*4, h*2, s});
    ll l2 = min({q*8, h*4, 2*s, d});
    if(l1*2 <= l2){
        cout << l1*n << endl;
    }else{
        cout << l2*(n/2) + l1*(n%2) << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
using ll = long long;

int main() {

	int n;
	cin >> n;

	vector<int> x(n);

	int i, sum = 0;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		sum += x[i];
	}

	int d = sum / n;
	int e = d - 1;
	int f = d + 1;

	int a = 0, b = 0, c = 0;

	for (i = 0; i < n; i++) {
		a += (x[i] - d) * (x[i] - d);
		b += (x[i] - e) * (x[i] - e);
		c += (x[i] - f) * (x[i] - f);
	}

	int ans = min(a, b);
	ans = min(ans, c);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
using namespace std;
#define REP(I,N) for (I=0;I<N;I++)
#define rREP(I,N) for (I=N-1;I>=0;I--)
#define rep(I,S,N) for (I=S;I<N;I++)
#define rrep(I,S,N) for (I=N-1;I>=S;I--)
#define FOR(I,S,N) for (I=S;I<=N;I++)
#define rFOR(I,S,N) for (I=N;I>=S;I--)
typedef unsigned long long ULL;
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fll;
const LL M=1e9+7;
const LL maxn=1e6+7;
const double eps=0.00000001;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<typename T>inline T powMM(T a,T b){T ret=1;for (;b;b>>=1ll,a=1ll*a*a%M) if (b&1) ret=1ll*ret*a%M;return ret;}

int MIN[maxn],lazy[maxn];
inline void add(int x,int val){
    lazy[x]+=val;MIN[x]+=val;
}
void update(int x,int l,int r,int val,int L,int R){
    if (l<=L&&R<=r){add(x,val);return;}
    if (lazy[x]){
        add(x<<1,lazy[x]);
        add(x<<1|1,lazy[x]);
        lazy[x]=0;
    }int mid=(L+R)/2;
    if (l<=mid) update(x<<1,l,r,val,L,mid);
    if (mid<r) update(x<<1|1,l,r,val,mid+1,R);
    MIN[x]=min(MIN[x<<1],MIN[x<<1|1]);
}
int query(int x,int l,int r,int L,int R){
    if (l<=L&&R<=r) return MIN[x];
    if (lazy[x]){
        add(x<<1,lazy[x]);
        add(x<<1|1,lazy[x]);
        lazy[x]=0;
    }int mid=(L+R)/2,ret=0;
    if (l<=mid) ret=min(ret,query(x<<1,l,r,L,mid));
    if (mid<r) ret=min(ret,query(x<<1|1,l,r,mid+1,R));
    return ret;
}
int n,m;
vector<int> have[maxn];

int i,j,k;
int l,r;
int main(){
    scanf("%d%d",&n,&m);
    FOR(i,1,n){
        scanf("%d%d",&l,&r);
        have[l].push_back(r);
    }
    FOR(i,0,m) update(1,i,i,m-i+1,0,m+1);
    int ans=min(0,m-n);
    FOR(i,0,m){
        if (i!=0) update(1,i+1,m+1,1,1,m+1);
        for (int r:have[i])
            update(1,i+1,r,-1,0,m+1);
//            printf("(%d)%d %d %d\n",i,r,m,-1);
//        printf("now ans=%d\n",MIN[1]);
        ans=min(ans,MIN[1]);
    }printf("%d\n",-ans);
}
/*
*/


Measured memory_bytes: 34560
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 5;
ll lcm(ll a,ll b){return a*b/__gcd(a,b);}
vector<int>chk(N);
int main()
{
   int n,one=0;
   cin>>n;
   vector<int>a(n);
   for(int i=0;i<n;i++)
   {
       cin>>a[i],chk[a[i]]++;
       if(a[i]==1)one++;
   }
   if(one==1)cout<<1<<endl,exit(0);
   else if(one>1)cout<<0<<endl,exit(0);
   int ans=0;
   sort(a.begin(),a.end());
   for(int i=0;i<n;i++)
   {
       int f=1;
       for(int j=a[i];j<=N;j+=a[i])
        if(chk[j]==1&&f)ans++,f=0,chk[j]=0;
         else if(chk[j])chk[j]=0,f=0;

   }
   cout<<ans<<endl;
}


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

int main()
{
  int n;
  int x,y,z,c;
  int ans=0;
  int i;
  double a,b;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    ans=0;
    for(x=1;x<=sqrt(i/6);x++){
      for(y=x;3*y*y+2*y*x+x*x<=i;y++){
        for(z=y;x*x+y*y+z*z+x*y+y*z+z*x<=i;z++){
          if(x*x+y*y+z*z+x*y+y*z+z*x==i){
            if(x==y && y==z) ans++;
            else if((x==y && x!=z) || (y==z && y!=x) || (z==x && z!=y)) ans+=3;
            else if(x!=y && y!=z && z!=x) ans+=6;
          }
        }
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<lld> vi;
typedef pair<lld,lld> pi;
#define F first
#define S second
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (lld i = a; i < b; i++)
lld r,j,l,x,y,m,b,n,s,f,q,i,z,p,k,d,t,u,e,g;string s1,s2,s3,s4;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin>>n;map<char,lld>ma;char ch;p=0;
  rep(i,0,n)
  {
    cin>>ch;
    ma[ch]++;    
  }
  if(ma.size()==4)
    cout<<"Four";
  else
    cout<<"Three";
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();

    for(int i=0; i<h; i++) {
    	String C = sc.next();
 
    		System.out.println(C);  
            System.out.println(C);
    }
}
}


Measured memory_bytes: 37088
#include <iostream>
//#define int long long
#define SIZE 101
#define VALUE 10001
//#define _DEBUG
using namespace std;
int N, W, Vs[SIZE], Ws[SIZE] , T[SIZE][VALUE];
int solve(){
    for(int i=0; i<=N; i++){
        for(int w=0; w<=W; w++){
            if(i==0 || w==0){
                T[i][w] = 0;
            }else if(w<Ws[i-1]){
                T[i][w] = T[i-1][w];
            }else{
                T[i][w] = max(T[i-1][w], T[i-1][w-Ws[i-1]]+Vs[i-1]);
            }
        }
    }
#ifdef _DEBUG
    for(int i=0; i<=N; i++){
        cout << Vs[i] << "," << Ws[i] << "\t";
        for(int w=0; w<=W; w++){
            cout << T[i][w] << " ";
        }cout << endl;
    }
#endif
    return T[N][W];
}
signed main(){
    while(cin >> N >> W){
        for(int i=0; i<N; i++){
            cin >> Vs[i] >> Ws[i];
        }
        cout << solve() << endl;
    }
}


Measured memory_bytes: 7064
object Main extends App {

  import scala.io.StdIn._


  val n = readLine.trim.toInt
  val frames = readLine.trim.split(' ').map(_.toInt)
  val sum = frames.sum
  var sam = 0
  for ((frame, idx) ← frames.zipWithIndex){
      if (math.abs(frames(sam) * n - sum) > math.abs(frame * n - sum)){
        sam = idx
      }
  }
  println(
    sam
  )

  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}

Measured memory_bytes: 25536
#define _'			'
A[_];long P[_],M=1e9+7,F[_],I[_],X;i,j,k,t;
//c(a,b)int*a,*b;{t=*a-*b?:a[1]-b[1];}
c(a,b)long*a,*b;{t=*a<*b?-1:*a>*b;}
p(a,b){return b?p(a%M*a%M,b/2)*(b%2?a:1L)%M:1;}
f(a,b){return F[a+b]*I[a]%M*I[b]%M;}
main(s){
  for(*I=1;++X<_;~scanf("%d",A+i)&&i++%2&&gets(P))I[X]=p(s=F[X]=X*s%M,M-2);
  for(qsort(A,i/2,8,c);j<i;P[j++-1]=X)
    for(X=f(t=--A[++j],s=--A[k=j]);k;
        X=s<A[k-=2]?X:(X-f(s-A[k],t-A[k+1])*P[k]%M+M)%M);
printf("%d",X);}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    string N;
    cin >> N;
    if (N == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a); i >= (b); --i)
#define sz(a) int((a).size())
#define pconent(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef long double ld;
const ll MOD =  1e9 + 7;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(v) (cout<<v<<" ** "<<endl)
template <class T> inline void dbv(T a) { for(auto x : a){ cout<<x<<" ** " ;} cout<<endl;}
void output()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    vector<ll> ce(n);
    vector<ll> cw(n);
    ll ans = LINF;
    ce[0] = s[0]=='E'?1:0;
    cw[0] = s[0]=='W'?1:0;
    FOR(i,1,n)
    {
        ce[i] = ce[i-1] + (s[i]=='E'?1:0);
        if(s[i]=='W')
        {
            cw[i] = cw[i-1]+1;
        }
        else
        {
            cw[i] = cw[i-1];
        }
    }
    // dbv(cw);
    // dbv(ce);
    FOR(i,1,n-1)
    {
        ans = min(ans,cw[i-1]+ce[n-1]-ce[i]);
    }
    ans = min(ans,ce[n-1]);
    ans = min(ans,cw[n-1]);
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t =1;
    FOR(i,0,t)
    {
        output() ;
    }
    return 0 ;
}

Measured memory_bytes: 5396
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		int c = saori.saori_hayami();
		int savea = 0;
		int saveb = 0;
		int savec = 0;
		int ans = 0;
		boolean flg = true;
		while(flg){
			if(!(a%2 == 0 && b%2 == 0 && c%2 == 0)){
				flg = false;
				continue;
			}
			if(a == b && b == c){
				ans = -1;
				break;
			}
			savea = a;
			saveb = b;
			savec = c;
			a = saveb/2 + savec/2;
			b = savea/2 + savec/2;
			c = saveb/2 + savea/2;
			ans++;
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

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

void Main() {
  int m1, d1;
  cin >> m1 >> d1;
  int m2, d2;
  cin >> m2 >> d2;
  if (m1 == m2)
    cout << 0 << endl;
  else
    cout << 1 << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



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

int main() {
  int n,k,ans = 0;
  cin >> n >> k;
  int s;
  for(int i = 0;i < n;i++){
    cin >> s;
    if(s >= k){
      ans++;
    }
  }
  cout << ans << endl;
}


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

int a[100005];
int main() 
{
	int k;
	cin >> k;
	for (int i = 1; i <= k; i++) 
	{
		cin >> a[i];
	}
	long long mmax = 2, mmin = 2;
	for (int i = k; i >= 1 && mmax >= mmin; i--)
	{
		if (mmin%a[i] != 0)
			mmin = mmin / a[i] * a[i] + a[i];
		mmax = (mmax / a[i] + 1)*a[i] - 1;
	}
	if (mmax >= mmin)
		cout << mmin << ' ' << mmax << endl;
	else
		cout << -1 << endl;
	
	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>

int	main()
{
	int	N, M;
	int	n, m;
	int	Nmax, Mmin, sum;

	Nmax = 1;
	scanf("%d %d\n", &N, &M);
	Mmin = N;
	for (int i = 0; i < M; i++)
	{
		scanf("%d %d\n", &n ,&m);
		if (n > Nmax)
			Nmax = n;
		if (m < Mmin)
			Mmin = m;
	}
	if ((Mmin - Nmax) < 0)
		sum = 0;
	else
		sum = (Mmin - Nmax) + 1;
	printf("%d\n", sum);
	return (0);
}

Measured memory_bytes: 128
use proconio::input;
use std::collections::VecDeque;

fn main() {
  input! {
    x: usize,
    y: usize,
    a: usize,
    b: usize,
    c: usize,
    mut pvs: [usize;a],
    mut qvs: [usize;b],
    mut rvs: [usize;c]
  }
  pvs.sort();
  pvs.reverse();
  qvs.sort();
  qvs.reverse();
  rvs.sort();
  rvs.reverse();
  
  let mut result = 0;

  let mut reds: VecDeque<usize> = vec![0;x].into_iter().collect();
  let mut greens: VecDeque<usize> = vec![0;y].into_iter().collect();
  
  for i in 0..x {
    reds[i] = pvs[i];
  }
  for i in 0..y {
    greens[i] = qvs[i];
  }
  
  while !rvs.is_empty() {
    let rs = reds[x-1];
    let gs = greens[y-1];
    let val = rvs.remove(0);
  
    if rs < gs {
      if val <= rs {
        break
      } else {
        reds.pop_back();
        reds.push_front(val);
      }
    } else {
      if val <= gs {
        break
      } else {
        greens.pop_back();
        greens.push_front(val);
      }
    }
  }
  
  let result = reds.iter().sum::<usize>() + greens.iter().sum::<usize>();
  println!("{}", result);
}


Measured memory_bytes: 9680
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;
#define mod 1000000007
 ll modularExponentiation(ll x,ll n,ll M) 
 { 
     if(n==0) 
         return 1; 
     else if(n%2 == 0)        //n is even 
         return modularExponentiation((x*x)%M,n/2,M); 
     else                             //n is odd 
         return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M; 
  
 } 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll ans = modularExponentiation(10LL, n, mod);
    ll ans1 = ((modularExponentiation(9LL, n, mod) * 2) % mod - modularExponentiation(8LL, n, mod) + mod) % mod;
    ans = (ans - ans1 + mod) % mod;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int h,w,d;
	cin>>h>>w>>d;
	int arr[h][w];
	map<int,pair<int,int>>vals;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++){
			cin>>arr[i][j];
		vals[arr[i][j]] = {i,j};
		}
	}

	int power[h*w+1];
	memset(power,0, sizeof(power));
	for(int i=d+1;i<=h*w;i++)
	{
		power[i] = power[i-d] + abs(vals[i].first - vals[i-d].first) + abs(vals[i].second - vals[i-d].second);
	}
	int q;
	cin>>q;
	while(q-->0)
	{
		int l,r;
		cin>>l>>r;
		cout<<power[r]-power[l]<<"\n";
	}

}


Measured memory_bytes: 9888
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
  int n,m;
  while ( cin >> n >> m, n || m ) {
    double f[101][101];
    double dp[101][101];
    for ( int i = 0; i < n; i++ ) {
      for ( int j = 0; j < n; j++ ) {
	cin >> f[i][j];
      }
    }

    for ( int i = 0; i < m; i++ ) {
      for ( int j = 0; j < n; j++ ) {
	dp[i][j] = 0.0;
      }
    }
    
    for ( int i = 0; i < n; i++ ) dp[0][i] = 1.0;

    for ( int i = 1; i < m; i++ ) {
      for ( int j = 0; j < n; j++ ) {
	for ( int k = 0; k < n; k++ ) {
	  dp[i][j] = max(dp[i][j], dp[i-1][k] * f[k][j]);
	}
      }
    }
    
    double ans = 0;
    for ( int i = 0; i < n; i++ ) ans = max( ans, dp[m-1][i] );
    printf("%.2f\n",ans);
  }	    
  return 0;
}

Measured memory_bytes: 1404
import sys
from collections import Counter
from operator import itemgetter
input = sys.stdin.readline

N, K = map(int, input().split())
TD = [tuple(map(int, input().split())) for _ in range(N)]
TD.sort(reverse=True, key=itemgetter(1))

selected = Counter()
ans = 0
stack = []

for t, d in TD[:K]:
    ans += d
    selected[t] += 1
    stack.append((t, d))
ans += len(selected) ** 2

tmp = ans
for t, d in TD[K:]:
    if t in selected:
        continue
    while stack:
        t0, d0 = stack.pop()
        if selected[t0] > 1:
            tmp += d - d0 + 2 * len(selected) + 1
            ans = max(ans, tmp)
            selected[t0] -= 1
            selected[t] += 1
            break
    else:
        break
print(ans)


Measured memory_bytes: 28072
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
using namespace std;
 
int main(){
    float a,b,c;
    cin >> a >> b >> c;
    
    // cout << sin(c/180*M_PI)*a*b/2 << endl << a + b +sqrt(a*a+b*b-2*cos(c/180*M_PI)*a*b) << endl << b*sin(c/180*M_PI) << endl;
    printf("%.6lf\n%.6lf\n%.6lf\n", a*b/2*sin(M_PI*c/180), a + b +sqrt(a*a+b*b-2*cos(M_PI*c/180)*a*b), b*sin(M_PI*c/180));
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define _end '\n'
#define Out(x) cout<<(x)<<_end
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    long sum = 0;
    int a[n];

    int i, len = n - 1;

    cin >> a[0];

    sum += Abs(a[0]);

    repi(i, n, 1) {
        cin >> a[i];

        sum += Abs(a[i] - a[i - 1]);
    }

    sum += Abs(a[len]);

    if (2 < n) {
        Out(sum - Abs(a[0]) - Abs(a[1] - a[0]) + Abs(a[1]));

        repi(i, len, 1) Out(sum - Abs(a[i + 1] - a[i]) - Abs(a[i] - a[i - 1]) + Abs(a[i + 1] - a[i - 1]));

        Out(sum - Abs(a[len] - a[len - 1]) - Abs(a[len]) + Abs(a[len - 1]));
    } else {
        Out(Abs(a[1]) * 2);
        Out(Abs(a[0]) * 2);
    }

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>                                                             
using namespace std;
 
int main()
{
    int a, b;
    cin >> a >> b;
    if (a < b)
        cout << "a < b" << endl;
    else if (a > b)
        cout << "a > b" << endl;
    else
        cout << "a == b" << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N,M;cin>>N>>M;
    int ans=(1900*M+100*(N-M))*pow(2,M);
    cout<<ans<<endl;
}

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

ans = 0
C = [0]
Xd = [-1] * (M+1)

for i in range(N):
    x = X if i==0 else x**2 % M
    
    if Xd[x] > -1:
        break
    Xd[x] = i
    ans += x
    C.append(ans)

loop_len = i - Xd[x]
if loop_len > 0:
    S = C[i] - C[Xd[x]]
    loop_num = (N - i) // loop_len
    ans += loop_num * S
    m = N - loop_num * loop_len - i
    ans += C[Xd[x]+m] - C[Xd[x]]

print(ans)

Measured memory_bytes: 13472