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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();

            int n = line[0];
            long m = line[1];
            var sLine = new string[n];
            var lLine = new long[n][];

            for (var i = 0; i < n; i++)
            {
                lLine[i] = Console.ReadLine().Split().Select(z => long.Parse(z)).ToArray();
            }

            lLine.OrderBy(o => o[0]);

            var totalMoney = 0L;
            var reminCount = m;

            foreach (var tmp in lLine.OrderBy(z => z[0]))
            {
                if (reminCount >= tmp[1])
                {
                    totalMoney += tmp[0] * tmp[1];
                    reminCount -= tmp[1];
                }
                else
                {
                    totalMoney += tmp[0] * reminCount;
                    break;
                }
            }

            Console.WriteLine(totalMoney);
        }
    }
}


Measured memory_bytes: 27832
#include <bits/stdc++.h>
using namespace std;
#define int long long 
using ldb = long double;
using pa = pair < int, int >;
#define F  first
#define S  second
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int a = n/500;
    n%= 500;
    int b = n/5;
    cout << a*1000 + b*5 ;
    return 0;
}
 

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

ll gcd(ll a, ll b) {
  return b == 0 ? a : gcd(b, a%b);
}

ll mypow(ll x, ll n) {
  if(n == 0) return 1;
  if(n % 2 == 0) return mypow(x*x%MOD, n/2);
  return mypow(x*x%MOD, n/2) * x % MOD;
}

ll solve(ll h, ll w) { // T = 1
  ll res = 0;
  // >のみの行と.のみの行のパターン
  res += mypow(2, h);
  res %= MOD;
  // vのみの列と.のみの列のパターン
  res += mypow(2, w);
  res %= MOD;
  // vと>の混成のパターン
  ll g = gcd(h, w);
  res += mypow(2, g);
  // 全部同じパターンが重複してるので引く
  res += MOD-3;
  res %= MOD;
  return res;
}

int main(void) {
  ll H, W, T;
  cin >> H >> W >> T;
  ll gwt = gcd(W, T);
  ll ght = gcd(H, T);
  ll w = W / gwt;
  ll h = H / ght;
  ll res = solve(h, w);
  res = mypow(res, gwt * ght);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 888
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


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


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

  char a, b;
  cin >> a >> b;
  cout << (a == b ? 'H' : 'D') << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())

dic = {}

for i in range(N):
    dic.setdefault(S[i], 0)
    dic[S[i]] += 1
s = list(dic.values())
ans = 1
for i in s:
    ans = ans * (i + 1) % (10 ** 9 + 7)

print(ans - 1)


Measured memory_bytes: 3956
from collections import deque

ans = []
while True:
    n, m = map(int, input().split())
    if n == 0 and m == 0:
        break

    state = 0
    for i in range(3):
        _, *cups = map(int, input().split())
        for cup in cups:
            state += i * 3**(cup-1)
    res = -1
    d = [-1] * 3**n
    que = deque([state])
    d[state] = 0
    while que:
        state = que.popleft()
        if state == 0 or state == 3**n - 1:
            res = d[state]
            break
        if d[state] > m:
            break

        state_copy = state
        tops = [-1] * 3
        for cup in range(n):
            tray = state_copy % 3
            state_copy //= 3
            tops[tray] = cup
        dt = [[1], [-1, 1], [-1]]
        for i, top in enumerate(tops):
            if top != -1:
                for di in dt[i]:
                    if top > tops[i + di]:
                        next_state = state + di * 3**top
                        if d[next_state] == -1:
                            d[next_state] = d[state] + 1
                            que.append(next_state)
    ans.append(res)

for a in ans:
    print(a)



Measured memory_bytes: 197456
#include<iostream>
#include<math.h>
using namespace std;
int n,x;
int l[105];
int main(){
	cin>>n>>x;
	for(int i = 0;i<n;i++){
		cin>>l[i];
	}
	int d = 0;
	int i = 0;
	while(d <= x){
		if(i>n) break;
		d+=l[i++];
		if(d > x) break;
	}
	cout<<i<<"\n";
	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  map<ll,ll> m;
  rep(i,n){
    ll a;
    cin >> a;
    a *= -1;
    m[a]++;
  }
  ll c = 0;
  ll ans = 1;
  for(auto u : m){
    if(u.se > 1){
      if(u.se > 3 && c == 0){
        c = 2;
        ans = u.fi * u.fi;
      }
      else{
        ++c;
        ans *= u.fi;
      }
      if(c == 2) break;
    }
  }
  if(c == 2)
    std::cout << ans << std::endl;
  else
    std::cout << 0 << std::endl;
  return 0;
}


Measured memory_bytes: 6528
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 105;
const int mod = 1000000007;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  cin>>n;
  ll ret = 0;
  for(int i=1;i<=n;i++){
    if(i%3==0||i%5==0)continue;
    ret += i;
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
  int n,t,tn[10];
  while(cin>>n){
    if(n==0) break;
    for(int i=0;i<10;i++) tn[i] = 0;
    for(int i=0;i<n;i++){
      cin >> t;
      tn[t]++;
    }
    for(int i=0;i<10;i++){
      if(tn[i]==0){
	cout << '-' << endl;
	continue; 
      }
      for(int j=0;j<tn[i];j++) cout << '*';
	cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1152
while True:
    h, w = map(int, input().split())

    if h == 0 and w == 0:
        break

    width = ''

    for i in range(h):
        if i % 2 == 0:
            for j in range(w):
                if j % 2 == 0:
                    width += '#'
                else:
                    width += '.'
        else:
            for j in range(w):
                if j % 2 != 0:
                    width += '#'
                else:
                    width += '.'
        print(width)
        width = ''

    print('')


Measured memory_bytes: 5608
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		for(int i=0;i<k;i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			a = min(a, n-a+1);
			b = min(b, n-b+1);
			System.out.println((min(a, b) % 3 + 2) % 3+1);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 13000
n, y = map(int,input().split())

for i in range(0,n+1):
  for j in range(0, n-i+1):
    if y == 10000*i + 5000*j + 1000*(n-i-j):
      print("{0} {1} {2}".format(i, j, n-i-j))
      exit()
print("-1 -1 -1")

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

int main() {
	string s;
	cin >> s;
	int half = s.length() / 2;
	bool flag_kai = true;
	rep(i,half) {
		if (s[i] != s[half-1-i]) flag_kai = false;
	}
	rep(i,half) {
		if (s[i+half+1] != s[half+half-i]) flag_kai = false;
	}
	int aa = s.length();
	rep(i,aa){
		if (s[i] != s[aa-1-i]) flag_kai = false;
	}
	if (flag_kai == true) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<memory.h>

int sentou(int a, int b);

int main() {
	int  H, A;
	int k;
	std::cin >> H >> A;
	k = sentou(H, A);
	std::cout << k << std::endl;
	return 0;
}

int sentou(int a, int b) {
	if (a % b == 0) {
		return a / b;
	}
	else {
		return a / b + 1;
	}
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	vector<char> a(101,'0');
	vector<char> b(101,'0');
	string s,t;
	cin >> s >> t;
	for(int i = 0; i < s.size(); i++) {
		a[100 - i] = s[s.size() - 1 - i];
	}
	for(int i = 0; i < t.size(); i++) {
		b[100 - i] = t[t.size() - 1 - i];
	}
	int flag =0;
	for(int i = 0; i < 101; i++) {
		if (a[i] > b[i]){
			flag = 1;
			break;
		}
		else if(b[i] > a[i]){
			flag = -1;
			break;
		}
	}
	if (flag == 1){
		cout << "GREATER" << endl;
	}
	else if (flag == -1){
		cout << "LESS" << endl;
	}
	else{
		cout << "EQUAL" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
h,w,k=gets.split.map(&:to_i)
m = h.times.map{gets.chomp}
last = nil
c = 0
head = 0
m.each do |l|
  cnt = l.count('#')
  if cnt == 0
    if last
      puts last
    else
      head += 1
    end
  else
    b = ''
    t = 0
    c += 1
    w.times do |j|
      t += 1 if l[j] == '#'
      c += 1 if l[j] == '#' && (1<t)
      b += '%d ' % c
    end
    puts b
    head.times{puts b} if head > 0
    head = 0
    last = b
  end
end


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    vector<vector<int>> c(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }
    vector<int> a(3);
    vector<int> b(3);
    for (int i = 0; i < 3; i++) {
        int min_v = *min_element(c[i].begin(), c[i].end());
        a[i] = min_v;
        for (int j = 0; j < 3; j++) {
            c[i][j] -= min_v;
        }
    }
    for (int i = 0; i < 3; i++) {
        if (c[0][i] != c[1][i] || c[1][i] != c[2][i]) {
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes" << "\n";
}

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

using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

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

    ll N;
    vector<ll> X;
    ll L;

    cin >> N;
    X.resize(N);

    for (ll i = 0; i < N; ++i) {
        cin >> X[i];
    }
    sort(X.begin(), X.end());

    cin >> L;

    X.resize(N+1);
    X[N] = X[N-1] + 1;
    N++;


    vector< vector<ll> > d; // doubling
    d.resize(N);
    for (ll i = 0; i < N; ++i) {
        d[i].resize(32);
    }

    for (ll i = 0; i < N; ++i) {
        d[i][0] = upper_bound(X.begin(), X.end(), X[i] + L) - X.begin() - 1;
    }

    for (ll j = 1; j < 32; ++j) {
        for (ll i = 0; i < N; ++i) {
            d[i][j] = d[ d[i][j-1] ][j-1];
        }
    }

    //for (ll i = 0; i < N; ++i) {
    //    cout << i << " " << X[i] << " " << d[i][0] << endl;
    //}

    ll Q;
    cin >> Q;

    while (Q--) {
        ll a;
        ll b;

        cin >> a >> b;
        a--;
        b--;

        if (a > b) {
            swap(a, b);
        }

        ll s = 0;
        
        for (ll i = 31; i >= 0; --i) {
            if (d[a][i] <= b) {
                a = d[a][i];
                s += (1LL << i);
            }
        }

        if (a != b) {
            s++;
        }

        cout << s << endl;
    }
}


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

#define N (300000)

int main(int argc, char const *argv[]) {
	int n;
	char s[N+1];
	scanf("%d", &n);
	scanf("%s", s);

	int i, j;

	int c[N] = {};

	for (i = 1; i < n; i++) {
		if (s[i] == 'E') {
			c[0]++;
		}
	}

	for (i = 1; i < n; i++) {
		c[i] = c[i-1];
		if (s[i-1] == 'W') {
			c[i]++;
		}
		if (s[i] == 'E') {
			c[i]--;
		}
	}

	int res = c[0];

	for (i = 0; i < n; i++) {
		// printf("%d\n", res);
		res = res < c[i] ? res : c[i];
	}
	// printf("\n");

	printf("%d\n", res);

	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

bool array_equal(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return false;
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return false;
    }
  }
  return true;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;

  vector<int> b(n);
  int sum = 0;
  for(int i=0; i<n - 1; i++) {
    cin >> b.at(i);
    if(i == 0) {
      sum += b.at(i);
    }
    else {
      sum += min(b.at(i), b.at(i - 1));
    }
    if(i == n - 2) {
      sum += b.at(i);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100005
#define INF 1000000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 998244353;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    map<int,int>m;
    REP(i,n){
        cin>>a[i];
        m[a[i]]++;
    }
    sort(ALL(a));
    int ans=0;
    for(int i=n-1;i>=0;i--){
        int t=1;
        if(m[a[i]]<=0)continue;
        m[a[i]]--;
        while(!(t<=a[i]&&a[i]<2*t)){
            t*=2;
        }
        t*=2;
        bool f=binary_search(ALL(a),t-a[i]);
        if(f&&m[t-a[i]]>0){
            ans+=1;
            m[t-a[i]]--;
        }
    }
    OUT(ans);
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}

//a,b x
int main(){
	ll N,M,K; cin>>N>>M>>K;
	rep(i,N+1)rep(j,M+1){
		if((N-i)*j+(M-j)*i==K){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
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; }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };
typedef pair<lint, char> pa;


template <std::int_fast64_t Modulus>
class modint
{
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept
	{
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept
	{
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept
	{
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept
	{
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept
	{
		a += rhs.a;
		if (a >= Modulus)
		{
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept
	{
		if (a < rhs.a)
		{
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept
	{
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept
	{
		u64 exp = Modulus - 2;
		while (exp)
		{
			if (exp % 2)
			{
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
typedef modint<MOD> ModInt;

ModInt mod_pow(ModInt x, lint n) {
	ModInt ret = 1;
	while (n > 0) {
		if (n & 1) (ret *= x);
		(x *= x);
		n >>= 1;
	}
	return ret;
}

ModInt func[200000];
void funcinit(int N)
{
	func[0] = 1;
	for (int i = 1; i <= N; i++)
	{
		func[i] = func[i - 1] * i;
	}
}
ModInt comb(ModInt n, ModInt r)
{
	if (n.a <= 0 || n.a < r.a)
	{
		return 1;
	}
	return func[n.a] / (func[r.a] * func[(n - r).a]);
}

lint S;
ModInt dp[2001][2001];
int main() {
	cin >> S;
	FOR(i, 3, S + 1) dp[1][i] = 1;
	FOR(i, 1, S + 1) {
		REP(j, S) dp[i][j + 1] += dp[i][j];
		FOR(j, 6, S + 1) {
			dp[i + 1][j] += dp[i][j - 3] - dp[i][2];
		}
	}
	ModInt ans = 0;
	REP(i, S) {
		ans += dp[i][S] - dp[i][S-1];
	}
	cout << ans.a << endk;
}


Measured memory_bytes: 34716
import java.util.Scanner;

class Main {
    static int[] heap = new int[2000000];
    static int size = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String command = sc.next();
            switch(command.charAt(0)) {
                case 'i':
                    int number = sc.nextInt();
                    insert(number);
                    break;
                case 'e':
                    if (command.charAt(1) == 'x') {
                        System.out.println(extract());
                        break;
                    } else {
                        return;
                    }
            }
        }
    }

    public static int extract() {
        int queue = heap[0];
        heap[0] = heap[size - 1];
        size--;
        maxHeap(0);
        return queue;
    }

    public static void insert(int number) {
        heap[size] = number;
        size++;
        swapParent(size - 1);
    }

    public static void swapParent(int i) {
        if (i > 0 && heap[i] > heap[(i - 1) / 2]) {
            int h = heap[(i - 1) / 2];
            heap[(i - 1) / 2] = heap[i];
            heap[i] = h;
            swapParent((i - 1) / 2);
        }
    }

    public static void maxHeap(int i) {
        if (i * 2 + 1 >= size) {
            return;
        }

        int tmp = i * 2 + 1;

        if (i * 2 + 2 < size) {
            if (heap[i * 2 + 1] < heap[i * 2 + 2]) {
                tmp = i * 2 + 2;
            }
        }

        if (heap[i] < heap[tmp]) {
            int h = heap[i];
            heap[i] = heap[tmp];
            heap[tmp] = h;
            maxHeap(tmp);
        }
    }
}


Measured memory_bytes: 555560
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<iomanip>
#include<bits/stdc++.h>
using namespace std;

/*define*/
#define rep(i, n) for(int i=0; i<n; ++i)
#define endl "\n"
typedef long long ll;

const long long mod = 1e18;
const long long INF=1e9;
int ci;

int main(){
    int n;
    cin >> n;
    vector<char> C(n);
    char c;
    int R=0, W=0;
    rep(i, n){
        cin >> c;
        C[i]=c;
        if(c=='R') R++;
        else W++;
    }
    //
//    cout << "R:" << R << "W:" << W << endl;
    int ans = 1e6;
    if(R==0 | W==0){
        cout << 0 << endl;
        cin >> ci;
        return 0;
    }
    //
    int left_w=0, right_r=R;
    rep(i, n){
        if(C[i]=='W') ++left_w;
        else --right_r;
        ans = min(ans, max(left_w, right_r));
    }
    cout << ans << endl;
//    cin >> ci;
}

Measured memory_bytes: 3632
#include <iostream>
#include <utility>
#include <cstdlib>
#include <cmath>
using namespace std;

int main() {
	long long h, w, ans = 9223372036854775807;
	cin >> h >> w;
	
	if(w >= 3) ans = min(ans, (long long) ((w % 3 ? 1 : 0) * h)); // ||
	
	if(h >= 3) ans = min(ans, (long long) ((h % 3 ? 1 : 0) * w)); // =
	
	long long half = floor(w / 2), a, b, c; // T
	for(long long H = 1; H < h; H++){ // H is the height for the upper part
		a = H * w;
		b = (h - H) * half;
		c = (h - H) * (w - half);
		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
	}
	
	half = floor(h / 2); // |-
	for(long long W = 1; W < w; W++){ // W is the width for the left part
		a = W * h;
		b = (w - W) * half;
		c = (w - W) * (h - half);
		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
//
// Created by Abhishek Bansal on 9/01/2020.
//
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

    string s, t; cin >> s >> t; int mi = t.length();
    for(int i=0;i<s.length();i++) {
        if (i+t.length() > s.length()) break;
        int cnt = 0;
        for(int j=0;j<t.length();j++) {
            if (s[i+j] != t[j]) cnt++;
        }
        mi = min(mi, cnt);
    }
    cout << mi;
    return 0;
}

Measured memory_bytes: 3588
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define maxn 200010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;

int mx[maxn], c[maxn], n;
vector<int> nxt[maxn];
map<int, int> F[maxn];
template <class T> void read (T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch))
    fl |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
int f(int x, int y, int fa) {
  if (F[x].count(y))
    return F[x][y];
  int ret = 0;
  for (auto &v : nxt[x]) {
    if (v != fa && v <= y)
      ret += 1 + f(v, y, x);
  }
  return F[x][y] = ret;
}
void dfs(int x, int fa) {
  mx[x] = max(mx[fa], fa);
  if (x > mx[fa])
    c[x] = c[fa] + f(x, mx[x], fa) + 1;
  else
    c[x] = c[fa] + f(x, mx[x], fa) - f(x, mx[fa], fa);
  for (auto &v : nxt[x]) {
    if (v != fa)
      dfs(v, x);
  }
}
int main() {
  read(n);
  for (int i = 1, u, v; i <= n - 1; i++) {
    read(u), read(v), nxt[u].pb(v), nxt[v].pb(u);
  }
  for (auto &v : nxt[1]) {
    dfs(v, 1);
  }
  for (int i = 2; i <= n; i++) {
    printf("%d%c", c[i], i == n ? '\n' : ' ');
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

ll a[maxn];
int n;

int main(){
    migmig
    cin >> n;
    for(int i = 0 ; i < n ; i ++)
		cin >> a[i];
	ll ans = 0;
	for(int i = 0 ; i < n ; i ++){
		if(a[i]%2){
			if(a[i+1]){
				a[i+1]--;
				a[i]--;
				ans++;
			}
		}
	}
	for(int i = 0 ; i < n ; i ++){
		ans+=a[i]/2 , a[i]%=2;	
    }
    for(int i = 0 ; i < n ; i ++){
		if(a[i] and a[i+1]){
			ans++;
			a[i+1]--;
		}
	}
	
	
	
	
	
	cout << ans;
    return(0);
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <bitset>
#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define p pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000'000'007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;
int main(){
    double a,b,h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
    return 0;
}

Measured memory_bytes: 256
void main(){
	string s = readln().chomp();
	foreach(i,c; s){
		if( (i+1)%2 ){
			if(c!='R' && c!='U' && c!='D'){
				writeln("No");
				return;
			}
		}else{
			if(c!='L' && c!='U' && c!='D'){
				writeln("No");
				return;
			}
		}	
	}
	writeln("Yes");
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


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

int main() {
    int k;
    cin >> k;
    
    queue<long long> que;
    for (long long i = 1; i < 10; i++) que.emplace(i);
    
    for (int _ = 0; _ < k - 1; _++) {
        long long res = que.front();
        que.pop();
        long long d = res % 10;
        if (d != 0) que.emplace(res * 10 + (d - 1));
        que.emplace(res * 10 + d);
        if (d != 9) que.emplace(res * 10 + (d + 1));
    }
    
    cout << que.front() << '\n';
    return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

lli data[110][110];

signed main(){

	lli w,h,n;
	cin>>w>>h>>n;

	REP(i,0,n){
		lli x,y,a;
		cin>>x>>y>>a;
		if(a==1){
			REP(j,0,h)REP(k,0,x){
				data[j][k]=1;
			}
		}
		else if(a==2){
			REP(j,0,h)REP(k,x,w)data[j][k]=1;
		}
		else if(a==3){
			REP(j,0,y)REP(k,0,w)data[j][k]=1;
		}
		else{
			REP(j,y,h)REP(k,0,w)data[j][k]=1;
		}
	}

	lli cnt=0;
	REP(i,0,h){
		REP(j,0,w){
			if(DEBUG)cout<<data[i][j]<<" ";
			cnt += ((data[i][j]==0)?1:0);
		}
		//cout<<endl;
	}

	cout<<cnt<<endl;
	return 0;
}

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

void BubbleSort(string C[], int N)
{
    for(int i = 0; i < N-1; i++){
        for(int j = N-1; j > i; j--){
            if(C[j][1] < C[j-1][1]) swap(C[j], C[j-1]);    
        }
    }
}

void SelectionSort(string C[], int N)
{
    for(int i = 0; i < N; i++){
        int min = i;
        for(int j = i+1; j < N; j++){
            if(C[min][1] > C[j][1]) min = j;
        }
        swap(C[min], C[i]);
    }
}

int main()
{
    int N;
    cin >> N;
    string C[N], B[N], S[N];
    bool stable = true;
    
    for(int i = 0; i < N; i++){
        cin >> C[i];
        B[i] = C[i];
        S[i] = C[i];
    }
    BubbleSort(B, N);
    for(int i = 0; i < N; i++){
        if(i) cout << " ";
        cout << B[i];
    }
    cout << endl << "Stable" << endl;
    
    SelectionSort(S, N);
    for(int i = 0; i < N; i++){
        if(B[i] != S[i]) stable = false; 
        if(i) cout << " ";
        cout << S[i];
    }
    cout << endl;
    if(stable){
        cout << "Stable" << endl;
    }
    else{
        cout << "Not stable" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3172
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char c[100];
int n,tot;
int main(){
	scanf("%s",c+1);
	n=strlen(c+1);
	if(c[1]!='A'||c[n]=='C'||c[2]=='C')
		{printf("WA\n");return 0;}
	for(int i=3;i<n;i++)if(c[i]=='C')tot++;
	if(tot!=1){printf("WA\n");return 0;}tot=0;
	for(int i=2;i<=n;i++)
		if(c[i]<'a'||c[i]>'z')tot++;
	if(tot>1){
		printf("WA\n");
		return 0;
	}
	printf("AC\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

using P=pair<int,int>;
void solve()
{
	int n;
	cin>>n;
	vector<P>red(n),blue(n);
	rep(i,n)cin>>red[i].first>>red[i].second;
	rep(i,n)cin>>blue[i].first>>blue[i].second;
	int ans=0;
	rep(i,n)swap(red[i].first,red[i].second);
	sort(rall(red));
	sort(all(blue));
	rep(i,n)swap(red[i].first,red[i].second);
	vector<bool>used(n);
	rep(i,n){
		rep(j,n){
			if(used[j])continue;
			if(red[j].first<blue[i].first&&red[j].second<blue[i].second){
				used[j]=true;
				++ans;
				break;
			}
		}
	}
	cout<<ans<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(vv) vv.begin(), vv.end()
 
using namespace std;
const ll maxn=1e6+100,inf=1e18,LOG=23,mod=1e9 + 7;
 
#define int ll

int n, W, w[maxn], v[maxn], dp[maxn];

main()
{
	IOS
	cin >> n >> W;
	forn(1, i, n)
	{
		cin >> w[i] >> v[i];
	}
	forn(1, i, n)
	{
		nfor(0, j, W)
		{
			if(j + w[i] <= W)
			{
				dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
			}
		}
		forn(0, j, W)
		{
			dp[j + 1] = max(dp[j + 1], dp[j]);
		}
	}
	cout << dp[W];
}

Measured memory_bytes: 5120
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;
bool visited[100005];
int wrong[100005];
int main()
{
  for(int i=1;i<100005;i++)
    visited[i] = true,wrong[i]=0;
  
  int n,m;
  cin >> n >> m;
  int good = 0, bad = 0;
  while(m--){
  	int x;string s;
    cin >> x >> s;
    if(s=="AC" && visited[x]==true)
    {
     good++;
     bad+=wrong[x];
     visited[x] = false;
    }
    else if(s=="WA" && visited[x]==true){
      wrong[x]++;
    }
  }
  cout<<good<<" "<<bad;
 return 0; 
}


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

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}

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

ll two(ll n) {
  ll c = 0;
  while (n % (0x01 << (c+1)) == 0) {
    c++;
  }
  return c;
}

ll solve() {
  int N;
  ll M;
  cin >> N >> M;

  vector<ll> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a[i];
    a[i] = a[i] / 2;
  }

  ll lc = a[0];
  ll nt = two(a[0]);
  for (int i = 1; i < N; i++) {
    if (two(a[i]) != nt) {
      return 0;
    }
    lc = lcm(lc, a[i]);
  }

  ll d = M / lc;
  return (d / 2) + (d % 2);
}

int main() {
  cout << solve() << endl;
  return 0;
}


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

int main(void)
{
	ll a, b;
	cin>>a>>b;
	string acon, bcon;
	acon=a+48;
	bcon=b+48;
	for(int i=1; i<b; i++)
		acon+=(a+48);

	for(int i=1; i<a; i++)
		bcon+=(b+48);

	if(acon>bcon)
		cout<<bcon<<"\n";

	else
		cout<<acon<<"\n";

	return 0;	
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#define rep(i,n) for(int i(0);i<n;i++)
using namespace std;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	set<int> st;
	rep(i,n){
		int a;
		cin >> a;
		st.insert(a);
	}
	cout << st.size() << endl;

    return 0;
}


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

int N;
int a[30][2];

int preorder(int r) {
	if (r == -1)return 0;
	cout << " " << r;
	preorder(a[r][0]);
	preorder(a[r][1]);
}
int inorder(int r) {
	if (a[r][0] != -1) inorder(a[r][0]);
	cout << " " << r;
	if (a[r][1] == -1)return 0;
	else inorder(a[r][1]);
}
void postorder(int r) {
	if (a[r][0] != -1) postorder(a[r][0]);
	if (a[r][1] != -1) postorder(a[r][1]);
	cout << " " << r;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N;
	bool c[30];
	int r;
	fill(c, c + N, false);
	for (int i = 0; i < N; i++) {
		cin >> r;
		cin >> a[r][0] >> a[r][1];
		c[a[r][0]] = true;
		c[a[r][1]] = true;
	}
	int root;
	for (int i = 0; i < N; i++) {
		if (c[i] == false) {
			root = i;
			break;
		}
	}
	cout << "Preorder" << endl;
	preorder(root);
	cout << endl;
	cout << "Inorder" << endl;
	inorder(root);
	cout << endl;
	cout << "Postorder" << endl;
	postorder(root);
	cout << endl;
}


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

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

long consumed_candies(long *a, int n, int x)
{
    int i;
    long sum = 0L;
    for (i = 0; i < n-1; i++)
    {
        long num_consumed = MAX(a[i] + a[i+1] - x, 0);
        long from_right = MIN(a[i+1], num_consumed);
        long from_left = num_consumed - from_right;
        a[i+1] -= from_right;
        a[i] -= from_left;
        sum += num_consumed;
        //printf("[i=%d; num_consumed=%ld; from_right=%ld; from_left=%ld]", i, num_consumed, from_right, from_left);
    }
    return sum;
}

int main(int argc, char **argv)
{
    int n, x;
    long *a;
    int i;
    
    scanf("%d %d", &n, &x);
    
    a = (long *)malloc(sizeof(long)*n);
    
    for (i=0; i<n; i++)
    {
        scanf("%ld", a+i);
    }
    
    printf("%ld", consumed_candies(a, n, x));
}

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

main() {
  int D[3];
  D[0] = 1;
  D[1] = D[2] = 0;
  char a, b;
  while(scanf("%c,%c", &a, &b) != EOF) {
    a -= 'A';
    b -= 'A';
    int tmp = D[a];
    D[a] = D[b];
    D[b] = tmp;
  }
  for(int i = 0; i < 3; ++i) {
    if(D[i] == 1) {
      cout << (char)('A' + i) << endl;
      break;
    }
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define F first
#define S second
#define Tsetso ios_base::sync_with_stdio(0) ; cin.tie(0) ;
using namespace std;
const ll N = 23, inf = 1e3+5, mod = 1e9+7, NN = 1e5+10;
ll n, a[N][N],dp[N][1<<21];
ll solve ( int idx , int msk)
{
    if (idx == n)
            return 1 ;
    if ( dp[idx][msk] != -1)
            return dp[idx][msk];
    ll res = 0 , lol = 1 ;
    for ( int j = 0 ; j < n ; j++)
    {
        if ( a[idx][j] && (msk & lol) == 0 )
            res = (res + solve(idx+1,msk | lol)) %mod;
        lol *= 2;
    }
    return dp[idx][msk] = res ;
}
int main()
{
    cin >> n ;
    for ( int i = 0 ; i < n ; i++)
            for ( int j = 0 ; j < n ; j++)
                    cin >> a[i][j] ;
    memset(dp,-1,sizeof dp);
    cout << solve(0,0);
}



Measured memory_bytes: 380472
n,a,b,c,d=map(int,input().split())
for i in range(n):
    if a+i*d-b>=c*(n-i-1)>=a+i*c-b or a+i*c-b<=d*(n-i-1)<=a+i*d-b or (d*(n-i-1)>a+i*d-b and c*(n-i-1)<a+i*c-b):
        print("YES")
        break
else:
    print("NO")

Measured memory_bytes: 39280
use std::io::*;
use std::str::FromStr;
use std::collections::BTreeMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let mut b_sum: u64 = 0;

    let mut mp: BTreeMap<u64,u64> = BTreeMap::new();

    for _ in 0..n {
        let a:u64 = read();
        let b:u64 = read();

        if mp.contains_key(&b) {
           let tmp = mp.get_mut(&b).unwrap();
           *tmp = *tmp + a;
        } else {
            mp.insert(b, a);
        }
    }

    for (k, v) in &mp {
        b_sum += *v;
        if b_sum > *k {
            println!("No");
            return;
        }
    }

    println!("Yes");
    return;
}



Measured memory_bytes: 8444
n=int(input())
l=list(map(int,input().split()))
c=0
l1=[]
for i in l:
  c+=i
  l1.append(c)
l2={}
for i in l1:
  if i in l2:
    l2[i]+=1
  else:
    l2[i]=1
s=0
for i in l2:
  if i==0:
    s+=l2[i]
  s+=l2[i]*(l2[i]-1)//2
print(s)

Measured memory_bytes: 41228
import Data.Function
import Data.List

main = do
  [h, w] <- map read . words <$> getLine
  sequence (replicate h getLine) >>= 
    putStr . unlines . (flip (:) <*> show . length) . 
    map (unwords . map show) .
    path w .
    map (map read . words)

path w =  map (\(from, to) -> case (from `divMod` w, to `divMod` w) of 
            ((y0, x0), (y1, x1)) -> map (+ 1) [y0, x0, y1, x1]) . 
          moves . zip indexes . concat . 
          zipWith ($) (cycle [id, reverse]) where
  indexes = concat . zipWith ($) (cycle [id, reverse]) . block w $ [0 ..]
  moves [_] = []
  moves ((from, n) : (to, m) : xs) 
    | odd n     = (from, to) : moves ((to, m + 1) : xs)
    | otherwise = moves ((to, m) : xs)

  block n = takeWhile (not . null) . map fst . 
            iterate (splitAt n . snd) . splitAt n 



Measured memory_bytes: 43132
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: i64,
        b: i64,
        mut k: i64,
    }
    for i in a..min(b + 1, a + k) {
        println!("{}", i);
    }
    for i in max(b - k + 1, a + k)..b + 1 {
        println!("{}", i);
    }
}


Measured memory_bytes: 4352
#!/usr/bin/env python
# coding: utf-8

# In[2]:


# H, W = map(int, input().split())
# data = [["a"]*(W+2)]
# for i in range(H):
#     data.append(list("a" + input() + "a"))
# data.append([["a"]*(W+2)])
# # print(data)


# In[5]:


# for h in range(H+1):
# #     print(data[h])
#     for w in range(W+1):
# #         print(data[h][w])
#         if data[h][w] == "#":
#             if data[h-1][w] != "#" and data[h][w-1] != "#" and data[h][w+1] != "#" and data[h+1][w] != "#":
#                 print("No")
#                 exit()

# print("Yes")


# In[ ]:


h, w = map(int, input().split())
s = [["a"]*(w + 2)]
 
for i in range(h):
    s.append(list("a" + input() + "a"))
s.append(["a"]*(w + 2))
 
for i in range(h + 1):
    for j in range(w + 1):
        if s[i][j] == "#":
            if s[i - 1][j] != "#" and s[i][j - 1] != "#" and s[i][j + 1] != "#" and s[i + 1][j] != "#":
                print("No")
                exit()
 
print("Yes")



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll mod=1e9+7;
double dp[301][301][301];
double solve(ll one,ll two,ll three,ll n){
	if(one<0||two<0||three<0){
		return 0;
	}
	if(one==0&&two==0&&three==0){
		return 0;
	}
	else if(dp[one][two][three]!=0)
		return dp[one][two][three];
	
	dp[one][two][three]=n+one*solve(one-1,two,three,n)+two*solve(one+1,two-1,three,n)+three*solve(one,two+1,three-1,n);
	dp[one][two][three]/=(one+two+three)*1.0;
	return dp[one][two][three];
}
int main(){
	ll n;
	cin>>n;
	ll one=0,two=0,three=0;
	for(int i=0;i<n;i++){
		ll temp;
		cin>>temp;
		if(temp==1){one++;}
		else if(temp==2){two++;}
		else {three++;}
	}
	cout<<fixed<<setprecision(9)<<solve(one,two,three,n);
	return 0;
	
}


Measured memory_bytes: 213248
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        s: [u64;n]
    }
    let mut s = s;
    s.sort();
    let mut sum: u64 = s.iter().sum();
    if sum % 10 == 0 {
        if let Some(&v) = s.iter().find(|&z| z % 10 != 0) {
            sum -= v
        } else {
            sum = 0
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 4352