akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

vector<int> v[100005];
int dist[100005];
int indegree[100005];
bool viz[100005];

int n,m;

void solve(int x)
{
    if(indegree[x] == 0 && !viz[x])
    {
        viz[x] = true;
        for(auto y: v[x])
        {
            indegree[y]--;
            dist[y] = max(dist[x]+1, dist[y]); 
            if(indegree[y] == 0)
                solve(y);
        }
    }       
    
}






int main()
{
    cin >> n >> m;
    int x,y;
    
    for(int i=1;i<=n;i++)
        v[0].pb(i), indegree[i]++;

    for(int i=0;i<m;i++)
    {
        cin >> x >> y;
        v[x].pb(y);
        indegree[y]++;
    }

    for(int i=0;i<=n;i++)
        solve(i);
        
    int ans= -1;

    for(int i = 0;i<=n;i++)
        ans = max(ans, dist[i]-1);
    cout << ans << endl;






}


Measured memory_bytes: 7928
#include <iostream>
#include <math.h>
#include <algorithm>  

using namespace std;

int main() {
	int n, x;
	cin >> n >> x;
	int arr[n];
	for (int i = 0; i < n; i++) {
	    int val;
	    cin >> val;
	    arr[i] = abs(val - x);
	}
	int res = 0;
	for (int i = 0; i < n; i++) res = __gcd(res, arr[i]);
	cout << res;
}

Measured memory_bytes: 640
#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int n; cin >> n;
  vi32 a(n); cin >> a;
  int sum = accumulate(all(a), 0);
  int ans = -1;
  f80 ma = 1e18;
  rep(i, n) {
    if (ma > abs(a[i] - (f80) sum / n)) {
      ans = i, ma = abs(a[i] - (f80) sum / n);
    }
  }
  cout << ans << '\n';
}


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

int n,min_;
int max_;
int b[100002] = {};

int main(){
    cin >> n;
    vector<int> a(n,0);
    cin >> a[0];
    b[a[0]]++;
    min_ = a[0];
    max_ = a[0];
    for(int i = 1; i < n; i++){
        cin >> a[i];
        b[a[i]]++;
        if(a[i] > max_){
            max_ = a[i];
        }else if(a[i] < min_){
            min_ = a[i];
        }
    } 
    int ans = 0;
    for(int j = min_; j <= max_; j++){
        if(ans < b[j - 1] + b[j] + b[j + 1]){
            ans = b[j - 1] + b[j] + b[j + 1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
int pcnt(int x) {
    return __builtin_popcount(x);
}
int f(int x) {
    if (x == 0) return 0;
    return f(x % pcnt(x)) + 1;
}
/* main */
int main(){
    // O(slogN): Nを何回logを取り続けたら1になるか
    // popcount(X_i) = popcount(X) +- 1
    // N = 1001101
    // popcount(X) = 4
    // popcount(X_i) = 5 or 3
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> x(n);
    for (int i = 0; i < n; i++) x[i] = s[i] - '0';

    int pc = 0;
    for (int i = 0; i < n; i++) pc += x[i];

    vector<int> ans(n);
    for (int b = 0; b < 2; b++) {
        int npc = pc;
        if (b == 0) npc++;
        else npc--;
        if (npc <= 0) continue;
        // 2進数 -> 10進数
        // ex) 1101
        // 1     1     0     1
        // 1 ->  2
        //   *2 +1
        //      =3 ->  6
        //         *2 +0
        //            =6 -> 12
        //               *2 +1
        //                  =13
        int r0 = 0; // 元のxの割ったあまり
        for (int i = 0; i < n; i++) {
            r0 = (r0 * 2) % npc;
            r0 += x[i];
        }
        // X  = 1101
        // X1 = 0101
        // X2 = 1001
        // X3 = 1111
        // X4 = 1100
        // if(X[i] == 0) r = (r + 2**i) % npc
        // if(X[i] == 1) r = (r - 2**i) % npc
        int k = 1;  // 2 ** i
        for (int i = n - 1; i >= 0; i--) {
            if (x[i] == b) {
                int r = r0;  // X_i % pcnt(X_i)
                if (b == 0) r = (r + k) % npc;
                else r = (r - k + npc) % npc;
                // 1回目の操作は2進数で行う +
                // 以降の操作はf(r)を愚直に計算
                ans[i] = f(r) + 1;
            }
            k = (k * 2) % npc;
        }
    }

    for (int i = 0; i < n; i++)
        cout << ans[i] << '\n';
}


Measured memory_bytes: 5248
n, w = map(int, input().split())
weight = []
value = []

for i in range(n):
    x, y = map(int, input().split())
    weight.append(x)
    value.append(y)

dp = [[10 ** 9 + 7 for i in range(sum(value) + 1)] for j in range(n + 1)]

dp[0][0] = 0

for i in range(n):
    for j in range(sum(value) + 1):
        if j - value[i] >= 0:
            dp[i + 1][j] = min(dp[i][j], dp[i][j - value[i]] + weight[i])

        else:
            dp[i + 1][j] = dp[i][j]

a = sorted(range(sum(value) + 1), reverse = True)

for i in a:
    if dp[n][i] <= w:
        print(i)
        break



Measured memory_bytes: 168112
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

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

const string STABLE = "STABLE";
const string UNSTABLE = "UNSTABLE";

struct Pos {
    int x, y;
    Pos() {}
    Pos(int a, int b): x(a), y(b) {}
};

struct S {
    int w; double ys;
    S() {}
    S(int a, double b): w(a), ys(b) {}
};

int W, H;
string P[60];
int visited[60][10];

S check(int h, int w) {
    // int bl, br, xl, xr;
    char num = P[h][w];
    int xl = 1000, xr = -1000;
    if (h == H-1) {
        for (int j = w; j >= 0; --j) {
            if (P[h][j] != num) { xl = j+1; break; }
            else if (j == 0) { xl = 0; }
        }
        for (int j = w; j < W; ++j) {
            if (P[h][j] != num) { xr = j; break; }
            else if (j == W-1) { xr = W; }
        }
    }

    queue<Pos> que;
    vector<S> objs;

    que.emplace(h, w);
    visited[h][w] = 1;
    double ys = 0;
    while (!que.empty()) {
        Pos pt = que.front(); que.pop();
        ys += pt.y;
        for (int d = 0; d < 4; ++d) {
            int nx = pt.x + dx[d], ny = pt.y + dy[d];
            if (nx < 0 || ny < 0 || nx >= H || ny >= W) { continue; }
            if (P[nx][ny] == num and !visited[nx][ny]) {
                visited[nx][ny] = 1;
                que.emplace(nx, ny);
            } else if (P[nx][ny] != num and P[nx][ny] != '.' and d == 2 and !visited[nx][ny]) {
                S obj = check(nx, ny);
                if (obj.w < 0 && obj.ys < 0) {
                    return obj;
                }
                objs.push_back(obj);
            } else if (P[nx][ny] != num and P[nx][ny] != '.' and d == 0) {
                xl = min(xl, ny);
                xr = max(xr, ny+1);
            }
        }
    }

    double sw = 4, yg = ys+2;
    for (S o : objs) {
        sw += o.w;
        yg += o.w * o.ys;
    }

    if (yg/sw <= xl || xr <= yg/sw) {
        return S(-1, -1);
    }

    return S(sw, yg/sw);
}

string solve() {
    for (int j = 0; j < H; ++j) for (int k = 0; k < W; ++k) visited[j][k] = 0;
    for (int j = 0; j < W; ++j) {
        if (P[H-1][j] != '.') {
            S r = check(H-1, j);
            if (r.w >= 0 || r.ys >= 0) {
                return STABLE;
            } else {
                return UNSTABLE;
            }
        }
    }
    return UNSTABLE;
}

int main() {
    while (true) {
        cin >> W >> H;
        if (W == 0 && H == 0) break;
        for (int j = 0; j < H; ++j) {
            cin >> P[j];
        }
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
  int h,w; cin>>h>>w; vector<string>board(60); rep(i,h)cin>>board[i];
  int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
  rep(i,h){rep(j,w){if(board[i][j]=='.'){
    int cnt=0;
    rep(k,8){
      int x=i+dx[k]; int y=j+dy[k];
      if(x>=0&&x<h&&y>=0&&y<w&&board[x][y]=='#')cnt++;
    }
    board[i][j]='0'+cnt;
  }
                   }
          }
  
  rep(i,h)cout<<board[i]<<endl;
}

Measured memory_bytes: 256
n,m=map(int, input().split())

a=[int(x) for x in input().split()]

kaisuu=0

for i in a:
    zantei=0
    while True:
        if i%2==0:
            zantei+=1
            i//=2
        else:
            break
    if kaisuu==0:
        kaisuu=zantei
    else:
        if kaisuu!=zantei:
            print(0)
            exit()

sks=a[0]//2

import math

for i in range(1,len(a)):
    sks=sks*(a[i]//2)//(math.gcd(sks,a[i]//2))

ans=int(m/(2*sks)+(1/2))

print(ans)

Measured memory_bytes: 85180
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1,
    x=-x;
  }
  while(x){
    f[s++]=x%10,
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
template<class S, class T> inline S divup_L(S a, T b){
  return (a+b-1)/b;
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int A[100000], B[100000], H, N;
int main(){
  int i, mx, res;
  rd(N);
  rd(H);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
      rd(B[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY, Q5VJL1cS;
    if(N==0){
      Q5VJL1cS = 0;
    }
    else{
      Q5VJL1cS = A[0];
      for(KL2GvlyY=1;KL2GvlyY<N;KL2GvlyY++){
        Q5VJL1cS = max_L(Q5VJL1cS, A[KL2GvlyY]);
      }
    }
    mx =Q5VJL1cS;
  }
  sort(B,B+N);
  res = divup_L(H,mx);
  for(i=0;i<N;i++){
    H -= B[N-i-1];
    if(H <= 0){
      chmin(res, i+1);
      break;
    }
    chmin(res, i+1 + (divup_L(H,mx)));
  }
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20171023-1 [beta]

// --- original code ---
// int N, H, A[100000], B[100000];
// {
//   int i, mx;
//   int res;
//   
//   rd(N,H,(A,B)(N));
//   mx = max(A(N));
//   sort(B,B+N);
// 
//   res = H /+ mx;
//   rep(i,N){
//     H -= B[N-i-1];
//     if(H <= 0){
//       res <?= i+1;
//       break;
//     }
//     res <?= i+1 + (H /+ mx);
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int N;
int main ()
{
    cin >> N;
    int res = N;
    rep(i, N + 1) {
        int cc = 0;
        int t = i; // i円を6^p円の形で払う
        while (t > 0) { cc += t % 6; t /= 6; }
        t = N - i; // 残りを9^p円の形で払う
        while (t > 0) { cc += t % 9; t /= 9; }
        chmin(res, cc);
    }
    out(res);
}
/*
 公式pdf解説
 
 https://atcoder.jp/contests/abc099/submissions/5186705
 公式pdf解説まんまっぽい
 2019/7/27 8:55 最短
 */


Measured memory_bytes: 256
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <set>

using std::set;
using std::swap;
int _w;

int a, b, c;

struct Triple {
	int a, b, c;
	Triple() {}
	Triple( int a, int b, int c ):
		a(a), b(b), c(c) {}
	bool operator<( const Triple &rhs ) const {
		if( a == rhs.a ) {
			if( b == rhs.b ) return c < rhs.c;
			else return b > rhs.b;
		} else {
			return a < rhs.a;
		}
	}
};

set<Triple> s;

void sort() {
	if( b < a ) swap(a, b);
	if( c < a ) swap(a, c);
	if( c < b ) swap(b, c);
}

void mark() {
	s.insert( Triple(a, b, c) );
}

bool exist() {
	return s.count( Triple(a, b, c) );
}

int main() {
	_w = scanf( "%d%d%d", &a, &b, &c );
	sort(), mark();
	int ans = 0;
	while(1) {
		if( a % 2 || b % 2 || c % 2 ) break;
		int aa = (b+c)/2;
		int bb = (a+c)/2;
		int cc = (a+b)/2;
		a = aa, b = bb, c = cc;
		sort();
		if( exist() ) return puts("-1"), 0;
		mark(), ++ans;
	}
	printf( "%d\n", ans );
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e4 + 5);
const double EPS = 1e-11;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, w, h;
    cin >> n >> w >> h;
    vector<P> xs(n), ys(n);
    REP(i,n){
        int x, y, w;
        cin >> x >> y >> w;
        xs[i].first = x-w;
        xs[i].second = x+w;
        ys[i].first = y-w;
        ys[i].second = y+w;
    }
    SORT(xs);
    SORT(ys);

    bool xok = true, yok = true;
    int pos = 0;
    REP(i,n){
        int xl=xs[i].first, xr=xs[i].second;
        xok &= xl <= pos;
        pos = max(pos, xr);
    }
    xok &= pos >= w;

    pos = 0;
    REP(i,n){
        int yl=ys[i].first, yr=ys[i].second;
        yok &= yl <= pos;
        pos = max(pos, yr);
    }
    yok &= pos >= h;
    
    cout << (xok||yok?"Yes":"No") << endl;
    return 0;
}



Measured memory_bytes: 4432
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    bool isfirst[26];
    bool isused[26];
    int N;
    while(cin>>N,N){
        fill(isfirst,isfirst+26,false);
        fill(isused,isused+26,false);
        vector<string> S;
        int K[26]={};
        for(int i=0;i<N;i++){
            string str;
            cin>>str;
            S.push_back(str);
            if(str.size()>1) isfirst[str[0]-'A']=true;
            for(auto c:str) isused[c-'A']=true;
        }
        for(int n=0;n<N-1;n++){
            for(int i=0,k=1;i<8;i++,k*=10){
                K[S[n][S[n].size()-1-i]-'A']+=k;
            }
        }
        for(int i=0,k=1;i<8;i++,k*=10){
            K[S[N-1][S[N-1].size()-1-i]-'A']-=k;
        }
        int used=0;
        for(int i=0;i<26;i++) if(isused[i])used++;
        int ans=0;
        int comb=(1<<used)-1;
        while(comb<(1<<10)){
            int perm[10];
            for(int i=0,p=0;i<10;i++){
                if(comb&(1<<i)){
                    perm[p++]=i;
                }
            }
            int x = comb&-comb, y=comb+x;
            comb=((comb&~y)/x>>1)|y;
            do{
                int num[26];
                int d,sum=0;
                for(int i=0,p=0;i<26;i++){
                    if(isused[i]){
                        num[i]=perm[p++];
                        if(isfirst[i]&&num[i]==0){
                            sum=-1;
                            break;
                        }
                        sum+=K[i]*num[i];
                    }
                }
                ans+=!sum;
            }while(next_permutation(perm,perm+used));
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3084
N = int(input())
A = list(map(int, input().split()))

def gcd(x, y):
    if x < 0 and y < 0:
        return -1
    if x < 0:
        return y
    if y < 0:
        return x


    x, y = max(x, y), min(x, y)
    r = x % y
    if r == 0:
        return y
    else:
        return gcd(r, y)

# Li = gcd(A1, A2, ..., Ai-1)
# Ri = gcd(Ai+1, Ai+2, ..., AN)

L = [-1] * N
R = [-1] * N

L[1] = A[0]
R[N-2] = A[N-1]

for i in range(2, N):
    L[i] = gcd(L[i-1], A[i-1])
for i in range(N-3, -1, -1):
    R[i] = gcd(R[i+1], A[i+1])

G = [gcd(L[i], R[i]) for i in range(N)]
print(max(G))


Measured memory_bytes: 14584
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias C = Tuple!(int, "i", long, "a");

void main()
{
    auto N = readln.chomp.to!int;
    long[] AS;
    C[] cs;
    foreach (i, a; readln.split.to!(long[])) {
        AS ~= a;
        cs ~= C(i.to!int, a);
    }
    sort!"a.a > b.a"(cs);
    auto DP = new long[][](N+1, N+1);
    foreach (x; 0..N) {
        foreach (y; 0..N-x) {
            auto i = cs[x+y].i;
            auto A = cs[x+y].a;
            DP[x+1][y] = max(DP[x+1][y], DP[x][y] + abs(i - x) * A);
            DP[x][y+1] = max(DP[x][y+1], DP[x][y] + abs(i - (N-y-1)) * A);
        }
    }

    long r;
    foreach (x; 0..N+1) {
        auto y = N-x;
        r = max(r, DP[x][y]);
    }
    writeln(r);
}

Measured memory_bytes: 34920
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int n, m;

int main() { 

  cin >> n >> m;

  if (m == n) {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const ll INF = (1LL << 60);
const int MAX_N = 1010;

vector<int> to[MAX_N];
vector<int> rto[MAX_N];
bool reachableFrom1[MAX_N];
bool reachableFromN[MAX_N];
bool ok[MAX_N];

void dfs(int v) {
    if (reachableFrom1[v]) return;
    reachableFrom1[v] = true;
    for (int u: to[v]) {
        dfs(u);
    }
}

void r_dfs(int v) {
    if (reachableFromN[v]) return;
    reachableFromN[v] = true;
    for (int u: rto[v]) {
        r_dfs(u);
    }
}

typedef tuple<int, int, ll> Edge;

int main() {
    int N, M;
    cin >> N >> M;
    vector<Edge> edges;
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        edges.emplace_back(a, b, -c);
        to[a].push_back(b);
        rto[b].push_back(a);
    }

    dfs(0);
    r_dfs(N - 1);
    rep(i, N) ok[i] = reachableFrom1[i] && reachableFromN[i];

    {
        // bellman-ford
        vector<ll> d(N, INF);
        d[0] = 0;
        bool upd = true;
        int step = 0;
        while (upd) {
            upd = false;
            rep(i, M) {
                ll a, b, c;
                tie(a, b, c) = edges[i];
                if (!ok[a]) continue;
                if (!ok[b]) continue;

                ll newD = d[a] + c;
                if (newD < d[b]) {
                    upd = true;
                    d[b] = newD;
                }
            }

            step++;
            if (step > N) {
                cout << "inf" << endl;
                return 0;
            }
        }

        cout << d[N - 1] * -1 << endl;
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	int N, Q;
	string S;
	
	cin >> N >> Q;
	cin >> S;

	vector<int> l(Q), r(Q);
	for (int i = 0; i < Q; i++)
	{
		cin >> l[i] >> r[i];
	}


	vector<int> sum(N + 1, 0);
	
	//ACが出る可能性があるのは2文字目から(0-indexedで1から)
	for (int i = 1; i < N; i++)
	{
		sum[i + 1] = sum[i];
		if (S[i - 1] == 'A' && S[i] == 'C') {
			sum[i + 1]++;
		}
	}

	//0 1 2 3 4 5 6
	// A C A C A C
	// 1 2 3 4 5 6

	for (int i = 0; i < Q; i++)
	{
		int ans = sum[r[i]] - sum[l[i]];
		cout << ans << endl;
	}
}



Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

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

	    int N=gi();
	    int x=gi();
	    long[] a=new long[N];

	    long c=0;
	    for (int i=0; i<N;i++) {
	    	a[i]=gi();
	    	if(i>0) {
	    		long y=a[i-1]+a[i];
	    		if(y>x) {
	    			long d=y-x;
	    			c+=d;
	    			a[i]=Math.max(a[i]-d, 0);
	    		}
	    	}
	    }

	    System.out.println(c);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 60532
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

j = 99
m = 0
for i in range(len(a)) :
    m += b[a[i]-1]
    if a[i]-1 == j+1 :
        m += c[j]
    j = a[i]-1
print(m)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
	int a, b;
	char op;

	for(;;){
		scanf("%d %c %d", &a, &op, &b);
		if(op=='?')
			break;

		printf("%d\n", op^'+' ? op^'-' ? op^'*' ? a/b : a*b : a-b : a+b);
	}

	return 0;
}



Measured memory_bytes: 2044
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println(o);
    }

    static Object run() {
        try (Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            BigDecimal bd = new BigDecimal((a + b) / 2.0).setScale(0, BigDecimal.ROUND_UP);
            return bd.longValue();
        }
    }
}

class ChenNumberUtil {
    static Collection<Integer> getDivisors(int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        }
        Collections.sort(al);
        return al;
    }
}

class ChenBitUtil {
    static int popCount(int bit) {
        return Integer.bitCount(bit);
    }

    static boolean isFlag(int bit, int i) {
        return 0 != (bit & (1 << i));
    }

    static int setTrue(int bit, int i) {
        return bit |= (1 << i);
    }

    static int setFalse(int bit, int i) {
        return bit &= ~(1 << i);
    }

    static int setReverse(int bit, int i) {
        return isFlag(bit, i) ? setFalse(bit, i) : setTrue(bit, i);
    }

    static int reverseAll(int bit) {
        return ~bit;
    }
}


Measured memory_bytes: 27172
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n string
	fmt.Scan(&n)

	cn := strings.Split(n, "")
	fmt.Println(swap(cn[0]) + swap(cn[1]) + swap(cn[2]))
}

func swap(s string) string {
	if s == "1" {
		return "9"
	}
	return "1"
}


Measured memory_bytes: 640
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

ll time[10010];
ll hito[10010];
ll st[10010];

int main(){
	ll z;
	while(scanf("%lld%*lld",&z),z){
		ll n;
		scanf("%lld",&n);
		rep(i,0,n)scanf("%lld%*lld%lld%lld",time+i,hito+i,st+i);
		ll m;
		scanf("%lld",&m);
		rep(i,0,m){
			ll start,end,hi;
			scanf("%lld%lld%lld",&start,&end,&hi);
			ll ans=0,cnt=0,pos=0;
			rep(t,540,1260){
				while(pos<n&&time[pos]<=t){
					if(hito[pos]==hi){
						if(st[pos]==1)cnt++;
						else cnt--;
					}
					pos++;
				}
				if(start<=t&&t<end)ans+=!!cnt;
			}
			printf("%lld\n",ans);
		}
	}
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
#define LL long long
#define ll k<<1
#define rr k<<1|1
#define lson l, m, ll
#define rson m + 1, r, rr
#define INF 0x3f3f3f3f
using namespace std;
const int N = 100000 + 5;
const int maxn = 1e5;
inline int max(int a, int b)
{
    return a > b ? a : b;
}
inline int min(int a, int b)
{
    return a < b ? a : b;
}
int dp[N][2][3];

int main()
{
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n;
    int res = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> x;

        dp[i][x][0] = dp[i - 1][!x][0] + 1;
        dp[i][x][1] = max(dp[i - 1][!x][2], dp[i - 1][!x][1]) + 1;
        dp[i][!x][2] = max(dp[i - 1][x][0], dp[i - 1][x][2]) + 1;
        res = max(res, max(dp[i][x][1], dp[i][!x][2]));
    }
    cout << res << endl;
    return 0;
}




Measured memory_bytes: 5556
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
// #define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
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;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

    int a,b,c;
    cin>>a>>b>>c;
    if(a<=c&&c<=b||b<=c&&c<=a)yes;
    else no;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int C = stdIn.nextInt();
         
        double Cc = C * Math.PI /180;
         
        double L = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(Cc));
        double h = b * Math.sin(Cc);
        double S = b * Math.sin(Cc) * a /2;
         
        System.out.println(S);
        System.out.println(L + a + b);
        System.out.println(h);
    }
}


Measured memory_bytes: 26308
#include <bits/stdc++.h>
using namespace std;
#define all(arr) arr.begin(), arr.end() 
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
string s;
bool yes=1;
//odd RUD, even LUD

int main(){
	IOS
	cin >> s;
	int l=s.length();
	for(int i=1;i<=l;i++){
		if(i&1){
			if(s[i-1]=='R' or s[i-1]=='U' or s[i-1]=='D'){
				continue;
			}
			else{
				yes=0;
				break;
			}
		}
		else{
			if(s[i-1]=='L' or s[i-1]=='U' or s[i-1]=='D'){
				continue;
			}
			else{
				yes=0;
				break;
			}
		}
	}
	if(!yes){
		cout << "No" << '\n';
	}
	else{
		cout << "Yes" << '\n';
	}
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
const double PI=3.1415926535897932;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll gcd(ll a, ll b){
    ll tmp;
    if(a%b == 0){
        return b;
    }
    else{
        return gcd(b, a%b);
    }
}


const ll SIZE = (1e5+10)*2;
ll a,b;
string s;

void ANS(){
    cout << "No\n";
}

int main(){
    cin >> a >> b;
    cin >> s;
    if(s.length() != a+b+1){
        ANS();
        return 0;
    }

    for(int i = 0; i < s.length(); i++){
        if(s[i] >= '0' && s[i] <= '9'){
            if(i==a){
                ANS();
                return 0;
            }
        }
        else{
            if(i == a && s[i] == '-')   continue;
            else{
                ANS();
                return 0;
            }
        }
    }

    cout << "Yes\n";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
    int n, m;
    cin >> n >> m;
    int a[200001], b[200001];
    int c[200001] {0};
    int d[200001] {0};
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        if(a[i] == 1){
            c[b[i]] = 1;
        }
        if(b[i] == n){
            d[a[i]] = 1;
        }
    }
    for(int i = 0; i <= n; i++){
        if(c[i] == 1 && d[i] == 1){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 3328
fun main(args: Array<String>) {
    val d = readLine()!!.map {it-'0'}

    for (i in 0 until 8) {
        var sol = d[0]
        var pr = "$sol"
        for (j in 0 until 3) {
            if (i and (1 shl j) != 0) {
                pr += "+${d[j+1]}"
                sol += d[j+1]
            }
            else {
                pr += "-${d[j+1]}"
                sol -= d[j+1]
            }
        }
        if (sol == 7) {
            println("$pr=7")
            return
        }
    }
}

Measured memory_bytes: 33660
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && a != c) {
    cout << "Yes" << endl;
  } else if (a == c && a != b) {
    cout << "Yes" << endl;
  } else if (b == c && a != b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

llint n,k;
const int D=60;
int db[D][200005];


void solve(){
  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> db[0][i];
    db[0][i]--;
  }
  for(int i=0;i<D-1;i++){
    for(int j=0;j<n;j++){
      db[i+1][j]=db[i][db[i][j]];
    }
  }
  int v=0;
  for(int i=D-1;i>=0;i--){
    llint l=1ll<<i;
    if(l<=k){
      v=db[i][v];
      k-=l;
    }
  }
  cout << v+1 << endl;
}

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


Measured memory_bytes: 50488
#include <cstdio>
#include <utility>
#include <queue>
#include <vector>
#include <iostream> 
#include <algorithm>
#include <math.h>
#include <map> 
#include <string.h> 
#include <string> 
#include <cctype> 

using namespace std;

string s,p; char t[201]; bool flag;

int main(){	
  
  cin>>s>>p; 
  
  for(int i=0; i<s.size(); i++){
    t[i]=s[i];
    }
  for(int i=0; i<s.size(); i++){
    t[i+s.size()]=s[i];
    }
  
 for(int j=0; j<s.size(); j++){
   string x;
  for(int i=j; i<j+p.size(); i++){
    x+=t[i];
    }
    if(p==x) {flag=true; break;}
  }
    
  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}

Measured memory_bytes: 3216
//============================================================================
// Name        : B.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

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

int x,y;

int dp[1000010];
pair<int,int> solve(int x, int y){
	memset(dp, -1, sizeof dp);
	int c = x;
	for(int i = 0;; ++i){
		//int q = c/y;
		int r = c%y;
		if(r == 0){
			return make_pair(i, 0);
		}
		if(dp[r] != -1){
			return make_pair(dp[r], i-dp[r]);
		}
		dp[r] = i;
		c = r*10;
	}
}

int main() {
	while(cin >> x >> y && x){
		auto ans = solve(x,y);
		cout << ans.first << ' ' << ans.second << '\n';
	}
}

Measured memory_bytes: 6956
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<pair<int, int>> CO(N);
	for (int i = 0; i < N; i++) cin >> CO[i].first >> CO[i].second;
	sort(CO.begin(), CO.end());
	unordered_map<string, int> PairNum;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			string S = to_string(CO[j].first - CO[i].first) + "," + to_string(CO[j].second - CO[i].second);
			PairNum[S]++;
		}
	}
	int MAX = 0;
	for (const auto& pair : PairNum) MAX = max(MAX, pair.second);
	cout << N - MAX << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define lint long long
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define SET(x, val) memset(x, val, sizeof(x))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int B = 9, N = (1<<18)+5, MOD1 = 1e9 + 7, MOD2 = 998244353;
const lint INF = 1e18;
const int SS = (1<<9)+2;
int n, q, dp[SS][N], v[N], w[N];
signed main()
{
    fastio;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> v[i] >> w[i];
    }
    for(int i = 1; i < SS; i++)
    {
        for(int j = 1; j < N; j++)
        {
            dp[i][j] = dp[i/2][j];
            if(w[i] <= j) dp[i][j] = max(dp[i][j], dp[i/2][j-w[i]] + v[i]);
        }
    }
    cin >> q;
    for(int it = 1; it <= q; it++)
    {
        int u, l;
        cin >> u >> l;
        vector<pii> obj;
        while(u>=SS)
        {
            obj.pb({v[u], w[u]});
            u/=2;
        }
        int sz = obj.size(), mx = 0;
        for(int i = 0; i < (1<<sz); i++)
        {
            int vt = 0, wt = 0;
            for(int j = 0; j < sz; j++)
            {
                if(((1<<j)&i) != 0)
                {
                    vt += obj[j].F; wt+=obj[j].S;
                }
            }
            if(wt <= l)
            {
                mx = max(mx, vt + dp[u][l-wt]);
            }
        }
        cout << mx << endl;
    }
}

Measured memory_bytes: 530972
import sys
for line in sys.stdin:
	s = line
	ans = ''
	flag = False
	reg = 1
	for i in range(0, len(s)-1):
		if flag:
			reg = int(s[i])
			flag = False
		else:
			if s[i] == '@':
				flag = True
			else:
				for j in range(0, reg):
					ans = ans + s[i]
					reg = 1
	print ans


Measured memory_bytes: 4644
#include<iostream>
#include<vector>
#define _USE_MATH_DEFINES
#include<math.h>
#include<algorithm>
#include<memory>
#include<string>
#define Rep(i,n) for(int i = 0;i < (n);i++)	
typedef long long ll;

int gcd(int a, int b) { if (b == 0)  return a;  else  return gcd(b, a % b);  }
int lcm(int a, int b) { return a * b / gcd(a, b); }
void swap(int& a, int& b) { int temp = a; a = b; b = temp; return; }
int ncr(int n, int r) { int a = 1; Rep(i, r) a = (a * (n - i)) / (i + 1); return a; }
int npr(int n, int r) { int a = 1; Rep(i, r) a *= n - i; return a; }
int mod(int a, int b) { return a % b; }


int main() {
	int k;
	int a, b;
	std::cin >> k;
	std::cin >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			std::cout << "OK" << std::endl;
			return 0;
		}
	}
	std::cout << "NG" << std::endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
struct node{
	int v,n;
}a[100005];
int cmp(node a,node b)
{
	return (a.n<b.n);
}
int main()
{
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >>m;
		a[i].v=i;
		a[i].n=m;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		if(i==1)
		cout << a[i].v;
		else
		cout << " " <<a[i].v;
	}
	cout <<endl;
}

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

k = (M + 1) // 2
s, e = 1, 2 * k
for _ in range(k):
    print(s, e)
    s, e = s + 1, e - 1

k = M // 2
s, e = N - 2 * k, N
for _ in range(k):
    print(s, e)
    s, e = s + 1, e - 1



Measured memory_bytes: 9284
#include <iostream>
#include <utility>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    std::cin >> a >>b;
    if(a>b)swap(a,b);
    if((b-a)%2==0){
        
        std::cout << abs(b-(b-a)/2) << std::endl;    
    }else{
        std::cout << "IMPOSSIBLE" << std::endl;
    }
}


Measured memory_bytes: 256
li = list(map(int,input().split()))

a = li[0]
b = li[1]
c = li[2]
d = li[3]


ac = a * c
bc = b * c
ad = a * d
bd = b * d
result = ac
if result < bc:
    result = bc
if result < ad:
    result = ad
if result < bd:
    result = bd
if a <= 0 and 0 <= b and result < 0:
    result = 0
if c <= 0 and 0 <= d and result < 0:
    result = 0
print(result)


Measured memory_bytes: 9192
function main(arg){
  arg = arg.trim().split(' ').map(str => parseInt(str, 10));
  var a = arg[0], b = arg[1];
  var out = ((a+b)%2 === 0) ? (a+b)/2 : 'IMPOSSIBLE';
  console.log(out);
}
main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

string s,t;

int main() {
    cin >> s >> t;
    int f = 0;
    rep(i,s.size()){
        if (s[i] != t[i]) f = 1;
    }
    (f) ? cout << "No" << endl : cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define int long long
#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;

int N, M;
vector<int> G[10];
bool used[10];

int dfs(int v)
{
    used[v] = true;
    int res = 0;
    for(int i = 0; i < (int)G[v].size(); i++){
        if(!used[G[v][i]])res += dfs(G[v][i]);
    }
    if(res == 0){
        int ret = 1;
        for(int i = 0; i < N; i++){
            if(!used[i])ret = 0;
        }
        used[v] = false;
        return ret;
    }
    used[v] = false;
    return res;
}

signed main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    cout << dfs(0) << endl;

    return 0;
}

/*



*/


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>

#define mod 1000000007
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;

int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};

int gcd(int a, int b) {
    int x = max(a, b);
    int y = min(a, b);
    int z = x % y;
    if(z == 0){
        return y;
    }else{
        return gcd(y, z);
    }
}

int lcm(int a, int b) {
    return (a*b)/gcd(a, b);
}

void solve() {
    deque<ll> deq;
    int n;
    cin >> n;
    ll a[n];
    REP(i, n) cin >> a[i];

    REP(i, n){
        if((i+1)%2 == n%2){
            deq.push_front(a[i]);
        }else{
            deq.push_back(a[i]);
        }
    }

    for(auto i = deq.begin(); i != deq.end(); i++){
        cout << *i << " ";
    }
    cout << endl;
}

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

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

using namespace std;

template <typename T>
T gcd(T a, T b) {
  while (a) {
    b %= a;
    std::swap(a, b);
  }
  return b;
}

template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] /= 2;
  }
  auto f = [](int64_t x) {
    int res = 0;
    while (x % 2 == 0) {
      x /= 2;
      res++;
    }
    return res;
  };
  int64_t c = f(A[0]);
  for (int i = 0; i < N; i++) {
    if (c != f(A[i])) {
      cout << 0 << '\n';
      return 0;
    }
  }
  int64_t l = 1;
  for (int i = 0; i < N; i++) {
    l = lcm(l, A[i]);
  }
  cout << (M / l + 1) / 2 << '\n';
  return 0;
}


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

int main() {long N; long K; cin >> N >> K;
vector<long> x(N);
long zero = 0;
long ans = 1e10;
for(int i = 0; i < N; i++) cin >> x.at(i);
for(int i = 0; i < N - K + 1; i++){
  if(x.at(i) <= zero && zero <= x.at(i + K - 1)){
    ans = min(ans, max(abs(x.at(i)), abs(x.at(i + K - 1))) + 2 * min(abs(x.at(i)), abs(x.at(i + K - 1))));
  }
  else{
    ans = min(ans, max(abs(x.at(i)), abs(x.at(i + K - 1))));
  }

}


// char ans = str[1][1];
 cout << ans << endl;
 return 0;
 }

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5+7;
int minv[maxn];
void build(int k,int l,int r){
    minv[k]=2147483647;
    if(l==r) return;
    int m=(l+r)>>1;
    build(k<<1,l,m);
    build(k<<1|1,m+1,r);
    minv[k]=min(minv[k<<1],minv[k<<1|1]);
}
void update(int k,int l,int r,int p,int v){
    if(l==r){
        minv[k]=v;
        return;
    }
    int m=(l+r)>>1;
    if(p<=m) update(k<<1,l,m,p,v);
    else update(k<<1|1,m+1,r,p,v);
    minv[k]=min(minv[k<<1],minv[k<<1|1]);
}
int query(int k,int l,int r,int pl,int pr){
    if(pl<=l&&r<=pr) return minv[k];
    int m=(l+r)>>1;
    int res=2147483647;
    if(pl<=m) res=min(res,query(k<<1,l,m,pl,pr));
    if(pr>m) res=min(res,query(k<<1|1,m+1,r,pl,pr));
    return res;
}
int main(){
    int n,q;
    cin>>n>>q;
    build(1,1,n);
    while(q--){
        int op,x,y;
        cin>>op>>x>>y;
        if(!op){
            update(1,1,n,++x,y);
        }
        else{
            if(x>y) swap(x,y);
            printf("%d\n",query(1,1,n,++x,++y));
        }
    }
    return 0;
}


Measured memory_bytes: 4168
n = int(input())

ans = [0 for _ in range(n+1)]
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            v = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if 1 <= v <= n:
                ans[v] += 1

for i in range(1, n+1):
    print(ans[i])

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

int findSumOfDiht(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int N,a,b;
    cin >> N >> a >> b;
    int total = 0;
    for(int i = 1;i <= N;++i){
        int sum = findSumOfDiht(i);
        if(a <= sum && sum <= b){
            total += i;
        }
    }
    cout << total<< endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int, input().split()))
minsa = 10 ** 16
#fu = 0
#sei = 0
for i in range(N-K+1):
    if x[i] <= 0 and x[i+K-1] <= 0:
        sa = -x[i]
        if minsa > sa:
            minsa = sa
            #fu = -x[i]
            #sei = 0
    if x[i] < 0 and x[i+K-1] > 0:
        sa = min(x[i + K-1], -x[i])*2 + max(x[i + K -1], -x[i])
        if minsa > sa:
            minsa = sa
            #fu = -x[i]
            #sei = x[i+K-1]
    if x[i] >= 0 and x[i+K-1] >= 0:
        sa = x[i+K-1]
        if minsa > sa:
            minsa = sa
            #fu = 0
            #sei = x[i+K-1]
print(minsa)
#print(fu)
#print(sei)
#print(min(fu,sei) * 2 + max(fu,sei))


Measured memory_bytes: 14780