akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, bool> pib;

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<double> vf;

typedef long double ld;

#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

#define printItr(A) for(auto itr = A.begin(); itr != A.end(); ++itr){cout << * itr << ", ";}cout << endl;

const double PI = 3.141592653589793;

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

int main() {
	ll N;
	string S;

	cin >> N;
	cin >> S;

	rep(i, S.size()) {
		char s = (S[i] + N - 'A') % 26 + 'A';
		S[i] = s;
	}

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <fstream> //ofstream
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int n,m;
void solve(){
        if(n<=m) {
                rep(i,m){
                        cout<<n;
                }
                cout<<endl;
        }else{
                rep(i,n){
                        cout<<m;
                }
                cout<<endl;
        }

}

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

        solve();
        return 0;
}


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

int r,c;
vector<vector<int> > sheet;


int main(){
    cin>>r>>c;
    sheet.resize(r+1);
    for(int i=0;i<r;++i){
        sheet[i].resize(c+1);
        for(int j=0;j<c;++j){
            cin>>sheet[i][j];
        }
    }
    sheet[r].resize(c+1);
    for(int i=0;i<r;++i){
        int horSum=0;
        for(int j=0;j<c;++j){
            horSum+=sheet[i][j];
        }
        sheet[i][c]=horSum;
    }
    for(int i=0;i<c+1;++i){
        int vertSum=0;
        for(int j=0;j<r;++j){
            vertSum+=sheet[j][i];
        }
        sheet[sheet.size()-1][i]=vertSum;
    }
    for(int i=0;i<sheet.size();++i){
        for(int j=0;j<sheet[i].size();++j){
                if(j!=0)cout<<" ";
                cout<<sheet[i][j];
            }
        cout<<endl;
    }
    
    return 0;
}



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

using ll = long long;
#define repi(n) for (int i = 0; i < n; i++)
#define repj(n) for (int j = 0; j < n; j++)
#define repk(n) for (int k = 0; j < n; k++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (auto i = a; i < b; i++)
#define repv(itr) for (auto&& v : itr)
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}

ll a[100100];
int main() {
  int n;
  cin >> n;
  repi(n) cin >> a[i];
  sort(a, a + n);
  ll mm = a[0];
  while (true) {
    ll mm2 = mm;
    repi(n) {
      ll v = a[i] % mm;
      if (0 < v && v < mm2) mm2 = v;
    }
    if (mm2 >= mm) break;
    mm = mm2;
  }
  cout << mm << endl;
}


Measured memory_bytes: 1024
//
// Created on 2020/09/28.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int n;
    cin>>n;
    vector<int>l(n);
    int max = 0;
    int index = 0;
    for (int i = 0; i < n; ++i) {
        int t;
        cin>>t;
        l[i]=t;
        if(max < t){
            index = i;
            chmax(max,t);
        }
    }
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        if(index == i)continue;
        sum += l[i];
    }
    if(sum > max){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
    a[i] -= i+1;
  }
  sort(a.begin(),a.end());
  auto f = [&](ll b){
    ll res = 0;
    rep(i,n) res += abs(a[i]-b);
    return res;
  };
  ll ans;
  if(n%2==0){
    ans = min(f(a[n/2-1]),f(a[n/2]));
  }else{
    ans = f(a[n/2]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
my $input = <STDIN>;
chomp $input;
my ($N, $X) = split / /, $input;
my $input = <STDIN>;
chomp $input;
my @x = split / /, $input;
@x = sort {$a <=> $b} @x;
for ($i=0; $i<$N; $i++) {
  $X -= $x[$i];
  if ($X<0) {
    last;
  }
}
if ($X>0) {
  $i--;
}
print "$i\n";

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, _begin, _end) for (__typeof(_end) end = _end, begin = _begin,  i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0, _len = (end); i < (_len); i += 1)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define readint ({int t;cin >> t;t;})
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}

template <typename T>
ostream& operator << (ostream& os, const vector<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

template <typename T>
ostream& operator << (ostream& os, const set<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

//#define int ll

class ATOrT {
public:

void solve(std::istream& cin, std::ostream& cout) {
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(N*A, B) << endl;

}


};


#undef int
int main() {


	ATOrT solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(0); ios::sync_with_stdio(0); out<<fixed<<setprecision(20);
	solver.solve(in, out);
	return 0;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
typedef long long lint;

int main() {
	int N;
	cin >> N;
	
	vector< lint > a(3 * N);
	for_(i,0,3*N) cin >> a[i];

	sort(a.begin(), a.end(), greater< lint >());
	
	lint ans = 0;
	for_(i,0,N) ans += a[i * 2 + 1];
	cout << ans << endl;
}

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

int main () {
  int A,B,C;
  cin>>A>>B>>C;
  if(A==B && A!=C){
    cout<<C<<endl;
  }
  if(B==C && A!=B){
    cout<<A<<endl;
  }
  if(C==A && C!=B){
    cout<<B<<endl;
  }
}


Measured memory_bytes: 256
/*
********************
Author : Sahil Kundu
********************
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mod 1000000007
#define pb(i) push_back(i)
#define f first
#define s second
#define mk(l,r) make_pair(l,r)
#define vi vector<int>
#define vl vector<ll>
#define vch vector<char>
#define all(vc) vc.begin(),vc.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ms(i,j) memset(i,j,sizeof i)
#define w(t) while(t--)
#define len(s) s.length()
#define rep(i,n) for(ll i=0;i<(n);++i)
#define repa(i,n) for(ll i=n;i>=0;i--)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define PI       3.14159265358979323846
#define fastIO ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
const ll MAX=1e5+5;
const ll INF=2e18;

#define INPUT_OUTPUT {\
    freopen("input.txt","r",stdin);\
    freopen("output.txt","w",stdout);\
}

// logical code of program starts here.
void solve()
{
    int n,w;
    cin>>n>>w;
    ll mx=1010*n+2;
    ll dp[mx];
    ll val[n+1],wt[n+1];
    rep(i,mx)dp[i]=INF;
    rep(i,n+1)cin>>wt[i+1]>>val[i+1];
    dp[0]=0;
    rep(i,n+1)
    {
        if(i==0)continue;
        repa(x,mx-1)
        {
            if(val[i]>x)break;
            dp[x]=min(dp[x],dp[x-val[i]]+wt[i]);
        }
    }
    repa(i,mx-1)
    if(dp[i]<=w)
    {
        cout<<i<<endl;
        break;
    }

}


// mian function 
int main()
{
    //INPUT_OUTPUT;//file handling
    fastIO;// fast input output
    clock_t start, end; 
    start = clock();
    int t;
    t=1;
    //cin>>t;
    w(t) solve();
    end = clock();   
    double time_taken = double(end - start)/double(CLOCKS_PER_SEC); 
    clog << "Time taken by program is : " << fixed 
    << time_taken << setprecision(5); 
    clog << " sec " << endl;
    return 0;
}

Measured memory_bytes: 4604
A,B,C,X,Y=map(int,input().split())

ans=10**10
# ABピザの枚数を全探索
for i in range(0,max(X,Y)*2+1,2):
  cost=i*C
  cost+=max(X-i//2,0)*A
  cost+=max(Y-i//2,0)*B
  if cost<ans:
    ans=cost
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef long long ll;

int main(void){
  int i,j;
  //  dic_t dic[200000];
  int ii[100];
  int ilen[100];
	int ia,ib,ic;
  scanf("%d",&ia);
  printf("%d\n",(ia+1)/2);
	return 0;

}


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

bool grid[10][10];

void rev(int y,int x){
  int dy[] = {1,0,-1,0,0}, dx[] = {0,1,0,-1,0};

  for(int i=0;i<5;i++){
    int sy = y+dy[i], sx = x+dx[i];
    if(sy<0 || sx<0 || sy>=10 || sx>=10)continue;
    grid[sy][sx] = !grid[sy][sx];
  }
}

int main(){
  int t;
  bool tmp[10][10];
  int ans[10][10];

  cin >> t;
  while(t--){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	cin >> grid[i][j];
	tmp[i][j] = grid[i][j];
      }
    }
    
    for(int i=0;i<(1<<10);i++){
      for(int j=0;j<10;j++){
	for(int k=0;k<10;k++)grid[j][k] = tmp[j][k];
      }

      for(int j=0;j<10;j++){
	if(i&(1<<j)){
	  rev(0,j);
	  ans[0][j] = 1;
	}else ans[0][j] = 0;
      }

      for(int j=1;j<10;j++){
	for(int k=0;k<10;k++){
	  if(grid[j-1][k]){
	    rev(j,k);
	    ans[j][k] = 1;
	  }else ans[j][k] = 0;
	}
      }

      bool f = false;
      for(int j=0;j<10;j++)f |= grid[9][j];
      if(!f)break;
    }

    for(int i=0;i<10;i++){
      for(int j=0;j<9;j++)cout << ans[i][j] << " ";
      cout << ans[i][9] << endl;
    }
    //if(t)cout << endl;
  }
}

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

int w, h;
int b[90][90];
int ans;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

void dfs(int x, int y, int s) {
	ans = max(ans, s);
	for(int k = 0; k < 4; k++) {
		int nx = x + dx[k], ny = y + dy[k];
		if(0 <= nx && nx < w && 0 <= ny && ny < h && b[ny][nx]) {
			b[ny][nx] = 0;
			dfs(nx, ny, s + 1);
			b[ny][nx] = 1;
		}
	}
}

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

	while(cin >> w >> h, w) {
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				cin >> b[i][j];
			}
		}

		ans = 0;
		for(int i = 0; i < w; i++) {
			for(int j = 0; j < h; j++) {
				dfs(j, i, 0);
			}
		}
		cout << ans << endl;
	}
}

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 998244353, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int main()
{
    int h1, m1, h2, m2, k, time, ans ;
    cin >> h1 >> m1 >> h2 >> m2 >> k ;
    if (m1 > m2) {
        h1++ ;
        time = (h2 - h1) * 60 ;
        time += (60 - m1) ;
        time += m2 ;
    }
    else {
        time = (h2 - h1) * 60 ;
        time += (m2 - m1) ;
    }
    ans = time - k ;
    cout << ans ;


    return 0 ;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_H = 1005;

int R,C;
char Field[MAX_H][MAX_H];

struct Pos {
  Pos(int r = 0, int c = 0) : r(r), c(c) {}
  int r, c;
};

int used[MAX_H][MAX_H];

int dr[] = {1,-1,0,0};
int dc[] = {0,0,1,-1};

bool isInField(int r, int c) {
  return 0 <= r && r < R && 0 <= c && c < C;
}

signed main()
{
  cin >> R >> C;
  queue<Pos> que;
  memset(used, -1, sizeof(used));
  REP(r,R) {
    REP(c,C) {
      cin >> Field[r][c];
      if(Field[r][c] == '#') {
        que.push(Pos(r,c));
        used[r][c] = 0;
      }
    }
  }

  int ans = 0;
  while(que.size()) {
    Pos pos = que.front(); que.pop();
    REP(d,4) {
      int nr = pos.r + dr[d];
      int nc = pos.c + dc[d];
      if(isInField(nr, nc)) {
        if(used[nr][nc] == -1) {
          used[nr][nc] = used[pos.r][pos.c]+1;
          ans = max(ans, used[nr][nc]);
          que.push(Pos(nr,nc));
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 25524
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, bool> pib;

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<double> vf;

typedef long double ld;

#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

#define printItr(A) for(auto itr = A.begin(); itr != A.end(); ++itr){cout << * itr << ", ";}cout << endl;

const double PI = 3.141592653589793;

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

int main() {
	string S;
	cin >> S;
	ll N = S.size()-1;
	ll n = S.size() / 2;

	ll count = 0;
	rep(i, n) {
		if (S[i] != S[N - i]) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a,b;
    scanf("%d %d", &a, &b);
    if(a<b){
        printf("a < b\n");
    }else if(a==b){
        printf("a == b\n");
    }else{
        printf("a > b\n");
    }

    return 0;
}


Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N;
string s;
bool used[1000100];
bool check(int x){
	memset(used,false,sizeof(used));
	vector<int> vI,vO;
	int cnt = 0;
	for(int i=N-1;i>=0;i--){
		if(s[i]=='I'){
			used[i]=true;
			vI.pb(i);
			cnt++;
		}
		if(cnt==x)break;
	}
	if(cnt<x)return false;
	reverse(all(vI));
	for(int i=N-1;i>=0;i--){
		if(sz(vI)==0)break;
		if(s[i]=='O'&&i<vI.back()){
			vO.pb(i);
			vI.pop_back();
		}
	}
	if(sz(vI)>0)return false;
	reverse(all(vO));
	for(int i=N-1;i>=0;i--){
		if(sz(vO)==0)break;
		if(s[i]!='O'&&!used[i]&&i<vO.back()){
			vO.pop_back();
		}
	}
	if(sz(vO)>0)return false;
	return true;
}
int main(){
	scanf("%d",&N);
	cin >> s;
	int l = 0,r = N;
	while(r-l>1){
		int mid = (l+r)/2;
		if(check(mid))l=mid;
		else r = mid;
	}
	printf("%d\n",l);
	return 0;
}

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

int s[1000];
int top=0;

void push(x){
  top++;
  s[top]=x;
}

int pop(){
  top--;
  return s[top+1];
}

void ka(){
  int a,b;

  b=pop();
  a=pop();
  push(a+b);
}

void sa(){
  int a,b;

  b=pop();
  a=pop();
  push(a-b);
}

void jo(){
  int a,b;

  b=pop();
  a=pop();
  push(a*b);
}



int main(){
  char str[100];

  while(scanf("%s",str)!=EOF){

    if(str[0]=='+') ka();
    else if(str[0]=='-') sa();
    else if(str[0]=='*') jo();
    else push(atoi(str));
  }

  printf("%d\n",s[1]);

  return 0;
}

Measured memory_bytes: 548
import java.util.*;

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

		int n = sc.nextInt();
		String s = sc.next();
		int x = 0;
		int max = 0;

		for(int i = 0;i < n;i++){
			if(s.charAt(i) == 'I'){
				x++;
			} else {
				x--;
			}
			if(x > max) max = x;
		}


		System.out.println(max);
	}
}



Measured memory_bytes: 23124
import math

def sd(n ,k):
    if k == 1:
        return n
    while n % k == 0:
        n /= k
    return n

def c1(n):
    n -= 1
    for i in range(1, (int)(math.sqrt(n)) + 1) : 
        if((n) % i == 0):
            sol.add(i)
            sol.add(n/i)

def c2(n):
    for i in range(1, (int)(math.sqrt(n)) + 1) : 
        if((n) % i == 0): 
            if sd(n,i) % i == 1:
                sol.add(i)
            if sd(n, n/i) % (n/i) == 1:
                sol.add(n/i)

n = int(input())
sol = {1}
c1(n)
c2(n)
print(len(sol)-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define s second
ll power(ll x, ll y){ ll ans = 1;x %= MOD;while(y){if(y&1)ans = (x * ans) % MOD;x = (x * x) % MOD;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
using namespace std;

ll helper(int** dp, int* currSkill, int i, int n, int m, int x, ll money) {
    if(i == n) {
        return INT_MAX;
    }
    
    int* tempCurrSkill = new int[m];
    for(int i = 0; i < m; i++) {
        tempCurrSkill[i] = currSkill[i];
    }
    
    ll smallAns = helper(dp, tempCurrSkill, i + 1, n, m, x, money);
    bool okay = true;
    for(int j = 1; j <= m; j++) {
        currSkill[j - 1] += dp[i][j];
        if(currSkill[j - 1] < x)
            okay = false;
    }
    money += dp[i][0];
    // for(int i = 0; i < m; i++) {
    //     cout << currSkill[i] << " ";
    // }
    // cout << endl;
    if(!okay) {
        ll smallAns2 = helper(dp, currSkill, i + 1, n, m, x, money);
        //cout << smallAns2 << "call" <<smallAns << endl;
        return min(smallAns2, smallAns);
    }  else {
        //cout << money << "nocall" <<smallAns << endl;
        return min(smallAns, money);
    }
}

int main() {
    fastio;
    ll n, m, x;
    cin >> n >> m >> x;
    int** dp = new int*[n];
    for(int i = 0; i < n; i++) {
        dp[i] = new int[m + 1];
    }
    
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= m; j++) {
            cin >> dp[i][j];
        }
    }
    
    int currSkill[m];
    memset(currSkill, 0, sizeof(currSkill));
    ll ans = helper(dp, currSkill, 0, n, m, x, 0);
    if(ans == INT_MAX) {
        cout << "-1\n";
    } else {
        cout << ans << endl;
    }
    return 0; 
}

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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> A(N + 1), B(N);
    for (int i = 0; i < N + 1; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> B[i];
    }
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        int cntl = min(A[i], B[i]);
        res += cntl;
        A[i] -= cntl;
        B[i] -= cntl;
        int cntr = min(A[i + 1], B[i]);
        res += cntr;
        A[i + 1] -= cntr;
        B[i] -= cntr;
    }
    cout << res << "\n";

    return 0;
}

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

int main() {
    int N, M, C; cin >> N >> M >> C;
    vector<int> B(M);
    int sum = 0, ans = 0;

    for (int i = 0; i < M; ++i) {
        cin >> B[i];
    }

    for (int j = 0; j < N; ++j) {
        sum = 0;
        for (int i = 0; i < M; ++i) {
            int A; cin >> A;
            sum += A*B[i];
        }
        sum += C;
        if(sum>0) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int size;
int A[500001];

void swap(int* a, int* b) 
{
    int tmp = *a;
     *a = *b;
    *b = tmp;
}

void maxheapify(int A[],int i)
 {
     int l = i * 2;
    int r = i * 2 + 1;

    int largest;
    if (l <= size && A[l] > A[i]) largest= l;
    else largest = i;
    if (r <= size && A[r] > A[largest]) largest = r;
    if (largest != i) {
     swap(&A[i], &A[largest]);
     maxheapify(A,largest);
 }


}

void buildmaxheap()
 {
     for (int i = size / 2; i > 0; i--) 
     {
         maxheapify(A,i);
 }

}

    void printing()
{
    int i;
 for (i = 1; i <= size; i++)
  {
      printf(" %d", A[i]);
 }
}
int main() 
{
    int i;
    scanf("%d", &size);

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

 buildmaxheap();
 printing();

 printf("\n");
 return 0;
}



Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long h = scanner.nextInt();
        long w = scanner.nextInt();
        long total = h*w;
        if(h==1 || w==1){
            System.out.println(1);
        }else{
            System.out.println(total/2 + total%2);
        }
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

const int MAX_L = 1000001;
const int MAX_SQRT_B = 1000001;
bool is_prime_array[MAX_L];
bool is_prime_small[MAX_SQRT_B];
const int mod = 1e9 + 7;
const int MAX = 200002;
ll fact[MAX], invfact[MAX];

#define MAX_V 1000000

ll mod_pow(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}

	return res;
}

ll mod_inverse(ll a, ll m) {
	return mod_pow(a, m - 2, m);
}

ll nCr(ll n, ll r) {
	return fact[n] * invfact[r] % mod * invfact[n - r] % mod;
}

void init() {
	fact[0] = invfact[0] = 1;
	rep(i, 1, MAX) {
		fact[i] = (fact[i - 1] * i) % mod;
		invfact[i] = mod_inverse(fact[i], mod);
	}
}

bool is_prime(int n) {
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) return false;
	}
	return n != 1;
}

vector<int> divisor(int n) {
	vector<int> res;
	for(int i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			res.push_back(i);
			if(i != n / i) res.push_back(n / i);
		}
	}
	return res;
}

map<int, int> prime_factor(int n) {
	map<int, int> res;
	for(int i = 2; i * i <= n; i++) {
		while(n % i == 0) {
			++res[i];
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

int eratosthenes(int n) {
	bool is_prime[n + 1];
	memset(is_prime, true, sizeof(is_prime));
	// prime[n];

	is_prime[0] = is_prime[1] = false;
	int ans = 0;
	rep(i, 2, n + 1) {
		if(is_prime[i]) {
			// prime[ans++] = i;
			ans++;
			for(int j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
	return ans;
}

// [a, b)の整数に対して篩を行う
ll segment_eratosthenes(ll a, ll b) {
	for(int i = 0; (ll)i * i < b; i++) is_prime_small[i] = true;
	for(int i = 0; i < b - a; i++) is_prime_array[i] = true;

	for(int i = 2; (ll)i * i < b; i++) {
		if(is_prime_small[i]) {
			for(int j = 2 * i; (ll)j * j < b; j += i) is_prime_small[j] = false; // [2, sqrt(b))の篩
			for(ll j = max(2LL, (a + i - 1) / i) * i; j < b; j += i) is_prime_array[j - a] = false; // [a, b)の篩
		}
	}
	ll rsl = 0;
	rep(i, 0, sqrt(b)) {
		if(is_prime_array[i]) rsl++;
	}
	return rsl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	init();
	int N, M;
	cin >> N >> M;
	map<int, int> m = prime_factor(M);

	ll rsl = 1;
	for(map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
		(rsl *= nCr(N + it->second - 1, N - 1)) %= mod;
	}

	cout << rsl << endl;
}


Measured memory_bytes: 4352
#include <cmath>
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
#include <iomanip>
using namespace std;

int main()
{
    int h, w;
    
    while(true) {
        cin >> h >> w;
        if(h == 0 && w == 0) return 0;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++) 
            {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }    
    return 0;
}


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

const int INF = 1 << 30;

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

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> key(M);
    for(int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b;
        key[i].first = a;
        for(int j = 0; j < b; ++j) {
            int c; cin >> c; c--;
            key[i].second |= (1 << c);
        }
    }
    vector<int> dp((1 << N) + 1, INF);
    dp[0] = 0;
    for(int bit = 0; bit < (1 << N); ++bit) {
        for(int i = 0; i < M; ++i) {
            chmin(dp[bit | key[i].second], dp[bit] + key[i].first);
        }
    }
    if(dp[(1 << N) - 1] == INF) cout << -1 << '\n';
    else cout << dp[(1 << N) - 1] << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>


#define int long long
using namespace std;


vector <int> g[200000];
int cnt[200000], myprev[200000], h[200000];
int timer = 0;


void dfs1(int u, int prev1, int d){
	h[u] = d;
	myprev[u] = prev1;
	cnt[u] = 1;
	for (int v : g[u]){
		if (v != prev1){
			dfs1(v, u, d + 1);
			cnt[u] += cnt[v];
		}
	}
}


signed main(){
	int n;
	cin >> n;
	
	int u, v;
	for (int i = 0; i < n - 1; ++i){
		cin >> u >> v;
		g[u - 1].push_back(v - 1);
		g[v - 1].push_back(u - 1);
	}

	dfs1(0, -1, 0);
	v = n - 1;
	int len = h[v] + 1 - 2;

	int v1 = v;
	for (int i = 0; i < len / 2; ++i){
		v1 = myprev[v1];
	}

	int k2 = cnt[v1] - 1;
	int k1 = cnt[0] - cnt[v1] - 1;

	if (k1 > k2){
		cout << "Fennec";
	}
	else{
		cout << "Snuke";
	}

	return 0;
}

Measured memory_bytes: 18176
#include <iostream>
#include <math.h>
using namespace std;

int a,b;
char ans;
void solve()
{
    if(a*b==15)
    {
        ans = '*';
    }
    else if(a+b==15)
    {
        ans = '+';
    }
    else
    {
        ans = 'x';
    }

}
int main()
{
    cin >> a >> b;
    solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int INF = 1e9 +7;
signed main(){
   int n,i0;
   cin>>n;
   int k[n+4]={};
   k[3]=1;
    k[4]=4;
    
    for(int i=5;i<n+4;i++){
        k[i]=k[i-1]*4-k[i-3]*2-k[i-4]*3;
      i0=i-3;
      while(i0>=3){
          k[i]+=k[i0-1]-k[i0];
          i0-=3;
      }
      i0=i-5;
      while(i0>=3){
          k[i]+=k[i0]-k[i0-1];
          i0-=3;
      }
       if(k[i]<0)while(k[i]<0)k[i]+=INF;
        else k[i]=k[i]%INF;
      
    }
    cout <<k[n+3];
    return 0;
}

Measured memory_bytes: 256
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
ans = 0
for i in range(n):
    l, r = na()
    ans += r - l + 1
print(ans)




Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll MOD = 1e9 + 7;
const ll INF = 1e10;

const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1)/2;
vector<vector<int>> G(MAXV);
vector<vector<int>> id(MAXN,vector<int>(MAXN));

int toID(int i,int j) {
    if (i > j) swap(i,j);
    return id[i][j];
}

vector<int> dp(MAXV,-1);
vector<bool> finished(MAXV,false);

int dfs(int v) {
    if (dp[v] != -1) {
        if (!finished[v]) {
            return -1;
        }
        return dp[v];
    }
    dp[v] = 1;
    for (int e : G[v]) {
        int res = dfs(e);
        if (res == -1) return -1;
        dp[v] = max(dp[v], dfs(e) + 1);
    }
    finished[v] = true;
    return dp[v];
}

int main() {
    int n; cin >> n;
    vector<vector<int>> a(n,vector<int>(n - 1));
    rep(i,n)rep(j,n - 1) {
        cin >> a[i][j];
        a[i][j] --;
    }

    int v = 0;
    rep(i,n)rep(j,n) {
        if (i < j) id[i][j] = v++;
    }

    rep(i,n) {
        rep(j,n - 1) {
            a[i][j] = toID(i,a[i][j]);
        }
        rep(j,n - 2) {
            G[a[i][j + 1]].push_back(a[i][j]);
        }
    }

    int ans = 0;
    rep(i,v) {
        int res = dfs(i);
        if (res == -1) {
            ans = -1;
            break;
        }
        ans = max(ans,dfs(i));
    }

    cout << ans << endl;
}

Measured memory_bytes: 37760
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

#define rep(i,a,n) for(int (i)=a;(i)<(int)(n);(i)++)
#define rrep(i,a,n) for(int (i)=(n)-1;(i)>=a;(i)--)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

int main() {
	rep(i,1,10010) {
			int x;
			cin >> x;
			if (x == 0) return 0;

			cout << "Case " << i << ": " << x << endl;
	}
}

Measured memory_bytes: 3060
def canc_loop(d):
    a = 2
    b = 1
    s = d + d
    if s > 10:
        s = 1 + s % 10
        b += 1
    while s != d:
        s += d
        a += 1
        b += 1
        if s >= 10:
            s = 1 + s % 10
            b += 1
    return a, b


def main():
    db = []
    for i in xrange(10):
        db.append(canc_loop(i))
    m = input()
    count = 0
    degi = []
    for _ in xrange(m):
        d, c = map(int, raw_input().split())
        a, b = db[d]
        while c >= a:
            count += c / a * b
            c = c / a + c % a
        degi.extend([d] * c)
    if not degi:
        return count
    d = degi.pop()
    while degi:
        d += degi.pop()
        count += 1
        if d >= 10:
            d = d % 10 + 1
            count += 1
    return count


print main()
            

Measured memory_bytes: 87964
N, M = map(int, input().split())
ab = [[int(x) for x in input().split()] for _ in range(M)]

ab = sorted(ab, key=lambda x: (x[0], x[1]))
cnt = 1
left, right = ab[0]
for a, b in ab[1:]:
    if b <= left or right <= a:
        cnt += 1
        left, right = a, b
    else:
        left = max(left, a)
        right = min(right, b)
print(cnt)


Measured memory_bytes: 30296
#include<bits/stdc++.h>
typedef long long ll;
#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
using namespace std;
ll t;
double arr[200005];
map<string,string>np;
vector<ll>v,v1;
int main()
{
    ll a,b,c,d,e,f=0,i,j,cnt=0;
    cin>>a>>b;
    double g;
    double h=0.0;
    for(i=1;i<=a;i++)
    {
        cin>>g;
        arr[i]=g*(g+1.0);
        arr[i]/=2.0;
        arr[i]/=g;
    }
    for(i=1;i<=a;i++)
    {arr[i]=arr[i]+arr[i-1];}
    for(i=b;i<=a;i++)
    {
        double k=arr[i]-arr[i-b];
        h=max(h,k);
    }
    printf("%0.10lf\n",h);
    return 0;

}


Measured memory_bytes: 1792
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

class UnionFind:
    def __init__(self, n):
        self._parent = [i for i in range(n)]
        self._rank = [0 for _ in range(n)]
        self._group_size = [1 for _ in range(n)]
        self.num_of_groups = n

    def find(self, x):
        vs = []
        while self._parent[x] != x:
            vs.append(x)
            x = self._parent[x]
        for v in vs: self._parent[v] = x
        return x

    def union(self, x, y):
        px, py = self.find(x), self.find(y)
        if px == py: return
        if self._rank[px] < self._rank[py]:
            self._parent[px] = py
            self._group_size[py] += self._group_size[px]
        else:
            self._parent[py] = px
            self._group_size[px] += self._group_size[py]
        if self._rank[px] == self._rank[py]:
            self._rank[py] += 1
        self.num_of_groups -= 1

    def is_same(self, x, y): return self.find(x) == self.find(y)
    def group_size(self, x): return self._group_size[self.find(x)]


def main():
    N, Q = LI()
    TUV = LIR(Q)

    uf = UnionFind(N+1)

    for t, u, v in TUV:
        if t == 0:
            uf.union(u, v)
        else:
            print(int(uf.is_same(u, v)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 130044
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int h,w;
    cin >>h>>w;
    vector<vector<char>> c(h,vector<char> (w,'.'));
    vector<bool> X(h,true);
    vector<bool> Y(w,true);
    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
            if(c[i][j]=='#'){
                X[j]=false;
                Y[i]=false;
                //trueの時には書かない  
            }
        }
    }
    bool all;
    rep(i,h){
        all=true;
        rep(j,w){
            if(X[j]||Y[i]){
                continue;
            }
            cout<<c[i][j];
            all = false;
        }
        if(!all){
        cout<<endl;
        }
    }
}

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

int main(void)
{
    int K,S;
    int X,Y,Z;
    int cnt = 0;

    cin >> K >> S;
    for(int i = 0; i <= K; i++ )
    {
        for(int j = 0; j <= K; j++)
        {
            Z = S - i - j;
            if(Z >= 0 && Z <= K)
                    cnt++;
        }
    }
        
    cout << cnt <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n,m,p,q,r,x,y;
	vector<int>::iterator u,v,z;
	for(;cin>>n>>m>>p>>q>>r;cout<<x<<endl){
		vector<int> s,t;
		s.push_back(0);
		for(s.push_back(r);m--;t.clear()){
			cin>>x>>y;
			u=upper_bound(s.begin(),s.end(),x);
			v=upper_bound(s.begin(),s.end(),y);
			
			if( v-s.begin()+1 & 1 )t.push_back(0);
			t.push_back(0);
			for(z=v;z<s.end();++z)
				t.push_back(*z - y);
			
			if(s.end()-u & 1)t.push_back(n-y);
			for(z=u;z<v;++z)
				t.push_back(*z-x+n-y);
			
			z = s.begin();
			if(v-s.begin() & 1)++z;
			if(!z[1])z+=2;
			if(*z+n-x==t.back()){++z;t.pop_back();}
			for(;z<u;++z)
				t.push_back(*z+n-x);
			
			s.swap(t);
		}
		s.insert( upper_bound(s.begin(),s.end(),p-1), 2, p-1);
		s.insert( lower_bound(s.begin(),s.end(),q), q );
		s.push_back(n);
		z = upper_bound(s.begin(),s.end(),p-1);
		if(z-s.begin() & 1) --z;
		for(x=0;*z<q;++z)
			m=*z++,x+=*z-m;
	}
}

Measured memory_bytes: 0
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    A, B = map(int, input().split())
    k = abs(A - B)
    if k % 2 != 0:
        print("IMPOSSIBLE")
    else:
        print(min(A, B) + (k // 2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func f(n int) int {
	N := n + 1
	d := N / 2
	ret := 0
	// out("d", d, "n", n)
	if N%2 == 1 {
		ret = (d % 2) ^ n
	} else {
		ret = d % 2
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	A, B := getInt(), getInt()

	// out(f(A - 1))
	// out(f(B))
	out(f(A-1) ^ f(B))
}


Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
    string r[3];

void solve(){
    for(int i=0;i<3;i++){
            if(r[i][0]==r[i][1]
            &&r[i][1]==r[i][2]
            &&r[i][0]!='+'){
                cout<<r[i][0]<<endl;
                return;
            }
            if(r[0][i]==r[1][i]
            &&r[1][i]==r[2][i]
            &&r[0][i]!='+'){
                cout<<r[0][i]<<endl;
                return;
            }
        }
        if(r[0][0]==r[1][1]
        &&r[1][1]==r[2][2]
        &&r[0][0]!='+'){
            cout<<r[0][0]<<endl;
            return;
        }
        if(r[0][2]==r[1][1]
        &&r[1][1]==r[2][0]
        &&r[2][0]!='+'){
            cout<<r[2][0]<<endl;
            return;
        }
        cout<<"NA"<<endl;
}

int main(){
    int i;
    while(cin>>r[0]&&r[0]!="0"){
        for(i=1;i<3;i++) cin>>r[i];
        solve();
    }
    return 0;
}


Measured memory_bytes: 3132
n=int(input())
a=[]
a.append(0)
a+=list(map(int,input().split()))
a.append(0)
cnt=0
for i in range(1,len(a)):
    cnt+=abs(a[i]-a[i-1])
for i in range(1,len(a)-1):
    p=abs(a[i]-a[i-1])+abs(a[i+1]-a[i])
    print(cnt-p+abs(a[i+1]-a[i-1]))


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

int main() {
  string s;
  cin >> s;
  ll gx,gy;
  cin >> gx >> gy;
  vector<ll> x;
  vector<ll> y;
  ll count=0;
  ll dir=1;
  ll xs=0,ys=0;
  for(ll i=0;i<s.size();i++) {
    if(s[i]=='F') {
      count++;
    }
    else {
      if(count>0) {
        if(dir>0) {
          x.push_back(count);
          xs+=count;
        }
        else {
          y.push_back(count);
          ys+=count;
        }
      }
      count=0;
      dir*=-1;
    }
  }
  if(count>0) {
    if(dir>0) {
      x.push_back(count);
      xs+=count;
    }
    else {
      y.push_back(count);
      ys+=count;
    }
  }
  vector<vector<ll>> dpx(x.size()+1,vector<ll>(xs*2+1));
  vector<vector<ll>> dpy(y.size()+1,vector<ll>(ys*2+1));
  dpx[0][xs]=1;
  dpy[0][ys]=1;
  for(ll i=0;i<x.size();i++) {
    for(ll j=0;j<xs*2+1;j++) {
      if(j+x[i]<xs*2+1) {
        dpx[i+1][j+x[i]]+=dpx[i][j];
      }
      if(j-x[i]>-1&&(i!=0||s[0]!='F')) {
        dpx[i+1][j-x[i]]+=dpx[i][j];
      }
    }
  }
  for(ll i=0;i<y.size();i++) {
    for(ll j=0;j<ys*2+1;j++) {
      if(j+y[i]<ys*2+1) {
        dpy[i+1][j+y[i]]+=dpy[i][j];
      }
      if(j-y[i]>-1) {
        dpy[i+1][j-y[i]]+=dpy[i][j];
      }
    }
  }
  if(gx>xs||gy>ys||gx<-xs||gy<-ys||dpx[x.size()][gx+xs]==0||dpy[y.size()][gy+ys]==0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 127488