akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

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

int main()
{
  int N;
  cin >> N;
  vector<P> v(N);

  for (int i = 0; i < N; i++)
  {
    cin >> v[i].second >> v[i].first;
  }

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

  ll now = 1e10;
  for (int i = N - 1; i >= 0; i--)
  {
    chmin(now, v[i].first);
    now -= v[i].second;
  }
  cout << (now >= 0 ? "Yes" : "No") << endl;
}

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

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

  int calc = 0;
  int tmp = N;
  while (tmp > 0) {
    calc += tmp % 10;
    tmp /= 10;
  }
  if (N % calc == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int main() {
    string s;
    cin >> s;
    bool flag = false;
    if (s[0] == s[1] and s[1] == s[2]) flag = true;
    if (s[1] == s[2] and s[2] == s[3]) flag = true;
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
typedef long long int ll;
const ll MOD = 1e9 + 7;

ll mod(ll x){
	x %= MOD;
	return x;
}

ll pow(ll x,ll n){
	if(n <= 0) return 1;
	ll t = pow(x,n/2);

	t = mod(t*t);

	if(n%2 == 1) t = mod(t*x);

	return t;
}

int main()
{
	string a; cin>>a;
	ll n = a.length();
	ll la=0,lq=0,rq=0,rc=0; ll ans = 0;
	for(ll i=0;i<n;i++){
		if(a[i]=='?')rq++;
		if(a[i]=='C')rc++;
	}

	for(ll i=0;i<n;i++){
		if(a[i]=='A') la++;
		if(a[i]=='C') rc--;
		if(a[i]=='?' or a[i]=='B'){
			if(a[i]=='?') rq--;
			ll l = mod(pow(3,lq)*la + pow(3,lq-1)*lq);
			ll r = mod(pow(3,rq)*rc + pow(3,rq-1)*rq);
			ans += mod(l*r);
			ans %= MOD;
			if(a[i]=='?')lq++;
		}

	}

	cout<<ans;	
}

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

int main() {
	int n, y;
	cin >> n >> y;

	rep(a, n + 1) {
		rep(b, n + 1) {
			int c = (y - 10000*a - 5000*b)/1000;
			if (a + b + c == n && c >= 0) {
				cout << a << " " << b << " " << c << endl;
				return 0;
			} 
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;

inline int read(){
	int sum=0,f=1;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
	return f*sum;
}

const int N=200001;
struct edge{int x,y;ll w;}a[N<<1];
int n,m,tot,fa[N];ll f[N],ans;

inline void add(int x,int y,ll z){
	a[++tot]=(edge){x,y,z};
}

inline int find(int x){return x==fa[x]? x:fa[x]=find(fa[x]);}

inline bool cmp(edge a,edge b){return a.w<b.w;}

int main(){
	n=read();m=read();
	for(int i=1;i<=n;i++) fa[i]=i;
	memset(f,0x3f,sizeof(f));
	while(m--){
		int x=read()+1,y=read()+1;ll z=read();
		add(x,y,z);f[x]=min(f[x],z+1);f[y]=min(f[y],z+2);
	}
	for(int i=1;i<=(n<<1);i++) f[i%n+1]=min(f[i%n+1],f[(i-1)%n+1]+2);
	for(int i=1;i<=n;i++) add(i,i%n+1,f[i]);
	sort(a+1,a+tot+1,cmp);
	for(int i=1;i<=tot;i++){
		int aa=find(a[i].x),b=find(a[i].y);
		if(aa!=b) ans+=a[i].w,fa[aa]=b;
	}
	printf("%lld\n",ans);
	return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int X; cin >> X;
	int sum = 0;
	for (int k = 1;; k++) {
		sum += X;
		if (sum % 360 == 0) {
			cout << k << endl;
			return;
		}
	}
}

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


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

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

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( a > b ) { a = b; return 1; } return 0; }

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

struct UnionFind{
    vector<int> par, rank;

    UnionFind( int N ){
        par.resize( N ), rank.resize( N );
        REP( i, N ) par[i] = i, rank[i] = 0;
    }

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

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

    void unite( int x, int y ){
        x = root( x ), y = root( y );

        if( x == y ) return;
        if( rank[x] < rank[y] ) swap( x, y );
        if( rank[x] == rank[y] ) rank[x]++;
        par[y] = x;
    }
};

signed main(){
    int N, M; cin >> N >> M;
    vector<int> p( N );
    REP( i, N ) cin >> p[i];

    UnionFind uf( N );
    REP( i, M ){
        int x, y; cin >> x >> y;
        x--, y--;
        uf.unite( x, y );
    }

    int ans = 0;
    REP( i, N ){
        if( uf.same( i, p[i] - 1) ) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

#define MMAX (1000*1000)
pair<int, int> _next[MMAX];
int _in[MMAX];
int _day[MMAX];

int getindex(int i, int j, int n)
{
    return min(i, j) * n + max(i, j);
}

bool searchsub(int day, int next, queue<int> &q)
{
    if( next < 0 ) return true;
    _in[next]--;
    _day[next] = max(_day[next], day);
    if( _in[next] == 0 ) q.push(next);
    return false;
}


int main()
{
    int n; cin >> n;
    vector<int> first(n);
    rep(i, n * n) { _next[i].first = -1;  _next[i].second = -1; _in[i] = 0; _day[i] = -1;}

    rep(i, n)
    {
        int pre = -1;    
        rep(j, n - 1)
        {
            int a; cin >> a; a--;
            int index = getindex(i, a, n);
            if(j == 0)
            {
                 first[i] = index;
            }
            else
            {
                if( _next[pre].first < 0 )
                {
                     _next[pre].first = index;
                }
                else
                {
                     _next[pre].second = index;
                }
            }
            _in[index]++;
            pre = index;
        }
    }

    int ans = 0;
    queue<int> q;
    rep(i, n)
    {
        searchsub(1, first[i], q);
    }

    while(!q.empty())
    {
        int index = q.front();
        q.pop();
        ans = max(ans, _day[index]);
        searchsub(_day[index] + 1, _next[index].first, q);
        searchsub(_day[index] + 1, _next[index].second, q);
    }
    bool flag = false;
    rep(i, n * n)
        if( _in[i] > 0 ) flag = true;

    if( flag )
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }

    return 0;    
}

Measured memory_bytes: 19224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, r, p, c;
V v;

int main(){
	while (cin >> n >> r&&n + r){
		REP(i, n){
			v.push_back(n - i);
		}
		REP(i, r){
			cin >> p >> c;
			V t;
			REP(i, c){
				t.push_back(v[p - 1 + i]);
			}
			REP(i, p - 1){
				t.push_back(v[i]);
			}
			FOR(i, p - 1 + c, n){
				t.push_back(v[i]);
			}
			v = t;
		}
		cout << v[0] << endl;
		v.clear();
	}
}

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

int main(){
    int n, m; cin >> n >> m;
    vector<int> a(m);
    vector<int> dp(n+1);
    for(int i = 0; i < m; i++){
        cin >> a[i];
    }
    dp[0] = 0;
    for(int i = 1; i <= n; i++){
        dp[i] = dp[i-1] + 1;
        for(int l = 0; l < m; l++){
            if(i - a[l] >= 0){
                dp[i] = min(dp[i], dp[i-a[l]] + 1);
            }
        }
    }
    cout << dp[n] << endl;
}


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

#define ff first
#define ss second
#define pb push_back

const int MAXN = 2e5 + 100, maxval = 2010, mod = 1e9 + 7;

int n;
int a[MAXN], b[MAXN];
int dp[maxval << 1][maxval << 1];
long long fact[MAXN], invfact[MAXN];
long long ans;

long long pw(long long a, long long b) {
    if (!b)
        return 1LL;
    long long tmp = pw(a, b / 2);

    tmp = tmp * tmp % mod;

    if (b & 1)
        tmp = tmp * a % mod;
    return tmp;
}

inline void sum(int &a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
    else if (a < 0)
        a += mod;
}

long long comb(int n, int r) {
    return fact[n] * (invfact[r] * invfact[n - r] % mod) % mod;
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    fact[0] = 1;
    invfact[0] = pw(fact[0], mod - 2);

    for (int i = 1; i < MAXN; i++) {
        fact[i] = fact[i - 1] * i % mod;
        invfact[i] = pw(fact[i], mod - 2);
    }

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        dp[maxval - a[i]][maxval - b[i]]++;
    }

    for (int i = 0; i < maxval * 2 - 2; i++)
        for (int j = 0; j < maxval * 2 - 2; j++) {
            sum(dp[i + 1][j], dp[i][j]);
            sum(dp[i][j + 1], dp[i][j]);
        }

    for (int i = 0; i < n; i++)
        ans = (ans + dp[maxval + a[i]][maxval + b[i]]) % mod;

    for (int i = 0; i < n; i++)
        ans = (ans - comb(2 * a[i] + 2 * b[i], 2 * a[i]) + mod) % mod;

    cout << ans * invfact[2] % mod << '\n';
    return 0;
}


Measured memory_bytes: 68096
#include <iostream>

int main(){
  int h, w;
  while(1){
    std::cin >> h >>  w;
    if(h==0 && w == 0)
      return 0;
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
        std::cout << '#';
      }
      std::cout << '\n';
    }
    std::cout << '\n';
  }
  return 0;
}



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

typedef long long LL;
const int N = 1005, K = 30;

std::vector<LL> v;
LL n, x[N], y[N];

void solve(LL x, LL y, int dep) {
	if (dep == v.size()) return void(std::cout << '\n');
	if (std::abs(x) > std::abs(y))
		if (x < 0) x += v[dep], std::cout << 'R';
		else x -= v[dep], std::cout << 'L';
	else
		if (y < 0) y += v[dep], std::cout << 'U';
		else y -= v[dep], std::cout << 'D';
	solve(x, y, dep + 1);
}
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) {
		std::cin >> x[i] >> y[i];
		if ((x[i] ^ x[1] ^ y[i] ^ y[1]) & 1)
			return std::cout << "-1\n", 0;
	}
	for (int i = K; ~i; --i) v.push_back(1LL << i);
	if ((x[1] ^ y[1] ^ 1) & 1) v.push_back(1);
	std::cout << v.size() << '\n';
	for (LL i : v) std::cout << i << ' ';
	std::cout << '\n';
	for (int i = 1; i <= n; ++i) solve(-x[i], -y[i], 0);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
#include <cassert>
#include <string>

using namespace std;
using ll = long long;

int main()
{
	int n;
	cin >> n;
	vector<double> val;
	vector<string> dig;

	for (int i = 0; i < n; i++) {
		double tmp;
		string tmp2;
		cin >> tmp >> tmp2;

		val.push_back(tmp);
		dig.push_back(tmp2);
	}

	//for (int i = 0; i < n; i++) {
	//	cout << val[i] << " " << dig[i] << endl;
	//}

	double res = 0;
	for (int i = 0; i < n; i++) {
		double tmp;
		if (dig[i] == "JPY") {
			tmp = val[i];
		} else if (dig[i] == "BTC") {
			tmp = val[i] * 380000.0;
		} else
			assert(false);
		res += tmp;
	}

	cout << res << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string N;
  cin >> N;
  if(N[0]=='9' || N[1]=='9'){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)


{


int a, b;


scanf("%d %d", &a, &b);


if(a < b)


{


printf("a < b\n");


}


else if (a > b)


{


printf("a > b\n");

}


else if (a == b)


{


printf("a == b\n");


}


return 0;


}

Measured memory_bytes: 580
#include<stdio.h>

int n, A[20];

int solve(int i, int m);

int main(){
  int q,m[200],i,judge,j;

  scanf("%d",&n);

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

  scanf("%d",&q);



  
  for(i = 0; i < q; i++){
    scanf("%d",&m[i]);
  }

  for(i = 0; i < q; i++){
    for(j = 0; j < n; j++){
      
      judge =  solve(j,m[i]);
      
      if(judge == 1){
	printf("yes\n");
	break;
      }
    }
    if (judge != 1)printf("no\n");
  }
  
  return 0;
}

int solve(int i, int m){
  int res;
  if(m == 0){
    return 1;
  }
  if(i >= n){
    return 0;
  }

  res = solve(i+1,m) || solve(i+1, m - A[i]);

 
  return res;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> vec(H);
  for (int i = 0; i < H; i++) {
  cin >> vec.at(i);
  vec.at(i) = '#' + vec.at(i) + '#';
  }
  
  string edge = "#";
  for (int j = 0; j < W + 1; j++) {
    edge += '#';
  }
  
  cout << edge << endl;
  for (int i = 0; i < H; i++) {
   cout << vec.at(i) << endl;
  }
  cout << edge << endl;
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val N = readLine()!!.toInt()
    val Larr = readLine()!!.split(" ").map(String::toInt)
    assert(Larr.size == N)
    (if (Larr.fold(0) {sum,ele -> sum + ele} - 2*Larr.max()!! > 0){"Yes"} else {"No"}).run(::println)
}
 

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

using int64 = long long;
const int64 kMod = 1000000007;

tuple<int64, int64, int64> extGcd(int64 x, int64 y) {
  int64 g0 = x, g1 = y;
  int64 a0 = 1, a1 = 0;
  int64 b0 = 0, b1 = 1;
  while (g1 > 0) {
    int64 q1 = g0 / g1;
    int64 g2 = g0 % g1;
    int64 a2 = a0 - q1 * a1;
    int64 b2 = b0 - q1 * b1;
    g0 = g1;
    g1 = g2;
    a0 = a1;
    a1 = a2;
    b0 = b1;
    b1 = b2;
  }
  if (a0 < 0) {
    a0 += y;
    b0 -= x;
  }
  return {g0, a0, b0};
}

int64 inv(int64 x) {
  auto t = extGcd(x, kMod);
  return get<1>(t);
}

int64 Comb(int64 n0, int64 r0) {
  if (r0 * 2 > n0)
    return Comb(n0, n0 - r0);
  int64 num = 1;
  int64 den = 1;
  for (int64 n = n0, r = r0; r; --n, --r) {
    num = num * n % kMod;
    den = den * r % kMod;
  }
  int64 ret = num * inv(den) % kMod;
  return ret;
}

int main() {
  int64 h, w, a, b;
  cin >> h >> w >> a >> b;

  int64 c0 = 1;
  int64 c1 = Comb(w - 1 + a - 1, a - 1);
  int64 ret = Comb(h + w - 2, h - 1) - c0 * c1;
  if (ret < 0)
    ret += kMod;
  for (int64 i = 2; i <= b; ++i) {
    c0 = c0 * (h - a + i - 2) % kMod * inv(i - 1) % kMod; 
    c1 = c1 * inv(a + w - i) % kMod * (w - i + 1) % kMod;
    ret -= c0 * c1 % kMod;
    if (ret < 0)
      ret += kMod;
  }
  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define DIVISOR 1000000007

int main(){
	long power=1;
	int i;
	int N;

	scanf("%d", &N);

	for(i=1; i<=N; i++){
		power *= i;
		power %= DIVISOR;
	}

	printf("%ld\n", power);

	return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
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; }
using namespace std;

const int mx = 100005;
typedef pair<int, int> pa;
#define to first
#define id second

int N, M;
vector<pa> G[mx];
int deg[mx], par[mx];
bool v_used[mx], e_used[mx], tree_used[mx];

void make_a_tree(int v = 0, int p = -1){
    v_used[v] = true;
    par[v] = p;
    for(pa e : G[v]){
        if(!v_used[e.to]){
            e_used[e.id] = true;
            tree_used[e.id] = true;
            make_a_tree(e.to, v);
        }
    }
}

void adjust(int v = 0){
    for(pa e: G[v]){
        if(tree_used[e.id] and e.to != par[v]){
            adjust(e.to);
        }
    }
    if(par[v] == -1)return;
    if(deg[v] % 2 == 0){
        cout << par[v]+1 << ' ' << v+1 << '\n';
        deg[par[v]]++;
    }else{
        cout << v+1 << ' ' << par[v]+1 << '\n';
        deg[v]++;
    }
}

signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    rep(i, M){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(pa(b, i));
        G[b].push_back(pa(a, i));
    }

    if((M % 2) == 1){
        cout << -1 << '\n';
        return 0;
    }

    make_a_tree();
    rep(i, N){
        for(pa e : G[i]){
            if(!e_used[e.id]){
                cout << i+1 << ' ' << e.to+1 << '\n';
                e_used[e.id] = true;
                deg[i]++;
            }
        }
    }

    adjust();
    return 0;

}

Measured memory_bytes: 16512
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
int dp[101][100001];
signed main(){
    int n,w;
    cin>>n>>w;
    P p[114514];
    for(int i=0;i<n;i++){
        cin>>p[i].first>>p[i].second;
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){
            if(i==0)dp[i][j]=0;
            else {
                if(j-p[i-1].first>=0){
                    dp[i][j]=max(dp[i-1][j],dp[i-1][j-p[i-1].first]+p[i-1].second);
                }else{
                    dp[i][j]=dp[i-1][j];
                }
            }
        }
    }
    cout<<dp[n][w]<<endl;
    return 0;
}


Measured memory_bytes: 80896
#include <iostream>
#include <vector> 
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <cerrno>
#include <stdio.h>
#include <stdlib.h>
#include <cfenv>
#include <stack>
#include <math.h>
#include <iomanip>
#include <limits>
#include <queue>
#define ll long long int
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    int N;
    cin >> N;

    int ret = 100000;

    for(int i=0;i<=N;i++){

        int tmp = i;
        int res = 0;

        while(tmp>0){
            res += tmp%6;
            tmp/=6;
        }

        tmp = N-i;
        
        while(tmp>0){
            res += tmp%9;
            tmp/=9;
        }

        if(ret>res){
            ret = res;
        }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            const string ANSUCCESS = "No";
            const string SUCCESS = "Yes";
            var input = Console.ReadLine();
            var first = input.First();

            var input2 = input.Replace(first, ' ').Replace(" ", "");
            if (input2.Length != 2)
            {
                Console.WriteLine(ANSUCCESS);
                return;
            }

            var input3 = input2.Replace(input2.First(), ' ').Replace(" ", "");
            if (input3.Length != 0)
            {
                Console.WriteLine(ANSUCCESS);
                return;
            }

            Console.WriteLine(SUCCESS);

        }
    }
}

Measured memory_bytes: 13268
#pragma region def
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
using pint = pair<int, int>;
const int INF = 1e9;
const long long llINF = 1e18;
#pragma endregion

int main () {
    int n, m, c;
    cin >> n >> m >> c;
    vint b(m);
    rep(i, m) cin >> b[i];
    vvint a(n, vint(m));
    rep(i, n) {
        rep(j, m) cin >> a[i][j];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int sum = c;
        for (int j = 0; j < m; j++) {
            sum += a[i][j] * b[j];
        }
        //cout << sum << endl;
        if (sum > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    char str[max]; cin >> str;
    int i; char tmp = 'R';
    int ans[max]={};
    int cnt=0, j=0, len=strlen(str);
    for (int i=0; i<len;i++) {
        if (tmp==str[i]) {
            cnt++;
            continue;
        }
        if (tmp=='R') {
            j=i; 
            ans[j] += cnt/2;
            ans[j-1] += (cnt+1)/2;
        } else {
            ans[j-1] += cnt/2;
            ans[j] += (cnt+1)/2;
        }
        cnt = 1;
        tmp=str[i];
    }
    ans[j-1] += cnt/2;
    ans[j] += (cnt+1)/2;
    int nn = strlen(str);
    for (int i=0; i<nn; i++) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 896
import heapq
n,m=map(int,input().split())
w=[[] for i in range(m)]
for i in range(n):
  a,b=map(int,input().split())
  a-=1
  if a>=m:
    continue
  w[a].append(-b)

h=[]
c=0
for i in range(m):
  for j in w[i]:
    heapq.heappush(h,j)
  try:
    c+=heapq.heappop(h)
  except:
    pass
print(-c)

Measured memory_bytes: 88960
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int N, X;
  cin >> N >> X;
  vector<int> m(N);
  rep(i, N){
    cin >> m.at(i);
  }
  int nec = accumulate(all(m), 0);
  X -= nec;
  int mini = m.at(0);
  rep(i, N){
    chmin(mini, m.at(i));
  }
  int res = X / mini;
  cout << N + res << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
const int maxn=100010;
struct rec{
	int data,next,dis;
}a[maxn*2];
long long dis[maxn],first[maxn],n,m,x,y,z,k,tot=0;

void read(long long &k) {
	k=0; int f=1; char c=getchar();
	while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while ('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
	k*=f;
}
int log2(int x) {
	return ceil(log(x)/log(2));
}
void add(int x,int y,int z) {
	tot++;
	a[tot].data=y;
	a[tot].dis=z;
	a[tot].next=first[x];
	first[x]=tot;
}
void dfs(int u,int fa,int d) {
	dis[u]=dis[fa]+d;
	int x=first[u];
	while (x!=0) {
		if (a[x].data!=fa) dfs(a[x].data,u,a[x].dis);
		x=a[x].next;
	}
}
int main() {
	read(n);
	for (int i=1;i<n;i++) {
		read(x); read(y); read(z);
		add(x,y,z); add(y,x,z);
	}
	read(m); read(k);
    dfs(k,0,0);
	for (int i=1;i<=m;i++) {
    	read(x); read(y);
    	printf("%lld\n",dis[x]+dis[y]);
    }
	return 0;
}



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

typedef long long ll;

ll gcd(ll x, ll y){
  if(x % y == 0){
    return y;
  } else { 
    return gcd(y, x%y);
  }
}

int main(){
  int N;
  cin >> N;
  ll tmpans = 1;
  for(int i = 0; i < N; i++){
    ll tmp;
    cin >> tmp;
    tmpans = tmpans / gcd(tmpans, tmp);
    tmpans = tmpans * tmp;
  }
  cout << tmpans << endl;
  
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

for i in range(1, N+1):
    a[i] = a[i-1] + a[i]
for i in range(1, M+1):
    b[i] = b[i-1] + b[i]

cnt = 0
b_idx = M
for i in range(N+1):
    if a[i] > K:
        break
    for j in range(b_idx, -1, -1):
        if a[i] + b[j] <= K:
            cnt = max(cnt, i+j)
            b_idx = j
            break
print(cnt)

Measured memory_bytes: 119388
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long t1,t2,a1,a2,b1,b2;cin>>t1>>t2>>a1>>a2>>b1>>b2;
    long long x = a1*t1+a2*t2,y=b1*t1+b2*t2;
    
    if(x==y){
        cout<<"infinity"<<endl;
        return 0;
    }
    //long long r = t1*a1-t1*b1;
    if((x>y&&a1<b1)||(x<y&&a1>b1)){
        long long A = (a1-b1)*t1;
        long long B = y-x;
        long long n=A/B;
        n*=2;
        if(A%B==0)n--;
        cout<<1+n<<endl;
        return 0;
    }
    cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 256
K = [0 for _ in range(10 ** 5 + 10)]
N = int(input())
A = list(map(int,input().rstrip().split(" ")))
ans = 0
for i in A:
    K[i] += 1
    ans += i
Q = int(input())
for i in range(Q):
    B,C = map(int,input().rstrip().split(" "))
    q = K[B]
    K[B] = 0
    K[C] += q
    ans += (C - B) * q
    print(ans)


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

int main(){
    int N;
    string S1, S2;
    cin >> N >> S1 >> S2;
    queue<int> q;
    bool one = true;
    for (int i = 0; i < S1.size() - 1; i++){
        if (S1.at(i) == S1.at(i + 1)){
            if (i == 0) q.push(0);
            q.push(1);
            one = false;
            //cout << "case1" << endl;
        }
        else{
            if (i > 0 && i < S1.size() - 2){
                if (S1.at(i - 1) == S1.at(i)) {
                    //cout << "case2" << endl;
                    one = true;
                    continue;
                }
                else{
                    q.push(0);
                    //cout << "case3" << endl;
                }
                
            }
            else {
                q.push(0);
                //cout << "case4" << endl;
            }
        }
    }
    if (one) q.push(0);
    
    /*
    while (!q.empty()){
        int ans = q.front();
        q.pop();
        cout << ans << endl;
    }
    */
    int64_t ans = 3;
    int re = q.front();
    q.pop();
    while (!q.empty()){
        int p = q.front();
        q.pop();
        if (p == 0){
            if (re == 0){
                ans *= 2;
                ans %= 1000000007;
            }
            else {
                ans *= 1;
                ans %= 1000000007;
            }
        }
        else {
            if (re == 0){
                ans *= 2;
                ans %= 1000000007;
            }
            else {
                ans *= 3;
                ans %= 1000000007;
            }
        }
        re = p;
       // cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
v = list(map(int,input().split()))

countT = np.bincount(v[0::2])
top = countT.argsort()[::-1]
countU = np.bincount(v[1::2])
under = countU.argsort()[::-1]

if top[0]==under[0]:
    print(N-max(countT[top[0]]+countU[under[1]], countT[top[1]]+countU[under[0]]))
else:
    print(N-countT[top[0]]-countU[under[0]])


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int n;
		cin >> n;
		if (!n)break;
		vector<string> v(n);
		REP(i, n) cin >> v[i];
		vi cnt(n,0);
		vi b;
		REP(i, n) {
			REP(j, v[i].size()) {
				if (v[i][j] == '.')cnt[i]++;
				else break;
			}
		}
		REP(i, n) {
			FOR(j,i+1,n) {
				if (cnt[i] == cnt[j]) {
					int flag = 1;
					REP(k, j - i) {
						if (cnt[i + k] < cnt[i])flag = 0;
					}
					if (flag) {
						REP(k, j - i) {
							v[i + k][cnt[i] - 1] = '|';
						}
					}
				}
			}
		}
		REP(i, n) {
			if(i!=0)v[i][cnt[i] - 1] = '+';
		}
		REP(i, n) {
			REP(j, v[i].size()) {
				if (v[i][j] == '.')v[i][j] = ' ';
			}
		}
		REP(i, n) {
			cout << v[i] << endl;
		}
	

	}
	return 0;
}

Measured memory_bytes: 3420
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using ld = long double;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vd = vector<double>;
using Vld = vector<long double>;
using Vll = vector<vector<ll> >;
using Vldd = vector<vector<ld> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Pli = pair<ll, int>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

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; }

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX / 10000;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

ll g(int n) {
	return ll(n) * (n + 1) / 2;
}

int main()
{
	int x;
	cin >> x;
	ll ans = 0;
	for (int i = 1; i <= x; i++) {
		ans += i * g(x / i);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
n=int(input())
a=[]
l=[[] for i in range(n)]
ind=[0 for i in range(n)]
s=set()
ans=1
from collections import deque
q=deque([])
for i in range(n):
    tmp=[int(j)-1 for j in input().split()]
    a.append(tmp)
    for j in tmp:
        if i<j:
            l[i].append((i,j))
        else:
            l[i].append((j,i))
    q.append(l[i][0])
ll=[]
while q:
    p=q.popleft()
    if p in s:
        s.remove(p)
        i,j=p
        if i in ll or j in ll:
            ans+=1
            ll=[i,j]
        else:
            ll.append(i)
            ll.append(j)
        if ind[i]<n-2:
            ind[i]+=1
            q.append(l[i][ind[i]])
        if ind[j]<n-2:
            ind[j]+=1
            q.append(l[j][ind[j]])
    else:
        s.add(p)

for i in range(n):
    if ind[i]!=n-2:
        print(-1)
        exit()
print(ans)






Measured memory_bytes: 103132
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = inf + 7;
const int N = (int)2e5 + 5;
void solve(){
	int a,b,c;
	set<int>s;
	cin>>a>>b>>c;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	cout<<(sz(s)==2?"Yes":"No");
}


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

Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define rep(i, n) for(int  i = 0; i < n; i++)

int main(){
    int n;
    cin >> n;
    int d[n];
    rep(i, n) cin >> d[i];
    int ans = 0;
    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            ans += d[i] * d[j];
        }
        
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

using namespace std;

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

  long long n, m, d;
  cin >> n >> m >> d;

  double ans = 0.0;
  if (d == 0) {
    ans = (m - 1) * 1.0 / n;
  } else {
    ans = (m - 1) * 2.0 * (n - d) / n / n;
  }
  cout << fixed << setprecision(10) << ans << endl;

  return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;

    int cnt = 0;
    for (int i = 1; i < n; i++)
        if (s[i] == 'E')
            cnt++;
    int ans = cnt;

    for (int i = 1; i < n; i++)
    {
        if (s[i] == 'E')
            cnt--;
        if (s[i - 1] == 'W')
            cnt++;
        ans = min(ans, cnt);
    }

    OP(ans);

    return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    int n, cnt=0, acnt=0, bcnt=0, both=0;
    cin >> n;
    for (int i=0; i<n; i++) {
        string s;
        cin >> s;
        bool a=false;
        bool topb = (s[0] == 'B');
        for (auto c:s) {
            if (a && c == 'B') cnt++;
            if (c == 'A') a = true;
            else a = false;
        }
        if (a && topb) both++;
        else if (a) acnt++;
        else if (topb) bcnt++;
    }
    //cerr << acnt << bcnt << both << cnt << '\n';
    int ans;
    if (acnt > 0 && bcnt > 0) ans = min(acnt, bcnt) + both + cnt;
    else if (acnt == 0 && bcnt == 0) ans = max(both - 1, 0) + cnt;
    else ans = both + cnt;
    cout << ans << '\n';
    return 0;
}


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

#ifdef _MSC_VER
#pragma warning(disable:4996)
#endif

using namespace std;

int main() {
	double a, b;
	cin >> a >> b;
	
	for (int value = 0; value <= 1250; value++) {
		if (floor(value * 0.08) == a && floor(value * 0.10) == b) {
			cout << value;
			return 0;
		}
	}
	cout << -1;
	return 0;
}



Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
a=min(A)
S={n%a for n in A if n%a!=0}

while len(S)>0:
    tmp=a
    a=min(S)
    S={n%a for n in S if n%a!=0}
    if tmp%a!=0:
        S.add(tmp%a)
print(a)


Measured memory_bytes: 62704
#include<stdio.h>
int main(){
	int a[1009],b[1009],c[1009];
	scanf("%s%s%s",a,b,c);
	
		printf("%c%c%c\n",a[0]-('a'-'A'),b[0]-('a'-'A'),c[0]-('a'-'A'));
	
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<numeric>
using namespace std;

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

    int ans = N % 1000;
    if(ans==0){
        cout << 0 << endl;;
    }
    else{
        cout << 1000-ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <numeric>
#include <iomanip>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
typedef pair<int,int> P;
const int MOD = 998244353;
const ll mod = 1e9 + 7;
const int mxN = 1e5 + 9;

char ar[7][7];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int H,K,W;
	string s;
	cin >> H >> W >> K;
	for(int i=0; i < H; i++){
        cin >> s;
        for(int j=0; j < W; j++) ar[i][j] = s[j];
	}
	ll ans = 0;
	for(int i=0; i < (1<<H); i++){
        for(int j=0; j < (1<<W); j++){
            int cnt = 0;
            for(int i2 = 0; i2 < H; i2++){
                for(int j2 = 0; j2 < W; j2++){
                    if( (i>>i2)&1 ) continue;
                    if( (j>>j2)&1 ) continue;
                    if( ar[i2][j2] == '#' ) ++cnt;
                }
            }
            if( cnt == K ) ++ans;
        }
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3608
//#include <ext/pb_ds/assoc_container.hpp> 
    // #include <ext/pb_ds/tree_policy.hpp> 
    #include <iostream>
    #include <iomanip>
    #include <sstream>
    #include <cstring>
    #include <vector>
    #include <deque>
    #include <queue>
    #include <set>
    #include <map>
    #include <valarray>
    #include <iterator>
    #include <functional>
    #include <limits>
    #include <algorithm>
    #include <numeric>
    #include <cmath>
    #include <cassert>
    #include <unordered_map>
    #include <unordered_set>
    #include <stack>
    using namespace std;
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define trace(x) cerr << #x << ": " << x << " " << endl;
     
    typedef int64_t ll;
     
    #define endl '\n'
    #define int ll
    ll mod=1e9+7;
    ll mod1=1e9+5;
     
    ll power(ll a,ll b)
    {
        if(b==0) return 1;
        else if(b%2==0)
            return power((((a%mod)*(a%mod))%mod),b/2)%mod;
        else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
    }
     
    // using namespace __gnu_pbds;
    // #define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
    //find_by_order(k)  returns iterator to kth element starting from 0;
    //order_of_key(k) returns count of elements strictly smaller than k;
    //erase,insert same as normal set
  
    int32_t main()
    {
        IOS
 
        
       int n,k;
       cin>>n>>k;
       int sum=0;
       int a[n+1];
       for(int i=1;i<=n;++i)
        cin>>a[i];
       sort(a+1,a+n+1);
       reverse(a+1,a+n+1);
       for(int i=k+1;i<=n;++i)
       sum+=a[i];
       cout<<sum; 


    }       

Measured memory_bytes: 1920
import sys
input = sys.stdin.readline

N, X, Y = map(int, input().split())
X -= 1
Y -= 1

ans = [0 for _ in range(N)]
for i in range(N) :
    for j in range(i+1, N) :
        k = min(j-i, abs(X-i) + abs(Y-j) + 1)
        ans[k] += 1

for i in range(N-1) :
    print(ans[i+1])


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

bool solve();

int main()
{
	if (solve())
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

bool solve()
{
	std::string w;
	std::cin >> w;
	int count[26]{};
	for (auto& c: w) count[c - 'a']++;
	for (int i{}; i < 26; i++)
		if (count[i] & 1)
			return false;

	return true;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <cassert>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n;
	int a[100005];
	int b[100005]={};
	int count=0,now=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}

	while(true){
		if(b[now]==1){
			count = -1;
			break;
		}
		if(now==1){
			break;
		}
		b[now] = 1;
		count++;
		now = a[now] -1;
		assert(now>=0);

	}

	cout<<count<<endl;
}

Measured memory_bytes: 1024
from queue import deque

while True:
    n, k = map(int, input().split())
    if not n:
        break
    q = deque(int(input()) for _ in range(k))
    ans = cur = sum(q)
    for _ in range(n - k):
        new = int(input())
        q.append(new)
        old = q.popleft()
        cur += new - old
        ans = ans if ans > cur else cur
    print(ans)


Measured memory_bytes: 8952
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    for (int i = 0; i < n; ++i)
        cin >> x[i];
    ll res = 0;
    for (int i = 1; i < n; ++i) {
        res += min((x[i] - x[i - 1]) * a, b);
    }
    cout << res << endl;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 1024
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	x, _ := strconv.Atoi(sc.Text())
	x--

	sc.Scan()
	y, _ := strconv.Atoi(sc.Text())
	y--

	d := make([][]int, n)
	for i := 0; i < n; i++ {
		d[i] = make([]int, n)
	}

	result := make([]int, n-1)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			result[min(j-i, abs(x-i)+abs(y-j)+1)-1]++
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for _, r := range result {
		w.WriteString(fmt.Sprintf("%d\n", r))
	}
	w.Flush()
}

func abs(s int) int {
	if s < 0 {
		return -s
	}
	return s
}

func min(s ...int) int {
	minContent := s[0]
	for _, el := range s {
		if el < minContent {
			minContent = el
		}
	}
	return minContent
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;
  cin>>s>>t;
  int n=s.length();
  int i=0;
  while(i<n&&s[i]==t[i])
    i++;
  if(i<n)
    cout<<"No"<<endl;
  else if(i==n)
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int calc(int x){
    if(!(360 % x)) return 360 / x;
    return calc(360 % x) * (360 / x);
}
inline int read(void){
    int num = 0, f = 1;
    char ch;
    while(!isdigit(ch=getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) num = num*10 + ch-'0', ch = getchar();
    return num * f; 
}
int main()
{
    int x = read();
    printf("%d\n", calc(x));
    return 0;
}


Measured memory_bytes: 3692
fn func(input_str: &str) {
    let mut iter = input_str.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut h_s = Vec::new();
    for _ in 0..n {
        let h: u32 = iter.next().unwrap().parse().unwrap();
        h_s.push(h);
    }

    let mut ans = 0;
    let mut cnt = 0;
    for i in 0..(n - 1) {
        if h_s[i] < h_s[i + 1] {
            if cnt > ans {
                ans = cnt;
            }
            cnt = 0;
        } else {
            cnt += 1;
        }
    }
    if cnt > ans {
        ans = cnt;
    }
    println!("{}", ans);
}

use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    func(&buf[..]);
}


Measured memory_bytes: 6396
x, n = map(int,input().split())
if n != 0:
  p = list(map(int,input().split()))
p_change = []
m = 0
if n == 0:
  print(x)
else:
    for i in p:
        p_change.append(abs(i-x))
 
    if x in p:
        for i in range(n+1):
            if i != 0 and p_change.count(i) != 2:
                m = i
                break
        if x-m in p:
            print(x+m)
        else:
            print(x-m)
    else:
        print(x)

Measured memory_bytes: 9212
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
sys.setrecursionlimit(int(1e+6))
MOD = int(1e+9) + 7
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

def main():
    N = i2n()
    A = i2nn()
    A.sort()
    A.reverse()
    # 5 4 3 2 1 1
    # 0: 5
    # 5: 5 4
    # 9: 5 3 4
    # 13: 5 3 4 2
    # 16: 5 1 3 4 2
    # 19: 5 1 3 1 4 2
    n = 0
    for i in range(1, N):
        n += A[i // 2]
    print(n)

main()


Measured memory_bytes: 34540