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

#define int long long
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; }

int a[200010];
int ans[200010];
signed main(){
	int n;
	cin >> n;

	int all = 0;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		all ^= a[i];
	}

	for(int i = 0;i < n;i++){
		ans[i] = a[i] ^ all;
		cout << ans[i];
		if(i < n-1){
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 6700
import numpy as np

h,w = map(int,input().split())
n = int(input())
lst = list(map(int,input().split()))

g = []
for i in range(n):
    for _ in range(lst[i]):
        g.append(i+1)

arr = np.array(g)
arr = arr.reshape([h,w])

ans = []
for i in range(h):
    tmp = list(arr[i])
    if i%2 != 0:
        tmp.reverse()
    ans.append(tmp)

for i in range(h):
    print(*ans[i])

Measured memory_bytes: 13660
#include<iostream>                                                                
#include<queue>                                                                   
using namespace std;                                                              
                                                                                  
int main(void) {                                                                  
  priority_queue<int> q;                                                          
  int N, a, b, c;                                                                 
  cin >> N;                                                                       
  for (int i=0; i<N; i++) {                                                       
    cin >> a >> b >> c;                                                           
    q.push(a);                                                                    
    q.push(b);                                                                    
    q.push(c);                                                                    
    a=q.top();                                                                    
    q.pop();                                                                      
    b=q.top();                                                                    
    q.pop();                                                                      
    c=q.top();                                                                    
    q.pop();                                                                      
    bool f=false;                                                                 
    if (a*a==(b*b+c*c)) {                                                         
      f=true;                                                                     
    }                                                                             
    if (f) {                                                                      
      cout << "YES" << endl;                                                      
    } else {                                                                      
      cout << "NO" << endl;                                                       
    }                                                                             
  }                                                                               
  return 0;                                                                       
}                                                                                 
                                                                                  
                  

Measured memory_bytes: 3020
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 2*(int)1e5 + 10;

int n, a[N], pref[N];
int32_t main(){_

   cin>>n;

   for (int i = 1; i <= n; ++i)
   {
      cin>>a[i];
      pref[i] = pref[i-1] + a[i];
   }

   int ans = inf;

   for (int i = 1; i < n; ++i)
   {
      smin(ans, abs(pref[i] - (pref[n]-pref[i])));
   }
   
   cout<<ans;
   #warning make sure N size is correct!
   return 0;
}

Measured memory_bytes: 3328
let ans, s = ref max_int, read_line ()
let _ = String.(iter (fun d -> let c, l, cs = ref 0, ref @@ length s, Array.init (length s) (get s) in
  while List.exists ((<>) d) @@ Array.(to_list @@ sub cs 0 !l) do for i = 1 to !l - 1 do if cs.(i) = d then cs.(i - 1) <- d done; decr l; incr c done; ans := min !ans !c) s); Printf.printf "%d\n" !ans

Measured memory_bytes: 4608
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N,K,Q;
vector<long long> A;

int main(){
  while(cin>>N>>K>>Q){
    A.resize(N);
    for(int i=0; i<N; ++i) cin>>A[i];
    
    long long res=1LL<<60;
    for(int i=0; i<N; ++i){
      vector<long long> vec,tmp;
      for(int j=0; j<N; ++j){
        if(A[j]<A[i]){
          if(tmp.size()>=K){
            sort(tmp.begin(), tmp.end());
            for(int k=0; k<(int)tmp.size()-(K-1); ++k) vec.push_back(tmp[k]);
          }
          tmp.clear();
        }
        else tmp.push_back(A[j]);
      }
      if(tmp.size()>=K){
        sort(tmp.begin(), tmp.end());
        for(int k=0; k<(int)tmp.size()-(K-1); ++k) vec.push_back(tmp[k]);
      }
      sort(vec.begin(),vec.end());
      if(vec.size()>=Q) chmin(res,vec[Q-1]-vec[0]);
    }    
    
    cout<<res<<endl;
  }
}

Measured memory_bytes: 3672
// https://atcoder.jp/contests/abc143/tasks/abc143_c

#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl;
using namespace std;
int main() {
    int N;
    string S;
    cin >> N >> S;

    int mode = S[0];

    int ans = 1;
    for(int i = 1; i < N; i++) {
        if(S[i] != mode) {
            mode = S[i];
            ans++;
            //watch(ans);
        }
    }


    cout << ans << endl;
}

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

using namespace std;

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

const int MAX_N = 100005;

int main(){
    int n;
    cin >> n;
    vl d(n-1), g(n);
    ll ans = 0;
	rep(i,n-1){
        cin >> d[i];
    }
    rep(i,n){
        cin >> g[i];
        ans += g[i];
    }
	priority_queue<ll> l;
	priority_queue<ll,vector<ll>,greater<ll> > r;
    l.push(g[0]),r.push(g[0]);
    ll lsum = 0, rsum = 0;
	rep(i,n-1){
		lsum += d[i], rsum += d[i];
		if(g[i+1] < l.top()-lsum){
			l.push(g[i+1]+lsum), l.push(g[i+1]+lsum);
			ll val = l.top() - lsum;
			ans -= val - g[i+1];
			l.pop();
			r.push(val-rsum);
		}else if(r.top()+rsum < g[i+1]){
			r.push(g[i+1]-rsum), r.push(g[i+1]-rsum);
			ll val = r.top() + rsum;
            ans -= g[i+1] - val;
			r.pop();
			l.push(val+lsum);
		}else{
			l.push(g[i+1]+lsum);
			r.push(g[i+1]-rsum);
		}
	}
	cout << ans << "\n";
}



Measured memory_bytes: 9496
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int n;
char s1[100], s2[100];
int main() {
	scanf("%d", &n);
	scanf("%s%s", s1, s2);
	int pre = 0;
	long long ans = 1;
	for(int i = 0; i < n; i++) {
		if(s1[i] == s1[i + 1]){
			if(pre == 0) {
				ans *= 6;
			} else if(pre == 2){
				ans *= 2;
			} else ans *= 3;
			pre = 1;
			i++; 
		} else {
			if(pre == 0) {
				ans *= 3;
			} else if(pre == 2)  ans *= 2;
			pre = 2;
		}
		ans %= 1000000007;
	}
	printf("%lld", ans);
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a[100000 + 5];
int main(){
	int n,k,q;
	cin >> n >> k >> q;
	for(int i=0;i<q;i++){
		int  t;
		cin >> t;
		a[t]++;
	}
	for(int i=1;i<=n;i++){
		if(q-a[i]> k-1){
			cout << "No" << endl;
		}else{
			cout << "Yes" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

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

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

  for(i=a; i <= b; i++)
  {
    if(c % i == 0)
      k++;
  }
  
  printf("%d\n", k);

  return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<=(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) ((flag)?(int)1:(int)0)
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

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

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

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

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int a,b; cin>>a>>b;
  cout<<(a-1)*(b-1);
}












Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	char c;
	cin >> c;

	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
		cout << "vowel" << endl;
	} else {
		cout << "consonant" << endl;
	}

	return 0;
}


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

int main()
{
	ll a,b,c,d=0,e;
	cin>>a>>b>>c;
	e=max(a-c,d);
	if(e)cout<<e<<" "<<b<<endl;
	else cout<<e<<" "<<max(b-(c-a),d)<<endl;
	return 0;
}

Measured memory_bytes: 256
// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define loop(i, a) for (int i = 0; i < a; i++)
#define revloop(i, a) for (int i = a-1; i > -1; i--)
#define show(a) cout << a << "\n"
#define showloop(a, len) for (int i = 0; i < len; i++) cout << a[i] << "\n"
#define debug(a) cout << #a << ": " << a << "\n"
#define MOD 1000000007
#define V vector
#define S set
#define P pair
#define M map;
#define PQ priority_queue

int main() {
//    freopen("inputs.txt", "w", stdout);
//    int n = maxN;
//    loop(i, n) cout << i+1 << " ";
    //freopen("inputs.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int x, a, b;
    cin >> x >> a >> b;
    int d1 = abs(x - a);
    int d2 = abs(x - b);
    (d1 < d2)?show("A"):show("B");

    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    f = []
    i = 2
    while i * i <= n:
        if n % i == 0:
            f.append(i)
            if i * i != n:
                f.append(n // i)
        i += 1
    if n != 1:
        f.append(n)
    f.sort()
    answer = float("inf")
    for ff in f:
        answer = min(answer, ff + n // ff - 2)
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3272
#include<iostream>
using namespace std;
int main()
{
	int n,heya[4][3][10];
	for(int i=0;i<4;++i){
		for(int j=0;j<3;++j){
			for(int k=0;k<10;++k){
				heya[i][j][k]=0;
			}
		}
	}
	cin >> n;
	for(int i=0;i<n;++i){
		int b,f,r,v;
		cin >> b >> f >> r >> v;
		heya[b-1][f-1][r-1] += v;
	}
	for(int i=0;i<4;++i){
		for(int j=0;j<3;++j){
			for(int k=0;k<10;++k){
				cout << " " << heya[i][j][k];
			}
			cout << endl;
		}
		if(i==3)break;
		cout << "####################" << endl;
	}
	return 0;
}

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

using namespace std;

struct Data
{
  int cost;
  vector<int> l;

  bool operator<(const Data &other) const
  {
    return cost > other.cost;
  }
};

int main()
{
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> l(N);
  for (int i = 0; i < N; i++)
    cin >> l[i];
  int ans = 1e9;
  for (int a = 0; a < (1 << N); a++)
    for (int b = 0; a + b < (1 << N); b++)
    {
      int tmp = 0;
      vector<int> stick[3], cost(3, (int)1e5);
      vector<pair<int, int>> change[3];
      for (int i = 0; i < N; i++)
        if (a & (1 << i))
          stick[0].push_back(l[i]);
        else if (b & (1 << i))
          stick[1].push_back(l[i]);
        else
          stick[2].push_back(l[i]);
      for (int i = 0; i < 3; i++)
        for (int j = 0; j < (1 << stick[i].size()); j++)
          if (j != 0)
          {
            int tmp = 0, cost = -1;
            for (int k = 0; k < stick[i].size(); k++)
              if (j & (1 << k))
              {
                cost++;
                tmp += stick[i][k];
              }
            change[i].push_back({cost * 10, tmp});
          }
      if (change[0].size() == 0 || change[1].size() == 0 || change[2].size() == 0)
        continue;
      for (pair<int, int> t : change[0])
        cost[0] = min(cost[0], abs(t.second - A) + t.first);
      for (pair<int, int> t : change[1])
        cost[1] = min(cost[1], abs(t.second - B) + t.first);
      for (pair<int, int> t : change[2])
        cost[2] = min(cost[2], abs(t.second - C) + t.first);
      ans = min(ans, cost[0] + cost[1] + cost[2]);
    }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
S = input()
ans = []
for i in range(2):
    pre_ans = 0
    _S = [s for s in S]
    if _S[0] == '0':
        if i == 1:
            _S[0] = '1'
            pre_ans += 1
    else:
        if i == 0:
            _S[0] = '0'
            pre_ans += 1
    for j in range(1,len(S)):
        if _S[j-1] == '0':
            if _S[j-1] == _S[j]:
                _S[j] = '1'
                pre_ans += 1
        else:
            if _S[j-1] == _S[j]:
                _S[j] = '0'
                pre_ans += 1
    ans.append(pre_ans)
print(min(ans))

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

pair<int64_t, int> ar[1234 * 1234];
int64_t bests[1234 * 1234];
int64_t cbests[1234 * 1234];

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

   for (;;)
   {
      int n;
      int64_t c;
#ifdef _DEBUG
      const auto read =
#endif
         scanf("%d%" PRId64 "", &n, &c);
#ifdef _DEBUG
      if (read != 2)
         break;
#endif
      for (auto i = 0; i < n; i++)
         scanf("%" PRId64 "%d", &ar[i].first, &ar[i].second);

      int64_t m = 0;
      {
         //clockwise
         int64_t tv = 0, bv = 0;
         for (auto i = 0; i < n; i++)
         {
            tv += ar[i].second;
            bv = max(bv, tv - ar[i].first);
            bests[i] = bv;
         }
         m = max(m, bv);
      }
      {
         //counterclockwise
         int64_t tv = 0, bv = 0;
         for (auto i = n - 1; 0 <= i; --i)
         {
            tv += ar[i].second;
            const auto wd = c - ar[i].first;
            bv = max(bv, tv - wd);
            cbests[i] = bv;
         }
         m = max(m, bv);
      }
      //if (1 < n)
      {
         {
            //clockwise then counterclockwise
            int64_t bv = 0;
            for (auto i = 0; i < n - 1; i++)
            {
               const auto& wd = ar[i].first;
               const auto tv = bests[i] + cbests[i + 1] - wd;
               bv = max(bv, tv);
            }
            m = max(m, bv);
         }
         {
            //counterclockwise then clockwise
            int64_t bv = 0;
            for (auto i = n - 1; 0 < i; --i)
            {
               const auto wd = c - ar[i].first;
               const auto tv = cbests[i] + bests[i - 1] - wd;
               bv = max(bv, tv);
            }
            m = max(m, bv);
         }
      }
      cout << m << '\n';
#ifdef _DEBUG
      memset(bests, 0, sizeof bests);
      memset(cbests, 0, sizeof cbests);
#else
      break;
#endif
   }

   return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <deque>

using namespace std;

void show(vector<set<int>> paths) {
	printf("-----\n");
	for (int i = 1; i < paths.size(); i++) {
		printf("%2d: ", i);
		for (auto e : paths[i]) {
			printf("%2d ", e);
		}
		printf("\n");
	}
}

int main() {
	int n, m, a, b;
	cin >> n >> m;

	vector<set<int>> paths(n + 1);
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		paths[a].insert(b);
		paths[b].insert(a);
	}

	int pos;
	for (int i = 1; i <= n; i++) {
		if (paths[i].size() > 0) {
			pos = i;
		}
	}

	deque<int> deq = {pos};
	set<int> used = {pos};


	while (1) {
		bool all_uses = true;
		for (auto e : paths[deq.back()]) {
			if (used.count(e) == 0) {
				deq.push_back(e);
				used.insert(e);
				all_uses = false;
				break;
			}
		}

		if (all_uses) {
			break;
		}
	}

	while (1) {
		bool all_uses = true;
		for (auto e : paths[deq.front()]) {
			if (used.count(e) == 0) {
				deq.push_front(e);
				used.insert(e);
				all_uses = false;
				break;
			}
		}

		if (all_uses) {
			break;
		}
	}

	cout << deq.size() << endl;
	for (int i = 0; i < deq.size(); i++) {
		if (i != 0) {
			cout << " ";
		}
		cout << deq[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 19968
a = [input().split() for l in range(3)]
n = int(input())
b = list(input() for i in range(n))
c = [[0] * 3 for i in range(3)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if b[i] == a[j][k]:
                c[j][k] = 1

if (c[0][0] == 1 and c[0][1] == 1 and c[0][2] == 1) or(c[1][0] == 1 and c[1][1] == 1 and c[1][2] == 1) or(c[2][0] == 1 and c[2][1] == 1 and c[2][2] == 1) or(c[0][0] == 1 and c[1][0] == 1 and c[2][0] == 1) or(c[0][1] == 1 and c[1][1] == 1 and c[2][1] == 1) or(c[0][2] == 1 and c[1][2] == 1 and c[2][2] == 1) or(c[0][0] == 1 and c[1][1] == 1 and c[2][2] == 1) or (c[0][2] == 1 and c[1][1] == 1 and c[2][0] == 1):
    print("Yes")
else:
    print("No")


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

int main()
{
ll a , b , c , d ;
cin >> a >> b >> c >> d ;
while(1){
  c-=b;
  if(c<=0)break;
  a-=d;
  if(a<=0){
    ans="No";
    break;
  }
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 3624
import sys
from collections import Counter
sys.setrecursionlimit(10**7)
mo=10**9+7
n=10**5

n=int(input())
a=[int(i) for i in input().split()]
a.sort()
b=[]
if n%2==1:
    b.append(0)
    for i in range(1,n//2+1):
        b.append(i*2)
        b.append(i*2)
else:
    for i in range(n//2):
        b.append(i*2+1)
        b.append(i*2+1)

ans=pow(2,(n//2),mo)
for i in range(n):
    if a[i]!=b[i]:
        ans=0
#print(a,b)

print(ans)


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

using namespace std;

int main(){
  string S, T;
  cin >> S;
  cin >> T;
  
  int slen = S.length();
  int count = 0;
  for(int i; i<slen; i++){
    if(S[i] != T[i]) count++;
  }
  
  cout << count << endl;
  return 0;
}

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

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

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

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

template<typename T>
void O(T t){
  cout << t << endl;
}

  const double EPS = 1e-8;
  const double INF = 1e12;
  typedef complex<double> P;//????´???°????????¢?????????????????¨?§£???
  namespace std {
    bool operator < (const P& a, const P& b) {//x????????????
      return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
    bool sorty(const P& a, const P& b) {//y????????????
      return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
    }
  }
  double cross(const P& a, const P& b) {//??????
    return imag(conj(a)*b);
  }
  double dot(const P& a, const P& b) {//??????
    return real(conj(a)*b);
  }

  struct L : public vector<P> {//??´???
    L(){};
    L(const P &a, const P &b) {
      push_back(a); push_back(b);
    }
  };

  typedef vector<P> G;

  struct C {//???
    P p; double r;
    C(){};
    C(const P &p, double r) : p(p), r(r) { }
  };

  int ccw(P a, P b, P c) {//3????????????????????§????????§??????????????????
    b -= a; c -= a;
    if (cross(b, c) > 0)   return +1;       // counter clockwise
    if (cross(b, c) < 0)   return -1;       // clockwise
    if (dot(b, c) < 0)     return +2;       // c--a--b on line
    if (norm(b) < norm(c)) return -2;       // a--b--c on line
    return 0;
  }
  bool intersectSS(const L &s, const L &t) {
    return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
      ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
  }

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll q;
  cin >> q;
  double x,y;
  rep(i,q){
    cin >> x >> y;
    P a(x,y);
    cin >> x >> y;
    P b(x,y);
    cin >> x >> y;
    P c(x,y);
    cin >> x >> y;
    P d(x,y);
    L ab(a,b),cd(c,d);
    std::cout << intersectSS(ab,cd) << std::endl;
  }
  return 0;
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int,int> p;

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

string s;

int main(){
    ios::sync_with_stdio(false);
    cin >> s;
    stack<int> st;
    stack<p> st2;
    int sum =0;
    for(int i=0; i < s.size(); i++){
        if(s[i]=='\\'){
            st.push(i);
        }
        else if(s[i]=='/' & st.size()>0){
            int j=st.top();st.pop();
            sum+=i-j;
            int a=i-j;
            while(st2.size() > 0 && st2.top().first>j){
                a+=st2.top().second;st2.pop();
            }
            st2.push(make_pair(j,a));
        }
    }
    
    vector<int> ans;
    int t=0;
    while(st2.size()){ans.pb(st2.top().second);st2.pop();}
    reverse(ans.begin(),ans.end());
    cout << sum << endl;
    cout << ans.size();
    REP(i,ans.size()){
        cout << " ";
        t+=ans[i];
        cout << ans[i];
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
list<int> l;
int main()
{
	list<int>::iterator it;
	list<int>::iterator it2;
	it = l.end();
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int x;
		scanf("%d",&x);
		if(x == 0)
		{
			int y;
			scanf("%d",&y);
			l.insert(it, y);
			it--;
		}
		else if(x == 1)
		{
			int y;
			scanf("%d",&y);
			int i;
			if(y > 0)
			{
				for(i=0; i<y; i++) it++;
			}
			else for(i=0; i<abs(y); i++) it--;
		}
		else if(x == 2) 
		{
			it2 = it;
			it2++;
			l.erase(it);
			it = it2;
		}
	}
	for(it = l.begin(); it != l.end(); it++) printf("%d\n",*it);
	return 0;
}


Measured memory_bytes: 18644
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, D, ans;
  cin >> N >> D;
  if (N % (2*D+1) == 0)
    ans = N / (2*D+1);
  else
    ans = (N / (2*D+1)) + 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
for i in range(n):
  a[i],b[i]=map(int,input().split())
  
c=zip(a,b)
c=sorted(c)
a,b=zip(*c)
#print(a)
#print(b)
ans=0
for i in range(n):
  if (b[i]<m):
    ans+=a[i]*b[i]
    m-=b[i]
  else:
    ans+=a[i]*m
    break
    
print(ans)

Measured memory_bytes: 26936
/* ex 9_1
series2 */
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
//条件　文字列を格納するスタックを定義、push,pop
typedef struct stack {
    int size;
    int count;        //現在格納されている文字数
    char data[SIZE];  //データ内容そのもの
    char *top;  //外部からのアクセス部はdata配列の一番後ろの番地のアドレスをさす
} stack;

void init_stack(stack *stk) {
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}
void push(stack *stk, char data) {
    if (stk->count <
        stk->size) {  //用意したstackの要領未満の時、入力文字をトップアドレスに追加する
        stk->top--;
        *(stk->top) = data;
        stk->count++;
    }
}
char pop(stack *stk) {
    char latest;
    if (stk->count > 0) {  //文字が残っている時
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    } else {
        latest = '\0';  //文字が残っていない時null文字を返す
    }
    return latest;
}

void printout(
    stack
        stk) {  // stackなので、再帰的に呼び出すことで正しい順にする。(直接呼び出すのは、stackとしての設計に反する)
    char out = pop(&stk);
    if (out) {  // outがnull文字でない時
        printout(stk);
        printf("%c", out);
    }
}

int main(void) {
    stack stk;
    init_stack(&stk);
    char inp = ' ';
    while (inp != '\n') {
        scanf("%c", &inp);
        if (inp == 'B') {  // BackSpaceの時削除
            pop(&stk);
        } else if (inp != '\n') {//最終文字でない時追加する
            push(&stk, inp);
        }
    }
    printout(stk);
    printf("\n");

    return 0;
}

Measured memory_bytes: 1596
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int[] a = new int[N];
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < N; ++i) {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
            min = Math.min(min, a[i]);
        }

        _out.println((max - min));
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21972
from collections import deque

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
INF = 1001001001
dist = [[INF for _ in range(w)] for _ in range(h)]
dist[0][0] = 0

d = deque()
d.append([0, 0])
while(d):
    y,x = d.popleft()
    difflist = [[1,0], [0,1], [-1, 0], [0, -1]]
    for dy, dx in difflist:
        y2 = y + dy
        x2 = x + dx
        if 0 <= y2 < h and 0 <= x2 < w and maze[y2][x2] != '#' and dist[y2][x2] == INF:
            d.append([y2, x2])
            dist[y2][x2] = dist[y][x] + 1

distribution = [0]*(h*w)
ans = 0
for i in range(h):
    for j in range(w):
        if dist[i][j] != INF:
            distribution[dist[i][j]] += 1
        elif maze[i][j] == '.':
            ans += 1

if dist[h-1][w-1] != INF:
    distend = dist[h-1][w-1]
    ans += sum(distribution) - distend -1
    print(ans)
else:
    print(-1)

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

using namespace std;

#define M_DEBUG if (1)

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)

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

using lint = long long;
typedef unsigned long long int ullint;


/******************************************************************************
	Main
******************************************************************************/

#define L_MAX_N 100001

int main()
{
    int n = 0;
    cin >> n;
    assert(n >= 1 && n <= pow(10, 5));

    int abcs[L_MAX_N][3] = {0};
    rep(i, n){
        cin >> abcs[i][0] >> abcs[i][1] >> abcs[i][2];
        assert(abcs[i][0] >= 1 && abcs[i][0] <= pow(10, 4));
        assert(abcs[i][1] >= 1 && abcs[i][1] <= pow(10, 4));
        assert(abcs[i][2] >= 1 && abcs[i][2] <= pow(10, 4));
    }
    int points[L_MAX_N][3] = {0}; // i 日目に j (a:0, b:1, c:2) を選んだ場合の幸せ度
    rep(i, n){
        rep(j, 3){
            rep(k, 3){
                if (j == k) continue;
                chmax(points[i+1][k], points[i][j] + abcs[i][k]);
            }
        }
    }

	int ret = points[n][0];
	chmax(ret, points[n][1]);
	chmax(ret, points[n][2]);
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main()
{
  set<int> st;
  int n, k;
  cin >> n >> k;
  rep(i, k)
  {
    int d;
    cin >> d;
    rep(j, d)
    {
      int a;
      cin >> a;
      st.insert(a);
    }
  }

  cout << n - st.size() << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;
using ll = long long;

const ll INF = 1LL << 50;

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

    ll dp[N + 1][W + 1];
    fill(dp[0], dp[1], -INF);
    dp[0][0] = 0;
    for (int i = 1; i <= N; ++i) {
        memcpy(dp[i], dp[i - 1], sizeof(dp[i]));
        int w;
        ll v;
        cin >> w >> v;

        for (int ws = 0; ws + w <= W; ++ws) {
            dp[i][ws + w] = max(dp[i][ws + w], dp[i - 1][ws] + v);
        }
    }

    cout << *max_element(dp[N], dp[N + 1]) << endl;
    return 0;
}


Measured memory_bytes: 79104
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    double a[n];
    rep(i,n)cin>>a[i];
    double ans = 0;
    rep(i,n)ans += 1.0/a[i];
    cout<<fixed<<setprecision(10)<<1.0/ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	string s,t ;
	cin >> s >> t ;
	for(int i=s.size()-t.size();i>=0;i--){
		bool ok = true ;
		for(int j=0;j<t.size();j++){
			if(s.at(i+j)!='?'&&s.at(i+j)!=t.at(j)){
				ok = false ;
				break ;
			}
		}
		if(ok){
			for(int j=0;j<t.size();j++) s.at(i+j) = t.at(j) ;
			for(int j=0;j<s.size();j++) if(s.at(j)=='?') s.at(j) = 'a' ;
			cout << s << endl ;
			return 0 ;
		}
	}
	cout << "UNRESTORABLE" << endl ;
}


Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    vector<ll> X(N);
    vector<ll> Y(N);
    rep(i, N) {
        cin >> X[i];
        Y[i] = X[i];
    }
    sort(all(Y));
    ll tmpA = Y[N/2];
    ll tmpB = Y[N/2-1];
    rep(i, N) {
        if (X[i] >= tmpA) {
            print(tmpB);
        } else {
            print(tmpA);
        }
    }
    return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, k,  m, y, q ;
string s, t, d;
ld w;

// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n>>k;
	vector<ld> a(n);
	for(ll i=0;i<n;i++) {
		cin>>a[i];
		a[i] = (a[i]+1)/2;
		if(i) a[i]+=a[i-1];
	}
	ld sum = a[k-1];
	for(ll i=k;i<n;i++) {
		sum = max(sum,a[i]-a[i-k]);
	}
	cout<<sum;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 6412
#include <iostream>

using namespace std;

int main() {
	int x, y;
	cin >> x >> y;
	while (x % y) {
		if (x >= y) {
			x %= y;
		}
		int tmp = y;
		y = x;
		x = tmp;
	}
	cout << y << endl;
	return 0;
}



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A;
	A.resize(N);
	for (int n = 0; n < N; n++) {
		cin >> A[n];
	}
	vector<int> grundy(K+1);
	for (int k = 0; k <= K; k++) {
		set<int> s;
		for (int n = 0; n < N; n++) {
			if (k - A[n] >= 0)s.insert(grundy[k - A[n]]);
		}
		int g = 0;
		while (s.find(g) != s.end())g++;
		grundy[k] = g;
	}
	if (grundy[K] == 0)cout << "Second" << endl;
	else cout << "First" << endl;
	return 0;
}

Measured memory_bytes: 640
N = int(input())
ans = 0
l = [0] * (10 ** 7 + 1)
for i in range(1, N + 1):
    for j in range(i, N + 1, i):
        l[j] += 1

for i in range(1, N + 1):
    ans += i * l[i]
print(ans)

Measured memory_bytes: 151116
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

//next_permutation
void nexp(ll*a,int cnt){
	int l=cnt-1,r=cnt-1;
	ll t;
	while(--l>=0&&a[l]>a[l+1]);
	if(l>=0){
		while(a[l]>a[r])r--;
		t=a[l];a[l]=a[r];a[r]=t;
	}
	for(l++,r=cnt-1;l<r;l++,r--)t=a[l],a[l]=a[r],a[r]=t;
}

ll fact(ll n){ll x=1;while(n)x*=n--;return x;}

ll n,m;
ll e[9][9];
ll a[9]={1,2,3,4,5,6,7,8};
ll ans;

void f(){
	ll flag=1;
	rep(i,0,n-1)flag&=e[a[i]][a[i+1]];
	ans+=flag;
}

int main(){
	scanf("%lld%lld",&n,&m);
	rep(i,0,m){
		ll p,q;
		scanf("%lld%lld",&p,&q);
		e[p][q]=e[q][p]=1;
	}
	ll cnt=fact(n-1);
	rep(i,0,cnt){
		f();
		nexp(a+1,n-1);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	ll t1, t2, a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	ll a3 = a1 * t1 + a2 * t2;
	ll b3 = b1 * t1 + b2 * t2;
	if(a3 == b3){
		cout << "infinity" << endl;
		return 0;
	}
	if(a3 > b3){
		swap(a1, b1);
		swap(a2, b2);
		swap(a3, b3);
	}
	if(a1 < b1){
		cout << 0 << endl;
		return 0;
	}
	const ll d1 = (a1 - b1) * t1;
	const ll d2 = b3 - a3;
	const ll answer = d1 / d2 * 2 + (d1 % d2 == 0 ? 0 : 1);
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
	int a,b,c;
	cin>>a>>b>>c;
	set<int> s;
	int cur=0;
	while(1){
		cur+=a;
		cur%=b;
		if(s.count(cur)){
			cout<<"NO";
			return 0;
		}
		s.insert(cur);
		if(cur==c){
			cout<<"YES";
			return 0;
		}
	}
}


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

namespace COJ1_7
{
    struct Node
    {
        public int parent;
        public int left;
        public int right;
    }
    class Program
    {
       
        static void Main(string[] args)
        {
            int root=0;
            int cnt = int.Parse(Console.ReadLine());
            Node[] nodes = new Node[cnt];

            for(int i = 0; i < cnt; i++)
            {
                nodes[i].parent = -1;
            }
            for(int i=0;i<cnt;i++)
            {
                var param = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
                nodes[param[0]].left = param[1];
                nodes[param[0]].right = param[2];
                if (param[1] != -1)
                {
                    nodes[param[1]].parent = param[0];
                }
                if (param[2] != -1)
                {
                    nodes[param[2]].parent = param[0];
                }
            }
            for(int i = 0; i < cnt; i++)
            {
                if (nodes[i].parent == -1) root = i;
            }
            StringBuilder stdout = new StringBuilder("Preorder\n");
            PreOrder(nodes,root, stdout);
            stdout.Append("\nInorder\n");
            InOrder(nodes, root, stdout);
            stdout.Append("\nPostorder\n");
            PostOrder(nodes, root, stdout);
            Console.WriteLine(stdout.ToString());
        }

        public static void PreOrder(Node[] node, int i,StringBuilder builder)
        {
            if (i == -1) return;
            builder.Append(" ").Append(i);
            PreOrder(node, node[i].left, builder);
            PreOrder(node, node[i].right,builder);
        }
        public static void InOrder(Node[] node, int i, StringBuilder builder)
        {
            if (i == -1) return;
            InOrder(node, node[i].left, builder);
            builder.Append(" ").Append(i);
            InOrder(node, node[i].right, builder);
        }
        public static void PostOrder(Node[] node, int i, StringBuilder builder)
        {
            if (i == -1) return;
            PostOrder(node, node[i].left, builder);
            PostOrder(node, node[i].right, builder);
            builder.Append(" ").Append(i);
        }
    }
}

Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
 
const double PI = acos(-1);
 
int main(){
	int N,M;
    cin >> N >> M;
    int a,sum=0;
    rep(i,M) {
        cin >> a;
        sum+=a;
    }
    sum = N - sum;
    if(sum < 0) {
        cout << -1 << "\n";
    } else {
        cout << sum << "\n";
    }
    return 0;
}

Measured memory_bytes: 3500
#include <iostream>
#include <cctype>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	cin >> n;
	rep(i,n){
		string s1,s2;
		cin >> s1;
		int ans=0;
		rep(j,s1.size()){
			if(isdigit(s1[j])){
				if(s1[j+1]=='m') ans+=(s1[j]-'0')*1000;
				if(s1[j+1]=='c') ans+=(s1[j]-'0')*100;
				if(s1[j+1]=='x') ans+=(s1[j]-'0')*10;
				if(s1[j+1]=='i') ans+=(s1[j]-'0')*1;
				j++;
			}else{
				if(s1[j]=='m') ans+=1000;
				if(s1[j]=='c') ans+=100;
				if(s1[j]=='x') ans+=10;
				if(s1[j]=='i') ans+=1;
			}
		}
		cin >> s1;
		rep(j,s1.size()){
			if(isdigit(s1[j])){
				if(s1[j+1]=='m') ans+=(s1[j]-'0')*1000;
				if(s1[j+1]=='c') ans+=(s1[j]-'0')*100;
				if(s1[j+1]=='x') ans+=(s1[j]-'0')*10;
				if(s1[j+1]=='i') ans+=(s1[j]-'0')*1;
				j++;
			}else{
				if(s1[j]=='m') ans+=1000;
				if(s1[j]=='c') ans+=100;
				if(s1[j]=='x') ans+=10;
				if(s1[j]=='i') ans+=1;
			}
		}
		if(ans/1000>=2) cout << ans/1000;
		if(ans/1000>=1) cout << "m";
		ans%=1000;
		if(ans/100>=2) cout << ans/100;
		if(ans/100>=1) cout << "c";
		ans%=100;
		if(ans/10>=2) cout << ans/10;
		if(ans/10>=1) cout << "x";
		ans%=10;
		if(ans>=2) cout << ans;
		if(ans>=1) cout << "i";
		cout << endl;
	}
}

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

#define fo(i, t) for(int i = 0; i < t; i++)
#define rfo(i, t) for(int i = n - 1; i > 0; i--)
#define pb push_back

/*typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vector<int>> mi;*/

using namespace std;

int main()
{
    long long a;
    long long result = 0;
    cin >> a;
    for(int i = 1; i < a; i++)
    {
        result += (a - 1) / i;
    }
    cout << result;
}


Measured memory_bytes: 3596
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

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


Measured memory_bytes: 640