akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

template <typename T>
struct node_t {
  T key;
  node_t *lc, *rc;
  explicit node_t(T v): key(v), lc(nullptr), rc(nullptr) {}
};

template <typename T>
using tree_t = node_t<T> *;

template <typename T>
void insert(node_t<T> *&t, T v) {
  tree_t<T> z = new node_t<T>(v);
  tree_t<T> y = nullptr;
  tree_t<T> x = t;
  while (x) {
    y = x;
    if (z->key < x->key) {
      x = x->lc;
    } else {
      x = x->rc;
    }
  }
  if (!y) {
    t = z;
  } else if (z->key < y->key) {
    y->lc = z;
  } else {
    y->rc = z;
  }
}

template <typename T>
bool find(tree_t<T> t, T k) {
  if (!t) { return false; }
  if (t->key == k) { return true; }
  return (k < t->key)? find(t->lc, k) : find(t->rc, k);
}

template <typename T>
void inorder_walk(tree_t<T> t) {
  stack<tuple<tree_t<T>, bool>> stk;
  stk.emplace(t, false);
  while (!stk.empty()) {
    tree_t<T> ptr; bool op;
    tie(ptr, op) = stk.top(); stk.pop();
    if (!ptr) { continue; }
    if (op) {
      cout << " " << ptr->key;
    } else {
      stk.emplace(ptr->rc, false);
      stk.emplace(ptr, true);
      stk.emplace(ptr->lc, false);
    }
  }
  cout << endl;
}

template <typename T>
void preorder_walk(node_t<T> *t) {
  stack<tree_t<T>> stk;
  stk.push(t);
  while (!stk.empty()) {
    auto const ptr = stk.top(); stk.pop();
    if (!ptr) { continue; }
    cout << " " << ptr->key;
    stk.push(ptr->rc);
    stk.push(ptr->lc);
  }
  cout << endl;
}

int main() {
  using Tree = node_t<lli> *;
  Tree tree = nullptr;
  int M; cin >> M;
  REP(query, M) {
    string S; cin >> S;
    if (S[0] == 'i') {
      lli K; cin >> K;
      insert(tree, K);
    } else if (S[0] == 'p') {
      inorder_walk(tree);
      preorder_walk(tree);
    } else {
      lli K; cin >> K;
      cout << (find(tree, K)? "yes":"no") << endl;
    }
  }
  return 0;
}



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

int main() {
  int N;
  long long x;
  cin >> N >> x;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) cin >> a.at(i);
  
  long long count = 0;
  for (int i = 0; i < N - 1; i++) {
    long long lhs = a.at(i);
    long long rhs = a.at(i + 1);
    if (lhs + rhs > x) {
      long long sum = lhs + rhs;
      long long sub_candies = sum - x;
      rhs -= sub_candies;
      count += sub_candies;
      if (rhs < 0) rhs = 0;
      a.at(i + 1) = rhs;
    }
  }
  cout << count << endl;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector< vector<int> > a(h, vector<int>(w));
  int cur = 0;
  int t = -1;
  for (int i = 0; i < h; i++) {
    if (s[i] == string(w, '.')) {
      continue;
    }
    if (t == -1) {
      t = i;
    }
    cur++;
    int first = 1;
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        if (!first) {
          cur++;
        }
        first = 0;
      }
      a[i][j] = cur;
    }
  }
  for (int i = t - 1; i >= 0; i--) {
    for (int j = 0; j < w; j++) {
      a[i][j] = a[i + 1][j];
    }
  }
  for (int i = t + 1; i < h; i++) {
    if (s[i] != string(w, '.')) {
      continue;
    }
    for (int j = 0; j < w; j++) {
      a[i][j] = a[i - 1][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << a[i][j] << " ";
    }
    cout << '\n';
  }
  return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
#include<string.h>

int main(void)
{
  int n = 0,max = 0,x = 0;
  char moji[110];
  scanf("%d",&n);
  scanf("%s",moji);
  
  for(int i = 0;i < strlen(moji);i++)
  {
    switch(moji[i])
    {
      case 'I':
        x += 1;
        break;
      case 'D':
        x -= 1;
        break;
    }
    if(max < x){max = x;}
  }
  
  printf("%d",max);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
  int x;
  cin >> x;
  int fx = [](int x){
    int ans = 0;
    while(x > 0){
      ans += x % 10;
      x /= 10;
    }
    return ans;
  }(x);
  cout << ((x % fx == 0) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const double PI=3.1415926535897932;
using namespace std;
typedef long long ll;

int main(void){
    ll n;
    cin>>n;
    ll a=n%1000;
    if(a!=0)cout<<1000-a<<endl;
    else cout<<0<<endl;
    
    
}

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

std::string S;
int N;
std::vector<int> evenPlace;

int calcPlace(int);
int calcNext(int);

int main()
{
	std::cin >> S;
	N = (int)S.size();
	evenPlace.resize(N, -1);
	for (int i{}; i < N; i++)
		calcPlace(i);
	std::vector<int> ans(N);
	for (auto& e: evenPlace) ans[e]++;
	for (int i{}; i < N; i++)
		printf("%d%c", ans[i], i + 1 == N? '\n': ' ');

	return 0;
}

int calcPlace(int index)
{
	if (evenPlace[index] >= 0) return evenPlace[index];
	evenPlace[index] = index;
	int next_even{calcNext(calcNext(index))};
	evenPlace[index] = calcPlace(next_even);
	return evenPlace[index];
}

int calcNext(int index)
{
	if (S[index] == 'L') return index - 1;
	else return index + 1;
}

Measured memory_bytes: 2944
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int X;
int Y;
int Z;
int main(){
  rd(X);
  rd(Y);
  rd(Z);
  wt_L(Z);
  wt_L(' ');
  wt_L(X);
  wt_L(' ');
  wt_L(Y);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200404-1

// --- original code ---
// int X, Y, Z;
// {
//   rd(X,Y,Z);
//   wt(Z,X,Y);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define ll long long
#define pi pair<int,int>
#define pii pair<pi,int>
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int n,m;
ll ans;
pi a[100100];
multiset <int> s;
vector <int> v[100100];
int main()
{
    go;
    cin>>n>>m;
    for(int i=0; i<n; i++)
    {
        cin>>a[i].F>>a[i].S;
        if(m-a[i].F>=0)
            v[m-a[i].F].pb(a[i].S);
    }
    for(int i=m-1;i>=0;i--)
    {
        for(int x : v[i])
            s.insert(x);
        if(s.empty()) continue;
        ans+=*(--s.end());
        s.erase(--s.end());
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 8576
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {

	static int[] color;
	static int n;

	public static void main(String[] args) throws IOException {

		Scanner in = new Scanner(System.in);

		n = in.nextInt();
		int m = in.nextInt();
		color = new int[n];

		List<List<Integer>> g = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			g.add(new ArrayList<Integer>());
		}
		for (int i = 0; i < m; i++) {
			int v1 = in.nextInt();
			int v2 = in.nextInt();

			g.get(v1).add(v2);
			g.get(v2).add(v1);
		}

		assignColor(g);

//		for (int i = 0; i < g.size(); i++) {
//			System.out.println(i + " " + g.get(i));
//		}
		int q = in.nextInt();
		for (int i = 0; i < q; i++) {
			int s = in.nextInt();
			int t = in.nextInt();
			if (color[s] == color[t]) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
	}
	private static void assignColor(List<List<Integer>> list) {
		Arrays.fill(color, -1);
		int id = 1;
		for (int i = 0; i < n; i++) {
			if (color[i] == -1) {
				dfs(list, i, id++);
			}
		}
	}

	public static void dfs(List<List<Integer>> list, int from, int id) {
		Deque<Integer> deque = new ArrayDeque<Integer>();

		deque.push(from);
		color[from] = id;

		while (!deque.isEmpty()) {
			from = deque.peek();
			boolean isConnect = false;
			for (int to : list.get(from)) {
				if (color[to] != -1) {
					continue;
				}
				isConnect = true;
				deque.push(to);
				color[to] = id;
				break;
			}
			if (!isConnect) {
				deque.pop();
			}
		}

	}

}




Measured memory_bytes: 117688
def jmp(h):
    n=len(h)
    dp=[0 for i in range(1000000)]
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(2,n):
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
    return dp[n-1]

n=int(input())
l=list(map(int,input().split()))
print(jmp(l))

Measured memory_bytes: 19524
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib> 
#include<cstring>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	char s[a+b+2];
	cin>>s;
	for(int i=0;i<strlen(s);i++){
//		cout<<"*  ";
		if(i==a){
				if(s[i]!='-'){
			 		cout<<"No"<<endl;	
			 		return 0;
				}
				else continue;
			}
//		cout<<"#  ";
else{
	if(s[i]>='0'&&s[i]<='9') {
		continue;	
		}
		else{
			
			cout<<"No"<<endl;
			return 0;
		}
}
		
	}
	cout<<"Yes";
	return 0;
} 

Measured memory_bytes: 256
PROGRAM sumOfTwoIntegers
      IMPLICIT NONE
      integer :: N
      integer :: ans
      
      read*,N
      
      if( mod(N,2)==1 )THEN
        ans = (N-1) / 2
      else
        ans = N/2 -1
      end if
      
      print*,ans
      
      
      
      
      
      
      END PROGRAM

Measured memory_bytes: 640
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<ll>>;

// dijkstra　
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
// dijkstra end


class UnionFind
{
public:
  ll par[100005];
  ll depth[100005];
  ll nGroup[100005];
 
  UnionFind(ll n) {
    init(n);
  }
 
  void init(ll n) {
    for(ll i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  ll root(ll x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(ll x, ll y) {
    return root(x) == root(y);
  }
 
  void unite(ll x, ll y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
// unionfind end

// nCr
const ll MAX = 500010;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// nCr end

// tree DP
vector<ll> depth;
vector<ll> g(10010,0);
ll c[10010];
void dfs(const Graph &G, ll v, ll p, ll &d) {
         g[v] = c[d-1];
    for (auto nv : G[v]) {
        if (nv == p) continue;
        d--;
        dfs(G, nv, v, d);
    }
}
// tree DP end
int main() {
  ll n; cin>>n;
  Graph G(n+1);
  rep(i,n-1){
    ll a,b; cin>>a>>b;
    G[a].pb(b);
    G[b].pb(a);
    }
  rep(i,n) cin>>c[i];
  sort(c,c+n);
  ll ans = 0;
  rep(i,n-1) ans += c[i];
  cout << ans << endl;
  ll k = n;
  dfs(G,1,-1,n);
  repl(i,1,k+1) cout << g[i] << " ";
}



Measured memory_bytes: 4668
#include <bits/stdc++.h>
#define MAX 100007

#define REP(i, N) for(int (i)=0; (i) < (N); (i)++)
#define PER(i, N) for(int (i)=(N)-1; (i) >= 0; (i)--)

using namespace std;
typedef long long ll;
typedef pair<ll, int> pii;

int main(){
    
    int x, y, z; cin >> x >> y >> z;

    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000


int main(){
	
	int N,K;
	cin>>N>>K;
	string S;
	cin>>S;
	char min_c = '{';
	for(int i=0;i<S.size();i++){
		min_c = min(min_c,S[i]);
	}
	
	string k(N,min_c);
	
	for(int i=0;i<K;i++){
		string T = S;
		reverse(S.begin(),S.end());
		T += S;
		
		string s = "{";
		for(int j=0;j<=N;j++){
			s = min(s,T.substr(j,N));
		}
		
		if(i!=K-1)reverse(s.begin(),s.end());
		S = s;
		if(S==k)break;
		
	}
	
	
	
	
	cout<<S<<endl;
		
	
	return 0;
}


Measured memory_bytes: 256
import Foundation

extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
}

let input = readLine()!.split(by: " ").map{Int($0)!}
let N = input[0]
let Q = input[1]
let S = readLine()!.characters.map{$0}

var sum = [0]
for i in 1...N {
    sum.append(sum[i-1])
    if (i != N) && (S[i-1] == "A") && (S[i] == "C") {
        sum[i] += 1
    }
}

for _ in 0..<Q {
    let input = readLine()!.split(by: " ").map{Int($0)!}
    print(sum[input[1]-1] - sum[input[0]-1])
}

Measured memory_bytes: 4216
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int N,Q;
  cin>>N>>Q;
  vector<ll> a(2*N),b(2*N);
  for(int i=0;i<2*N;i++) cin>>a[i];
  for(int i=0;i<2*N;i++) cin>>b[i];

  multiset<ll> se;
  ll ans=a[0]+a[2*N-1];
  int odd=0;
  for(int i=1;i<2*N-1;i++){
      se.insert(abs(a[i]-b[i]));
      ans+=max(a[i],b[i]);
      if(a[i]<b[i]) odd^=1;
  }

  for(int i=0;i<Q;i++){
      int p,x,y;
      cin>>p>>x>>y;
      p--;
      ll res=ans;
      if(p==0||p==2*N-1){
          res=res-a[p]+x;
      }else{
          res-=max(a[p],b[p]);
          res+=max(x,y);
          if(a[p]<b[p]) odd^=1;
          if(x<y) odd^=1;
          se.erase(se.find(abs(a[p]-b[p])));
          se.insert(abs(x-y));
      }
      a[p]=x;
      b[p]=y;
      
      if(odd==1) cout<<res-*(se.begin())<<endl;
      else cout<<res<<endl;
      ans=res;
  }

  return 0;
}


Measured memory_bytes: 14208
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

LL N, M;
LL fact[123456];
LL finv[123456];

LL mpow(LL a, LL x) {
	if (x == 0)return 1;
	LL tmp = mpow(a, x / 2);
	tmp *= tmp;
	tmp %= M;
	if (x % 2)tmp *= a;
	tmp %= M;
	return tmp;
}

inline LL comb(LL n, LL r) {
	if (r < 0 || n < r)return 0;
	LL tmp = fact[n] * finv[r];
	tmp %= M;
	tmp *= finv[n - r];
	tmp %= M;
	return tmp;
}

int main(void)
{
	cin >> N >> M;
	fact[0] = finv[0] = 1;
	for (LL i = 1; i < 123400; ++i) {
		fact[i] = fact[i - 1] * i;
		fact[i] %= M;
		finv[i] = mpow(fact[i], M - 2);
	}
	LL total = 0;
	for (int p = 1; p < N; ++p) {
		int q = N - p;
		LL ans = comb(N, p);
		ans *= mpow(2, comb(p, 2));
		ans %= M;
		ans *= mpow(2, comb(q, 2));
		ans %= M;
		LL sum = 0;
		LL mone = 1;
		for (int j = 0; j <= p; ++j) {
			LL tmp = (mone * comb(p, j)) % M;
			tmp *= mpow((mpow(2, p - j) + M - 1) % M, q);
			tmp %= M;
			sum += tmp;
			sum %= M;
			mone *= (M - 1);
			mone %= M;
		}
		ans *= sum;
		ans %= M;
		total += ans;
		total %= M;
	}
	cout << total << endl;
	return 0;
}



Measured memory_bytes: 5028
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
#define N 200001
int a[N],n;
int cnt;
int main(){
    while (scanf("%d",&n)!=EOF){
        cnt = 0;
        do{
            int r = n % (-2);
            int c = n / (-2);
            if (r==-1)
            {
                c++;
                r += 2;
            }

            a[cnt++] = r;
            n = c;
        }while(n);
        for (int i=cnt-1;i>=0;i--)
            printf("%d",a[i]);
        printf("\n");
    }
    return 0;
}




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

using namespace std;

int main(){
    int k,s;
    cin>>k>>s;
    int x,y,z;
    int ans=0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            z=s-(j+i);
            if(z>=0&&z<=k){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

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

    int x, y, a, b, c; cin>>x>>y>>a>>b>>c;
    vector<int> p(a), q(b), r(c);
    for(int i=0; i<a; i++) cin>>p[i];
    for(int i=0; i<b; i++) cin>>q[i];
    for(int i=0; i<c; i++) cin>>r[i];

    sort(all(p), greater<int>());
    sort(all(q), greater<int>());

    vector<int> v;
    for(int i=0; i<x; i++) v.emplace_back(p[i]);
    for(int i=0; i<y; i++) v.emplace_back(q[i]);
    for(int i=0; i<c; i++) v.emplace_back(r[i]);

    sort(all(v), greater<int>());

    ll ans = 0;
    for(int i=0; i<x+y; i++) ans += v[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

int battle(const std::string& taro, const std::string& hanako)
{
    // draw
    if (taro == hanako) {
        return 0;
    }

    for (std::size_t i = 0; i < taro.length(); ++i) {
        if (hanako.length() <= i) {
            return 1;
        }

        if ((char)(taro[i]) < (char)(hanako[i])) {
            return -1;
        } else if ((char)(taro[i]) > (char)(hanako[i])) {
            return 1;
        } else {
            continue;
        }
    }

    return -1;
}

int main()
{
    std::size_t n;
    std::cin >> n;

    int scoreT = 0, scoreH = 0;
    for (std::size_t i = 0; i < n; ++i) {
        std::string t, h;
        std::cin >> t >> h;
        int result = battle(t, h);
        if (result == 1) {
            scoreT += 3;
        } else if (result == -1) {
            scoreH += 3;
        } else {
            scoreT += 1;
            scoreH += 1;
        }
    }

    std::cout << scoreT << " " << scoreH << std::endl;

    return 0;
}


Measured memory_bytes: 3164
#include <stdio.h>
#include <string.h>

char s[100010];
char t[100010];

int ans[100010];
int main(){
	scanf("%s %s",s,t);
	int sm=(s[0]=='-'),tm=(t[0]=='-');
	int sn=strlen(s+sm),tn=strlen(t+tm);
	for(int i=0;i<sn;i++){
		if(sm)ans[i]-=s[sn+sm-1-i]-'0';
		else ans[i]+=s[sn-1-i]-'0';
	}
	for(int i=0;i<tn;i++){
		if(tm)ans[i]-=t[tn+tm-1-i]-'0';
		else ans[i]+=t[tn-1-i]-'0';
	}
	for(int i=0;i<100005;i++){
		while(ans[i]<0)ans[i]+=10,ans[i+1]--;
		while(ans[i]>9)ans[i]-=10,ans[i+1]++;
	}
	if(ans[100005]<0){
		printf("-");
		for(int i=0;i<100005;i++)ans[i]=9-ans[i];
		ans[0]++;
		int crr=0;
		while(ans[crr]==10)ans[crr]=0,ans[++crr]++;
	}
	int digit=0;
	for(int i=0;i<100005;i++)if(ans[i])digit=i;
	for(int i=digit;i>=0;i--)printf("%d",ans[i]);
	puts("");
}


Measured memory_bytes: 2440
#include<stdio.h>
int main(void){
int a,b,c=0;
   scanf("%d %d %d",&a,&b,&c);
  while(a!=-1 || b!=-1 || c!=-1){
   if(a==-1||b==-1)
     printf("F\n");
   else if(a+b>=80)
     printf("A\n");
   else if(a+b>=65&&a+b<80) 
     printf("B\n");
   else if(a+b>=50&&a+b<65)
     printf("C\n");
   else if(a+b>=30&&a+b<50){
     if(c>=50)
       printf("C\n");
     else
       printf("D\n");
   }
   else
     printf("F\n");
     scanf("%d %d %d",&a,&b,&c);
 }
  return 0;
}    



Measured memory_bytes: 2044
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

ll N, A, B;


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

	ll ans;
	if (A + B >= N) {
		ans = min(A, N);
	}
	else {
		ans = (N / (A + B)) * A;
		ans += min(N % (A + B), A);
	}

	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long long int n=1,s=0,r=0,q=0,a,b;
    
    cin >> n >> a >> b;
    s = a+b;
    r = n%s;
    q = n/s;
    
    if(r>=a)
        cout <<q*a+a;
    else
        cout << q*a+r;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <iomanip>
#include <cmath>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long 
//#define int long long
#define ld long double
#define vi deque<int>
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define iii pair<int,ii>
#define il pair<int,ll>
#define pll pair<ll,ll>
#define _path pair<ll,pair<ll,int> > 
#define vv deque
//#define endl '\n'
//#define mp make_pair
using namespace std;
const int MAXN = 10000+5;
const int MAXK = 1000+5;
const ll INF = 1e18;
ll arr[MAXN];
ll dp[MAXK][MAXN];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// int t;
	// cin >> t;
	// while(t--)
	// {
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	int ans=0;
	
	// sort(a,a+j);
	// for(int i=0;i<j;i++)
	// 	cout << a[i] << " " ;
	//cout << endl;
	for(int i=0;i<n-2;i++)
	{
		for(int j=i+1;j<n-1;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if((a[i]!=a[j] && a[i]!=a[k] && a[j]!=a[k]) && (a[i]+a[j]>a[k] && a[j]+a[k]>a[i] & a[i]+a[k]>a[j]))
					{
						//cout << a[i] << " " << a[j] << " "<< a[k] << endl;
						ans++;
					}
				
			}
		}
	}
	cout  << ans << endl;

	
	
		return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k; cin >> n >> k;
  ll sq = sqrt(n);
  vector<ll> v;
  rep(i,sq){
      v.push_back(i+1);
  }
  rep(i,sq){
      v.push_back(n/(i+1));
  }
  sort(all(v));
  vector<ll> ans(v.size());
  vector<ll> coe(v.size());
  rep(i,v.size()){
      if(i==0)ans[i] = 1;
      else ans[i] = v[i] - v[i-1];
      if(i==0)coe[i] = 1;
      else coe[i] = v[i] - v[i-1];
  }
  rep(i,k-1){
      ll sum = 0;
      rep(i,ans.size()){
          sum += ans[i];
      }
      vector<ll> tmp(ans.size(), 0);
      rep(i,ans.size()){
          tmp[i] = sum * coe[i] % MOD;
          sum -= ans[ans.size()-1-i];
      }
      ans = tmp;
  }
  ll fans = 0;
  rep(i,ans.size()){
      fans += ans[i];
      fans %= MOD;
  }
  cout << fans << endl;

}

Measured memory_bytes: 2424
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf 1000000000000000000

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,k;
    cin>>n>>k;
    vi a(n);
    int m=0;
    rep(i,n){
        cin>>a[i];
        m=max(m,a[i]);
    }
    int g=__gcd(a[0],a[1]);
    Rep(i,2,n){
        g=__gcd(g,a[i]);
    }
    if(k%g==0&&k<=m){
        cout<<"POSSIBLE"<<endl;
    }
    else{
        cout<<"IMPOSSIBLE"<<endl;
    }
}

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

int cmp(const int *a,const int *b){
  return *a-*b;
}
int main(){
  int n,d[100],i,j=1;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&d[i]);
  qsort(d,n,sizeof(int),cmp);
  for(i=1;i<n;i++) if(d[i]-d[i-1]) j++;
  printf("%d",j);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#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++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  int n;
  cin >> n;
  cout << 48 - n << endl;
  
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    string s;
    cin >> s;
    cout << "2018"+s.substr(4, s.length()-4) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

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


Measured memory_bytes: 6728
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N, count=0;
	bool r = false;
	cin >> N;
	while(N--){
		int d1, d2;
		cin >> d1 >> d2;
		if(d1==d2)
			count++;
		else
			count = 0;
		if(count==3){
			r = true;
		}
	}

	if(r)
		Yes();
	else
		No();

	return 0;
}



Measured memory_bytes: 3612
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;
void main()
{
    long N;
    scan(N);
    double sum = 0;
    foreach (_; 0 .. N)
    {
        double x;
        string t;
        scan(x, t);
        // writeln(x,t);
        if (t == "BTC")
        {
            sum += x * 380000.0;
        }
        else
        {
            sum += x;
        }
        // writeln(sum);
    }
    writeln(sum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
using pp=pair<ll,pair<ll,ll>>;
#define MAX 1000000
#define MOD 998244353
#define INF 1000000000000000000

int main(){
  int N;
  cin>>N;
  cout<<1-N<<endl;;
}


Measured memory_bytes: 3640
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    for (i, line) in stdin.lock().lines().enumerate() {
        let x: i32 = line.unwrap().trim().parse().unwrap();
        match x {
            0 => break,
            _ => println!("Case {}: {}", i+1, x),
        }
    }
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int R, G;
	cin >> R >> G;
	cout << 2 * G - R << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int cost[10][10];
int num[220][220];

int main(){
    int h, w;
    cin >> h >> w;

    rep(i,10) rep(j,10) cin >> cost[i][j];
    rep(i,h) rep(j,w) cin >> num[i][j];


    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++)cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
        }
    }

    ll ans =0;

    rep(i,h){
        rep(j,w){

            if(num[i][j] != -1){
                ans += cost[num[i][j]][1];
            }

        }
    }

    dunk(ans);


}

Measured memory_bytes: 384
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
sa = defaultdict(int)
for i,x in enumerate(a):
    sa[(i+1)-x] += 1
res = 0
for i,x in enumerate(a):
    res += sa[i+1+x]
print(res)

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	int N, ans=INF;
	string S;

	cin >> S;

	ans = S.length();
	rep(i,S.length()-1){
		if( S[i] != S[i+1] ) chmin(ans, max<int>(i+1, S.length()-i-1));
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
 
typedef struct Node {
  int x;
  struct Node *prev;
  struct Node *next;
} Node;
 
Node *head, *tail;
 
void dump() {
  int l = 0;
  Node *p = head;
  while (p != NULL) {
    if (l == 0)  printf("%d",  p->x);
    else printf(" %d", p->x);
    ++l;
    p = p->next;
  }
  printf("\n");
}
 
void insert(int x) {
  Node *nod = malloc(sizeof(Node));;
  nod->x = x;
  nod->prev = NULL;
  nod->next = NULL;
 
  if (head == NULL) {
    head = nod;
    tail = nod;
  } else {
    nod->next = head;
    head->prev = nod;
    head = nod;
  }
}
 
void delete(int x) {
  Node *p = head;
  int flg = 0;
 
  while (flg == 0 && p != NULL) {
    if (p->x == x) {
      Node *c = p;
      if (c->prev != NULL) {
        p->prev->next = c->next;
      } else {
        head = c->next;
      }
 
      if (c->next != NULL) {
        p->next->prev = c->prev;
      } else {
        tail = c->prev;
      }
      flg = 1;
    } else {
      p = p->next;
    }
  }
}
 
void deleteFirst() {
  if (head == tail) {
    head = NULL;
    tail = NULL;
  } else if (head != NULL) {
    if (head->next != NULL) head->next->prev = NULL;
    head = head->next;
  }
}
 
void deleteLast() {
  if (head == tail) {
    head = NULL;
    tail = NULL;
  } else if (tail != NULL) {
    if (tail->prev != NULL) tail->prev->next = NULL;
    tail = tail->prev;
  }
}
 
int main(int argc, char **argv) {
 
  int n;
  scanf("%d\n", &n);
 
  int i;
  int x;
  char buf[256];
  char tmp[256];
  for (i = 0; i < n; ++i) {
    fgets(buf, 256, stdin);
 
    if (buf[0] == 'i' || buf[6] == ' ') {
      sscanf(buf, "%s %d", tmp, &x);
 
      if (buf[0] == 'i') insert(x);
      else               delete(x);
    } else if (buf[6] == 'F') {
      deleteFirst();
    } else if (buf[6] == 'L') {
      deleteLast();
    }
  }
 
  dump();
 
  return 0;
}



Measured memory_bytes: 36028
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n,m;cin >> n >> m;
    vvi g(n);
    rep(i, m) {
        int a,b;cin >> a >> b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    queue<int> que;
    que.push(0);
    vi dist(n,inf);
    vb bo(n,false);
    dist[0]=0;
    bo[0]=true;
    while(!que.empty()) {
        int p = que.front();que.pop();
        // cout << p << endl;
        for(auto e:g[p]) {
            if(bo[e]) continue;
            dist[e]=dist[p]+1;
            bo[e]=true;
            que.push(e);
        }
    }
    if(dist[n-1]==2) cout << "POSSIBLE\n";
    else cout << "IMPOSSIBLE\n";
    return 0;
}

Measured memory_bytes: 18248
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
ll N, M, K,H,W, ans, mi1,mi2,sum;
string s;
int main() {
	cin >> N;
	vector<LL> 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];
	}
	ans = 0;
	K = 0;
	for (int i = 0; i < N; i++) {
		ans += min(A[i], B[i]);
		if (A[i] < B[i]) {
			ans += min(A[i+1],(B[i] - A[i]));
			A[i + 1] = max(K,A[i + 1] - (B[i] - A[i]));
		}
	}
	cout <<ans<< endl;
	return 0;
}



Measured memory_bytes: 1792
import math
n,m=map(int,input().split())
if n-m==1 or n-m==-1:
  print(math.factorial(n)*math.factorial(m)%1000000007)
elif n-m==0:
  print(2*math.factorial(n)*math.factorial(m)%1000000007)
else:
  print(0)

Measured memory_bytes: 10888
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,m;
  cin>>n>>m;
  vl H(n);
  rep(i,n)cin>>H[i];
  vi C(n,1);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    if(H[a]<=H[b])C[a] = 0;
    if(H[b]<=H[a])C[b] = 0;
  }
  int cnt = 0;
  rep(i,n)cnt+=C[i];
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 4556
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables ***************/
int a, b;
/**********************************************/

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

    cin >> a >> b;

    if(a <= b){
        cout << a << endl;
    }else{
        cout << a-1 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
const int N=200005;

ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
 

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   /* #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif*/
    cout<<fixed<<setprecision(15);
    
    ll a,b;
    cin>>a>>b;
    cout<<max(0LL,a-2LL*b);
    
    return 0;
}

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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    double tmp1,tmp2;
    tmp1 = c/b;
    tmp2 = a/d;
    
    if(tmp1*b < c) tmp1++;
    if(tmp2*d < a) tmp2++;

    if(tmp1 <= tmp2) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	std::string S, X, Y;
	int a;
	std::cin >> a >> S;
	int ans = 0;
	for (int i = 1;i < a;++i) {
		int cnt = 0;
		X = S.substr(0, i);
		Y = S.substr(i, a - i);
		bool isinX[26], isinY[26];
		for (int i = 0; i < 26; i++) {
			isinX[i] = false;
			isinY[i] = false;
		}
		for (int j = 0; j < i; j++) {
			isinX[X[j] - 'a'] = true;
		}
		for (int j = 0; j < a - i; j++) {
			isinY[Y[j] - 'a'] = true;
		}
		for (char c = 'a'; c <= 'z'; c++) {
			if (isinX[c - 'a'] && isinY[c - 'a']) {
				cnt++;
			}
		}
		ans = std::max(ans, cnt);
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
import static java.lang.System.out;
public class Main {
     public static void main(String[] args){
          String str = new java.util.Scanner(System.in).nextLine();
          String[] tmp = str.split(" ");
          int a = Integer.parseInt(tmp[0]);
          int b = Integer.parseInt(tmp[1]);
           
          int area = a * b;
          int circu = (a + b) * 2;
          out.print(area + " ");                                                                                                           
          out.println(circu);
     }
}

Measured memory_bytes: 25916