akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename T>
struct Monoid {
  T id;
  fn<T(T, T)> op;
  Monoid(T e, fn<T(T, T)> f)
    : id(e), op(f) {
  }
};

template<typename T>
class SegT {
private:
  vector<T> data;
  Monoid<T> monoid;
  int size = 1;

public:
  SegT(const int &n, const Monoid<T> &m = Monoid<int>(INF, [](int a, int b) { return min(a, b); }))
    : monoid(m) {
    while (size < n) size *= 2;
    data = vector<T>(2 * size, monoid.id);
  }

  void update(int i, const T &x) {
    i += size;
    data[i]                = x;
    while (i /= 2) data[i] = monoid.op(data[i * 2], data[i * 2 + 1]);
  }

  // fold [a, b) by monoid.op
  T query(const int &a, const int &b, const int &k = 1, const int &l = 0, int r = -1) {
    if (r == -1) r = size;
    if (r <= a || b <= l) return monoid.id;
    if (a <= l && r <= b) return data[k];
    return monoid.op(query(a, b, k * 2, l, (l + r) / 2),
                     query(a, b, k * 2 + 1, (l + r) / 2, r));
  }
};

void solve() {
  int n, q;
  cin >> n >> q;
  SegT<int> t(n, Monoid<int>(2147483647, [](int a, int b) { return min(a, b); }));
  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com) {
      cout << t.query(x, y + 1) << endl;
    } else {
      t.update(x, y);
    }
  }
}

Measured memory_bytes: 4964
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const long long int mod=1e9+7;
int main()
{
      long long int i,ans=1,l;
      cin>>l;
      for(i=1;i<=l;i++)
      {
           ans*=i;
           ans%=mod;
      }
      cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;

bool dfs(const vector<vector<int> >& e, int node, int target, vector<int>& visited, int depth) {
    visited[node] = 1;
    if (target == node) {
        return true;
    }

    depth++;
    if (depth > 2) {
        return false;
    }

    auto& c = e[node];
    rep(i, c.size()) {
        if (visited[c[i]] <= 0) {
            if (dfs(e, c[i], target, visited, depth)) {
                return true;
            }
        }
    }
    return false;
}

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

    vector<int> a(m), b(m);
    rep(i, m) cin >> a[i] >> b[i];
    
    vector<vector<int> > e(n + 1, vector<int>());
    rep(i, m) {
        e[a[i]].push_back(b[i]);
        e[b[i]].push_back(a[i]);
    }

    vector<int> visited(n + 1);
    if (dfs(e, 1, n, visited, 0)) {
        put("POSSIBLE")
    }
    else {
        put("IMPOSSIBLE")

    }


    return 0;
}

Measured memory_bytes: 17472
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(input())

# def LIST(): return list(map(str, input().split()))
# def LIST(): return list(input())

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
K = INT()

ans = 1
for i in range(N):
    ans = min(ans * 2, ans + K)
print(ans) 


Measured memory_bytes: 5144
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;
const int MAXM=100000;
const int MAXQ=100000;
const int MAXD=10;

int n,m;
int ghead[MAXN],gnxt[2*MAXM],gto[2*MAXM];
int nq;
int qx[MAXQ],qd[MAXQ],qc[MAXQ];

int been[MAXN];
int col[MAXN];
void dfs(int at,int d,int c) {
	if(been[at]>=d) return; else been[at]=d;
	if(col[at]==0) col[at]=c;
	if(d>0) for(int x=ghead[at];x!=-1;x=gnxt[x]) dfs(gto[x],d-1,c);
}

void run() {
	scanf("%d%d",&n,&m);
	REP(i,n) ghead[i]=-1;
	REP(i,m) {
		int a,b; scanf("%d%d",&a,&b); --a,--b;
		gnxt[2*i+0]=ghead[a],ghead[a]=2*i+0,gto[2*i+0]=b;
		gnxt[2*i+1]=ghead[b],ghead[b]=2*i+1,gto[2*i+1]=a;
	}
	scanf("%d",&nq);
	REP(i,nq) scanf("%d%d%d",&qx[i],&qd[i],&qc[i]),--qx[i];
	
	memset(been,-1,sizeof(been));
	memset(col,0,sizeof(col));
	for(int i=nq-1;i>=0;--i) dfs(qx[i],qd[i],qc[i]);
	REP(i,n) printf("%d\n",col[i]);
}

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


Measured memory_bytes: 4608
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;

int main()
{
    vector<int> nums(4);
    string s;
    cin >> s;
    for(int i=0; i<4; i++){
        nums[i]=s[i]-'0';
    }
        if(nums[0]+nums[1]+nums[2]+nums[3]==7){
            printf("%d+%d+%d+%d=7\n", nums[0], nums[1], nums[2], nums[3]);
            return 0;
        }
        if(nums[0]+nums[1]+nums[2]-nums[3]==7){
            printf("%d+%d+%d-%d=7\n", nums[0], nums[1], nums[2], nums[3]);
            return 0;
        }
        if(nums[0]+nums[1]-nums[2]+nums[3]==7){
            printf("%d+%d-%d+%d=7\n", nums[0], nums[1], nums[2], nums[3]);
            return 0;
        }
        if(nums[0]+nums[1]-nums[2]-nums[3]==7){
            printf("%d+%d-%d-%d=7\n", nums[0], nums[1], nums[2], nums[3]);
            return 0;
        }
        if(nums[0]-nums[1]+nums[2]+nums[3]==7){
            printf("%d-%d+%d+%d=7\n", nums[0], nums[1], nums[2], nums[3]);
            return 0;
        }
        if(nums[0]-nums[1]+nums[2]-nums[3]==7){
            printf("%d-%d+%d-%d=7\n", nums[0], nums[1], nums[2], nums[3]);
            return 0;
        }
        if(nums[0]-nums[1]-nums[2]+nums[3]==7){
            printf("%d-%d-%d+%d=7\n", nums[0], nums[1], nums[2], nums[3]);
            return 0;
        }
        if(nums[0]-nums[1]-nums[2]-nums[3]==7){
            printf("%d-%d-%d-%d=7\n", nums[0], nums[1], nums[2], nums[3]);
        }
    

    return 0;
}

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

using namespace std;
typedef long long nagai;

const int MX = 4000001;

int main()
{
	int n;
	cin >> n; 
	vector<int> a(n);
	bitset<MX> cur;
	cur[0] = 1;
	nagai sm = 0;
	for (auto& x : a)
	{
		cin >> x;
		cur |= cur << x;
		sm += x;
	}
	sm = (sm + 1) / 2;
	int ans = 10000000, ansi = -1;
	for (int i = 0; i < MX; ++i)
		if (cur[i] && abs(i - sm) <= ans)
			ans = abs(i - sm), ansi = i;
	cout << ansi << endl;
}


Measured memory_bytes: 1664
#include<iostream>
#include<string>
using namespace std;
int main(){
  int a,b,c,k;string s,t,u;cin>>a>>b>>c;
  if(a>=b&&b>=c){
    s=to_string(a),t=to_string(b);
    s+=t;
    k=atoi(s.c_str());
    cout<<k+c;
    }
  else if(a>=c&&c>=b){
    s=to_string(a),t=to_string(c);
    s+=t;
    k=atoi(s.c_str());
    cout<<k+b;
    }
  else if(b>=c&&c>=a){
    s=to_string(b),t=to_string(c);
    s+=t;
    k=atoi(s.c_str());
    cout<<k+a;
    }
  else if(b>=a&&a>=c){
    s=to_string(b),t=to_string(a);
    s+=t;
    k=atoi(s.c_str());
    cout<<k+c;
    }
  else if(c>=a&&a>=b){
    s=to_string(c),t=to_string(a);
    s+=t;
    k=atoi(s.c_str());
    cout<<k+b;
    }
  else{
    s=to_string(c),t=to_string(b);
    s+=t;
    k=atoi(s.c_str());
    cout<<k+a;
    }
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  ll n;
  cin >> n;
  ll count = 0, ans = 0;

  while (n) {
    if (n == 1) {
      ans += pow(2, count);
    } else {
      ans += pow(2, count);
    }
    count++;
    n /= 2;
  }

  cout << ans << endl;
}


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string d[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string s;
  cin>>s;

  for(int i=0;i<7;i++){
    if(s==d[i]){
      cout<<7-i<<endl;
    }
  }

  return 0;
}


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

int main() {
	int k;
	string s;
	cin >> k >> s;
	if(k < s.size())
	{
		s = s.substr(0,k) + '.' + '.' + '.';
	}
	cout << s << endl;
	return 0;
}


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

#define endl '\n'
#define ll long long
#define rint register int

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision


bool isPrime(ll n)
{
	// Corner cases
	if (n <= 1)  return false;
	if (n <= 3)  return true;

	// This is checked so that we can skip
	// middle five numbers in below loop
	// if (n % 2 == 0 || n % 3 == 0) return false;

	for (ll i = 2; i * i <= n; i ++)
		if (n % i == 0 )
			return false;

	return true;
}

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

 

	ll t, i, x, j, y, 	z = 0, k, n;
	// db a, b;
	cin >> n ;
	i = 2;
	while (i * i <= n) {
		if (n % i == 0) {
			k = 0, j = 0;
			while (n % i == 0) {
				n /= i;
				j++;
				if (j > k)	k = j, z++, j = 0;
			}
		}
		i++;
	}



	// ce(n)
	z += isPrime(n);
	ce(z)
}


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

int main()
{
  int n,w,r,rr,m,ans;
  w=0;
  r=0;
  rr=0;
  cin>>n;
  m=n;
  vector<char> c(n);
  for(int i=0;i<n;i++)
  {
    cin>>c.at(i);
  }
  for(int i=n-1;i>=0;i--)
  {
    if(c.at(i)=='W')
    {
      c.pop_back();
      m--;
    }
    else
    {
      break;
    }
  }
  for(int i=0;i<m;i++)
  {
    if(c.at(i)=='W')
      w++;
    else
      r++;
  }
  for(int i=0;i<r;i++)
  {
    if(c.at(i)=='R')
      rr++;
  }
  ans=min(min(r,w),r-rr);
  cout<<ans<<endl;
}


Measured memory_bytes: 3656
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

typedef long long ll;

int main() {
  char S[15], A[15];
  cin >> S;

  int N = strlen(S);
  ll ans = 0;
  for (int bit = (1 << N) - 1; bit >= (1 << N-1); --bit) {
    int pos = 0;
    for (int i = 0; i < N; ++i) {
      A[pos] = S[i];
      ++pos;
      if (bit >> i & 0x1) {
        A[pos] = 0;
        ans += atoll(A);
        pos = 0;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b=[]
cnt = 0
for i in range(n):
    if a[i]>=3200:
        cnt+=1
    else:
        for j in range(1,9):
            if a[i]<400*j:
                b.append(j)
                break
if len(set(b))==0:
    print(1,cnt)
else:
    print(len(set(b)),len(set(b))+cnt)


Measured memory_bytes: 3060
// AOJ 1032 Course Planning for Lazy Students
// 2018.2.28 bal4u

#include <stdio.h>
#include <string.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

#define MAX (1<<20)
typedef struct { int s; short c; } Q;
Q q[MAX+10]; int top, tail;
int c[20], r[20];
char mk[MAX];

int bitcount(int bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main()
{
	int n, U, i, j, k, s, t;
	
	while (n = in()) {
		U = in();
		for (i = 0; i < n; i++) {
			c[i] = in(), r[i] = 0;
			k = in(); while (k--) r[i] |= 1 << in();
		}

		memset(mk, 0, sizeof(mk));
		q[0].s = q[0].c = 0, top = 0, tail = 1; mk[0] = 1;
		while (top != tail) {
			s = q[top].s, k = q[top++].c;
			if (k >= U) break;
			for (j = 1, i = 0; i < n; i++, j <<= 1) {
				if (s & j) continue;
				t = s | j;
				if ((r[i] & s) == r[i] && !mk[t]) {
					mk[t] = 1;
					q[tail].s = t, q[tail++].c = k + c[i];
				}
			}
		}
		printf("%d\n", bitcount(s));
	}
	return 0;
}


Measured memory_bytes: 11060
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[1001],d[1001],f,g,h,i,j,z;
	scanf("%d",&a);
	for(i=0;i<a;i++) scanf("%d %d",&s[i],&d[i]);
	scanf("%d",&f);
	for(i=a;i<a+f;i++) scanf("%d %d",&s[i],&d[i]);
	for(i=0;i<a+f;i++){
		for(j=i+1;j<a+f;j++){
			if(s[i]>s[j]){
				g=s[i];
				s[i]=s[j];
				s[j]=g;
				g=d[i];
				d[i]=d[j];
				d[j]=g;
			}
		}
	}
	h=a+f;
	for(i=0;i<a+f;i++){
		for(j=i+1;j<a+f;j++){
			if(s[i]==s[j]&&d[i]>d[j]){
				g=s[i];
				s[i]=s[j];
				s[j]=g;
				g=d[i];
				d[i]=d[j];
				d[j]=g;
			}
			if(s[i]==s[j]&&d[i]==d[j]){
				s[i]=-1;
				d[i]=-1;
			}
		}
	}
	for(i=0;i<a+f;i++){
		z=0;
		if(s[i]!=-1&&d[i]!=-1){
			printf("%d:%02d",s[i],d[i]);
			z=1;
			if(i==a+f-1) z=0;
		}
		if(z==1) printf(" ");
	}
	printf("\n");
}

Measured memory_bytes: 2752
#include <bits/stdc++.h>
using namespace std;
#define ll long long  
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int n;
   cin>>n;
   int arr[n+1]={0};
   for(int i=1;i<=n;i++)
   cin>>arr[i];
   ll l[n+1]={0}; 
   l[1]=arr[1];l[2]=arr[2];
   for(int i=3;i<=n;i++)
   l[i]=l[i-2]+arr[i];
   ll dp[n+1][2];
   for(int i=0;i<=n;i++)
   {
       dp[i][0]=0;
       dp[i][1]=0;
   }dp[1][0]=0;
   dp[2][0]=arr[1];
   dp[1][1]=arr[1];
   dp[2][1]=arr[2];
   dp[3][0]=max(arr[2],arr[1]);dp[3][1]=arr[3];  //-100  -10
   dp[4][0]=l[3];dp[4][1]=arr[4]+dp[3][0];          //-1010    -100
   for(int i=5;i<=n;i++)
   {
       
       if(i%2)
       {
           dp[i][1]=max(dp[i-2][1],dp[i-2][0]);
           dp[i][1]=max(dp[i][1],dp[i-3][1]);
           dp[i][1]=max(dp[i][1],dp[i-3][0]);
           dp[i][1]+=arr[i];
           dp[i][0]=max(dp[i-1][1],dp[i-1][0]);
       }
       else
       {
           dp[i][1]=max(dp[i-2][1],dp[i-2][0]);
           dp[i][1]=max(dp[i][1],l[i-3]);
           dp[i][1]+=arr[i];
           dp[i][0]=l[i-1];
       }
       //cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<i<<endl;
       
   }
   cout<<max(dp[n][1],dp[n][0])<<endl;
      
    return 0;
}
//make all values ll





Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> s(N);
    rep(i, N) cin >> s[i];
    sort(ALL(s));
    int ans = accumulate(ALL(s), 0);
    rep(i, N) {
        if (ans % 10 == 0) {
            if ((ans - s[i]) % 10 != 0) {
                cout << ans - s[i] << endl;
                return 0;
            }
        }
    }
    if (ans % 10 == 0) cout << 0 << endl;
    else cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}



int main(){
    int n;
    cin >> n;
    int a[n+2];
    a[0]=0;
    int b[n+1];
    int max=0;
    for(int i=1;i<n+1;i++){
        cin >> a[i];
        max+=abs(a[i]-a[i-1]);
    }
    a[n+1]=0;
    max+=abs(a[n]);

    

    for(int i=1;i<n+1;i++){
        if((a[i-1]<=a[i]&&a[i]<=a[i+1])||(a[i-1]>=a[i]&&a[i]>=a[i+1])){
            cout << max << endl;
        }else{
            int c_max = max;
            c_max-=abs(a[i-1]-a[i]);
            c_max-=abs(a[i]-a[i+1]);
            c_max+=abs(a[i-1]-a[i+1]);
            cout << c_max << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int x;
    cin >> x;
    v.push_back(x);
  }
  sort(ALLOF(v));

  int base = 0;
  ll sum = 0;
  rep(i,N){
    if(sum*2<v[i]){
      base = i;
    }
    sum += v[i];
  }

  cout << N-base << endl;
  
  return 0;
}


Measured memory_bytes: 892
#include <cstdio>
#include <vector>
#include <algorithm>
 
 
using namespace std;
 
#define  INF (1<<29)
int matrix[201][201];
void warshall_floyd(int n) { 
    // nは頂点数,matrixにはグラフの距離を格納した2次元配列（隣接行列）
    // d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）
    for (int i = 0; i < n; i++)      // 経由する頂点
      for (int j = 0; j < n; j++)    // 開始頂点
        for (int k = 0; k < n; k++)  // 終端
          matrix[j][k] = min(matrix[j][k], matrix[j][i] + matrix[i][k]);
}
 
int main(){
    int N,M,R;
    int r[9];
    scanf("%d %d %d", &N, &M, &R);
    for(int i=0;i<R;i++){
        int in;
        scanf("%d",&in);
        in--;
        r[i] = in;
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
        if(i!=j) matrix[i][j] = INF; 
        else matrix[i][j] = 0;
        }
    }
    for(int i=0; i<M; i++){
        int A,B,C;
        scanf("%d %d %d",&A,&B,&C);
        if(matrix[A-1][B-1]>C) matrix[A-1][B-1] = matrix[B-1][A-1] = C;
    }

    sort(r, r+R);

    warshall_floyd(N);

    /*for(int i=0; i <min(N,8); i++){
        for(int j; j < min(N,8); j++){
            printf("%d\n",matrix[i][j]);
        }
    }*/

    int res = INF;
    do {
        int buf = 0;
        for(int i=0;i<R-1; i++) buf += matrix[r[i]][r[i+1]]; 
        if(res > buf) res = buf;
    } while(next_permutation(r, r+R));   // 次の順列を生成
    printf("%d\n",res);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[101][100010];
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= 100000; ++j) {
            dp[i+1][j] = dp[i][j];
            if (j == v[i] || (j > v[i] && dp[i][j-v[i]] != 0 && dp[i][j-v[i]] + w[i] <= W)) {
                if (dp[i+1][j] == 0) {
                    dp[i+1][j] = dp[i][j-v[i]] + w[i];
                } else {
                    dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]] + w[i]);
                }
            }
        }
    }
    int ans = 0;
    for (int j = 0; j <= 100000; ++j) {
        if (dp[N][j] != 0) {
            ans = max(ans, j);
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
     
    int N,K;
    cin >>N>>K;

    ll ans=-1;
    queue<pair<ll,ll>> M;

    if(K<=(N-1)*(N-2)/2){
        for(int i=2;i<=N;i++){
          //  if(K<=0)break;
            M.push({1,i});
            K-=i-2;
          //  printf("-%d\n",K);
        }
        for(int i=2;i<N;i++){
            for(int k=i+1;k<=N;k++){
                if(K==0)break;
                M.push({i,k});
                K++;
            }
                if(K==0)break;
        }
        ans=M.size();
    }
    cout << ans <<endl;
    while(!M.empty()){
        pair<ll,ll> ne=M.front();
        cout<< ne.first  <<" "<<ne.second<<endl;   
        M.pop();
    }

    return (0);
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main(String[] args) {
		// practice contest

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if ((a + b) % 2 == 0) {
			System.out.println((a + b) / 2);
		} else {
			System.out.println("IMPOSSIBLE");
		}

	}
}


Measured memory_bytes: 22736
#pragma comment (linker, "/STACK:256000000")
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(const size_t n, const size_t m, const T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
constexpr ll pow2(const int n) { return 1ll << n; }
constexpr int INF = 1 << 28; constexpr ll LINF = 1ll << 60;
constexpr int MAX = 1e5 + 5; constexpr int MOD = 1e9 + 7; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N, Ma, Mb;
vi A, B, C;
vv<int> dp;

int main() {
    cin >> N >> Ma >> Mb;
    A.resize(N);
    B.resize(N);
    C.resize(N);
    rep(i, N) {
        cin >> A[i] >> B[i] >> C[i];
    }

    dp = vvec(N + 1, 401 * 401, INF);
    dp[0][0] = 0;

    rep(i, 1, N + 1) {
        rep(j, 401 * 401) {
            const int a = j % 401;
            const int b = j / 401;
            if (a + A[i - 1] > 400 || b + B[i - 1] > 400) continue;
            const int k = a + A[i - 1] + 401 * (b + B[i - 1]);

            chmin(dp[i][j], dp[i - 1][j]);
            chmin(dp[i][k], dp[i - 1][j] + C[i - 1]);
        }
    }

    int ans = INF;
    rep(j, 401 * 401) {
        const int a = j % 401;
        const int b = j / 401;
        if (a * Mb == b * Ma && a != 0 && b != 0) {
            chmin(ans, dp[N][j]);
        }
    }
    if (ans == INF) {
        write(-1);
    }
    else {
        write(ans);
    }
}

Measured memory_bytes: 26752
N, K = map(int, open(0).read().split())

X = str(N + 1)
dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(len(X) + 1)]
dp[0][0][0] = 1

for i in range(len(X)):
    D = int(X[i])
    for j in range(2):
        for k in range(K + 1):
            for d in range((9 if j == 1 else D) + 1):
                if k + int(d != 0) <= K:
                    dp[i + 1][j | (d < D)][k + int(d != 0)] += dp[i][j][k]

print(dp[-1][-1][-1])


Measured memory_bytes: 40560
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;

// ABC 162 c

long long GCD(long long x, long long y){
  if (y == 0) return x;
  else return GCD(y, x % y);
}

int main() {
  int k;
  cin >> k;
  int res = 0;
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
        res += GCD(GCD(a, b), c);
      }
    }
  }
  cout << res << "\n";
}


Measured memory_bytes: 3592
def r_search(S, i):
  for j in range(i, len(S)):
    if S[j] == "L":
      return j-1
  return j-1

def l_search(S, i):
  for j in range(i, len(S)):
    if S[j] == "R":
      return j-1
  return j

S = input()

i = 0
while i < len(S):
  r = r_search(S, i)
  l = l_search(S, r+1)
  #print(f"{i} {r} {l}")


  r_num = r - i + 1
  l_num = l - r

  r_result = r_num//2
  l_result = r_num//2
  if r_num % 2 == 1: 
    r_result += 1

  r_result += l_num//2
  l_result += l_num//2
  if l_num % 2 == 1: 
    l_result += 1

  print("0 "* (r_num-1), end="")
  print(r_result, end=" ")
  print(l_result, end=" ")
  print("0 "* (l_num-1), end="")
  i = l+1

print("")

Measured memory_bytes: 4720
n = int(input())
s = input()


e = [0]
w = [0]

cnt_e = 0
cnt_w = 0
for i in range(n):
	if s[i] == "E" :
		cnt_e += 1
	else:
		cnt_w += 1

	e.append(cnt_e)
	w.append(cnt_w)

ans = 10000000000
for j in range(n):
	t = w[j]  + e[n] - e[ j +1 ]
	
	ans = min(ans,t)

print(ans)

Measured memory_bytes: 17644
nn = int(input())
aa = [list(map(int,input().split())) for l in range(nn)]

myflag = 0
isexist = 0

for i in range(nn):
    if (aa[i][0] == aa[i][1]):
        if myflag == 0:
            myflag = 1
        else:
           myflag = myflag + 1
           if myflag == 3:
               isexist = 1
    else:
        myflag = 0

if isexist == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62404
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int samecount(string S){
    int A = 0;
    for(int i = 0;i < S.size();i++){
        int QA = 1;
        for(int j = i ;j < S.size() - 1;j++){
           if(S.at(j) == S.at(j + 1)){
               QA++ ;
           }
           if(S.at(j) != S.at(j + 1)){
               break;
           }
           
        }
        A = max(QA,A);
    }
    return A;
}

int64_t minn(int64_t a,int64_t b){
    if(a >= b) return b;
    else return a;
}
int main(){
    string S;
    cin >>S;
    bool frag = 1;
    for(int i = 0;i < 27;i++){
        for(int j = 0;j < S.size();j++){
            if(count(S.begin(),S.end(),'a'+i) > 1) frag = 0; 
        }
    }
    if(frag) cout << "yes" <<endl;
    else cout << "no" << endl;
}





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

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
const int INF = INT_MAX;
const ll MOD = 998244353;

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int N,K,L;
    cin >> N >> K >> L;
    UnionFind road(N),train(N);
    repeat(i, K){
        int p,q;
        cin >> p >> q;
        p--;q--;
        road.unionSet(p, q);
    }
    repeat(i, L){
        int r,s;
        cin >> r >> s;
        r--;s--;
        train.unionSet(r, s);
    }
    map<Pii,int> S;
    repeat(i, N){
        S[make_pair(road.root(i),train.root(i))]++;
    }
    repeat(i, N){
        cout << S[make_pair(road.root(i),train.root(i))];
        if(i==N-1){
            cout << endl;
        }else{
            cout << " ";
        }
    }
    return 0;
}



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

#define INF 1e9
using namespace std;

int main() {

    int N; cin >> N;

    int number_a_0 = 0;
    int number_a_minus = 0;
    int min_a_abs = INF;

    long long sum = 0;

    vector<int> A(N);

    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        sum += abs(A[i]);

        if (A[i] == 0) {
            number_a_0 += 1;
        }

        if (A[i] < 0) {
            number_a_minus += 1;
        }

        min_a_abs = min(min_a_abs, abs(A[i]));
    }

    if (number_a_minus > 0) {
        if (number_a_0 > 0 || number_a_minus % 2 == 0) {
            cout << sum << endl;
        } else {
            cout << sum - (min_a_abs * 2) << endl;
        }
    } else {
        cout << sum << endl;
    }
}

Measured memory_bytes: 640
import java.util.Scanner;


public class Main{
    public  static void main(String[] args) {
    	try (Scanner sc = new Scanner(System.in)) {
    		int[] dp=new int[20001];
    		int A=sc.nextInt();
    		int B=sc.nextInt();
    		int C=sc.nextInt();
    		int X=sc.nextInt();
    		for(int i=0; i<=A; i++) {
    			for(int j=0; j<=B; j++) {
    				for(int k=0; k<=C; k++) {
    					if(i*500+j*100+k*50<=X) {
    						dp[i*500+j*100+k*50]+=1;
    					}
    				}
    			}
    		}
    		System.out.println(dp[X]);
    	}
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MOD (long long)(1e9+7)
#define MAX_VAL (int)(1100000)

long long fac[MAX_VAL], mmi[MAX_VAL];

void factorial_mod(){
	 fac[0]=fac[1]=1;
	for(long long i = 2; i < MAX_VAL; fac[i]%=MOD,i++)
		fac[i] = fac[i-1]*(i%MOD);
}

long long power_mod(long long x, long long n){
	long long ans = 1;
	for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
		if(n&1)ans*=x;
	return ans%MOD;
}

void exgcd(int a, int b, int &x, int &y){
	if(b == 0){
		x = 1;
		y = 0;
		return ;
	}
	exgcd(b,a%b,y,x);
	y -= a/b * x;
}

void modular_multiplicatibe_inverse(){
	int x, y;  
	exgcd(fac[MAX_VAL-1],MOD,x,y);
	mmi[MAX_VAL-1] = x;
	for(long long i = MAX_VAL-2; i >= 0; mmi[i]%=MOD,i--)
		mmi[i] = mmi[i+1]*((i+1)%MOD);
}

long long combination(long long n, long long r){
	return n < r ? 0 :fac[n]*(mmi[r]*mmi[n-r]%MOD)%MOD;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int Y, X;
	int sum = 0;
	
	factorial_mod();
	modular_multiplicatibe_inverse();
	
	cin>>X>>Y;
	
	sum = X + Y;
	
	if(sum%3){
		cout<<"0"<<endl;
	} else {
		if(X*2 < Y || Y*2 < X) cout<<"0"<<endl;
		else {
			int x = sum - sum*2/3;
			int y = Y - x;
			int z = x;
			
			
			// cout<<y<<" "<<x<<" "<<z<<endl;
			
			cout<<combination(z, y)<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 17408
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.IOException;
import java.util.stream.Collectors;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int[] b = in.Int(N);
            List<Integer> ans = new ArrayList<>();
            List<Integer> tmp = IntStream.of(b).boxed().collect(Collectors.toCollection(ArrayList::new));
            for (int i = 0; i < N; i++) {
                boolean f = false;
                for (int j = N - i; j > 0; j--) {
                    if (tmp.get(j - 1) == j) {
                        tmp.remove(j - 1);
                        ans.add(j);
                        f = true;
                        break;
                    }
                }
                if (!f) {
                    out.println(-1);
                    return;
                }
            }
            Collections.reverse(ans);
            ans.forEach(out::println);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}



Measured memory_bytes: 28628
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict

def main():
    N = II()
    xy = []
    for _ in range(N):
        xy.append(LI())
    xy2g = defaultdict(int)
    g2xy = defaultdict(set)
    for x, y in xy:
        y = -y
        gx = xy2g[x]
        gy = xy2g[y]
        if gx != 0 and gy != 0 and gx != gy:  # merge
            if len(g2xy[gx]) < len(g2xy[gy]):
                gx, gy = gy, gx
            for xy in g2xy[gy]:
                xy2g[xy] = gx
            g2xy[gx] |= g2xy[gy]
            g2xy[gy].clear()
        else:
            g = gx or gy or x
            xy2g[x] = xy2g[y] = g
            g2xy[g] |= {x, y}
    ans = -N
    for xys in g2xy.values():
        nx = len([1 for xy in xys if xy > 0])
        ny = len(xys) - nx
        ans += nx * ny
    return ans

print(main())

Measured memory_bytes: 114652
import java.io.*;
import java.util.*;

public class Main {

    static int N, M;
    static int[] P, Y;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();

        P = new int[M];
        Y = new int[M];
        for (int i = 0; i < M; i++) {
            P[i] = sc.nextInt();
            Y[i] = sc.nextInt();
        }

        PrintWriter pw = new PrintWriter(System.out);
        for (City c : solve()) {
            pw.println( String.format("%06d", c.p) + String.format("%06d", c.pi + 1) );
        }
        pw.flush();
    }

    static City[] solve() {
        City[] C = new City[M];

        Map<Integer, List<City>> pc = new HashMap<>();
        for (int i = 0; i < M; i++) {
            int p = P[i];
            int y = Y[i];
            C[i] = new City(p, y);

            if( !pc.containsKey(p) ) {
                pc.put(p, new ArrayList<>());
            }
            pc.get(p).add(C[i]);
        }

        for (List<City> p : pc.values()) {
            p.sort(Comparator.comparingInt(c -> c.y));
            for (int i = 0; i < p.size(); i++) {
                p.get(i).pi = i;
            }
        }
        return C;
    }

    static class City {
        int p, y;
        int pi;

        public City(int p, int y) {
            this.p = p;
            this.y = y;
        }
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 121712
h,w = map(int,input().split())
field = [input() for i in range(h)]

row = [False]*h
col = [False]*w

for i in range(h):
    for j in range(w):
        if field[i][j] == '#':
            row[i] = True
            col[j] = True
            

for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(field[i][j],end='')
            
        print()

Measured memory_bytes: 4468
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

const int N=3e5+2, INF=N;

int dp[N];

pair <int, int> f(int n, int *a)
{
    int inc=0, dec=0;
    dp[0]=-INF;
    for(int i=1; i<=n; ++i)
        dp[i]=INF;
    for(int i=1; i<=n; ++i)
    {
        int j=upper_bound(dp, dp+n+1, a[i])-dp;
        if(dp[j-1] < a[i] && a[i] < dp[j])
        {
            dp[j]=a[i];
            inc=max(inc, j);
        }
    }
    dp[0]=-INF;
    for(int i=1; i<=n; ++i)
        dp[i]=INF;
    for(int i=n; i>=1; --i)
    {
        int j=upper_bound(dp, dp+n+1, a[i])-dp;
        if(dp[j-1] < a[i] && a[i] < dp[j])
        {
            dp[j]=a[i];
            dec=max(dec, j);
        }
    }
    return {inc, dec};
}

int ans[N];

void solve(int *arr, int n, int a, int b)
{
    a=min(a, n);
    b=min(b, n);
    b=min(b, n-a+1);
    for(int i=1; i<=a; ++i)
        arr[i]=n-a+i;

    for(int i=2; i<=b; ++i)
        arr[n-b+i]=n-a-i+2;

    if(n-a-b+1>0 && a>0 && b>0)
        solve(arr+a, n-a-b+1, a-1, b-1);
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    solve(ans, n, a, b);
    auto tmp=f(n, ans);
    if(a!=tmp.first || b!=tmp.second)
        cout << "-1\n";
    else
    {
        for(int i=1; i<=n; ++i)
            cout << ans[i] << ' ';
        cout << endl;
    }
    return 0;
}


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    string s;
    cin >> s;
    int res = 0;
    if(s == "SUN"){
        res = 7;
    }else if( s == "MON"){
        res = 6;
    }else if(s == "TUE"){
        res = 5;
    }else if(s == "WED"){
        res = 4;
    }else if(s == "THU"){
        res = 3;
    }else if(s == "FRI"){
        res = 2;
    }else{
        res = 1;
    }

    cout << res << endl;
}

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

typedef long long LL;
#define MAXN 51
#define _MOD 1000000009

int H,W;
char M[MAXN][MAXN];
int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    std::ios_base::sync_with_stdio(false);

    scanf("%d %d", &H, &W);
    for (int i = 0; i < H; i++)
        scanf("%s", M[i]);

    int ok = 1;
    if (H == 1 && W == 1 && M[0][0] == '.')
        ok = 0;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (M[i][j] == '.')
                continue;

            if ((i == 0 || M[i-1][j] == '.' ) &&
                (i == H-1 || M[i+1][j] == '.') &&
                (j == 0 || M[i][j-1] == '.') &&
                (j == W-1 || M[i][j+1] == '.')) {
                ok = 0;
                break;
            }

        }
        if (!ok)
            break;
    }

    if (ok)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 256
N, M, K = map(int, input().split())
mod = 998244353
ans = 0
nCi = [1]

for i in range(1, N+1):
    nCi.append(nCi[i-1]*(N-i) * pow(i, mod-2, mod) % mod)


for i in range(K+1):
    ans += M * pow(M - 1, N-1-i, mod) * nCi[i]
    ans %= mod

print(ans)


Measured memory_bytes: 16908
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;(i)<(n);i++)
typedef long long ll;
using namespace std;
int main(void){
    int n; cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    vector<int> a(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    map<vector<int> , int> mp;
    rep(i,n) a[i] = i+1;
    do{
        mp[a] = mp.size();
    }while(next_permutation(a.begin(),a.end()));
    cout << abs(mp[p]-mp[q]) << endl;
}




Measured memory_bytes: 5248
N = int(input())
A = [int(a) for a in input().split()]
if min(A) == 0:
    print(0)
else:
    ans = 1
    M = 10**18
    for i in A:
        ans *= i
        if ans > M:
            print(-1)
            break
    else:
        print(ans)


Measured memory_bytes: 21780
#include <iostream>
#include <string>
using namespace std;
  
int main(){
    while (true)
    {
        int x[200] = {};
        fill(x, x+200, 0);
        int a;
        cin >> a;
        if (cin.eof()) { break; }
        while (true)
        {
            x[a]++;
            x[a] = x[a] % 2;
            cin >> a;
            if (a == 0) { break; }
        }
        cin >> a;
        int count = 0;
        for(int i=3;i<101;i++){
            if (x[i] == 1) { count++; }
        }
        if(x[1] == 1 && x[2] == 1 && count ==0) {
            cout << "OK" << endl;
        }
        else{
            cout << "NG" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010

int main(){
	IOS;
	ll a,b,c;cin>>a>>b>>c;
	cout<<max(c-(a-b),0ll);
	return 0;
}



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

int main() {
    int N,K,R,S,P;
    cin >> N >> K >> R >> S >> P;

    string T;
    cin >> T;

    int Ans = 0;
    int chk = 0;

    for(int i = 0; i < K; i++){
        chk = 0;

        for(int j = i; j < N; j += K){
            if(j >= K && T.at(j - K) == T.at(j) && chk%2 == 0){
                chk++;
                continue;
            }else if(j >= K && T.at(j - K) == T.at(j) && chk%2 != 0){
                chk++;
                if(T.at(j) == 'r') Ans += P;
                if(T.at(j) == 'p') Ans += S;
                if(T.at(j) == 's') Ans += R;
            }else{
                chk = 0;
                if(T.at(j) == 'r') Ans += P;
                if(T.at(j) == 'p') Ans += S;
                if(T.at(j) == 's') Ans += R;

            }
        }
    }

    cout << Ans << endl;



}


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

int main()
{
    int a,b,c;
    while(~scanf("%d%d%d",&a,&b,&c))
    {
        if(a==b && a!=c)
        {
            cout<< c <<endl;
        }
        else
        if(a==c && a!=b)
        {

            cout<< b <<endl;
        }
        else
            if(b==c && b!=a)
        {
            cout<< a << endl;
        }
    }
}

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

int main(){
    int n;
    cin >> n;
    int a;
    vector<int> list(n);
    string ans = "APPROVED";
    for(int i=0; i<n; i++){
        cin >> a;
        if(a%2==0 && a%3!=0 && a%5!=0){
            ans = "DENIED";    
        }
    }
    cout << ans;
}


Measured memory_bytes: 256