akhauriyash/Code-Regression huggingface dataset:
//2:25
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vp;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    ll n;
    cin>>n;
    vector<ll> now;
    ull ans1 = 0;
    ull ans2 = 0;
    ll sum = 0;
    bool mf;
    ll fir;
    ll sec;

    cin>>fir;
    sum+=fir;
    if(fir<0){
        mf = true;
    }else{
        if(fir==0){
            sum++;
            ans1++;
        }
        mf = false;
    }
    rep(i,n-1){
        ll nn;
        cin>>nn;
        now.pb(nn);
    }

    rep(i,n-1){
        sum+=now[i];
        ll h=0;
        if(mf && sum<1){
            h = -sum+1;//-(-3)+1=4
            sum+=h;
        }
        if(!mf && -1<sum){
            h = -sum-1;//-(3)-1=-4
            sum+=h;
            h *= -1;
        }
        ans1+=h;
        if(sum<0){
            mf = true;
        }else if(sum>0){
            mf = false;
        }
    }
    ll th=0;
    sum = 0;
    if(fir<0){
        th = -fir+1;//-(-3)+1=4
        sum=1;
        mf = false;
    }else{
        th = -fir-1;//-(3)-1=-4
        sum=-1;
        th *= -1;
        mf = true;
    }
    ans2+=th;
    rep(i,n-1){
        sum+=now[i];
        ll h=0;
        if(mf && sum<1){
            h = -sum+1;//-(-3)+1=4
            sum+=h;
        }
        if(!mf && -1<sum){
            h = -sum-1;//-(3)-1=-4
            sum+=h;
            h *= -1;
        }
        ans2+=h;
        if(sum<0){
            mf = true;
        }else if(sum>0){
            mf = false;
        }
    }
    cout<<min(ans1,ans2)<<endl;

    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
int main(){
    int n, i;
    long long count = 0, max = -1000000, min = 1000000, add = 0;
    cin >> n;
    int num;
    for(i=0; i<n; i++){
        cin >> num;
        add += num;
        if(max < num){
            max = num;
        }
        if(min > num){
            min = num;
        }
    }
    cout << min << " " << max << " " << add << endl;
    
    return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  int a,b; char op;
  cin >> a >> op >> b;
  cout << (op=='+' ? a+b : a-b) << endl;
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

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

int ans[100005];

void dfs(int v, int p, ll summary, vector<vector<pii>> &G){
  for(auto e: G[v]){
    int u = e.first;
    if(u==p) continue;
    if((summary + (ll)e.second)%2==1) ans[u] = 1;
    // cout<<summary<<endl;
    dfs(u,v,summary + e.second,G);
  }
}

signed main()
{
  int n;
  cin>>n;
  vector<vector<pii>> G(n);
  rep(i,n-1){
    int u,v,w; cin>>u>>v>>w;
    u--;v--;
    G[u].emplace_back(v,w);
    G[v].emplace_back(u,w);
  }
  dfs(0, -1, 0, G);
  rep(i,n){
    cout<<ans[i]<<endl;
  }
}


Measured memory_bytes: 8960
#include<iostream>
#include<vector>
#include<algorithm>
  
using namespace std;
  
string in;
vector<int> V;
string wild = "01+-*()";
int ans = -1;
bool OVER;
  
bool isnum(string s){
  for(int i = 0; i < s.length(); i++)
    if(s[i] != '0' && s[i] != '1') return false;
  
  return true;
}
  
bool ispara(string s){
  int p = 1;
  if(s[0] != '(') return false;
  
  for(int i = 1; i < s.length()-1; i++){
    if(s[i] == '(') p++;
    if(s[i] == ')') p--;
    if(p == 0) return false;
  }
  return true;
}
bool isope(string s){
  
  int p = 0;
  for(int i = 0; i < s.length(); i++){
    if(s[i] == '(') p++;
    if(s[i] == ')') p--;
    if(p == 0 && (s[i] == '-' || s[i] == '+' || s[i] == '*')) return true;
  }
  return false;
}
  
bool parapos(string s){
  int p = 0;
  
  for(int i = 0; i < s.length(); i++){
    if(s[i] == '(') p++;
    if(s[i] == ')') p--;
  }
  return p == 0;
}
  
bool isvalid(string s){
  
  if(!parapos(s)) return false;
  if(s == "") return false;
  else if(isnum(s)) return true;
  else if(ispara(s)) return isope(s.substr(1,s.length()-2))&&isvalid(s.substr(1,s.length()-2));
  else{
    int p = 0;
  
    for(int i = 0; i < s.length(); i++){
      if(s[i] == '(') p++;
      if(s[i] == ')') p--;
      if(p == 0 && s[i] == '+') return isvalid(s.substr(0,i))&&isvalid(s.substr(i+1));
      if(p == 0 && s[i] == '-') return isvalid(s.substr(0,i))&&isvalid(s.substr(i+1));
    }
  
    for(int i = 0; i < s.length(); i++){
      if(s[i] == '(') p++;
      if(s[i] == ')') p--;
      if(p == 0 && s[i] == '*') return isvalid(s.substr(0,i))&&isvalid(s.substr(i+1));
    }
  }
  return false;
}
  
int tob(string s){
  reverse(s.begin(),s.end());
  int out = 0;
  for(int i = 0; i < s.length(); i++){
    out += (s[i]-'0')<<i;
  }
  return out;
}

bool inside(int num){
  return (0<=num && num<1024); 
}
  
int get(string s){
  //  cout << "S " << s << endl;
   
  if(isnum(s)){
    int tmp = tob(s);
    if(!inside(tmp)) OVER = true;
    return tmp;
  }
  else if(ispara(s)) return get(s.substr(1,s.length()-2));
  else{
    int p = 0;
    
    for(int i = s.length(); i >= 0; i--){
      if(s[i] == '(') p++;
      if(s[i] == ')') p--;
      if(p == 0 && s[i] == '+'){
	int tmp = get(s.substr(0,i))+get(s.substr(i+1));
	if(!inside(tmp)) OVER = true;
	return tmp;
      }
      if(p == 0 && s[i] == '-'){
	int tmp = get(s.substr(0,i))-get(s.substr(i+1));
	if(!inside(tmp)) OVER = true; 
	return tmp;
      }
    }
    
    for(int i = s.length(); i >= 0; i--){
      if(s[i] == '(') p++;
      if(s[i] == ')') p--;
      if(p == 0 && s[i] == '*'){
	int tmp =  get(s.substr(0,i))*get(s.substr(i+1));
	if(!inside(tmp)) OVER = true;
	return tmp;
      }
    }
  }
}
  
void solve(int n){
  
  if(n < V.size()){
    for(int i = 0; i < wild.length(); i++){
      in[V[n]] = wild[i];
      solve(n+1);
    }
  }else{
 
    if(isvalid(in)){
      OVER = false;
      int num = get(in);
      if(inside(num) && !OVER) ans = max(ans,num);
    }
  }
}
  
int main(){

  cin >> in;
  for(int i = 0; i < in.length(); i++)
    if(in[i] == '.') V.push_back(i);
  
  solve(0);
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>

int main(void)
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int small, midium, large;
    if ((a >= b) && (b >= c)) {
        small = c;
        midium = b;
        large = a;
    } else if ((a >= c) && (c >= b)) {
        small = b;
        midium = c;
        large = a;
    } else if ((b >= a) && (a >= c)) {
        small = c;
        midium = a;
        large = b;
    } else if ((b >= c) && (c >= a)) {
        small = a;
        midium = c;
        large = b;
    } else if ((c >= a) && (a >= b)) {
        small = b;
        midium = a;
        large = c;
    } else if ((c >= b) && (b >= a)) {
        small = a;
        midium = b;
        large = c;
    }
    printf("%d %d %d\n", small, midium, large);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    vector<vector<int> > paper(10, vector<int>(10, 0));
    int ret1 = 100;
    int ret2 = 0;

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

    for(;;){
        int x0, y0, size;
        char c;
        if(!(cin >> x0 >> c >> y0 >> c >> size))
            break;
        for(int i=0; i<4*size+1; ++i){
            int y = y0 + dy[i];
            int x = x0 + dx[i];
            if(y < 0 || y > 9 || x < 0 || x > 9)
                continue;
            if(paper[y][x] == 0)
                -- ret1;
            ++ paper[y][x];
            ret2 = max(ret2, paper[y][x]);
        }
    }

    cout << ret1 << endl << ret2 << endl;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> A(30, 0);
  for (int i = 0; i < N; i++)
  {
    int64_t n;
    cin >> n;
    for (int j = 0; j < A.size(); j++)
    {
      if (n % 2 == 1)
      {
        A.at(j)++;
      }
      n /= 2;
      if (n <= 0)
        break;
    }
  }
  for (int i = 0; i < A.size(); i++)
  {
    if (A.at(i) == 0 || (N % 3 == 0 && A.at(i) == N * 2 / 3))
    {
      continue;
    }
    else
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

int main() {

    int n;
    cin >> n;

    vector<int> b(n - 1);
    vector<int> a(n);

    for(int i = 0; i < n - 1; ++i) {
        cin >> b[i];

    }

    a[0] = a[1] = b[0];

    for(int i = 1; i < n - 1; ++i) {

        if(b[i] < a[i]) {
            a[i] = b[i];
        }

        a[i + 1] = b[i];
    }
    
    int sum = 0;
    for(int i = 0; i < n; ++i) {
        sum += a[i];
   //     cout << a[i] << " ";
    }
    //cout << endl;
    cout << sum << endl;

    return 0;

}

Measured memory_bytes: 256
/*
  -------------
  Prateek Celly
  DA-IICT
  -------------
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n,k,f=0;
  cin>>n>>k;
  ll a[n];
  for(ll i=1;i<=n;i++) {a[i-1]=k+i-1; if(a[i]==0) f=1;}
  sort(a,a+n);
  ll sum=0,ans=1e18,val;
  for(ll i=0;i<n;i++) sum+=a[i];
  //if(f) {cout<<sum; return 0;}
  for(ll i=0;i<n;i++){
    if(abs(a[i])<ans) ans=abs(a[i]),val=a[i];
  }
  cout<<sum-val;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N;
  cin >> N;
  int64_t ans;
  cin >> ans;
  for (int i = 1; i < N; i++) {
    int64_t A;
    cin >> A;
    ans = gcd(ans, A);
  }
  cout << ans << endl;
}

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

namespace ConsoleApp14
{
    class Program
    {
        static void Main(string[] args)
        {
            var solver = new Solver();
            solver.Calc();
        }
    }

    public class Solver
    {
        public class Ans
        {
            public long No;
            public bool bSuccess;
        }



        public void Calc()
        {


            var NM = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
            var N = NM[0];
            var M = NM[1];

            var anss = new Ans[M];
            for (var i = 0; i < M; i++)
            {
                var pp = Console.ReadLine().Split().ToArray();
                anss[i] = new Ans { No = int.Parse(pp[0]), bSuccess = pp[1] == "AC" };
            }

            var dic = anss.GroupBy(x => x.No);

            var a = 0;
            var p = 0;
            foreach (var d in dic)
            {
                var pl = 0;
                var al = 0;
                foreach (var ans in d)
                {
                    if (ans.bSuccess)
                    {
                        al++;
                        a++;
                        break;
                    }
                    else
                    {
                        pl++;
                    }
                }
                if (al == 1)
                {
                    p += pl;
                }
            }


            Console.WriteLine($"{a} {p}");

        }
    }
}

Measured memory_bytes: 31716
N, M = map(int, input().split())

py = []
for i in range(M):
    py.append(list(map(int, input().split())))
    py[i].append(i)

py.sort(key=lambda x: (x[0], x[1]))

number = []
for i in range(M):
    if i == 0:
        ct = 1
        number.append((str(py[i][0]).zfill(6) + str(ct).zfill(6), py[i][2]))
    else:
        if py[i-1][0] == py[i][0]:
            ct += 1
            number.append((str(py[i][0]).zfill(6) + str(ct).zfill(6), py[i][2]))
        else:
            ct = 1
            number.append((str(py[i][0]).zfill(6) + str(ct).zfill(6), py[i][2]))

number.sort(key=lambda x: x[1])

for i in number:
    print(i[0])


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  string x; cin >> x;
  int scnt=0, tcnt=0;
  for(int i = 0; i < x.length(); ++i) {
    if(x[i] == 'S') scnt++;
    else if(x[i] == 'T' && tcnt < scnt) tcnt++;
  }
  cout << (int)x.length() - 2 * tcnt << endl;

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}
 
int main(){
	string s1, s2;
	cin>>s1>>s2;

	vector< vector<ll> > dp(s1.size()+1, vector<ll> (s2.size()+1));
	FOR0(i, s2.size()+1)
		dp[0][i] = 0;
	FOR0(i, s1.size()+1)
		dp[i][0] = 0;

	FOR1(i, s1.size())
		FOR1(j, s2.size())
				dp[i][j] = s1[i-1] == s2[j-1] ? dp[i-1][j-1]+1 : max(dp[i-1][j], dp[i][j-1]);

	int i = s1.size(), j = s2.size(), ans = dp[s1.size()][s2.size()];

	string res = "";
	while(res.size() != ans){
		if(s1[i-1] == s2[j-1]){
			res.push_back(s1[i-1]);
			i--; j--;
		}
		else if(dp[i-1][j] == dp[i][j]) i--;
		else j--;
	}	
	reverse(res.begin(), res.end());
	cout<<res<<"\n";
}

Measured memory_bytes: 70784
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;

ll dp[101][100003];
ll a[100];
int main()
{
	int n,k;
	int ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	fill(dp[0],dp[101],0);
	dp[0][0]=1;
	for(int i=1;i<n+1;i++)
	{
		for(int j=0;j<100001;j++)
		{
			if(dp[i-1][j]>0)
			{
				dp[i][j]+=dp[i-1][j];
				dp[i][min(j+(int)a[i-1]+1,100002)]-=dp[i-1][j];
			}
		}
		for(int j=1;j<100003;j++)
		{
			dp[i][j]=dp[i][j]+dp[i][j-1];
		}
		for(int j=0;j<100003;j++)
		{
			dp[i][j]%=MOD;
			if(dp[i][j]<0)
				dp[i][j]+=MOD;
		}
	}
	dp[n][k]%=MOD;
	if(dp[n][k]<0)
		dp[n][k]+=MOD;
	cout<<dp[n][k]<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string a,b;
  cin>>a>>b;
  puts(a==b ? "H" : "D");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
vector<int> grf[MAXN];
int visited[MAXN],tin[MAXN],low[MAXN];
int timer = 0, n,m;
set<int> arp;
set<pair<int,int>> brgs;

void dfs1(int u,int p=-1){
    visited[u]=true;
    tin[u]=low[u]= timer++;
    int childs=0;
    for(auto x: grf[u]){
        if(x==p){continue;}
        if( visited[x]){
            // ancestor
            low[u]=min(low[u],tin[x]);
        }
        else{
            childs++;
            dfs1(x,u);
            low[u] = min(low[u],low[x]);
            if(p!= -1 and low[x] >= tin[u]){
                arp.insert(u);
            }
        }
    }

    if( p==-1 and childs>1){
        arp.insert(u);
    }
}

void dfs(int u,int p=-1){
    visited[u]=true;
    tin[u]=low[u]=timer++;
    for(auto x:grf[u]){
        if(x==p){continue;}
        if(visited[x]){
            // ancestor
            low[u] = min(low[u], tin[x]);
        }
        else{
            dfs(x,u);
            low[u] = min(low[u],low[x]);
            if(low[x] > tin[u]){
                brgs.insert({min(u,x),max(u,x)});
            }
        }
    }
}


int main() {
    // freopen("./input.txt","r",stdin);
    // freopen("./output.txt","w",stdout);
    cin>>n>>m;
    for(int i=0; i<m; i++){
        int x,y; cin>>x>>y;
        grf[x].push_back(y);
        grf[y].push_back(x);
    }
    for(int i=0; i<n; i++){
        if(!visited[i]){
            dfs(i);
        }
    }
    for(auto p: brgs){
        cout<<p.first<<" "<<p.second<<"\n";
    }
}


Measured memory_bytes: 7192
#include <iostream>
#include <vector>

int main() {
    int n, m;
    std::cin >> n >> m;

    using matrix = std::vector< std::vector< int > >;
    matrix A(n, std::vector< int >(m));
    for (auto &c: A) for (auto &r: c) std::cin >> r;

    matrix B(m, std::vector< int >(1));
    for (auto &c: B) for (auto &r: c) std::cin >> r;

    for (int i = 0; i < n; ++i) {
        int rec = 0;
        for (int j = 0; j < m; ++j) {
            rec += A[i][j] * B[j][0];
        }

        std::cout << rec << std::endl;
    }
}


Measured memory_bytes: 3156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public String findLcs(String s1, String s2) {
        int m=s1.length();
        int n=s2.length();
        int[][] dp =new int[m+1][n+1];
        for(int i=1;i<m+1;++i) {
            for(int j=1;j<n+1;++j) {
                if(s1.charAt(i-1)!=s2.charAt(j-1)) {
                    dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
                } else {
                    dp[i][j]=dp[i-1][j-1]+1;
                }
            }
        }
        StringBuilder lcs = new StringBuilder();
        int p1=m,p2=n;
        while (p1>0&&p2>0) {
            if(s1.charAt(p1-1)==s2.charAt(p2-1)) {
                lcs.append(s1.charAt(p1-1));
                --p1;
                --p2;
            } else {
                if(dp[p1-1][p2]>=dp[p1][p2-1]) {
                    --p1;
                } else {
                    --p2;
                }
            }
        }
        return lcs.reverse().toString();
    }

    public static void main(String[] args) throws IOException {
        InputStreamReader r=new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(r);
        String str1=null;
        Main f = new Main();
        str1=reader.readLine();
        String str2=reader.readLine();
        System.out.println(f.findLcs(str1,str2));
    }

}


Measured memory_bytes: 82628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
 
    // 集合をマージする
    // すでに同じ集合ならfalseが返る
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (data[y] < data[x]) swap(x, y);  // マージテク
        data[x] += data[y];
        data[y] = x;
        return true;
    }
 
    // ある要素がどの集合に属しているかを答える
    int root(int x) {
        // 根に直接つなぎ直す
        return data[x]<0 ? x : (data[x]=root(data[x]));
    }
 
    // ある集合の大きさを答える
    int size(int x) {
        return -data[root(x)];
    }
};

int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll>p(n),x(m),y(m);
    UnionFind uf(n);
    ll answer = 0;
    REP(i,n){
        cin >> p[i];
        p[i]--;
    }
    REP(i,m){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }

    REP(i,m){
        uf.merge(x[i],y[i]);
    }
    REP(i,n){
        if(uf.root(p[i])==uf.root(i)){
            answer++;
        }
        else{
            //cout << uf.root(p[i]) << " debug " << uf.root(i)<< endl;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 2944
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define fi first
#define se second
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define v(T) vector<T>
#define p(T, N) pair<T, N>
#define ii p(int, int)
#define vi v(int)
#define vii v(p(int, int))
#define vvi v(v(int))
#define vl v(long long)
#define vll v(p(long long, long long))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define qsortsi(v) sort(v.begin(), v.end(), [](pair<int, int> aoeui, pair<int, int> boeui){return aoeui.se < boeui.se;})
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define elif else if
#define fori(i, n) for(ll i = 0; i < n; i++)
#define foris(i, a, b) for(ll i = a; i < b; i++)
#define forise(i, a, b) for(ll i = a; i <= b; i++)
#define ford(i, n) for(ll i = n; i >= 0; i--)
#define fords(i, a, b) for(ll i = a; i >= b; i--)
#define fordse(i, a, b) for(ll i = a; i > b; i--)
#define forr(i, a) for (auto &i: a)
#define rev(a) reverse(a.begin(), a.end())
#define revf(a, b, c) (reverse(a.begin() + b, a.begin() + c))
#define digits(i) (int)((log(i)/(log(10))+1)
#define umap unordered_map
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
const int mod = 1000000007;

int N;
vi arr;

int main() {
  io();
  cin >> N;
  fori(i, N) {
    int a;
    cin >> a;
    arr.pb(a);
  }
  
  qsort(arr);
  int ret = abs(arr[arr.size() - 1] - arr[0]);
  
  cout << ret;
  
  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

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

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

int main()
{
        string S, ans;
        cin >> S;
        cout << S[0] << (S.size() - 2 - '0') + '0' << S[S.size() - 1] << endl;

        return 0;
}


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

using namespace std;

typedef long long int ll;

#define FOR(i,l,r) for(i=l;i<r;i++)

#define REP(i,n) FOR(i,0,n)

#define ALL(x) x.begin(),x.end()

#define P pair<ll,ll>

#define F first

#define S second

signed main(){

  ll N;cin>>N;N%=10;string ans="hon";
  if(N<2||N==6||N==8)ans="pon";
  if(N==3)ans="bon";
  
  cout<<ans<<endl;

  return 0;

}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
int main(){
    long long n,c,k;
    cin >> n >> c >> k;
    long long t[n];
    rep(i,n){
        cin >> t[i];
    }
    sort(t,t+n);
    int ans = 0;
    long long st[2] = {0,t[0]};
    rep(i,n){
        if((t[i] - st[1] )> k){
            ans++;
            st[0] = i;
            st[1] = t[i];
        }
        else if(i-st[0] >= c){
            ans++;
            st[0] = i;
            st[1] = t[i];
        }        
    }
    cout << ans + 1 << endl;
}

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

int main(){
    int a,b,c,x,y; cin >>a>>b>>c>>x>>y;
    
    ll result=pow(10,10);
    for(int ci=0;ci<=max(x,y)*2;ci++){
        if(ci%2) continue;
        ll sum=0;
        sum=c*ci+a*(max(x-ci/2,0))+b*(max(0,y-ci/2));
        //cout<<sum<<endl;
        result=min(result,sum);
    }
    
    cout<<result<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
const long long INF = 1e18;

struct SegmentTree{
private:
  int n;
  vector<long long> data;
public:
  SegmentTree(vector<long long> V){
    int sz = V.size();
    n = 1;
    while(n < sz) n *= 2;
    data.resize(2*n-1,-INF);
    for(int i = 0; i < sz; ++i) data[n-1+i] = V[i];
    for(int i = n-2; i >= 0; --i) data[i] = max(data[2*i+1],data[2*i+2]);
  }
  long long get_max(int a, int b, int k=0, int l=0, int r=-1){
    if(r < 0) r = n;
    if(a <= l and b >= r) return data[k];
    if(l >= b or r <= a) return -INF;
    long long vl = get_max(a,b,2*k+1,l,(l+r)/2);
    long long vr = get_max(a,b,2*k+2,(l+r)/2,r);
    return max(vl,vr);
  }
};

int main(){
  int N;
  cin >> N;
  vector<pair<long long,long long>> V;
  long long s = 0;
  for(int i = 0; i < N; ++i){
    long long a, b;
    cin >> a >> b;
    s += b;
    V.emplace_back(a,b);
  }
  sort(V.begin(), V.end());
  vector<long long> A(N+1,0), B(N+1,0);
  for(int i = 0; i < N; ++i){
    A[i+1] = V[i].first;
    B[i+1] = V[i].second + B[i];
  }
  for(int i = 1; i < N+1; ++i){
    B[i] -= A[i];
  }
  //cerr << "B : "; for(auto b : B) cerr << b << " "; cerr << endl;
  SegmentTree st(B);
  long long ans = 0;
  for(int i = 1; i < N+1; ++i){
    long long t = st.get_max(i,N+1) - B[i-1] - A[i-1] + A[i];
    //cerr << i << " " << t << endl;
    //cerr << i << " " << st.get_max(i,N+1) << endl;
    ans = max(ans,t);
  }
  cout << ans << endl;
}



Measured memory_bytes: 30732
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let num: Vec<char> = read::<String>().chars().collect();
    let a: i64 = num[0].to_digit(10).unwrap() as i64;
    let b: i64 = num[1].to_digit(10).unwrap() as i64;
    let c: i64 = num[2].to_digit(10).unwrap() as i64;
    let d: i64 = num[3].to_digit(10).unwrap() as i64;

    if a + b + c + d == 7 {
        println!("{}+{}+{}+{}=7", a, b, c, d);
        return;
    }
    if a - b + c + d == 7 {
        println!("{}-{}+{}+{}=7", a, b, c, d);
        return;
    }
    if a + b - c + d == 7 {
        println!("{}+{}-{}+{}=7", a, b, c, d);
        return;
    }
    if a - b - c + d == 7 {
        println!("{}-{}-{}+{}=7", a, b, c, d);
        return;
    }
    if a + b + c - d == 7 {
        println!("{}+{}+{}-{}=7", a, b, c, d);
        return;
    }
    if a - b + c - d == 7 {
        println!("{}-{}+{}-{}=7", a, b, c, d);
        return;
    }
    if a + b - c - d == 7 {
        println!("{}+{}-{}-{}=7", a, b, c, d);
        return;
    }
    if a - b - c - d == 7 {
        println!("{}-{}-{}-{}=7", a, b, c, d);
        return;
    }
}


Measured memory_bytes: 4352
#pragma warning disable
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
using System.Collections;
using static System.Math;
using static System.Console;
class E { static void Main() => new J(); }
class J
{
	const int Mod = 1000000007;
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	public J()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var a = G();
		int X = a[1], Y = a[0];
		var N = F();
		a = G();
		var map = new int[X, Y];
		int p = 0, q = 0;
		for (var c = 0; c < N; c++)
		{
			for (var i = 0; i < a[c]; i++)
			{
				map[p, q] = c + 1;
				if (q % 2 == 0)
				{
					p++;
					if (p == X) { p--; q++; }
				}
				else
				{
					p--;
					if (p < 0) { p++; q++; }
				}
			}
		}
		for (var y = 0; y < Y; y++)
		{
			for (var x = 0; x < X; x++) Write(map[x, y] + (x == X - 1 ? "" : " "));
			WriteLine();
		}
	}
	long GCD(long a, long b)
	{
		var n = (ulong)Abs(a); var m = (ulong)Abs(b);
		if (n == 0) return (long)m; if (m == 0) return (long)n;
		int zm = 0, zn = 0;
		while ((n & 1) == 0) { n >>= 1; zn++; }
		while ((m & 1) == 0) { m >>= 1; zm++; }
		while (m != n)
		{
			if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; }
			else { n -= m; while ((n & 1) == 0) n >>= 1; }
		}
		return (long)n << Min(zm, zn);
	}
}

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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) ((int)(x).size())

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const int inf = 1e9 + 5;
const int mod = 1e9 + 7;
const ll INF = 4e18 + 5;

char s[200200];
int n;
stack <char> st;

int main() {
	scanf("%s", s);
	n = strlen(s);

	for(int i=0; i<n; ++i) {
		if(s[i]=='T' && sz(st) && st.top() == 'S') 
			st.pop();
		else
			st.push(s[i]);
	}

	printf("%d", sz(st));
	return 0;
}

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

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

  bool is_satisfied= false;
  for(int h=0; h<=H; h++){
    for(int w=0; w<=W; w++){
      if(h*(W-w)+ (H-h)*w == N){
        is_satisfied= true;
        break;
      }
    }
  }

  string ans= is_satisfied ? "Yes"
                           : "No";
  cout << ans << endl;
}

Measured memory_bytes: 384
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll=long long;
using db=double;
///***************************************************** CONSTANTS ******************************************************///

int const N=1e6+3;
ll MOD=1e9+7,fact[N];
const long long inf=(long long)1e18;
const long double PI=3.14159265358979;

///************************************************ CONTAINER DEFINITIONS ***********************************************///

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///************************************************ SHORT FORM KEYWORDS *************************************************///

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define I insert
#define lb lower_bound
#define ub upper_bound
#define endl '\n'

///************************************************ SHORT FORM FUNCTIONS ************************************************///

#define loop(a,b) for(ll i=a;i<b;i++)
#define loopr(a,b) for(ll i=a-1;i>=b;i--)
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define stll(x) stoll(x, nullptr, 10);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define all(a) a.begin(),a.end()
#define mxa(a,N) *max_element(a,a+N)
#define mna(a,N) *min_element(a,a+N)
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


///************************************************ SOLUTION STARTS HERE ************************************************///
///======================================================================================================================///

void solve(){
    ll n;
    cin>>n;
    ll x=((n/1000)+1)*1000;
    x-=n;
    if(n%1000==0) x=0;
    cout<<x<<endl;
}
int main()
{
    io();
    int T=1;//cin>>T;
    while(T--) solve();
    return 0;
}


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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;i<(n);i++)
#define vecadd emplace_back

int main(){
  int n;
  cin>>n;
  
  if(n==1){
    cout<<"Yes"<<endl;
    return 0;
  }
  
  int max=0;
  
  rep(i,n){
    int n1=0;
    cin>>n1;
    int dis=max-n1;
    if(dis>1){
      cout<<"No"<<endl;
      return 0;
    }
    else if(dis<0){
      max=n1;
    }
  }
  
  cout<<"Yes"<<endl;
  
  return 0;
}


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

int n, mx, a, b, cnt[100005];
int main()
{
	int i, t;
	cin >> n;
	for (i= 1; i <= n; i++) {
		scanf ("%d", &t);
		mx = max(mx, t);
		cnt[t]++;
	}
	if (cnt[mx - 1] + cnt[mx] < n) {
		cout << "No";
		return 0;
	}
	if (cnt[mx] == n) {
		if (mx == n - 1 || mx <= n / 2) {
			cout << "Yes";
		} else {
			cout << "No";
		}
	} else {
		if (cnt[mx - 1] + 1 <= mx && mx <= cnt[mx - 1] + cnt[mx] / 2) {
			cout << "Yes";
		} else {
			cout << "No";
		}
	}
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    map<char,int> m;
    rep(i,4)m[s[i]]++;
    if(m.size()==2 && m[s[0]]==2)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
big = 800001
sml = 400000
pp = [[[] for _ in range(big)] for _ in range(8)]
mm = [[[] for _ in range(big)] for _ in range(4)]
for _ in range(n):
  x,y,d = input().split()
  x = int(x)
  y = int(y)
  if d == 'R':
    pp[0][+x+y].append(+y)
    pp[2][+x-y].append(-y)
    mm[0][y].append(x)
  if d == 'L':
    pp[4][-x+y].append(+y)
    pp[6][-x-y].append(-y)
    mm[1][y].append(x)
  if d == 'U':
    pp[1][+x+y].append(+x)
    pp[5][-x+y].append(-x)
    mm[2][x].append(y)
  if d == 'D':
    pp[3][+x-y].append(+x)
    pp[7][-x-y].append(-x)
    mm[3][x].append(y)
import bisect
inf = 10**10
ans = inf
def ser(lx,ly,su):
  global ans
  for xx in lx:
    b = bisect.bisect_left(ly,su-xx)
    try:
      ans = min(ans,(xx+ly[b]-su)*10)
    except:
      pass
for d in range(4):
  xd = 2*d
  yd = 2*d+1
  for sun in range(-sml,sml+1):
    if pp[xd][sun] and pp[yd][sun]:
      pp[xd][sun].sort()
      pp[yd][sun].sort()
      #print(pp[xd][sun],pp[yd][sun],sun,xd,yd)
      ser(pp[xd][sun],pp[yd][sun],sun)
for sun in range(0,sml+1):
  if mm[0][sun] and mm[1][sun]:
    mm[0][sun].sort()
    mm[1][sun].sort()
    for xx in mm[0][sun]:
      b = bisect.bisect_left(mm[1][sun],xx)
      try:
        ans = min(ans,(mm[1][sun][b]-xx)*5)
      except:
        pass
for sun in range(0,sml+1):
  if mm[2][sun] and mm[3][sun]:
    mm[2][sun].sort()
    mm[3][sun].sort()
    for yy in mm[2][sun]:
      b = bisect.bisect_left(mm[3][sun],yy)
      try:
        ans = min(ans,(mm[3][sun][b]-yy)*5)
      except:
        pass
#print(ans)
if ans == inf:
  print('SAFE')
else:
  print(ans)

Measured memory_bytes: 472848
#include <bits/stdc++.h>
using namespace std;
#define array_input int n;cin>>n;int a[n+1],i;for(i=1;i<=n;i++){cin>>a[i];}
#define array_output for(i=1;i<=n;i++){cout<<a[i]<<" ";}cout<<endl;
#define quicker ios::sync_with_stdio(false);
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
const double pi=acos(-1);
const double eps=1e-6;
#define INF 2147483647
#define long_INF 18446744073709551615
#define hehe 23333333

void read(int &x)
{
    x=0;
	char c=getchar();
    while(c<'0' || c>'9')c=getchar();
    while(c>='0' && c<='9')
	{
        x=x*10+c-'0';
        c=getchar();
    }
}

void write(int x)
{
    if(x==0)
	{
		putchar(48);
		return;
	}
    int len=0,dg[20];
    while(x>0)
	{
		dg[++len]=x%10;
		x/=10;
	}
    for(int i=len;i>=1;i--)
	{
		putchar(dg[i]+48);
	}
}

int w(ll x)
{
	int ans;
	ans=0;
	while (x!=0)
	{
		x/=10;
		ans++;
	}
	return ans;
}

int main()
{
	int a,b;
	cin>>a>>b;
	int x,y,z;
	x=a+b;
	y=a-b;
	z=a*b;
	cout<<max(max(x,y),z)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
using namespace std; 
int main() {
	int n;
	const long long mod = 1e9 + 7;
	scanf("%d", &n);
	if (n <= 1) {
		printf("0");
	}
	else {
		long long ret = 1;
		for (int i = 0; i < n; i++) {
			ret = ret * 10 % mod;
		}
		long long tmp = 1;
		for (int i = 0; i < n; i++) {
			tmp = tmp * 8 % mod; 
		}
		long long a = 1;
		for (int i = 0; i < n; i++) {
			a = a * 9 % mod; 
		}
		tmp = (a * 2 + mod - tmp) % mod;
		ret = (ret + mod - tmp) % mod;
		printf("%d", ret);
	}
}

Measured memory_bytes: 1736
#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define ifor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long double ld;
typedef long long int lli;
const double eps = 1e-11;
int vex[4] = {1, 0, -1, 0};
int vey[4] = {0, 1, 0, -1};
lli MOD = 1000000007;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    rep(j, 4)
    {

        int c[100005] = {};
        if (j == 0) {
            c[0] = 0;
            c[n - 1] = 0;
        }
        if (j == 1) {
            c[0] = 1;
            c[n - 1] = 0;
        }
        if (j == 2) {
            c[0] = 0;
            c[n - 1] = 1;
        }
        if (j == 3) {
            c[0] = 1;
            c[n - 1] = 1;
        }

        rep(i, n)
        {
            if (c[i] == 0 && s[i] == 'o') {
                c[(i + 1 + n) % n] = c[(i - 1 + n) % n];
            } else if (c[i] == 1 && s[i] == 'o') {
                c[(i + 1 + n) % n] = !c[(i - 1 + n) % n];
            } else if (c[i] == 0 && s[i] == 'x') {
                c[(i + 1 + n) % n] = !c[(i - 1 + n) % n];
            } else if (c[i] == 1 && s[i] == 'x') {
                c[(i + 1 + n) % n] = c[(i - 1 + n) % n];
            }
        }
        bool flag = true;
        rep(i, n)
        {
            //cout << c[i] << ' ';
            if (c[i] == 0 && s[i] == 'o') {
                flag &= (c[(i + 1 + n) % n] == c[(i - 1 + n) % n]);
            } else if (c[i] == 1 && s[i] == 'o') {
                flag &= (c[(i + 1 + n) % n] == !c[(i - 1 + n) % n]);
            } else if (c[i] == 0 && s[i] == 'x') {
                flag &= (c[(i + 1 + n) % n] == !c[(i - 1 + n) % n]);
            } else if (c[i] == 1 && s[i] == 'x') {
                flag &= (c[(i + 1 + n) % n] == c[(i - 1 + n) % n]);
            }
        }
        if (flag) {
            rep(i, n)
            {
                if (c[i])
                    cout << 'W';
                else
                    cout << 'S';
            }
            cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};
int main()
{
    int h,w;
    cin >> h >> w;
    int si,sj;
    cin >> si >> sj;
    int ti,tj;
    cin >> ti >> tj;
    si--; sj--; ti--; tj--;
    vector<string> g(h);
    rep(i,h) cin >> g[i];
    const ll inf = 1e9;
    vector<vector<int>> dist(h,vector<int> (w,inf));
    deque<P> q;
    dist[si][sj] = 0;
    q.emplace_back(si,sj);
    while(!q.empty()){
        int i = q.front().first;
        int j = q.front().second;
        int d = dist[i][j] ;
        // cout << d << endl;
        q.pop_front();
        rep(v,4){
            int ni = i + di[v];
            int nj = j + dj[v];
            if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if(g[ni][nj] == '#') continue;
            if(dist[ni][nj] <= d) continue;
             dist[ni][nj] = d;
             q.emplace_front(ni,nj);
        }
        for(int ei = -2; ei <= 2; ei++){
            for(int ej = -2; ej <= 2; ej++){
                int ni = i + ei;
                int nj = j + ej;
                if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if(g[ni][nj] == '#') continue;
                if(dist[ni][nj] <= d + 1) continue;
                dist[ni][nj] = d+1;
                q.emplace_back(ni,nj);
                
            }
        }

    } 
    // rep(i,h){
        // rep(j,w){
            // cout << dist[i][j] << " ";
        // }
        // cout << endl;
    // }
    int ans = dist[ti][tj];
    if (ans == inf) ans = -1;
    cout << ans << endl;
return 0;
}


Measured memory_bytes: 9608
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  cin >> N;
  int d1,d2,count=0,flag=0;
  for(int i=0;i<N;i++){
  	cin >> d1 >> d2;
    if(d1==d2){
    	count++;
    }else{
    	count=0;
    }
    if(count>=3){
    	flag++;
    }
  }
  if(flag!=0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;

const int N=1000006;

int n,ans,cnt,sz;
int a[N],b[N];

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=n;i++) b[++sz]=a[i];
	sort(b+1,b+1+sz);
	sz=unique(b+1,b+1+sz)-b-1;
	for (i=1;i<=n;i++) a[i]=lower_bound(b+1,b+1+sz,a[i])-b;
	for (i=1;i<=n;i++){
		cnt=abs(a[i]-i)&1;
		if (cnt) ans++;
	}
	printf("%d\n",ans/2);
	return 0;
}

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

const int inf=1e9+5;
int main()
{
	ios_base::sync_with_stdio(false);	
	cin.tie(NULL);
	int n{0};
	cin>>n;
	int arr[n]={0};
	for(int i=0;i<n;++i)
	{
		cin>>arr[i];
	}
	int dp[n+1]={0};
	dp[0]=inf;
	dp[1]=arr[0];
	dp[2]=abs(arr[1]-arr[0]);
	dp[3]=min(abs(arr[2]-arr[0]),abs(arr[2]-arr[1])+dp[1]);
	for(int i=4;i<=n;++i)
	{
		dp[i]=min(abs(arr[i-1]-arr[i-3])+dp[i-2],abs(arr[i-1]-arr[i-2])+dp[i-1]);
	}
	cout<<dp[n]<<"\n";
	return 0;
}

Measured memory_bytes: 1024
n,k=map(int,input().split())
p=list(map(int,input().split()))

e=[0] #1000までの期待値
def calc(num):
    re=0
    kaku=1/num
    for i in range(1,num+1):
        re+=kaku*i
    return re
for i in range(1,1001):
    e.append(calc(i))
#pを期待値に置き換え    
for i in range(n):
    a=p[i]
    p[i]=e[a]
    
#累積和    
wa=[0,p[0]]
for i in range(1,n):
    wa.append(wa[i]+p[i])

ans=0
for i in range(1,n+1):
    s=i
    g=i+(k-1)
    if n<g:
        break
    now_=wa[g]-wa[s-1]
    if ans<now_:
        ans=now_
print(ans)

Measured memory_bytes: 24552