akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <stack>
using namespace std;

int h, w, n;
int map[1000][1000];
int map_t[1000][1000];
int step;
vector<pair<int, int> > point;


bool SearchAndCollect(int goal)
{
	vector<pair<int, int> > point_t;
	for (int i = 0; i < point.size(); i++)
	{
		if (point[i].first > 0)
		{
			if (map_t[point[i].first - 1][point[i].second] == goal)
			{
				return true;
			}
			else if (map_t[point[i].first - 1][point[i].second] != -1)
			{
				map_t[point[i].first - 1][point[i].second] = -1;
				pair<int, int> temp;
				temp.first = point[i].first - 1;
				temp.second = point[i].second;
				point_t.push_back(temp);
			}
		}

		if (point[i].first < h - 1)
		{
			if (map_t[point[i].first + 1][point[i].second] == goal)
			{
				return true;
			}
			else if (map_t[point[i].first + 1][point[i].second] != -1)
			{
				map_t[point[i].first + 1][point[i].second] = -1;
				pair<int, int> temp;
				temp.first = point[i].first + 1;
				temp.second = point[i].second;
				point_t.push_back(temp);
			}
		}

		if (point[i].second > 0)
		{
			if (map_t[point[i].first][point[i].second - 1] == goal)
			{
				return true;
			}
			else if (map_t[point[i].first][point[i].second - 1] != -1)
			{
				map_t[point[i].first][point[i].second - 1] = -1;
				pair<int, int> temp;
				temp.first = point[i].first;
				temp.second = point[i].second - 1;
				point_t.push_back(temp);
			}
		}

		if (point[i].second < w - 1)
		{
			if (map_t[point[i].first][point[i].second + 1] == goal)
			{
				return true;
			}
			else if (map_t[point[i].first][point[i].second + 1] != -1)
			{
				map_t[point[i].first][point[i].second + 1] = -1;
				pair<int, int> temp;
				temp.first = point[i].first;
				temp.second = point[i].second + 1;
				point_t.push_back(temp);
			}
		}
	}
	point.clear();
	for (int i = 0; i < point_t.size(); i++)
	{
		if (point.size() <= i)
		{
			point.resize(point.size() + 1);
		}
		point[i] = point_t[i];
	}
	step++;
	return false;
}

int TimeFrom(int start)
{
	step = 1;
	int goal = start + 1;
	if (start == 10)
	{
		goal = 1;
	}

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			map_t[i][j] = map[i][j];
		}
	}

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (map[i][j] == start)
			{
				pair<int, int> temp;
				temp.first = i;
				temp.second = j;
				point.clear();
				point.push_back(temp);
				while (SearchAndCollect(goal) == false)
				{
				}
				return step;
			}
		}
	}
}

int main()
{
	string line;
	while (cin >> h >> w >> n)
	{
		for (int i = 0; i < h; i++)
		{
			cin >> line;
			for (int j = 0; j < w; j++)
			{
				switch (line[j])
				{
				case 'S':
					map[i][j] = 10;
					break;

				case '.':
					map[i][j] = 0;
					break;

				case 'X':
					map[i][j] = -1;
					break;

				default:
					map[i][j] = line[j] - '0';
					break;
				}
			}
		}

		int cnt = 0;
		for (int i = 0; i < n; i++)
		{
			if (i == 0)
			{
				cnt = cnt + TimeFrom(10);
			}
			else
			{
				cnt = cnt + TimeFrom(i);
			}
		}

		cout << cnt << endl;
	}


	return 0;
}

Measured memory_bytes: 9020
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}



int main() {
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll>a(n),b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    vector<ll>s(m+1);
    rep(i,m) s[i+1] = s[i] + b[i];
    ll ans = 0;
    for(ll i = 0;i<=n;i++) {
        if((i-1)>=0) k -= a[i-1];
        ll left = -1;
        ll right = s.size();
        while(abs(right-left) > 1) {
            ll mid = (right+left)/2;
            if(s[mid]<=k) left = mid;
            else right = mid;
        }
    
        if(k>=0)ans = max(ans,left+i);
    }
    cout << ans << endl;
}



Measured memory_bytes: 8008
import java.util.Scanner;

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

        sc.nextLine();
        String[] s = sc.nextLine().split(" ");
        boolean ok = true;
        for (String s1 : s) {
            int a = Integer.parseInt(s1);
            if(a % 2 == 0 ) {
                if (a % 3 == 0 || a % 5 == 0){
                    ok = true;
                } else {
                    ok = false;
                    break;
                }
            }
        }
        if (ok) {
            System.out.println("APPROVED");
        } else {
            System.out.println("DENIED");
        }
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using lb=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   ll a,b;
           cin>>a>>b;
           if(a*b<=0){
            cout<<"Zero"<<endl;
             return 0;
           }
           if(a>0||(b-a)%2==1){
             cout<<"Positive"<<endl;
           }
           else{
            cout<<"Negative"<<endl; 
           }
}

Measured memory_bytes: 3604
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = int64_t;
#define MAX_N 1010
#define MAX_M 100010
const long long mod = pow(10, 9) + 7;
#define vect vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vect) for(int aqw=0;aqw<vect.size();aqw++){cout<<vect[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INF 100100101001LL;
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 10010
#define PI 3.141592653589793
#define vecP vector<P>
//cout << setprecision(15) << std::fixed;


int main() {
	ll n;
	cin >> n;
	vecll A(n), B(n + 1, 0);
	for (int i = 0;i < n;i++) {
		cin >> A[i];
	}
	for (int i = 0;i < n;i++) {
		B[i + 1] = B[i] + A[i];
	}
	ll ans = INF;
	for (int i = 1;i < n;i++) {
		ans = min(ans, abs(B[i] - (B[n] - B[i])));
	}
	print(ans);
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;

vector<int> perfects = {1};

void getPerfects() {
    for (int i = 2; i < 33; i++) {
        int ii = i*i;
        while (ii <= 1000) {
            perfects.push_back(ii);
            ii *= i;
        }
    }
    sort(perfects.begin(),perfects.end());
}

int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    int X; cin >> X;
    getPerfects();
    auto it = upper_bound(perfects.begin(),perfects.end(),X);
    it--;
    cout << *it << '\n';

    return 0;
}


Measured memory_bytes: 256
K = int(input())

runrun = []
def check(N):
    global runrun
    n = str(N)
    runrun.append(int(n))
    if len(n) == 10:
        return 0
    if n[-1] == "9":
        check(int(n+"8"))
        check(int(n+"9"))
        return
    elif n[-1] == "0":
        check(int(n+"0"))
        check(int(n+"1"))
        return
    else:
        c = int(n[-1]) - 2
        for i in range(3):
            c += 1
            cc = str(c)
            check(int(n+cc))
        return

for i in range(1,10):
    check(i)

runrun.sort()
print(runrun[K-1])
        

Measured memory_bytes: 11336
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  int ans = 0;
  rep(i,n){
    if(a[a[i]-1] == i+1) ans++;
  }
  cout << ans/2 << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
    int a,b;
    cin >> a >> b;
    if(a > 8 || b > 8){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t; cin >> t;
  while(t--) {
    ll n, m, a, b;
    cin >> n >> m >> a >> b;
    cout << floor_sum(n, m, a, b) << endk;
  }
  return 0;
}


Measured memory_bytes: 3696
using System;

namespace KE
{
    class Prime
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var sum = 0;
            
            for(var i = 0; i < n; i++)
            {
                if(isPrime(int.Parse(Console.ReadLine())))
                {
                    sum++;
                }
            }
            Console.WriteLine(sum);
            
        }
        
        static bool isPrime(int x)
        {
            if(x == 2)
            {
                return true;
            }
            
            if (x < 2 || x % 2 == 0)
            {
                return false;
            }
            
            var index = 3;
            
            while(index <= Math.Sqrt(x))
            {
                if(x % index == 0)
                {
                    return false;
                }
                index = index + 2;
            }
            
            return true;
        }
    }
}


Measured memory_bytes: 17952
#include<iostream>
#include<queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N]; //距離で訪問状態(color)を管理する

void bfs(int s){
    queue<int> q; //標準ライブラリのqueueを使用
    q.push(s);
    for(int i=0; i<n; i++) d[i] = INFTY;
    d[s] = 0; //最初の距離をゼロに設定
    int u;
    while(!q.empty()){ //キューがある限りループ
        u = q.front(); q.pop(); //キューを取り出し、削除
        for(int v=0; v<n; v++){
            if(M[u][v] == 0) continue; //初項は飛ばす
            if(d[v] != INFTY) continue; //すでに距離が記録されたものは飛ばす
            d[v] = d[u] + 1; //距離をプラス１して代入
            q.push(v); //キューに追加
        }
    }
    for(int i=0; i<n; i++){
        cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
    }
}

int main(){
    int u, k, v;

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

    for(int i=0; i<n; i++){ //隣接リストから隣接行列へ変換
        cin >> u >> k;
        u--;
        for(int j=0; j<k; j++){
            cin >> v;
            v--;
            M[i][v] = 1;
        }
    }

    bfs(0);

    return 0;
}


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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"
#include "profile.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define profile(X) LOG_DURATION(X)
#else
#define debug(...) 42
#define profile(...) 42
#endif

using ll = int64_t;
using ld = double;
const ld EPS = 1e-9;
const int MOD = 1e9 + 7;
const ld PI = 3.141592653589793;
const int maxn = 600001;
using cd = complex<double>;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

int l[maxn];
int r[maxn];
int d[maxn];
int up[maxn];
int par[maxn];

pair<int, int> _find(int v) {
    if (v == par[v]) {
        return {v, 0};
    }
    auto x = _find(par[v]);
    par[v] = x.first;
    up[v] += x.second;
    return {par[v], up[v]};
}

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    profile("all");
    auto solve = [](int _) {
        int n, m;
        cin >> n >> m;
        for (int i = 1; i <= n; ++i) {
            par[i] = i;
        }
        for (int i = 1; i <= m; ++i) {
            cin >> l[i] >> r[i] >> d[i];
            auto root1 = _find(l[i]);
            auto root2 = _find(r[i]);
            if (root1.first == root2.first) {
                int dist_r = up[r[i]];
                int dist_l = up[l[i]];
                int exp = dist_r - dist_l;
                if (exp != d[i]) {
                    cout << "No";
                    return;
                }
            }
            par[root2.first] = root1.first;
            up[root2.first] = d[i] - up[r[i]] + up[l[i]];
        }
        cout << "Yes";
    };


    fast_io();

    cout.precision(9);
    cout <<
         fixed;
    for (int i = 1; i <= 1; ++i)
        solve(1);


}

Measured memory_bytes: 6684
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long

int main() {
	int arr[4][4];
	for (int i = 1; i <= 3; i++)
		for (int j = 1; j <= 3; j++)
			cin >> arr[i][j];
	if (arr[1][1] - arr[1][2] == arr[2][1] - arr[2][2]
			&& arr[3][1] - arr[3][2] == arr[2][1] - arr[2][2]
			&& arr[1][1] - arr[1][3] == arr[2][1] - arr[2][3]
			&& arr[3][1] - arr[3][3] == arr[2][1] - arr[2][3]
			&& arr[1][2] - arr[1][3] == arr[2][2] - arr[2][3]
			&& arr[3][2] - arr[3][3] == arr[2][2] - arr[2][3]) {
		cout << "Yes\n";
	} else
		cout << "No\n";
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int tmpMin = Integer.MAX_VALUE;
		int maxProfit = Integer.MIN_VALUE;
		
		int r1 = Integer.parseInt(sc.next());
		tmpMin = Math.min(tmpMin, r1);
		
		for(int i=1; i<n; i++) {
			int r = Integer.parseInt(sc.next());
			maxProfit = Math.max(maxProfit, r-tmpMin);
			tmpMin = Math.min(tmpMin, r);
		}
		System.out.println(maxProfit);
    }
}


Measured memory_bytes: 71060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> v(n+1,0);
  for(int i=1;i<=k;i++){
  	int d;
    cin>>d;
    for(int j=1;j<=d;j++){
      int temp;
      cin>>temp;
      v[temp]=1;
    }
  }
  int cnt=0;
  for(int i=1;i<=n;i++){
  	if(v[i]==0) cnt++;
  }
   cout<<cnt<<'\n';
}


Measured memory_bytes: 3640
# Fast IO (only use in integer input)

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def main():

    N = int(input())
    Resident = []
    for i in range(N):
        x,y,p = map(int,input().split())
        Resident.append((x,y,p))

    minCost = [float("inf")] * (N+1)

    preCalRange = 1 << N

    horizontalLineDistance = []
    verticalLineDistance = []

    for i in range(preCalRange):
        railRoad = bin(i)[2:]
        railRoad = '0' * (N - len(railRoad)) + railRoad
        horizontalLineDistance.append([])
        verticalLineDistance.append([])
        goodList1 = horizontalLineDistance[i]
        goodList2 = verticalLineDistance[i]
        for j in range(N):
            goodList1.append(min(abs(Resident[j][0]),abs(Resident[j][1])))
            goodList2.append(min(abs(Resident[j][0]),abs(Resident[j][1])))
            for k in range(N):
                if railRoad[k] == '1' and abs(Resident[j][0] - Resident[k][0]) < goodList1[j]:
                    goodList1[j] = abs(Resident[j][0] - Resident[k][0])
                if railRoad[k] == '1' and abs(Resident[j][1] - Resident[k][1]) < goodList2[j]:
                    goodList2[j] = abs(Resident[j][1] - Resident[k][1])

    loopCount = 1 << N
    for i in range(loopCount):
        numNewRailroad = bin(i)[2:].count('1')
        j = i
        while j >= 0:
            j &= i
            goodList1 = horizontalLineDistance[j]
            goodList2 = verticalLineDistance[i - j]
            cost = 0
            for k in range(N):
                cost += Resident[k][2] * min(goodList1[k], goodList2[k])
            if minCost[numNewRailroad] > cost:
                minCost[numNewRailroad] = cost
            j -= 1
    for elem in minCost:
        print(elem)

main()

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
void debug(vector<T> &vec) {
    for (auto x : vec) {
        cout << x << " ";
    }
    cout << endl;
    return;
}

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

int main() {
    int N, W, H;
    cin >> N >> W >> H;
    vector<int> coveredY(H + 1, 0), coveredX(W + 1, 0);
    auto solve = [&](vector<int> vec) {
        for (int i = 0; i < vec.size() - 1; i++) {
            vec[i + 1] += vec[i];
            if (vec[i] > 0) continue;
            return false;
        }
        return true;
    };

    REP(i, N) {
        int x, y, r;
        cin >> x >> y >> r;
        coveredY[max(0, y - r)] += 1;
        coveredY[min(W, y + r)] -= 1;
        coveredX[max(0, x - r)] += 1;
        coveredX[min(H, x + r)] -= 1;
    }

    if (solve(coveredX) || solve(coveredY)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 4468
/* in the name of allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 100 + 5, W = 1e5 + 5;
long long n, w, a[N], v[N], dp[N][W];

void readInput() {
	cin >> n >> w;
	for (int i = 1; i <= n; i++)
		cin >> a[i] >> v[i];
}

void solve() {
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= w; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j >= a[i] && dp[i][j] < dp[i - 1][j - a[i]] + v[i])
				dp[i][j] = dp[i - 1][j - a[i]] + v[i];
		}
	cout << dp[n][w] << endl;
}


int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve();
	return 0;

}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int R; cin >> R;

    string res = "AGC";
    if(R < 1200){
        res = "ABC";
    }
    else if(R < 2800){
        res = "ARC";
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
use itertools::interleave;
use proconio::input;
use std::io::Write;

pub trait Echo {
    fn echo(&self);
    fn echo_b(&self, out: &mut std::io::Stdout) -> Result<(), std::io::Error>;
}

macro_rules! impl_echo {
    ($($t:ty),*) => {
        $(
            impl Echo for $t {
                fn echo(&self){
                    self.echo_b(&mut std::io::stdout()).unwrap();
                }

                fn echo_b(&self, out: &mut std::io::Stdout) -> Result<(), std::io::Error>{
                    writeln!(out,"{}", &self)?;
                    Ok(())
                }
            }
        )*
    };
}

macro_rules! impl_echo_f {
    ($($t:ty),*) => {
        $(
            impl Echo for $t {
                fn echo(&self){
                    self.echo_b(&mut std::io::stdout()).unwrap();
                }

                fn echo_b(&self, out: &mut std::io::Stdout) -> Result<(), std::io::Error>{
                    writeln!(out,"{:.12}", &self)?;
                    Ok(())
                }
            }
        )*
    };
}

impl_echo!(u8, u16, u32, u64, u128, usize);
impl_echo!(i8, i16, i32, i64, i128, isize);
impl_echo!(&str, String, char);
impl_echo_f!(f32, f64);

impl<T: Echo> Echo for Vec<T> {
    fn echo(&self) {
        self.echo_b(&mut std::io::stdout()).unwrap();
    }
    fn echo_b(&self, out: &mut std::io::Stdout) -> Result<(), std::io::Error> {
        for i in self {
            i.echo_b(out).unwrap();
        }
        Ok(())
    }
}

fn main() {
    input! {
        n: isize,
    };
    let res = if n < 30 { false } else { true };
    yn(res);
}

#[allow(dead_code)]
fn yn(i: bool) {
    if i {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define pb push_back
ll n,m;
string a[505];
ll dp[505][505][2];
bool ok(ll x, ll y)
{
        if(x<0 || x >= n || y <0 || y >= m) return false;
        return true;
}
ll blk, wh;
bool vis[505][505];
ll dx[4] = {0,0,1,-1};
ll dy[4] = {-1,1,0,0};
void bfs(ll x,ll y)
{
        blk=0;
        wh=0;
        queue<ll> q;
        q.push(x); q.push(y);
        vis[x][y]=true;
        blk++;
        while(q.empty()== false) {

                ll X = q.front(); q.pop();
                ll Y = q.front(); q.pop();
                for(ll i=0;i<4;i++) {
                        ll xx = X + dx[i];
                        ll yy = Y + dy[i];
                        if(ok(xx,yy) && !vis[xx][yy] && a[xx][yy] != a[X][Y]) {
                                if(a[xx][yy] == '#') blk++;
                                else wh++;
                                vis[xx][yy]=true;
                                q.push(xx); q.push(yy);
                        }
                }
        }
}
int main()
{
        cin >> n >>m;
        for(ll i=0;i<n;i++) {
                cin >> a[i];
        }
        ll ans = 0;
        memset(dp,-1,sizeof dp);
        //cout << solve(0,1,1) << endl; return 0;
        for(ll i=0;i<n;i++) {
                for(ll j=0;j<m;j++) {
                        //if(a[i][j] == '#')
                        if(!vis[i][j] && a[i][j] == '#') {bfs(i,j);
                        //cout << i << " " << j <<
                        ans += blk*wh;
                        }
                }
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 4608
#include <iostream>

using namespace std;

int main(void){
  int n;
  cin >> n;
  
  long long a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }

  long long max, min;
  max = 0;
  min = 1000000001LL;
  for(int i=0; i<n; i++){
    if(a[i] > max){
      max = a[i];
    }
    if(a[i] < min){
      min = a[i];
    }
  }

  cout << max-min << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;

    int dx=x2-x1,dy=y2-y1;
    REP(i,2){
        swap(dx,dy); dx*=-1;
        x2+=dx; y2+=dy;
        cout<<x2<<' '<<y2<<' ';
    }
    cout<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,l,m,k,total,h,w,n,xmax,ymax,x,y,st,ed;
    	cin>>n>>m;
    	if(n==m)
    	cout<<"Yes";
    	else
    	cout<<"No";
    } 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Vsort(a) sort(a.begin(), a.end())
using namespace std;

int main () {
  
  int n, x, t, count;
  cin >> n >> x >> t;
  
  count = 0;
  
  if (n % x == 0){
    count = n / x;    
  }else{
    n = n - (n % x);
    n = n + x;
    count = n / x;
  }
  
  cout << count * t;
  
  return 0 ;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

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

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


int main() {
    int a,b;cin >> a >> b;
    cout << a-b+1;
    
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
N,K = map(int,input().split())
edges = [[] for _ in range(N)]
used = [False]*N
mod = 10**9+7
for _ in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
def f(n,c):
    sm = 1
    t = K-c
    for m in edges[n]:
        if not used[m]:
            used[m] = True
            if t <= 0:
                print(0)
                exit(0)
            sm = (sm*f(m,2)*t) % mod
            t -= 1
    return sm
used[0] = True
print(K*f(0,1) % mod)

Measured memory_bytes: 93304
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cmath>
#include<sstream>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<utility>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<list>
#include<set>
#include<stdlib.h>
#include<time.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
struct XY
{
	int x;
	int y;
};
vector<long long> Prime;
void SieveOfEratosthenes(long long e) //setup vector<long long>Prime(~x)
{
	bool *x=new bool[e];
	for (long long i = 0; i <= e; i++)x[i] = false;
	for (long long i = 2; i <= e; i++)
	{
		if (x[i]);
		else
		{
			Prime.push_back(i);
			for (long long l = i; l <= e; l += i)x[l] = true;
		}
	}
	return;
}
int StringToInt(string a)
{
	stringstream ss;
	int x;
	ss << a;
	ss >> x;
	return x;
}
string IntToString(int a)
{
	stringstream ss;
	string x;
	ss << a;
	ss >> x;
	return x;
}
int GetRandom(int MIN, int MAX)
{
	static int flag=0;
	if (flag == 0)
	{
		srand((unsigned int)time(NULL));
		flag = 1;
	}
	return MIN + (int)(rand()*(MAX - MIN + 1.0) / (1.0 + RAND_MAX));
}
int in()
{
	int x;
	cin >> x;
	return x;
}
void outl(string a)
{
	cout << a << endl;
	return;
}
void outl(int a)
{
	cout << a << endl;
	return;
}
void out(string a)
{
	cout << a;
	return;
}
void out(int a)
{
	cout << a;
	return;
}
/*
(char)'1' - (int)48 = (int)1;
???1111181
 (char)A=(int)65
 (char)a=(int)97
*/
////////////////////////////////////////////////////

int main()
{
	while (1)
	{
		vector<pair<int, string > > a;
		pair<int, string> z;
		z.first = 0;
		z.second = "A";
		for (int i = 0; i < 5; i++)
		{
			a.push_back(z);
			z.second='B'+i;
		}
		bool end = false;
		for (int i = 0; i < 5; i++)
		{
			int x = in() + in();
			if (i == 0 && x == 0)
			{
				end = true;
				break;
			}
			a[i].first += x;
		}
		if (end)break;
		sort(a.begin(), a.end());
		cout << a[4].second << " " << a[4].first << endl;

	}

}

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

typedef long long ll;

const ll INF = 1e15;

int n,k;
int li[305];

ll memo[305][305][305];

ll dp(int id, int bef, int sisa){
	if(sisa < 0) return INF;
	if(id > n) return 0;
	ll &ret = memo[id][bef][sisa];
	if(ret != -1) return ret;
	ret = min(dp(id+1,bef,sisa-1),dp(id+1,id,sisa) + max(0,li[id] - li[bef]));
	return ret;
}

int main(){
	memset(memo,-1,sizeof(memo));
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&li[i]);
	ll ans = dp(1,0,k);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 221952
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
	int d,r;
	double a,b,f,w;
	f=0.0;
	a=0.0;
	b=0.0;
	w=0.00000;
	cin>>a>>b;
	d=a/b;
	r=(int)a%(int)b;
	f=(double)a/(double)b;

	cout<<d<<' '<<r<<' '<<fixed<<setprecision(5)<<f<<endl;
	
}


Measured memory_bytes: 3268
#include <iostream>
using namespace std;
int main(void){
   int S,h,m,s;
   cin>>S;
   h=S/3600;
   m=(S%3600)/60;
   s=(S%3600)%60;

   cout<<h;
   cout<<":";
   cout<<m;
   cout<<":";
   cout<<s;
   cout<<endl;


}


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

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  cin >> n;

  vector<int> v(n);
  REP(i,n){
    cin >> v[i];
  }

  int ans = 0;
  int l = 0, r = 1;
  while(true){
    if(r >= n){
      ans = max(ans, r - l - 1);
      break;
    }

    if(v[r-1] >= v[r]){
      r++;
    }else{
      ans = max(ans, r - l - 1);
      l = r;
      r++;
    }

  }
  cout << ans << endl;

  return 0;
}



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

using namespace std;

const int inf = 1e9;
int n,k,s;

int main()
{
	cin>>n>>k>>s;
	for(int i = 1; i <= k; i ++) cout<<s<<" ";
	if(s < inf) {
		for(int i = k + 1; i <= n; i ++) cout<<inf<<" ";
	}
	else for(int i = k + 1; i <= n; i ++) cout<<1<<" ";
	putchar(10);
	return 0;
}

Measured memory_bytes: 1280
import sys
sys.setrecursionlimit(10**7)
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 sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

from functools import lru_cache

def main(): 
    s = SI()
    if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
        print('Bad')
    else: print('Good')
      
main()

Measured memory_bytes: 3700
import 'dart:io';

void main() {
  List<String> NandK = stdin.readLineSync().split(' ');
  List<int> P =
      stdin.readLineSync().split(' ').map((x) => int.parse(x)).toList();
  int K = int.parse(NandK[1]);
  int ans = 0;
  P.sort();
  for (int i = 0; i < K; i++) {
  ans += P[i];
  }
  print(ans);
}

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

int calc_squared_dist(vector<int> y, vector<int> z)
{
    int sum = 0;
    assert(y.size() == z.size());
    for (int i = 0; i < y.size(); i++)
    {
        sum += (y[i] - z[i]) * (y[i] - z[i]);
    }
    return sum;
}

int main()
{
    int N, D;
    cin >> N >> D;

    vector<vector<int>> X(N, vector<int>(D));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < D; j++)
        {
            cin >> X[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            int squared_dist = calc_squared_dist(X[i], X[j]);
            int dist = 0;
            while (dist * dist <= squared_dist)
            {
                if (dist * dist == squared_dist)
                {
                    ans++;
                }
                dist++;
            }
        }
    }
    cout << ans << endl;
}


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

int main() {
  int n;
  cin>>n;
  vector<long long int> vec(n+1);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  long long int a=1,b=0,c=0,d=0;
  
  for(int i=0;i<n;i++){
    if(vec.at(i)==vec.at(i+1)){
      a++;
    }
    if(vec.at(i)!=vec.at(i+1)){
      if(a>3&&d==0){
        b=vec.at(i);
        c=vec.at(i);
        break;
      }
      if(a>1&&d==0){
        b=vec.at(i);
        d++;
      }
      else if(a>1&&d==1){
        c=vec.at(i);
        break;
      }
      a=1;
    }
  }
  cout<<b*c<<endl;
}

Measured memory_bytes: 1024
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt
  val a = StdIn.readLine().split(" ").map(_.toLong)

  println(a.max - a.min)
  /* NG
  val r = a.foldLeft((1L, 1L)){ (acc, ai) =>
    val min = scala.math.min(acc._1, ai)
    val max = scala.math.max(acc._2, ai)
    (min, max)
  }
  */
}

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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<int> sg;
    sg.push_back(1);
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i-1]) {
            sg[sg.size()-1]++;
        } else {
            sg.push_back(1);
        }
    }

    if (s[0] == '0') {
        sg.insert(sg.begin(), 0);
    }
    if (s[n-1] == '0') {
        sg.push_back(0);
    }

    int ps[sg.size()+1];
    ps[0] = 0;
    for (int i = 1; i <= sg.size(); i++) {
        ps[i] = ps[i-1] + sg[i-1];
    }

    int ans = 0;
    if (2 * k + 1 > sg.size()) {
        ans = n;
    } else {
        for (int i = 0; i + 2 * k + 1 <= sg.size(); i += 2) {
            ans = max(ans, ps[i+2*k+1] - ps[i]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1272
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

		while(sc.hasNext()) {

			int m = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();

			if(m == -1 && f == -1 && r == -1) {
			//	System.out.println("??????????????????");
				break;
			}

			if(m == -1 || f == -1) {
				list.add("F");
			}
			else if(80 <= m + f) {
				list.add("A");
			}
			else if(65 <= m + f && m + f  < 80) {
				list.add("B");
			}
			else if(50 <= m + f && m + f  < 65) {
				list.add("C");
			}
			else if(30 <= m + f && m + f  < 50) {
				if(50 <= r) {
					list.add("C");
				}
				else {
					list.add("D");
				}
			}
			else if(m + f < 30) {
				list.add("F");
			}
		}

		for(String s : list) {
			System.out.println(s);
		}
	}
}

Measured memory_bytes: 26148
#include <bits/stdc++.h>
using namespace std;
# define ll  long long  int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;  
  
    while (y > 0) 
    { 
      
        if (y & 1) 
            res = (res*x) % p; 
  
      
        y = y>>1;
        x = (x*x) % p;   
    } 
    return res; 
} 
bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{ 
       return (a.first > b.first); 
}
typedef pair<int,int> ii;
// bool cmp(ii a,ii b)
// {
// 	if(a.ff==b.ff)
// 	{
// 		return a.ss>b.ss;
// 	}
// 	else
// 		a.ff<b.ff;
// }
   ll dp[27][200004]={0};
   bool visit[100000]={0};
int  main()
{
//    #ifndef ONLINE_JUDGE
//    freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
//    #endif
   IOS;
 	ll a,b;
 	cin>>a>>b;
 	ll r=__gcd(a,b);
 	ll p=a*b;
 	ll e=p/r;
 	cout<<e;
}


Measured memory_bytes: 256
from sys import stdin
input = stdin.readline

n, m = map(int,input().split())
from1 = [0]*(n+1)
ton = [0]*(n+1)
for i in range(m):
    a, b = map(int,input().split())
    if a == 1: from1[b] = 1
    if b == n: ton[a] = 1
for i in range(n+1):
    if from1[i] and ton[i]:
        print("POSSIBLE")
        break
else: print("IMPOSSIBLE")

Measured memory_bytes: 6132
N = int(input())
A = list(map(int,input().split()))
total = 0
X = [0]*N
flag = False
subcount = 0

for i in range(N):
    if A[i] == 0:
        flag = True
    elif A[i] < 0:
        subcount += 1
    X[i] = abs(A[i])
    total += X[i]

if flag or (subcount % 2 == 0):
    print(total)
else:
    print(total-2*min(X))


Measured memory_bytes: 14332
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define All(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef double db;
typedef vector<int> VI;
typedef pair<int,int> PII;
const db PI=acos(-1.0);
const db eps=1e-6;
const ll mod=1e9+7;
const int inf=2147483647;
const int maxn=100005;
ll qpow(ll x,ll y) {ll ans=1,base=x; while(y){if(y&1)ans=(ans*base)%mod;base=(base*base)%mod;y>>=1;} return ans;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

int n;
ll dp[2005][2005];
struct node{
	int id,val;
}a[2005];
bool cmp(node x1,node x2){
	return x1.val<x2.val;
}
int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i].val),a[i].id=i;
	sort(a+1,a+1+n,cmp);
	rep(i,1,n) dp[i][i]=1ll*a[1].val*abs(a[1].id-i);
	rep(len,2,n){
		for(int i=1,j=i+len-1;j<=n;i++,j=i+len-1){
			dp[i][j]=max(dp[i+1][j]+1ll*a[len].val*abs(a[len].id-i),dp[i][j-1]+1ll*a[len].val*abs(a[len].id-j));
		}
	}
	printf("%lld\n",dp[1][n]);
	return 0;
}

Measured memory_bytes: 25880
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll n; cin >> n;
    vector<ll> a(n+1);
    a[0] = 0;
    for(ll i=1;i<n+1;i++){
        cin >> a[i];
    }

    vector<ll> ans(n+1);
    ans[0] = 0;

    if(n%2 == 0){
        ll idx = n;
        for(ll i=1;i<=n/2;i++){
            ans[i] = a[idx];
            idx -= 2;
        }
        idx = 1;
        for(ll i=n/2+1;i<=n;i++){
            ans[i] = a[idx];
            idx += 2;
        }
    }

    if(n%2 == 1){
        ll idx = n;
        for(ll i=1;i<=n/2+1;i++){
            ans[i] = a[idx];
            idx -= 2;
        }
        idx = 2;
        for(ll i=n/2+2;i<=n;i++){
            ans[i] = a[idx];
            idx += 2;
        }
    }


    for(ll i=1;i<=n;i++) cout << ans[i] << " ";
    cout << endl;
    return 0;
}



Measured memory_bytes: 5376
#include <iostream>
#include <cstring>
#include <queue>
#include <utility>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
const int INF = 1<<25;
int main(){
	int c, n, m, s, d, a, b, f;
	
	while(cin >> c >> n >> m >> s >> d && (c || m || n || s || d)) {
		s--, d--;
		int cost[110][110] = {}, ret[11][110];
		rep(i,m) {
			cin >> a >> b >> f;
			a--, b--;
			cost[a][b] = cost[b][a] = f;
		}
		rep(i,c+1) {
			rep(j,n) { 
				ret[i][j] = INF;
			}
		}
		queue<pair<int, int> > q;
		q.push(make_pair(c,s));
		ret[c][s] = 0;
		while(!q.empty()) {
			int node = q.front().second, nc = q.front().first; q.pop();
			rep(i,n) {
				if(cost[node][i]) {
					if(ret[nc][i] > ret[nc][node] + cost[node][i]) {
						ret[nc][i] = ret[nc][node] + cost[node][i];
						q.push(make_pair(nc, i));
					}
					if(nc>0 && ret[nc - 1][i] > ret[nc][node] + cost[node][i] / 2) {
						 ret[nc - 1][i] = ret[nc][node] + cost[node][i] / 2;
						 q.push(make_pair(nc-1, i));
					}
				}
			}	
		}
		int res = INF;
		rep(i,c+1) {
			res = min(res,ret[i][d]);
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1280
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    int n = scan!int, m = scan!int;
    long[] as = scan!long(n);
    auto uf = new UnionFind(n);
    foreach(_; 0 .. m){
        int x = scan!int, y = scan!int;
        uf.unite(x, y);
    }

    int treecnt;
    foreach(i; 0 .. n) if(uf.find(i) == i) treecnt += 1;

    // 無理な場合は抜ける
    if((treecnt - 1) * 2 > n){
        "Impossible".print;
        return;
    }

    // 何もしなくてよい場合も抜ける
    if(treecnt == 1){
        "0".print;
        return;
    }


    // 各Union内での最小コストの点は採用される
    // それ以外は、全Unionを通じて小さいものから採用される
    S[] vs = new S[](n);
    foreach(i; 0 .. n){
        int r = uf.find(i);
        if(as[i] < vs[r].value) vs[r] = S(as[i], i);
    }

    long ans;
    int cnt;
    foreach(v; vs){
        if(v.value == infty) continue;
        ans += v.value;
        as[v.id] = infty;
        cnt += 1;
    }

    as.sort();
    foreach(i; 0 .. treecnt - 2) ans += as[i];

    ans.print;
}

const long infty = 1_000_000_999;
struct S{
    long value = infty;
    int id = -1;
}


class UnionFind{
    int[] rootOf;
    int[][] kidsOf;
    this(int n){
        rootOf = new int[](n);
        kidsOf = new int[][](n);
        foreach(i; 0 .. n) rootOf[i] = i, kidsOf[i] = [i];
    }
    void unite(int a, int b){
        log("a:", a, "b:", b);
        int ra = rootOf[a], rb = rootOf[b];
        if(ra == rb) return;
        if(kidsOf[ra].length < kidsOf[rb].length) unite(b, a);
        else foreach(k; kidsOf[rb]) rootOf[k] = ra, kidsOf[ra] ~= k;
    }
    int find(int a){
        return rootOf[a];
    }
    int getSize(int a){
        return kidsOf[rootOf[a]].length.to!int;
    }
}

Measured memory_bytes: 21032