akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int X = nextInt();
  int Y = nextInt();
  int A = nextInt();
  int B = nextInt();
  int C = nextInt();

  vector< pair<int,int> > all;
  REP(i, A) { all.push_back( {nextInt(), 1} ); }
  REP(i, B) { all.push_back( {nextInt(), 2} ); }
  REP(i, C) { all.push_back( {nextInt(), 3} ); }

  sort(ALL(all));
  reverse(ALL(all));

  ll ans = 0;

  int both = 0;
  int a = 0;
  int b = 0;
  int i = 0;
  while (a + b + both < X + Y) {
    const int value = all[i].first;
    const int color = all[i].second;
    if (color == 1) {
      if (a < X) {
        a++;
        ans += value;
      }
    } else if (color == 2) {
      if (b < Y) {
        b++;
        ans += value;
      }
    } else {
      both++;
      ans += value;
    }
    i++;
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		


VI v[100005];

struct UnionFind {
	vector<int> par;
	int cnt;
	UnionFind(int size_) : par(size_, -1), cnt(size_) { }
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (par[y] < par[x]) swap(x, y);
			par[x] += par[y]; par[y] = x;
			cnt--;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int find(int x) {
		return par[x] < 0 ? x : par[x] = find(par[x]);
	}
	int size(int x) {
		return -par[find(x)];
	}
	int size() {
		return cnt;
	}
};



int main() {
	
	int n, m;
	cin >> n >> m;
	UnionFind uf(n + m);
	vector<bool> b(m, false);
	int res = 0;
	REP(i, n) {
		int k;
		cin >> k;
		REP(j, k) {
			int l;
			cin >> l;
			l--;
			if (!b[l]) {
				b[l] = true;
				res++;
			}
			uf.unite(i, n + l);
		}
	}

	if (uf.size(0) == res + n)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    int n; 
    cin >> n;
    int smin = 101;
    int tot = 0;
    rep(i, n) {
        int s; cin >> s;
        if (s%10) smin = min(smin, s);
        tot += s; 
    }
    int ret = 0;
    if (tot%10) ret = tot;
    else {
        if (smin != 101) ret = tot-smin;
    } 
    cout << ret << endl; 
    return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def gcd(a, b):
  if a < b:
      a, b = b, a
  while a % b != 0:
      a, b = b, a % b
  return b


A, B = MAP()
def lcm(a, b):
    y = a*b / gcd(a, b)
    return int(y)
print(lcm(A, B))

Measured memory_bytes: 5200
n = int(input())
plan = [[0,0,0]]
for i in range(n):
    plan.append(list(map(int, input().split())))

for i in range(n):
    dt = plan[i+1][0] - plan[i][0]
    dx = plan[i+1][1] - plan[i][1]
    dy = plan[i+1][2] - plan[i][2]
    if (dx+dy)%2 == 0:
        if dt%2 == 0 and dt >= dx+dy:
            pass
        else:
            print('No')
            exit()
    else:
        if dt%2 == 1 and dt >= dx+dy:
            pass
        else:
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 27324
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n, t;
    cin >> n >> t;
    vpair d(n);
    rep(i, n) cin >> d[i].fi >> d[i].se;
    sort(all(d));

    int ans = 0;
    vvint dp(n+1, vint(t, 0));
    rep(i, n) {
        rep(j, t) {
            dp[i+1][j] = dp[i][j];
            ans = max(ans, dp[i+1][j] + d[i].se);
            if (j-d[i].fi >= 0) dp[i+1][j] = max(dp[i][j], dp[i][j-d[i].fi] + d[i].se);
        }
    }

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

Measured memory_bytes: 35584
from collections import deque

S = deque(input())
Q = int(input())
reverse_mode = False #反転毎に全体を反転しているとTLEする
reversed_count = 0
 
for i in range(Q):
    query = [str(e) for e in input().split()]
    if len(query)==1:
        reversed_count += 1
        #反転のモードを切り替える
        if reverse_mode == False:
            reverse_mode = True
        elif reverse_mode == True:
            reverse_mode = False
    
    else:
        if reverse_mode == False:
            if query[1]=="1":
            #先頭に追加
                S.appendleft(query[2])
            else:
            #末尾に追加
                S.append(query[2])
        elif reverse_mode == True:
            if query[1]=="1":
            #反転した先頭に追加＝末尾に追加
                S.append(query[2])
            else:
            #反転した末尾に追加＝先頭に追加
                S.appendleft(query[2])

#終了時に反転回数に応じて逆転orそのままにする
if reversed_count%2 != 0:
    S.reverse()
    
#print(S)
print(''.join(map(str,S)))

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

int main()
{
    int n,m;
    cin>>n;
    vector<int>a(n);
    REP(i,n)cin>>a[i];
    cin>>m;
    vector<int>b(m);
    REP(i,m)cin>>b[i];
    vector<int>c;
    set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
    for(auto i:c)cout<<i<<endl;
}



Measured memory_bytes: 6432
from itertools import product as P

a, b, c, d = input()

ops = P(("+", "-"), repeat=3)
for op1, op2, op3 in ops:
    f = f"{a}{op1}{b}{op2}{c}{op3}{d}"
    if eval(f) == 7:
        print(f + "=7")
        break

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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
// #define forn(i,n) for(ll i=0; i<(n); i++)
#define forn for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'
#define FILL(x,v) memset(x,v,sizeof(x))
#define pb push_back


template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}
void min_self(int &a, int b){
	a = min(a, b);
}

const int INF = 1e9 + 5;

void solve(){
	int n;
	cin >> n;
	vi a(n);
	forn cin >> a[i];
	vi dp(n, INF);
	// min cost of stone n
	dp[0] = 0;
	for(int i=0;i<n;i++){
		for(int j:{i+1, i+2}){
			min_self(dp[j], dp[i] + abs(a[i]-a[j]));
		}
	}
	cout << dp[n-1] << en;
}

int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
 
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
    return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int H,W;
  vector<string> a;
  cin >> H >> W;
  char board[H][W];
  for(int i = 0; i < H; i ++){
    for(int j = 0 ; j < W; j++){
      cin >> board[i][j];
    }
  }

  for(int i = 0; i < H; i ++){
    for(int j = 0 ; j < W; j++){
      if(board[i][j] == '.') continue;
      else{
        string s = "";
        for(int k = 0; k < W; k++){
          s = s + board[i][k];
        }
        a.push_back(s);
        break;
      }
    }
  }


  for(int j = 0 ; j < W; j++){
    for(int i = 0; i < a.size(); i++){
      if(a[i][j] == '.' && i == a.size()-1){
        for(int k = 0; k < a.size(); k++) a[k][j] = 'x';
      }
      else if(a[i][j] == '.') continue;
      else break;
    }
  }
  
  for(int i = 0; i < a.size(); i++){
    for(int j = 0; j < W; j++){
      if(a[i][j] != 'x') cout << a[i][j] ;
    }
      cout << endl;
  }

  return 0;
}


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

int main(void)
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int sum = 0;

    while(a > 0 && k > 0)
    {
        --k;
        --a;
        ++sum;
    }
    while(b > 0 && k > 0)
    {
        --k;
        --b;
    }
    while(c > 0 && k > 0)
    {
        --k;
        --c;
        --sum;
    }
    cout << sum << endl;
    
    return 0;
}



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

#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()
const int INF = 100000000;

int n, m;
vector<int> room(100100, INF);
vector<int> result(100100);
vector<vector<int>> way(100100, vector<int>(0));

void input() {
  cin >> n >> m;
  int a, b;
  rep(i, m) {
    cin >> a >> b; a--; b--;
    way[a].push_back(b);
    way[b].push_back(a);
  }
}

void bfs() {
  queue<int> q;
  q.push(0);
  room[0] = 0;
  while(!q.empty()) {
    int t = q.front(); q.pop();
    rep(i, way[t].size()) {
      if(room[way[t][i]] != INF) continue;
      room[way[t][i]] = room[t] + 1;
      result[way[t][i]] = t + 1;
      q.push(way[t][i]);
    }
  }
}

bool check() {
  rep(i, n) {
    if(room[i] == INF) {
      return false;
    }
  }
  return true;
}

void solve() {
  input();
  bfs();
  if(check()) {
    cout << "Yes" << endl;
    repi(i, 1, n) {
      cout << result[i] << endl;
    }
  } else {
    cout << "No" << endl;
  }
}

inline void Main() {
  // code
  solve();
}

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


Measured memory_bytes: 10664
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long[][] n = new long[N][3];
		long[][] sum = new long[4][N];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 3; j++)
				n[i][j] = sc.nextLong();
			sum[0][i] = n[i][0] + n[i][1] + n[i][2];
			sum[1][i] = n[i][0] + n[i][1] - n[i][2];
			sum[2][i] = n[i][0] - n[i][1] + n[i][2];
			sum[3][i] = -n[i][0] + n[i][1] + n[i][2];
		}

		long max = 0;
		for (int i = 0; i < 4; i++) {
			max = Math.max(max, max(N, M, sum[i]));
		}
		System.out.println(max);
	}

	private static long max(int N, int M, long[] sum) {
		Arrays.sort(sum);
		long s0 = 0;
		long s1 = 0;
		long max = 0;
		for (int i = 0, j = N - 1; i < M; i++, j--) {
			s0 += sum[i];
			s1 += sum[j];
		}
		max = Math.max(max, Math.abs(s0));
		max = Math.max(max, Math.abs(s1));
		return max;
	}

}


Measured memory_bytes: 27900
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
int main(void){
    int a,b,q;cin>>a>>b>>q;
    vector<ll> s(a+2),t(b+2);
    s[0]=(1e+11)*(-1);
    t[0]=(1e+11)*(-1);
    rep(i,a)cin>>s[i+1];
    rep(i,b)cin>>t[i+1];
    s[a+1]=(1e+11);
    t[b+1]=(1e+11);
    rep(i,q){
        ll x;cin>>x;
        //cout<<x<<endl;
        ll right=a,left=0;
        while(right-left>1){
            ll buf=(right+left)/2;
            if(x>s[buf]){
                left=buf;
            }else{
                right=buf;
            }
        }
        ll sx=s[right]-x,sy=x-s[right-1];
        if(sx<0){
            sx=1e+11;
            sy=x-s[a];
        }
        //cout<<sx<<" "<<sy<<endl;
        right=b,left=0;
        while(right-left>1){
            ll buf=(right+left)/2;
            if(x>t[buf]){
                left=buf;
            }else{
                right=buf;
            }
        }
        ll tx=t[right]-x,ty=x-t[right-1];
        if(tx<0){
            tx=1e+11;
            ty=x-t[b];
        }
        //cout<<tx<<" "<<ty<<endl;
        ll res=1e+11;
        if(sx<1e+11&&tx<1e+11) res=max(sx,tx);
        if(sy<1e+11&&ty<1e+11) res=min(res,max(sy,ty));
        //cout<<res<<endl;
        res=min(res,min(2*sx+ty,sx+ty*2));
        res=min(res,min(2*sy+tx,sy+tx*2));
        cout<<res<<endl;
        //return 0;
    }
}

Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int high = 0;
		int count = 0;
		int tmp = 0;
		int max = 0;

		for(int i=1;i<=N;i++) {
			high = sc.nextInt();
			if(high <= max) {
				tmp = tmp + 1;
				max = high;
			}else {
				max = high;
				if(tmp>count) {
					count = tmp;
				}
				tmp = 0;
			}
		}
		if(tmp>count) {
			count = tmp;
		}
		System.out.println(count);

	}
}


Measured memory_bytes: 50052
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define uni(v) v.erase(unique(v.begin(), v.end()), v.end())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (ll) a / __gcd(a, b) * b
#define what_is(x) cerr << #x << " is " << x << endl;

using namespace std;

void write();
template <typename T, typename... Args>
void write(T x, Args... args);
template <typename T>
void print_all(vector<T>& a);

ll fpow(ll b, ll n, ll m) {
    ll res = 1;
    while (n) {
        if (n & 1) res = (res * b) % m;
        n >>= 1;
        b = (b * b) % m;
    }
    return res;
}
ll gcdex(ll u, ll m) { return fpow(u, m - 2, m); }

void solve() {
    ll n, p;
    string s;
    cin >> n >> p >> s;

    if (p == 2 || p == 5) {
        ll res = 0;
        for (int i = 0; i < n; ++i) res += (s[i] - '0') % p == 0 ? i + 1 : 0;
        cout << res << '\n';
        return;
    }

    vll m(n + 1), a(p);
    for (int i = n; i--;) {
        m[i] = (s[i] - '0') * fpow(10, n - i - 1, p) % p;
        m[i] = (m[i] + m[i + 1]) % p;
        a[m[i]]++;
    }

    ll res = 0, x = 0;
    for (int i = n; i--;) {
        res += a[x];
        a[m[i]]--;
        x = m[i] % p;
    }

    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

void write() { cout << "\n"; }
template <typename T, typename... Args>
void write(T x, Args... args) {
    cout << x << ' ';
    write(args...);
}
template <typename T>
void print_all(vector<T>& a) {
    for (int i = 0; i < a.size(); ++i) cout << a[i] << " \n"[i == a.size() - 1];
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll N, X, M, ans;
map <ll, bool> visited, used;
int main(){
  cin >> N >> X >> M;

  ll Rest = N - 1;
  ans = X;
  visited[X] = true;
  ll now = X;

  while (Rest > 0){
    now = now * now % M;
    if (visited[now]) break;
    visited[now] = true;
    ans += now;
    Rest--;
  }

  vector <ll> Loop;
  while (!used[now]) {
    Loop.push_back(now);
    used[now] = true;
    now = now * now % M;
  }

  ll S = Loop.size();
  ll sum = 0;
  for (int i = 0; i < S; i++) sum += Loop[i];
  ans += sum * (Rest / S);
  Rest %= S;

  for (int i = 0; i < Rest; i++){
    ans += Loop[i];
  }


  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 9860
#include<algorithm>
#include<math.h>
#include<string>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
#define fo0(i,n) for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define cinmod ios::sync_with_stdio(false);cin.tie(0)
#define X1 first
#define X2 second
template<typename T> inline T gcd(T a, T b) { T t;if (a < b) { while (a) { t = a;a = b % a;b = t; }return b; } else { while (b) { t = b;b = a % b;a = t; }return a; } }
template<typename T> inline T sqr(T x) { return x * x; }
int a[200005];
int v[200005];//出现次数
int ans[200005];
long long C[200005];//C(n,2)
vector<int>tag;
int main()
{
    cinmod;
    int n;
    cin >> n;
    fo0(i, n)cin >> a[i];
    for (long long i = 2; i <= n; i++){C[i] = i * (i - 1) / 2; }
    fo0(i, n)
    {
        v[a[i]]++;
        if (v[a[i]] == 2)tag.push_back(a[i]);
    }
    long long all = 0;

    for (int i = 0; i < tag.size(); i++)
    {
        all += C[v[tag[i]]];
    }
    fo0(i, n)
    {
        if (v[a[i]] < 2)cout << all << endl;
        else
        {
            cout << all - (v[a[i]] - 1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5248
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<cmath>
 
#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
 
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9
#define MOD 1000000007
 
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; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}

typedef std::pair<ll, ll> P;

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}
 
using namespace std;

int main()
{
    string s;
    list <char> lc;
    cin >> s;
    ll q;
    cin >> q;
    ll dir = 1;

    rep(i, s.size()){
        lc.push_back(s[i]);
    }

    rep(i, q){
        ll t;
        cin >> t;
        if(t == 1){
            dir *= -1;
        }else{
            ll f;
            char c;
            cin >> f >> c;
            ll dir_loc = 1;
            if(f == 2) dir_loc = -1;
            dir_loc *= dir;
            if(dir_loc == 1){
                lc.push_front(c);
            }else{
                lc.push_back(c);
            }
        }
    }

    if(dir == 1){
        for(auto itr = lc.begin(); itr != lc.end(); ++itr) {
            cout << *itr;
        }
    }else{
        for(auto itr = lc.rbegin(); itr != lc.rend(); ++itr) {
            cout << *itr;
        }
    }


}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m ;
    cin>>m;
    return m ;
}
int main()
{
  int n;
  cin>>n;
 string s;
 cin>>s;
 int x=0,mx=0;
 for(int i=0;i<n;++i){
    if(s[i]=='I')
        x++;
    mx=max(x,mx);
    if (s[i]=='D')
        x--;
 }
 cout<<mx<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int  n;
  cin >> n;
	vector<long long int> a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a.at(i);
	}
  vector<long long int> b(n);
  for(int i=0;i<n;i++){
    b.at(i)=a.at(i);
  }
	sort(a.begin(),a.end());
	int m = a.at(n-1);
    int p = a.at(0);
  vector<long long int> value(m+1);
  value.at(p)=1;
	for(int i=0;i<n-1;i++){
      int k= a.at(i);
      int l = a.at(i+1);
      if(k==l){
			value.at(k) = value.at(k)+1;
		}
		else{
			value.at(l) = 1;
		}
	}
	long long int sum=0;
 

  for(int i=0;i<m+1;i++){
    sum = sum + (value.at(i))*(value.at(i)-1)/2;
  }
  
  for(int i=0;i<n;i++){
    cout << sum - value.at(b.at(i))+1 << endl;
}
}


Measured memory_bytes: 7168
#include <stdio.h>
#include <stdlib.h>
#define N 36

typedef struct{
  int a;
  char c;
}Card;

int decision(int, Card *);

Card C[N];

int main(){

  int i, j;
  int n, minv;
  Card CB[N], CS[N], TMP;
  char kamase[2];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s", kamase);

    C[i].a = atoi(&kamase[1]);
    C[i].c = kamase[0];

    CB[i] = C[i];
    CS[i] = C[i];
  }


  //Bubble
  for(i = 0; i < n; i++){
    for(j = n - 1; j > i; j--){//
      if(CB[j].a < CB[j - 1].a){
	TMP = CB[j];
	CB[j] = CB[j - 1];
	CB[j - 1] = TMP;
      }

    }

    }

  //Sellect
  for(i = 0; i < n; i++){
    minv = i;

    for(j = i; j < n; j++){
      if(CS[j].a < CS[minv].a){
	minv = j;
      }

    }

    TMP = CS[i];
    CS[i] = CS[minv];
    CS[minv] = TMP;
    }

  for(i = 0; i < n; i++){
    printf("%c%d", CB[i].c, CB[i].a);
    if(i < n - 1) printf(" ");
  }

  if(decision(n, &CB[0]) == 0) printf("\nStable\n");
  else printf("\nNot stable\n");

  for(i = 0; i < n; i++){
    printf("%c%d",CS[i].c, CS[i].a);
    if(i < n - 1) printf(" ");
  }

  if(decision(n, &CS[0]) == 0) printf("\nStable\n");
  else printf("\nNot stable\n");

  return 0;
}

int decision(int n, Card *CC){

  int i, j;
  Card TMP;
  
  for(i = 0; i < n - 1; i++){
    TMP = CC[i];
    
    if(TMP.a == CC[i + 1].a){

      for(j = 0; j < n; j++){

	if(C[j].c == TMP.c && C[j].a == TMP.a) break;
	if(C[j].c == CC[i + 1].c && C[j].a == CC[i + 1].a) return 1;

      }
      
    }
    
  }

  return 0;
}

Measured memory_bytes: 612
/* You can't hack me! */
#pragma warning(disable : 4996)
#include"bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vch;
typedef set<ll> sll;
#define fo(i,n) for(ll i=0; i<(n); i++)
#define FO(i,a,b) for(auto i=a; i!=(b); i+=(b)>(a)?1:-1)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(c) c.begin(), c.end()
#define sc scanf
#define pr printf
#define il(x) sc("%lld", &(x))
#define id(x) sc("%Lf", &(x))
#define os(x) pr("%lld ", x)
#define on(x) pr("%lld\n", x)
#define nl pr("\n")

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll t=1;
    //il(t);
    while(t--)
    {
        ll s, w;
        il(s);
        il(w);
        pr("%s\n", s>w?"safe":"unsafe");
    }
    cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "s\n";
    return 0;
}

Measured memory_bytes: 3876
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	static Scanner scanner;

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

	    long N=gl();
	    long K=gl();
	    long a=Math.floorDiv(N, K);
	    long b=(K*(a+1))-N;
	    long c=N-(K*a);
        

        //System.out.print(s);

        if (b>c) {
        	System.out.println(c);
        }else {
        	System.out.println(b);
        }
	}
	
	// ユークリッドの互除法
    public static int uclid(int m, int n) {
    	if (m<n) {
			m^=n;
			n^=m;
			m^=n;
		}

		while(true) {
			int t=m%n;
			if (t==0) {
				return n;
			} else {
				m=n;
				n=t;
			}
		}
    }

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35568
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LLINF 1<<63-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define MOD 1000000007
void swap(int* x,int* y){
  int tmp=*x;*x=*y;*y=tmp;
}

int main(){
  int a,b,c,d,e,k;
  scanf("%d%d%d",&a,&b,&c);
  scanf("%d%d%d",&d,&e,&k);
  if(e-a>k)printf(":(\n");
  else printf("Yay!\n");

  //printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;

/**
 * Created by Ayushi on 30 May 2020.
 * Problem:
 * Round:
 */

public class Main {
    public static void main(String[] args) throws IOException {
        StringTokenizer st;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer(br.readLine(), " ");
        int h1 = Integer.parseInt(st.nextToken());
        int m1 = Integer.parseInt(st.nextToken());
        int h2 = Integer.parseInt(st.nextToken());
        int m2 = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        br.close();

        int t1 = (h1*60)+m1;
        int t2 = (h2*60)+m2;

        int d = t2 - t1;
        d -= k;
        System.out.println(d);
    }
}


Measured memory_bytes: 32484
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int h, w;
        while((h = scn.nextInt()) != 0 | (w = scn.nextInt()) != 0) {
            rect(h, w);
            System.out.println();
        }
    }
    
    private static void rect(int h, int w) {
        for(int i = 0; i++ < h; System.out.println()) {
            for(int j = 0; j++ < w; System.out.print("#"));
        }
    }
}

Measured memory_bytes: 36900
using System;

namespace atCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] temp = Console.ReadLine().Split(' ');
            int a = int.Parse(temp[0]);
            int b = int.Parse(temp[1]);
            int c = int.Parse(temp[2]);
            int d = int.Parse(temp[3]);
            int result = 0;

            for (int i = 0; i <= 100; i++)
            {
                if (a + 1 <= i && i <= b && c + 1 <= i && i <= d)
                {
                    result++;
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main()
{

  int n, i, j, key;
  int A[N+1];

  scanf("%d", &n);

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

  trace(A, n);

  for(i=2; i<=n; i++){

    key = A[i];
    j = i-1;
    while(j>=0 && A[j]>key){
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
    }
    trace(A, n);
  }


  return 0;

}

Measured memory_bytes: 608
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
    int N, h, K;
    cin >> N >> K;
    vector<int> Hs(N);
    for(int i = 0; i < N; ++i){
        cin >> h;
        Hs[i] = h;
    }
    vector<int> table(N, 2e9);
    table[0] = 0;
    
    for(int i = 1; i < N; ++i){
        for(int j = i; j <= min(i+K-1, N-1); ++j){
            if(i == 1){
                table[j] = abs(Hs[j]-Hs[i-1]);
            }else{
                table[j] = min(table[j], abs(Hs[j]-Hs[i-1])+table[i-1]);
                // cout << j << " " << i << endl;
            }
            // cout << "i = " << i << " j = " << j << " ";
            // for(auto a : table){
            //     cout << a << " ";
            // }
            // cout << "\n";
        }
    }
    // for(auto i : table){
    //     cout << i << endl;
    // }
    cout << table[N-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<pi> vpi;

#define debugone(x) cout << #x << " " << x << endl;
#define debugtwo(x) cout << #x << "-------------" << endl;for(auto &it: x) cout << it << " ";cout << endl;
#define debugthree(x, i, j) cout << #x << "------------" << endl;cout << "from " << i << " to " << j << endl;for(int k=i; k<=j; k++) cout << x[k] << " ";cout << endl;

const int mod = (int)1e9 + 7;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;
	vector<pair<pair<string, int>, int>> v;
	for(int i = 0; i < n; i++){
		string s;
		int x;
		cin >> s >> x;
		v.push_back({{s, (-1) * x}, i});
	}

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

	for(int i = 0; i < n; i++){
		cout << v[i].second + 1 << "\n";
	}

}	

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int A, B;
    scanf("%d %d", &A, &B);
    if(A <= 5){printf("0\n");}
    else if(6 <= A && A <= 12){printf("%d\n", B/2);}
    else printf("%d\n", B);
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	string A, B;
	cin >> A >> B;
	while (A.length() > B.length()) B = "0" + B;
	while (B.length() > A.length()) A = "0" + A;
	if (A == B) cout << "EQUAL" << endl;
	else if (A > B) cout << "GREATER" << endl;
	else cout << "LESS" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define ll long long
const ll MOD=1e9+7;
ll n,dp[10000][10000],sum[10000][10000];
char s[100000];
int main(){
	scanf("%lld %s", &n,&s);
	dp[1][1]=1;
	sum[1][1]=1;
	for(ll i=2;i<=n;i++){
		for(ll j=1;j<=i;j++){
			if(s[i-2]=='>') dp[i][j]=sum[i-1][j-1]%MOD;
			else dp[i][j]=sum[i-1][i-1]-sum[i-1][j-1]%MOD;
			sum[i][j]=(sum[i][j-1]+dp[i][j]+MOD)%MOD;
		}
	}
	printf("%lld", sum[n][n]%MOD);
}


Measured memory_bytes: 469248
#include<bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define lli long long int
#define pb push_back
#define pob pop_back
#define rep(i,a,b) for(lli i=a;i<b;i++)
#define repv(a,b) for(int i=a;i>=b;i--)
#define itr vector<lli> :: iterator
#define maximum(a,b,c)  max(a,max(b,c))
#define minimum(a,b,c) min(a,min(b,c))
#define tim clock_t
#define fs first
#define sc second
#define db double

#define PI 3.14159265
db eps = 1e-8;
db a,b,x;
inline void fast()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
bool check(double mid)
{
    double ang = mid * PI / 180;
    double V;
    if(ang < atan(a/b))
    {
        V = b * (b * tan(ang)) * 0.5 * a;
        //cout << "up " << mid << " " << V << endl;
    }
    else
    {
        V = (a * b - a * (a * tan(PI / 2 - ang)) * 0.5) * a;
        //cout << "ang = " << ang << endl;
        //cout << "down " << a*b << " " << a * (a * cot(ang)) * 0.5 << " " << mid << " " << V << endl;
    }
 
    if(V>x) return 1;
    return 0;
}
void solve()
{
	double n,k,ctr=0,m=0,y,ans=0;
	cin>>a>>b>>x;
	db low=0.00,high=90.000,mid;
	while(low+eps<high)
	{
		mid = (low+high)/2.0;
		if(check(mid))
		{
			ans = max(ans,mid);
			//cout<<mid<<" ";
			high = mid;
		}
		else
			low=mid;
	}
	 printf("%.10lf",90-low);
}

int main()
{
	fast();
	lli t;
	//cin>>t;
	t=1;
	while(t--)
	{
		solve();
	}
	
	
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <istream>
#include <algorithm>

#ifdef _MSC_VER
#define scanf scanf_s
#define KEYWAIT getchar();getchar();
#else
#define KEYWAIT
#endif

int main()
{
    int a, b;
    std::string s;

    std::cin >> a >> b;
 
    int c = 0;

    for (; a <= b; a++) {
        s = std::to_string(a);
        if (s[0] == s[4] && s[1] == s[3])c++;
    }

    std::cout << c << std::endl;

    KEYWAIT

    return 0;
}


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

long long gcd(long long x, long long y) {
    return y ? gcd(y, x % y) : x;
}

int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    long long sum_b = 0;
    long long sum_a = 0;
    if (c == d) {
        sum_b = b / c;
        sum_a = (a - 1) / c;
        cout << (b - a + 1) - (sum_b - sum_a) << endl;
        return 0;
    }

    sum_b = b / c + b / d - b / ((c * d) / gcd(c, d));
    sum_a = (a - 1) / c + (a - 1) / d - (a - 1) / ((c * d) / gcd(c, d));

    cout << (b - a + 1) - (sum_b - sum_a) << endl;

    return 0;
}

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

int memo[101][10001];
int w[101], v[101];
int dp(int i, int j)
{
    if (i == 0)
        return 0;
    if (memo[i][j] >= 0)
        return memo[i][j];
    if (j - w[i - 1] < 0)
        return memo[i][j] = dp(i - 1, j);

    return memo[i][j] = max(dp(i - 1, j), dp(i - 1, j - w[i - 1]) + v[i - 1]);
}

int main()
{
    for (int i = 0; i < 101; i++)
    {
        for (int j = 0; j < 10001; j++)
        {
            memo[i][j] = -1;
        }
    }
    int N, W;
    scanf("%d %d", &N, &W);
    for (int k = 0; k < N; k++)
    {
        scanf("%d %d", &v[k], &w[k]);
    }
    printf("%d\n", dp(N, W));
}


Measured memory_bytes: 6684
def main(a_b: list):
    l = [0 for _ in range(4)]

    for a, b in a_b:
        l[a - 1] += 1
        l[b - 1] += 1

    if max(l) == 2:
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    a_b = [list(map(int, input().split())) for _ in range(3)]

    main(a_b)


Measured memory_bytes: 3060
a = []
b = []
count = 0

while n = gets
  ax, bx = n.chomp.split(" ")
  a[count], b[count] = ax.to_i, bx.to_i
  count += 1
end

for i in 0..count-1
  aa = a[i]
  bb = b[i]

  if b[i] > a[i]
    a[i] = b[i]
    b[i] = aa
  end

  while b[i] != 0
    c = a[i] % b[i]
    a[i] = b[i]
    b[i] = c
  end

  puts a[i].to_s + " " + ((aa/a[i])*(bb/a[i])*a[i]).to_s
end

Measured memory_bytes: 8536
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define i_INF int(1e9)
#define ll_INF ll(1e9) * ll(1e9)
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll x, y;

void solve() {
    ll ans = ll_INF;
    if (y >= x) {
        ans = min(ans, abs(y - x));
    }
    if (-y >= -x) {
        ans = min(ans, abs(-y - (-x)) + 2);
    }
    if (y >= -x) {
        ans = min(ans, abs(y - (-x)) + 1);
    }
    if (-y >= x) {
        ans = min(ans, abs(-y - x) + 1);
    }
    cout << ans << endl;
}

int main() {
    cin >> x >> y;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[])
{
int i, x, y, tmp;


for(i=1;;i++){
scanf("%d %d", &x, &y);
if (x==0&&y==0){
break;
}
if (x<=y) {
printf("%d %d\n", x, y);
}
if(x>y){
tmp = x;
x = y;
y = tmp;
printf("%d %d\n", x, y);
}
}
return 0;
}


Measured memory_bytes: 1976
#include<stdio.h>
int main(void){
  int a,b,i,j;
  while(1){
    scanf("%d %d",&a,&b);
    if(a==0&&b==0)return(0);
    for(i=0;i<a;i++){
      for(j=0;j<b;j++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return(0);
}

		     

Measured memory_bytes: 1784
n,m = map(int,input().split())
drink = []
for i in range(n):
    l = list(map(int,input().split()))
    drink.append(l)
drink.sort()

res = 0
piv = 0
while m > 0:
    buy = min(m, drink[piv][1])
    res += buy * drink[piv][0]
    m -= buy
    piv += 1
print(res)


Measured memory_bytes: 27960
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>


#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

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; }
void SWAP(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void SWAP(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


class D {
	int n, k;
public:
	D()
	{
		cin >> n >> k;
	}
	void solve()
	{
		ll ans{ 0 };
		for (int div{ k + 1}; div <= n; div++)
		{
			int loops{n / div};
			ans += ((ll)div - 1 - (k - 1)) * loops;
			ans += (ll)max(0, n - (div * loops + k) + 1);
		}

		if (k == 0)
		{
			ans -= (ll)n;
		}

		cout << ans << endl;
	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main()
{
	int a, b;
	std::cin >> a >> b;
	if(a<b){
		std::cout << "a" << " < " << "b" << "\n";
	} else if(a>b) {
		std::cout << "a" << " > " << "b" << "\n";
	} else {
		std::cout << "a" << " == " << "b" << "\n";
	}
	return 0;
}

Measured memory_bytes: 1124
#include <stdio.h>
#include <stdlib.h>
int main(){
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
if(abs(a-c) <= d) printf("Yes\n");
else if(abs(a-b) <= d && abs(b-c) <= d) printf("Yes\n");
else printf("No");
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
int n, H;
int w[1<<18];
long long F[1<<18], Mod = 1000000007, IT[18][1<<18], D[30][30], Ans, InvF[1<<18], InvF2[1<<18];
long long Go(int a){
    if(a==1)return 1;
    return Go(a/2)*a%Mod;
}
void Put(int dep, int a, int x){
    a+=n;
    while(a){
        IT[dep][a]+=x;
        a>>=1;
    }
}
long long Pow(long long a, long long b){
    long long r=1;
    while(b){
        if(b&1)r=r*a%Mod;
        a=a*a%Mod;b>>=1;
    }
    return r;
}
void DFS(int a, int dep){
    int i, j;
    int bb=a,ee=a;
    while(bb<n){
        bb*=2,ee=ee*2+1;
    }
    bb-=n,ee-=n;
    for(i=bb;i<=ee;i++){
        Put(dep, w[i], F[n+i]*F[n+w[i]]%Mod);
    }

    if(dep!=H-1){
        DFS(a*2,dep+1);
        DFS(a*2+1,dep+1);
    }
    else{
        for(i=0;i<H;i++){
            int x = n+w[a-n];
            for(j=H-1;j>=0;j--){
                D[i][j]=IT[i][x];
                x>>=1;
            }
        }
        long long tp = F[a]*F[n+w[a-n]]%Mod;
        long long ss=0;
        for(i=0;i<H-1;i++){
            long long s=0;
            for(j=0 ;j<H-1;j++){
                D[i][j]-=D[i+1][j]+D[i][j+1]-D[i+1][j+1];
                if(D[i][j]){
                    int x = n+w[a-n];
                    s=(s+D[i][j]%Mod*InvF2[x>>(H-j-1)])%Mod;
                }
            }
            ss=(ss + s*InvF2[a>>(H-i-1)])%Mod;
        }
        Ans=(Ans+ss*tp)%Mod;
    }

    for(i=bb;i<=ee;i++){
        Put(dep, w[i], -(F[n+i]*F[n+w[i]]%Mod));
    }
}
int main(){
    int i;
    scanf("%d",&H);
    n = 1<<(H-1);
    for(i=0;i<n;i++){
        scanf("%d",&w[i]);
        w[i]--;
    }
    F[0]=1;
    for(i=1;i<n+n;i++){
        F[i]=Go(i);
    }
    for(i=0;i<n+n;i++)InvF[i]=Pow(F[i],Mod-2);
    for(i=0;i<n+n;i++)InvF2[i]=InvF[i]*InvF[i/2]%Mod;
    DFS(1,0);
    Ans=(Ans+Mod)%Mod;
    Ans=Ans*Pow(2,Mod-2)%Mod;
    printf("%lld\n",Ans);
}

Measured memory_bytes: 45228
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
/*
using ll = long long;
using P = pair<int, int>;
*/
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dp[1001][1001];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    string x, y;
    rep(l,q){
        memset(dp, 0, sizeof(dp));
        cin >> x >> y;
        rep(i,x.size())rep(j,y.size()){
            if(x[i] == y[j]) dp[i+1][j+1] = dp[i][j] + 1;
            else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
        }
        cout << dp[x.size()][y.size()] << endl;
    }
    return 0;
}


Measured memory_bytes: 7104
import sys
S = input().strip()

tmp = list(S)
tmp.reverse()
reversedS = "".join(tmp)

if S != reversedS:
    print("No")
    sys.exit(0)

T = S[:(len(S)-1)//2]

tmp = list(T)
tmp.reverse()
if T != "".join(tmp):
    print("No")
    sys.exit(0)

W = S[(len(S)+3)//2-1:]

tmp = list(W)
tmp.reverse()
if W != "".join(tmp):
    print("No")
    sys.exit(0)

print("Yes")


Measured memory_bytes: 3188
n = gets.to_i
x = gets.chomp
xs = x.to_i(2)
xc = x.count('1')
def mpow(n, p, mod)
  return 0 if mod.zero?
  r = 1
  while p > 0
    r = r * n % mod if p & 1 == 1
    n = n * n % mod
    p >>= 1
  end
  r
end
def popcount(u)
  return 0 if u.zero?
  a = u % u.to_s(2).count('1')
  1 + popcount(a)
end
xsp = mpow(xs, 1, xc + 1)
xsm = mpow(xs, 1, xc - 1)
n.times do |i|
  if x[i] == '0'
    y = xsp + mpow(2, n - i - 1, xc + 1)
    y = mpow(y, 1, xc + 1)
  elsif xc == 1
    puts '0'
    next
  else
    y = xsm - mpow(2, n - i - 1, xc - 1)
    y = mpow(y, 1, xc - 1)
  end
  puts popcount(y) + 1
end

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

int main() {
  int H, W;
  cin >> H >> W;
  string S[55];
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  vector<int> dx = {-1, 0, 1, -1, 1, -1, 0, 1};
  vector<int> dy = {-1, -1, -1, 0, 0, 1, 1, 1};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        int cnt = 0;
        for (int k = 0; k < 8; k++) {
          int X = j + dx[k];
          int Y = i + dy[k];
          if (0 <= X && X < W && 0 <= Y && Y < H && S[Y][X] == '#')
            cnt++;
        }
        S[i][j] = '0' + cnt;
      }
    }
  }
  for (int i = 0; i < H; i++) {
    cout << S[i] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  }
  vi dp(N,0);
  dp[0] = 3;
  ll ans = 1;
  rep(i,N) {
    ans *= dp[A[i]];
    ans %= MOD;
    dp[A[i]+1]++;
    dp[A[i]]--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024