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

namespace ConsoleApp93 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            var a = new int[N];
            var b = new int[N];
            var c = new int[N];
            var d = new int[N];

            var redList = new List<Tuple<int, int>>();
            var blueList = new List<Tuple<int, int>>();

            for (int i = 0; i < N; i++) {
                var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
                a[i] = st[0];
                b[i] = st[1];
                redList.Add(new Tuple<int, int>(a[i], b[i]));
            }
            redList.Sort((p, q) => q.Item2.CompareTo(p.Item2));

            for (int i = 0; i < N; i++) {
                var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
                c[i] = st[0];
                d[i] = st[1];
                blueList.Add(new Tuple<int, int>(c[i], d[i]));
            }
            blueList.Sort((p, q) => p.Item1.CompareTo(q.Item1));

            int cnt = 0;

            for (int i = 0; i < N; i++) {
                int blue_x = blueList[i].Item1;
                int blue_y = blueList[i].Item2;
                var pairList = redList.Where(x => (x.Item1 < blue_x && x.Item2 < blue_y)).ToList();
                Tuple<int, int> pairTuple;
                if (pairList.Count() != 0) {
                    pairList.Sort((p, q) => q.Item2.CompareTo(p.Item2));
                    pairTuple = pairList[0];
                    redList.Remove(new Tuple<int, int>(pairTuple.Item1, pairTuple.Item2));
                    cnt++;
                }
            }

            Console.WriteLine(cnt);

        }
    }
}


Measured memory_bytes: 13524
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>

using namespace std;

int main() {
	double a, b, c, d, e, f, x, y, det;
	while(cin >> a >> b >> c >> d >> e >> f){
		det = a * e - b * d;
		x = (c * e - b * f)/det;
		y = (-c * d + a * f)/det;
		if(x == 0) x = 0;
		if(y == 0) y = 0;
		cout << fixed << setprecision(3) << x << " " << y << endl;
	}
}

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

// using mint = modint1000000007;
// using mint = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

void solve() {
    Int h, w, n;
    cin >> h >> w >> n;
    Int ma = max(h, w);
    Int res = n / ma;
    if (n % ma != 0) res++;
    print(res);
}

int main() {
    solve();
    return 0;
}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c ;
  int sum = a+b+c;
  int max = 0;
  
  if ( a>=b) max = a;
  else max = b;
  if (max >=c){}
  else max = c;
  
  cout << sum - max;
  
  
}




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

#define crap ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CN cout<<"NO\n"
#define CY cout<<"YES\n"

using namespace std;
using ll = long long;
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
// #define MAXN 1000001 
// ll sieve[MAXN]; 
// void makesieve()
// {
//     sieve[1] = 1; 
//     for (int i = 2; i < MAXN; i++) 
//         sieve[i] = i; 
//     for (int i = 4; i < MAXN; i += 2) 
//         sieve[i] = 2; 
//     for (int i = 3; i * i < MAXN; i++) { 
//         if (sieve[i] == i) { 
//             for (int j = i * i; j < MAXN; j += i) 
//                 if (sieve[j] == j) 
//                     sieve[j] = i; 
//         } 
//     } 
// }
ll powerflow(ll x, ll n)
{
    ll res;
    if (n == 0) {
        return 1;
    }
    res = powerflow(x, n-1);             // recurse
    if(INT_MAX / res < x) {          // check for overflow
        return -1; //LONG_MAX;
    }
    return x * res;
}
ll mod=1000000007;
ll power(ll a,ll b,ll m)
{
    ll res=1;
    while(b!=0)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        b=b/2;
        a=(a%mod*a%mod)%mod;
    }
    return res;
}
struct compare  
 {  
   bool operator()(const int& l, const int& r)  
   {  
       return l > r;  
   }  
 };
 ll recur(int n)
 {
    if(n==0) return 1;
    if(n<=2) return 0;
    ll ans=0;
    for(int i=3;i<=9;i++)
        ans+=recur(n-i);
    return ans;

 }
void solve()
{
    ll n; cin>>n;
    if(n==1) cout<<"0\n";
    else
    {
        ll k1=power(10,n,mod),k2=power(8,n,mod);
        ll k3=power(9,n,mod);
        k3=(k3*2)%mod;
        ll ans=(k1+k2)%mod;
        ans=(ans-k3+mod)%mod;
        cout<<ans;
    }
}
int main()
{
    crap;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r", stdin) ;
        freopen("output.txt","w", stdout) ;
        freopen("error.txt","w", stderr) ;
    #endif
    int t;t=1;
    //cin>>t;
    while(t--)
        {solve();}
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
using namespace std;
long long ans = 0;
bool pl[100]={0};
string s;
void cal(int l)
{
    long long a1=0;
    for(int i = 0; i<l+1; i++)
    {
        a1= a1*10+s[i]-'0';

        if(pl[i]&&i<l+1)
        {
            ans+=a1;
            a1=0;
        }


    }
    ans+=a1;

}


void ba(int d,int l)
{

    if(d==l-1)
    {
        pl[d]=0;

        cal(l);
        pl[d]=1;

        cal(l);
        return;
    }

    else
    {
        pl[d]=0;
        ba(d+1,l);
        pl[d]=1;
        ba(d+1,l);
        return;
    }

}


int main()
{
    cin>>s;
    if(s.length()==1)
    {
        cout<<s[0]-'0';
    }
    else
    {

    ba(0,s.length()-1);

    cout<<ans;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main (){
    string s;
    cin >> s;
    for(int i=0;i<s.length();i++){
        if(s.find(s[i])!=i){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}

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

Cij = [0] * 100
for i in range(1, N + 1):
    Cij[int(str(i)[0] + str(i)[-1])] += 1

count = 0
for i in range(10):
    for j in range(10):
        count += Cij[i * 10 + j] * Cij[j * 10 + i]

print(count)

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int N; cin >> N;
    VL s(N); REP(i,N) cin >> s[i];

    ll ans = 0;
    FOR(x,1,N-1){
        ll sum = 0;
        int l = 0, r = N-1;

        if((N-1)%x == 0){
            while(l<r){
                sum += s[l]+s[r];
                l += x;
                r -= x;
                chmax(ans, sum);
            }
        }
        else{
            while(l<N-1-x && r>x){
                sum += s[l]+s[r];
                l += x;
                r -= x;
                chmax(ans, sum);
            }
        }
    }

    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

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


int a[100005];
int b[100005];
int c[100005];

int aa[100005];
int bb[100005];
int cc[100005];

int32_t main() {
	int n;
	cin >> n;

	for(int i = 0; i < n; i++)
		cin >> a[i] >> b[i] >> c[i];

	aa[0] = a[0];
	bb[0] = b[0];
	cc[0] = c[0];

	for(int i = 1; i < n; i++){
		aa[i] = a[i] + max(bb[i-1], cc[i-1]);
		bb[i] = b[i] + max(aa[i-1], cc[i-1]);
		cc[i] = c[i] + max(bb[i-1], aa[i-1]);
	}

	cout << max(max(aa[n-1], bb[n-1]), cc[n-1]) << endl;

	return 0;
}


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

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

		if( a == b )
		{
		cout << "a == b" << endl;
		}else{
			if( a > b)
			{
			cout << "a > b" << endl;
			}else{
			cout << "a < b" << endl;
			}
		}

}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int d, g;
vector<int > p, c;
bool possible(const int n)
{
  int nc = n;//num
  int sc = 0;//score
  // complete
  bool flag2 = false;
  bool bflag = false;
  // cout << "n, g =" << n <<", "<< g<< endl;
  for(int i = 0; i <(1<<d); i++){
    nc = n;
    sc = 0;
    bflag = false;
    // choose complete problem
    vector<bool > comp(d, false);
    // cout << "choose complete" << endl;
    for(int j = d - 1;j >= 0;j --){
      if(i&(1<<j)){
	if(nc - p[j] < 0){
	  bflag = true;
	  break;
	}
	// cout << "j = "<< j << endl;
	sc += (j+1)*100*p[j]+c[j];
	nc -= p[j];
	comp[j] = true;
      }
    }
    if(bflag){
      continue;
    }
    // cout << "i = " <<std::bitset<3>(i)<< endl;
    // cout << "nc, sc = "  << nc << ", " << sc << endl;
    if(sc >= g){return true;}
    // choose complete problem
    // the reminder
    for(int j = d - 1;j >= 0;j --){
      if(nc == 0){
	break;
      }
      if(!comp[j]){
	sc += (j+1)*100*min(p[j] - 1,nc);
	nc -= min(p[j] - 1,nc);
      }
    }
    // the reminder
    // cout << "sc, nc= " << sc << ", "<<nc<< endl;
    if(sc >= g){
      return true;
    }
  }
  return false;
  // if(flag2)return true;
  // else return false;
  // return false;
}
int main()
{

  cin >> d >> g;
  p.resize(d);
  c.resize(d);
  REP(i, d){
    cin >> p[i] >> c[i];   
  }
  int l = 0;
  int r = 0;
  int sc = 0;
  REP(i, d){
    r += p[i];
    sc += (i+1)*100*p[i] + c[i];
  }
  // cout << "l,r,sc(r) = " << l << ", " << r <<  ", " << sc << endl;
  if(sc < g){
    // cout << "IMPOSSIBLE"<<endl;
    return 0;
  }
  //binary search
  while(r - l > 1){
    int c = (r + l)/2;
    bool flag = possible(c);
    // cout << "possible(" << c << ") = " << (flag?"true":"false") << endl;
    if(flag){
      r = c;
    }else{
      l = c;
    }
  }
  //binary search
  cout << r << endl;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>

using namespace std;

class agcB {
public:
    void solve(istream& in, ostream& out) {
        int N, M, Q;
        in >> N >> M;
        vector<int> a(M), b(M);
        vector<vector<int>> g(N);
        for (int i = 0; i < M; ++i) {
            in >> a[i] >> b[i];
            g[a[i]-1].push_back(b[i]-1);
            g[b[i]-1].push_back(a[i]-1);
        }
        in >> Q;
        vector<int> v(Q), d(Q), c(Q);
        for (int i = 0; i < Q; ++i) {
            in >> v[i] >> d[i] >> c[i];
            --v[i];
        }
        
        vector<int> col(N, 0);
        vector<int> within(N, -1);
        for (int i = Q-1; i >= 0; --i) {
            if (within[v[i]] >= d[i]) {
                continue;
            }
            within[v[i]] = d[i];
            queue<pair<int,int>> q;
            q.emplace(v[i], d[i]);
            while (!q.empty()) {
                int u = q.front().first, dist = q.front().second;
                q.pop();
                if (col[u] == 0) {
                    col[u] = c[i];
                }
                //cout << "paint " << u << " with " << c[i] << endl;
                if (dist > 0) {
                    for (int vv : g[u]) {
                        if (within[vv] < dist-1) {
                            q.emplace(vv, dist-1);
                            within[vv] = dist-1;
                        }
                    }
                }
            }
        }
        for (int i = 0; i < N; ++i) {
            out << col[i] << "\n";
        }
    }
};


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

	agcB solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  int n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;

  bool ok = true;
  rep(i,n){
    if(a[i]%2==0){
      if(a[i]%3!=0&&a[i]%5!=0)ok=false;
    }
  }
  cout<<(ok?"APPROVED":"DENIED")<<endl;

}

Measured memory_bytes: 256
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int cnt[100100];
int done[100100];
int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m;
    int tc;
    int sum = 0;
    int ac = 0, wa = 0;
    cin >> n >> m;
    for(i=1;i<=m;i++)
    {
        string s;
        cin >> curr >> s;
        if(done[curr]) continue;
        if(s[0] == 'A')
        {
            done[curr] = 1;
            ac++;
            wa += cnt[curr];
        }
        else
        {
            cnt[curr]++;
        }
    }
    cout << ac << " " << wa << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
using namespace std;
const int X_MX = 1e9;
int x;

int main() {
    cin >> x;
    int time = 0;
    int sum = 0;
    while (1) {
        time++;
        sum += time;
        if (sum >= x) break;
    }

    cout << time << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    // それぞれの地点からスタート、mapで（現在位置、スタート）を保持
    // multisetで横移動の長さを保持
    int H, W;
    cin >> H >> W;

    map<int, int> mp;
    rep(i, W) mp[i] = i;
    multiset<int> vals;
    rep(i, W) vals.insert(0);

    rep(i, H) {
        int l, r;
        cin >> l >> r;
        --l;
        auto it = mp.lower_bound(l);
        int edge = -1; // lとrの中でスタートの右端
        while (it != mp.end() && it->first <= r) {
            edge = it->second;
            int x = it->first - it->second;
            mp.erase(it++);
            vals.erase(vals.find(x));
        }
        if (edge >= 0 && r < W) {
            vals.insert(r-edge);
            mp[r] = edge;
        }
        if (vals.empty()) puts("-1");
        else {
            int ans = *vals.begin() + i + 1;
            printf("%d\n", ans);
        }        
    }
    return 0;
}

Measured memory_bytes: 22392
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define mod 1000000007
#define inf 9999999999999999ll
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll an=0;
    vii e(n-1,mp(0,0));
    vv g(n,vi());
    for(ll i=0;i<n-1;i++)
    {
        cin>>e[i].F>>e[i].S;
        e[i].F--;
        e[i].S--;
        g[e[i].F].pb(e[i].S);
        g[e[i].S].pb(e[i].F);
    }
    for(ll i=0;i<n;i++)
    {
        an=max(an,(ll)g[i].size());
    }
    queue <ll> q;
    vb vis(n,false);
    vis[0]=true;
    q.push(0);
    map <ii,bool> color;
    map  <ii,ll> co;
    while(!q.empty())
    {
        ll u=q.front();
        q.pop();
        ll c=1;
        for(ll i=0;i<g[u].size();i++)
        {
            ll v=g[u][i];
            if(!vis[v])
            {
                while(color[mp(u,c)]==true || color[mp(v,c)])
                {
                    c++;
                }
                color[mp(u,c)]=true;
                color[mp(v,c)]=true;
//                tr3(u,v,c);
                co[mp(u,v)]=co[mp(v,u)]=c;
                vis[v]=true;
                q.push(v);
            }
        }
    }
    cout<<an<<endl;
    for(ll i=0;i<e.size();i++)
    {
        cout<<(co[mp(e[i].F,e[i].S)])<<endl;
    }
}


Measured memory_bytes: 33152
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a, b, c;

    a = sc.nextInt();
    b = sc.nextInt();
    c = sc.nextInt();

    if (a > b) {// b < a
      if (c > a) {// b < a < c
        System.out.printf("%d %d %d", b, a, c);
      } else if (c < b) {// c < b < a
        System.out.printf("%d %d %d", c, b, a);
      } else {// b < c < a
        System.out.printf("%d %d %d", b, c, a);
      }
    } else {// a < b
      if (c > b) {// a < b < c
        System.out.printf("%d %d %d", a, b, c);
      } else if (c < a) {// c < a < b
        System.out.printf("%d %d %d", c, a, b);
      } else {// a < c < b
        System.out.printf("%d %d %d", a, c, b);
      }
    }

    System.out.printf("\n");
    sc.close();
  }
}



Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ss second
#define ff first
#define endl "\n";
int32_t main(){
	int n,k;
	cin>>n>>k;
	if(abs(n-k)%2==1) cout<<"IMPOSSIBLE";
	else{
		cout<<min(n,k)+(max(n,k)-min(n,k))/2;
	}
}

Measured memory_bytes: 256
n = int(input())
x= [int(x) for x in input().split()]
x.sort(reverse=True)

c = 0
if n%2 == 0:
  t = (n-2)//2
  print(x[n//2-1] + sum(x[0:t]) + sum(x[1:t+1]))
  #print(x[n//2] ,x[0:t], x[1:t+1] )
    
if n%2 == 1:
  t = (n-1)//2
  print(sum(x[0:t]) + sum(x[1:t+1]))

Measured memory_bytes: 93988
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

using Flow = int;
struct FlowEdge {
  int src, dst;
  Flow cap;
  int rev;
  FlowEdge(const int s = 0, const int d = 0, const Flow c = 0, const int r = 0) : src(s), dst(d), cap(c), rev(r) {}
};

using FlowEdges = std::vector<FlowEdge>;

class FlowGraph {
  std::vector<FlowEdges> g;

public:
  FlowGraph(const int size = 0) : g(size) {}
  size_t size() const { return g.size(); }
  FlowEdges &operator[](const int i) & { return g[i]; }

  void addEdge(const int src, const int dst, const Flow c = 1) {
    g[src].emplace_back(src, dst, c, g[dst].size());
    g[dst].emplace_back(dst, src, 0, g[src].size() - 1);
  }
};

template<Flow inf = std::numeric_limits<Flow>::max() / 8> Flow fordFulkerson(FlowGraph g, const int source, const int sink) {
  std::vector<int> used(g.size());
  std::function<Flow(int, Flow)> dfs = [&](int v, Flow f) -> Flow {
    if (v == sink) return f;
    used[v] = true;
    for (auto &e : g[v]) {
      if (used[e.dst] || e.cap <= 0) continue;
      Flow d = dfs(e.dst, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        g[e.dst][e.rev].cap += d;
        return d;
      }
    }
    return 0;
  };
  Flow s = 0;
  for (;;) {
    std::fill(used.begin(), used.end(), false);
    Flow f = dfs(source, inf);
    if (f == 0) return s;
    s += f;
  }
}

main {
  int n, m;
  cin >> n >> m;
  FlowGraph g(n);
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    g.addEdge(a, b, c);
  }
  cout << fordFulkerson(g, 0, n - 1) << endl;
}

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

using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")

#define fastio               \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
//#define int long long
#define ll long long
#define endl "\n"
#define inf ULLONG_MAX
#define gcd __gcd
#define deb(x) cout << #x << " " << x << endl;
#define pr(x) cout << x << endl;

#define sz(a) ((ll)(a).size())
#define all(v) (v).begin(), (v).end()
#define tr(c, it) for (auto(it) = (c).begin(); (it) != (c).end(); it++)
#define pres(c, val) ((c).find(val) != (c).end())
#define cpres(c, val) (find(all(c), val) != (c).end())
#define dec greater<ll>()
#define sortv(x) sort(all(x))
#define revsortv(x) sort(all(x), dec)
#define com(x) ((x) * (x + 1) / 2)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bg begin()
#define ed end()
#define bs binary_search // to find if an element is present or not in Ologn time, return a boolean
#define ub upper_bound   // to find an element strictly greater than the given no.
#define lb lower_bound   // lb(v,begin(), v.end(), n) gives the iterator

#define fo(n) for (ll i = 0; i < n; i++)
#define fo1(n) for (ll i = 1; i < n; i++)
#define fo2(i, n) for (ll i = 0; i < n; i++)
#define fo3(i, a, b) for (ll i = a; i < b; i++)
#define fors(a) cin >> a[i]
#define forp(a) cout << a[i] << " "
#define prv(a, n)  \
    fo(n) forp(a); \
    cout << endl;
#define fob(i, a, b) for (ll i = (b); i >= (a); i--)

typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef unordered_map<string, ll> umsl;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;

#define scan(v, n)   \
    vl v;            \
    fo(n)            \
    {                \
        ll item;     \
        cin >> item; \
        v.pb(item);  \
    }

const ll INF = 0xFFFFFFFFFFFFFFFL;;
const ll N = 1e9 + 7;
void swap1(ll a,ll b){
    ll temp;
    temp=a;
    a=b;
    b=temp;
}
void solve()
{

ll n,q;
cin>>n;
scan(a,n);
ll sum=0;
ll count[100002];
fo(100002)count[i]=0;
cin>>q;
fo(n){
    count[a[i]]++;
    sum=sum+a[i];
}
ll b,c;
fo(q){
    cin>>b>>c;
    sum=sum-b*count[b]+c*count[b];
    cout<<sum<<endl;
    count[c]=count[c]+count[b];
    count[b]=0;
}


}



int32_t main(int32_t argc, char **argv)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*#ifndef ONLINE_JUDGE
    freopen("inputf.txt", "r", stdin);
    freopen("outputf.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif*/

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

    cerr << endl
         << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

    return 0;
}

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

int gcd_th(int a, int b, int c){
  return gcd(a, gcd(b, c));
}


int main(void){
  int N;
  cin >> N;
  while(N > 0){
    if(N % 10 == 7){
      cout << "Yes";
      return 0;
    }
    else N /= 10;
  }
  cout << "No";
  return 0;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

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

ll lcm(ll x, ll y) {
    return x/gcd(x, y)*y;
}

int main() {
    int N;
    cin >> N;
    priority_queue<ll, vector<ll>, greater<ll>> T;
    rep(i, N) {
        ll t;
        cin >> t;
        T.push(t);
    }
    ll ans = T.top();
    T.pop();
    while(T.size() > 0) {
        ans = lcm(ans, T.top());
        T.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) {return log(b) / log(a);}

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}



int main() {
	int n, k;
	k = 2;
	cin >> n;
	vector<int> h(n);
	rep(i, n) {
		cin >> h[i];
	}
	vector<int> a(n);
	a[0] = 0;
	FOR(i, 1, n) {
		int mi = INF;
		rep(j, k) {
			if (i - j - 1 < 0) {
				continue;
			}
			mi = min(mi, a[i - j - 1] + abs(h[i] - h[i - j - 1]));
		}
		a[i] = mi;
	}
	cout << a[n - 1] << endl;
}


Measured memory_bytes: 1024
n,m,k=map(int,input().split())
mod = 998244353
nCi = [1]#n-1からi個えらぶ場合の数
for i in range(n):
  next = nCi[i]*(n-1-i)*pow(i+1,mod-2,mod)
  next %= mod
  nCi.append(next)
#print(nCi)
ans = 0
for i in range(k+1):
  ans += m*pow(m-1,n-i-1,mod)*nCi[i]
  ans %= mod
print(ans)

Measured memory_bytes: 16892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;



void solve(){
    ll n,m;
    cin >> n >> m;
    ll s[n+10];
    ll t[m+10];
    rep(i,n){
        cin >> s[i+1];
    }
    rep(i,m){
        cin >> t[i+1];
    }
    ll dp[n+10][m+10];
    ll sum[n+10][m+10];

    rep(i,n+1){
        dp[i][0]=0;
        sum[i][0]=0;
        sum[i][m]=0;
    }
    rep(i,m+1){
        dp[0][i]=0;
        sum[0][i]=0;
        sum[n][i]=0;
    }
    for(ll i=1; i<=n; i++){
        for(ll j=1; j<=m; j++){
            if(s[i]==t[j]) dp[i][j]=(sum[i-1][j-1]+1)%MOD;
            else dp[i][j]=0;
            sum[i][j]=((sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+MOD)%MOD+dp[i][j])%MOD;
        }
    }
    
    ll ans = 0;
    rep(i,n+1){
        rep(j,m+1){
            //cout << "dp[" << i << "][" << j << "]:" << dp[i][j] << endl;
            //cout << "sum[" << i << "][" << j << "]:" << sum[i][j] << endl;
            ans =  (ans + dp[i][j]) % MOD;
        }
    }



    cout << ans+1 << endl;
}

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

Measured memory_bytes: 63232
#include<bits/stdc++.h>
#define MAXN 200010
using namespace std;
int n,A[MAXN],BIT[MAXN];
long long ans;
void Add(int i,int x){
	while(i>=1)BIT[i]+=x,i-=i&-i;
}
int Query(int i){
	int res=0;
	while(i<=n)res+=BIT[i],i+=i&-i;
	return res;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	for(int i=1;i<=n;i++){
		Add(A[i],1);
		if(Query(A[i])==i)ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int main(){
	
	int s1[5], s2[5];
	
	while(true){
		
		cin >> s1[0] >> s2[0];
		
		if(s1[0] == 0 && s2[0] == 0){
			break;
		}
		
		for(int i = 1; i < 5; i++){
			cin >> s1[i] >> s2[i];
		}
		
		int max = 0;
		int ans = 0;
		
		for(int i = 0; i < 5; i++){
			if(max < s1[i] + s2[i]){
				max = s1[i] + s2[i];
				ans = i;
			}
		}
		
		string ans_str = "A";
		
		ans_str[0] = 'A' + ans;
		
		cout << ans_str << " " << max << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3084
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		long N= keyboard.nextLong();
		long A = keyboard.nextLong();
		long B = keyboard.nextLong();
		
		long ans = 0;
		
		if(N%(A+B) == 0) {
			ans = N/(A+B)*A;
		}else if(N%(A+B) <= A) {
			ans = N/(A+B)*A+N%(A+B);
		}else{
			ans = N/(A+B)*A+A;
		}
		
		System.out.print(ans);
		keyboard.close();	
		
	}
}


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


int main() {
    int n;
    cin >> n;
    vector<int> value(n), cost(n);
    for (int i = 0; i < n; i++) {
        cin >> value.at(i);
    }

    for (int i = 0; i < n; i++) {
        cin >> cost.at(i);
    }

    long sum = 0;
    for (int i = 0; i < n; i++) {
        sum += max(0, value.at(i) - cost.at(i));
    }

    cout << sum << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#define max 1000000007
using namespace std;
int main()
{
	int i,n,j,k;
	int a[100005];
	long long int ans=1;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	 	scanf("%d",&a[i]);
	sort(a,a+n);
	if(n%2!=0)
	{
		for(i=2;i<=n-1;i+=2)
		if(a[0]!=0||a[i-1]!=i||a[i]!=i)
		{
			printf("0\n");
			break;
		}
		if(i>n-1)
		{
			for(j=1;j<=(n-1)/2;j++)
			ans=(ans*2)%max;
			printf("%lld\n",ans);
		}
	}
	if(n%2==0)
	{
		for(i=1;i<=n;i+=2)
		if(a[i-1]!=i||a[i]!=i)
		{
			printf("0\n");
			break;
		}
		if(i>n-1)
		{
			for(j=1;j<=n/2;j++)
			ans=(ans*2)%max;
			printf("%lld\n",ans);
		}
	}	 
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
    int n,d,x,y;
    cin>>n>>d;
    x=n/(2*d+1);
    y=n%(2*d+1);
    if(y==0)
    {
        cout<<x;
    }
    else{
        cout<<x+1;
    }
    return 0;
}


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

using namespace std;

#define il inline
#define Rep(i, s, e) for (int i = s; i <= e; ++i)

const int N = 1000010;

il int read() {
	bool f = true; int x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = false; c = getchar();}
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	return f ? x : -x;
}

int t[N], n;
il int lowbit(int x) {return x & (-x);}
il void update(int x, int k) {while (x <= n) t[x] += k, x += lowbit(x);}
il int query(int x) {int ans = 0; while (x) ans += t[x], x -= lowbit(x); return ans;}

int m, lst[N], a[N], ans[N];
struct node {int l, r, pos;} q[N];
il bool cmp(node a, node b) {return a.r < b.r;}

int main() {
	n = read();
	m = read();
	Rep(i, 1, n) a[i] = read();
	Rep(i, 1, m) q[i].l = read(), q[i].r = read(), q[i].pos = i;
	sort(q + 1, q + m + 1, cmp);
	Rep(i, 1, m) {
		Rep(j, q[i - 1].r + 1, q[i].r) {
			if (lst[a[j]]) update(lst[a[j]], -1);
			update(j, 1), lst[a[j]] = j;
		}
		ans[q[i].pos] = query(q[i].r) - query(q[i].l - 1);
	}
	Rep(i, 1, m) printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 17376
s_l = list(input())
n = len(s_l)

# 公式解説参照
dp_dict = {0:1}
t = 0
for i in range(n):
    a = int(s_l[-(i+1)])
    t = (t + a*(pow(10,i,2019)))%2019
    dp_dict[t] = dp_dict.get(t,0) + 1

ans = 0
for val in dp_dict.values():
    ans += val*(val-1)//2

print(ans)


Measured memory_bytes: 10452
#include<stdio.h>
int main()
{
    int a,z=1,i,sum=0;
    scanf("%d",&a);
    int c[a];
    for(i=0;i<a;i++){
        scanf("%d",&c[i]);
    }
    for(i=0;i<a;i++,z++)
    {
       if(c[i]!=z) sum++;
    }
    if(sum<=2)printf("YES\n");
    else printf("NO\n");
    return 0;
}


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

#define endl '\n'
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define SORT(v) sort(all(v))
#define SORTD(v) sort(all(v), greater<int>())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<30
#define v(T) vector<T>
#define vv(T) v(v(T))
#define print(x) cout<<x<<endl
#define printv(v) for(auto i : v){cout<<i<<" ";}cout<<endl
#define printu(v) for(auto i : v){print(i);}
#define readv(v, n) for (int i=0;i<n;i++)cin >> v[i]
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

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 i, j, k;
vi v;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i, n) {
		int k;
		cin >> k;
		v.push_back(k);
	}
	int ans = INF;
	rep(i,n) {
		int t = i;
		int suma = 0;
		int sumb = 0;
		rep(j,n) {
			if (j <= i) {
				suma += v[j];
			} else {
				sumb += v[j];
			}
		}
		chmin(ans, abs(suma - sumb));
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, raw_input().split())

#if(a | b | c == 0):break

canArrive = False
i = 0
now = 0
while True:
    if now % 60 <= c and c <= now % 60 + a:
        canArrive = True
        break
    #end if
    now += (a + b)
    if now % 60 == 0 : break
#end while
if canArrive:
    print c + 60 * (now // 60)
else:
    print -1
    #end if

#end while

Measured memory_bytes: 6436
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i;
  cin>>n;
  vector<pair<int,int>> vp;
  for(i=0;i<n;i++)
  {
    int a,b;
    cin>>a>>b;
    vp.push_back({b,a});
  }
  
  sort(vp.begin(),vp.end());
  long long t=0;
  for(i=0;i<n;i++)
  {
    if(t+vp[i].second<=vp[i].first)
    {
      t=t+vp[i].second;
      continue;
    }
    else 
    {
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
  return 0;
}

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

int main(){
  int N; cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);
  int count = 0;
  for (int i = 0; i < N; i++){
    int count2 = 1;
    for (int j = 0; j < i; j++){
      if ( vec.at(i) == vec.at(j) ) count2 *= 0;
    }
    count += count2;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
use std::io;


fn main() {
    let (w, h, x, y, r) = {
        let i = read::<isize>();
        (i[0], i[1], i[2], i[3], i[4])
    };
    let res = if x >= r && y >= r && x + r <= w && y + r <= h {
        "Yes"
    } else { "No" };
    println!("{}", res);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


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

int main(void){
  ll n, a, b;
  cin >> n >> a >> b;
  if(a > b || n == 0 || ((a != b) && (n == 1))){
    cout << 0;
    return 0;
  }

  ll sum;
  sum = (n - 2) * (b - a) + 1;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
int main()
{
    int N;
    scanf("%d", &N);
    std::string s;
    std::cin >> s;
    int numR = 0, numB = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        if (s[i] == 'R')
        {
            ++numR;
        }
        else
        {
            ++numB;
        }
    }
    if (numR > numB)
    {
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
    return 0;
}


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

int main(){
	int N;
	cin >> N;
	int s[10000];
	int l = 0;
	if(N!=0){
	while(N!=0){
		//cout << N%(-2) <<"\n";
		if(N%(-2)==0) {
			s[l] = 0;
			l++;
			N = N / (-2);
		} else {
			s[l] = 1;
			l++;
			if(N%(-2)==1){
				N = N / (-2);
			}else {
				N = N / (-2) + 1;
			}
		}
	}

	for(int i = l-1; i>=0;i--){
		cout << s[i];
	}
		cout <<"\n";
	} else {
		cout <<"0\n";
	}
	return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, n;
    cin >> x >> n;
    int maxn = 101;
    if (!n) {
        cout << x << endl;
    } else {
        vector<int> p(n);
        for (int i = 0; i < n; i++) {
            cin >> p[i];
        }
        for (int i = 0; i <= maxn; i++) {
            bool flag1 = true, flag2 = true;
            for (int j = 0; j < n; j++) {
                if (x + i == p[j] ){
                    flag1 = false;
                    break;
                }
            }
            for (int j = 0; j < n; j++) {
                if (x - i == p[j] ){
                    flag2 = false;
                    break;
                }
            }
            if (flag1 && !flag2) {
                cout << x + i << endl;
                break;
            } else if (!flag1 && flag2) {
                cout << x - i << endl;
                break;
            } else if (flag1 && flag2) {
                cout << x - i << endl;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<assert.h>
#define INT_MAX 2147483647
typedef long long ll;
using namespace std;
ll min(ll x, ll y){
	return x > y ? y : x;
}
int main(){
	//freopen("input.txt", "r", stdin);
	int n,W;
	cin >> n>>W;
	vector<ll>val(n);
	vector<ll>wgt(n);
	int sum = 0;
	for (int i = 0; i < n; i++){
		cin >> wgt[i] >> val[i];
		sum += val[i];
	}
	vector<ll>dp(sum + 1,INT_MAX);
	dp[0] = 0;
	for (int i = 0; i < n; i++){
		for (int j = sum; j >= val[i]; j--){
			dp[j] = min(dp[j], dp[j - val[i]] + wgt[i]);
		}
	}
	for (int i = sum; i >= 0; i--){
		if (dp[i] <= W){
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

bool f[1010101];

int main(){
	int n; cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	sort(all(a));
	int ans = 0;
	rep(i,n){
		if(f[a[i]]) continue;
		if(i>=n-1 || a[i]!=a[i+1]) ans++;
		for(int j=a[i]; j<=1000000; j+=a[i]) f[j] = true;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 5004
import math
def combinations(x, y):
    return math.factorial(x) // (math.factorial(x - y) * math.factorial(y))
    
n, k = map(int, input().split())
if k == 1:
    print(n - k + 1)
else:    
    for i in range(k):
        if n - k < i:
            print("0")
        else:
            print(combinations(n - k + 1, i + 1) * combinations(k - 1, i) % (10 ** 9 + 7))

Measured memory_bytes: 3316
def kaibu(n):
    if str(n) == str(n)[::-1]:
        return True
    return False

def solve():
    a, b = map(int, input().split())
    ans = 0
    for i in range(a, b+1):
        if kaibu(i) == True:
            ans += 1
    print(ans)
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 9100
class UnionFind():
    # 初期化（初期状態は全要素が根）
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # xの根を返す O(log n)
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            # 経路圧縮も同時に行う
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        # 根が同じならx,yは既に同じグループ
        if x == y:
            return

        # xとyのサイズを比較し、xのほうが小さい場合はx,yをswapする
        # ※unionは大きい方のグループに小さい方のグループを引っ付けるため。
        # ※負の数なので不等号の向きに注意
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        # xにyをくっつける
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 要素xが属するグループのサイズ（要素数）を返す
    def size(self, x):
        return -self.parents[self.find(x)]

    # 要素x, yが同じグループに属するかどうかを返す
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    # すべての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # グループの数を返す
    def group_count(self):
        return len(self.roots())

    # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    # print()での表示用
    # ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m, k = map(int,input().split())
ab = []
cd = []

# 友達関係
frineds = [0] * n
# ブロック関係
block = [0] * n

for i in range(m):
    ab.append(list(map(int,input().split())))
    frineds[ab[i][0]-1] += 1
    frineds[ab[i][1]-1] += 1

# Union Find 初期化
uf = UnionFind(n)
# 友達関係をもとにUniteする
for _ab in ab:
    uf.union(_ab[0]-1, _ab[1]-1)

for i in range(k):
    cd.append(list(map(int,input().split())))
    
    # 同じグループ内の場合
    if uf.same(cd[i][0]-1, cd[i][1]-1):
        block[cd[i][0]-1] += 1
        block[cd[i][1]-1] += 1

for i in range(n):
    ans = uf.size(i) - 1 - frineds[i] - block[i]
    print(ans)

Measured memory_bytes: 58164
#include <stdio.h>

int main(void){

int nazo;
  
int N,Q;


nazo=scanf("%d",&N);
char S[N];
nazo=scanf("%d",&Q);
nazo=scanf("%s",S);

int l;
int r;
  
int ans;
  
int dp[N];
dp[0]=0;  
  
for(int i=1;i<N;i++){
if(S[i-1]=='A'&&S[i]=='C'){
  dp[i]=dp[i-1]+1;
}else{
  dp[i]=dp[i-1];
}
}
  
for(int i=0;i<Q;i++){
  ans=0;
  nazo=scanf("%d",&l);
  nazo=scanf("%d",&r);
  
  ans=dp[r-1]-dp[l-1];
  printf("%d\n",ans);
}
  
return 0;

}

Measured memory_bytes: 1280
#include <stdio.h>

int main() {
  int n,a[101],i,j,m;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  int cnt=0;
  for(i=0; i<n; i++) {
    m=i;
    for(j=i+1; j<n; j++) {
      if(a[j]<a[m]) m=j;
    }
    if(a[i]>a[m]) {
      int tmp=a[i];
      a[i]=a[m];
      a[m]=tmp;
      cnt++;
    }
  }
  for(i=0; i<n; i++) {
    if(i) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}


Measured memory_bytes: 604