akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    S = input()
    N = len(S)

    if S != S[::-1]:
        return False

    t = S[:(N - 1) // 2]
    if t != t[::-1]:
        return False

    t = S[(N + 3) // 2 - 1:]
    if t != t[::-1]:
        return False

    return True


def main():
    if solve():
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9868
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;class Program
{
	static void Main(string[] args)
	{
        //var exStdIn = new System.IO.StreamReader( "stdin.txt" );System.Console.SetIn( exStdIn );
		const long inf = 100000000000000;
		
		var nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
		long n = nk[0];
		var p = Console.ReadLine().Split().Select(long.Parse).ToArray();
		for (int i = 0; i < n; i++)
		{
			p[i]--;
		}
		var c = Console.ReadLine().Split().Select(long.Parse).ToArray();
		
		long finalAns = -inf;
		for (int s = 0; s < n; s++)
		{

			long mx = -inf;
			long k = nk[1];
			long sm = 0;
			long now = s;
			long cnt = 0;
			do{
				now = p[now];
				sm+=c[now];
				cnt++;
			}while(now!=s);

			long ans = 0;
			if(sm>=0){
				if(k/cnt>1){
					mx = 0;
					ans+=sm*(k/cnt-1);
					k%=cnt;
					k+=cnt;
				}
			}else{
				k = Min(k, cnt+1);
			}

			now = s;
			long tmp = 0;
			for (int j = 0; j < k; j++)
			{
				now = p[now];
				tmp+=c[now];
				if(tmp>mx){
					mx = tmp;
				}
			}
			ans+=mx;
			if(ans>finalAns)finalAns = ans;
		}
		Console.WriteLine(finalAns);
	}
}


Measured memory_bytes: 29412
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);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();

		List<Integer> a = new ArrayList<>();
		int current = 1;
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (s.charAt(i) == '0' + current) count++;
			else {
				current = 1 - current;
				a.add(count);
				count = 1;
			}
		}

		a.add(count);
		if (a.size() % 2 == 0) a.add(0);

		int[] sum = new int[a.size() + 1];
		for (int i = 1; i < a.size() + 1; i++) {
			sum[i] = sum[i - 1] + a.get(i - 1);
		}

		int answer = 0;
		for (int i = 0; i < a.size(); i += 2) {
			int l = i;
			int r = Math.min(l + 2 * k + 1, a.size());
			answer = Math.max(answer, sum[r] - sum[l]);
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 26308
#include<bits/stdc++.h>
using namespace std;
int n,m;
char ch[200][200];
string st;
int main()
{
	cin>>n>>m;
	getline(cin,st);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)ch[i][j]=getchar();
		getline(cin,st);
	}
	for(int i=1;i<=2*n;i++)
	{
		for(int j=1;j<=m;j++)putchar(ch[(i+1)/2][j]);
		cout<<endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#define __mode_debug__
/*   ξ
     ll
   ＿ll＿
 ／  ∞  ＼
│*  Ａ  *│
│*  Ｃ  *│
│*  祈  *│
│*  願  *│
│*      *│
 ￣￣￣￣￣    */
//C++14 (GCC 5.4.1)
#include <bits/stdc++.h>
using namespace std;
#ifdef __mode_debug__
    #define DBG
#else
    #define DBG if(false)
#endif

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)

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

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

//DUMP
//  ostream vector<T> , vector<vector<T>> , set<T> ,queue<T> , priority_queue<T> , pair<T,U> , map<T,U>
template<class T> ostream& operator<<(ostream&os,vector<T>&vec){os<<"{ ";rep(i,vec.size()) os<<((i==0)?"":", ")<<i<<":"<<vec[i];os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,vector<vector<T>>&vec){os<<"{"<<endl;rep(i,vec.size())os<<"\t   "<<i<<":"<<vec[i]<<((i==vec.size()-1)? "":",")<<endl;os<<"\t }";return os;}
template<class T> ostream& operator<<(ostream&os,set<T>&p){os<<"{ ";repi(itr,p)  os<<((itr==p.begin())?"":", ")<<*itr;os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,queue<T>&p){queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.front();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T> ostream& operator<<(ostream&os,priority_queue<T>&p){priority_queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.top();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T,class U> ostream& operator<<(ostream&os,pair<T,U>&p){os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T,class U> ostream& operator<<(ostream&os,map<T,U>&p){os<<"{ ";repi(itr,p)os<<((itr==p.begin())?"":", ")<<itr->first<<":"<<itr->second;os<<" }";return os;}
void dump_f(string &nm,char t){cerr<<endl;}
template<class T,class... Ts> void dump_f(string &nm,char t,T &&x,Ts&&... ts){int l=nm.find_first_of(',');string name(nm,0,l),nx(nm,l+1,-1);if(t=='\n') cerr<<"  "<<name<<"\t: "<<x<<t;else cerr << name<<": "<<x<<","<<t;dump_f(nx,t,forward<Ts>(ts)...);}
template<class... Ts> void dump_m(int &&ln,string &&nm,char t,Ts&&... ts){cerr<<"[ln: "<<ln<<"]"<<t;dump_f(nm,t,forward<Ts>(ts)...);}
#define dump(...) DBG dump_m(__LINE__,#__VA_ARGS__,'\n',__VA_ARGS__)
#define dl(...) DBG dump_m(__LINE__,#__VA_ARGS__,'\t',__VA_ARGS__)

#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(V.begin(),V.end(),c))


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

    cout << (char)(C+1) <<endl;
    return (0);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
 size_t strlen(const char *s);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::vector<int> graph[10050];//graph頂点数のsize
const int N=100010;
const int P=1000000007;
long long int compare_int(const void *a, const void *b)
{
    return *(long long int*)a - *(long long int*)b;//a-b昇順
}
//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ
//	cout<<(n-2)*180<<endl;
//	string s="hoge";
//	cout<<ans<<endl;
//	int  n  ,a  ,b  ,c  ,d  ,e  ,f  ;
//	cin  >>n  >>a  >>b  >>c  >>d  >>e  >>f  ;

/*
	memset(b, '\0', sizeof(b));
初期化*/


/*
	len = strlen(s);
文字列長さ*/


/*
	string s;
	s.size()
*/


/*ソート
	qsort(b, 10, sizeof(int), compare_int);
*/


/*
	char s[N];
	strlen(s)
/*
	if(  <  )puts("Yes");
	else puts("No");
*/
/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/
double to_deg(double r) {
    return r * 180.0 / (atan(1.0) * 4.0);
}

int main(){
	double a, b, x,kaku;
	cin>>a>>b>>x;
	if(a*a*b*0.5>x){
		kaku=b*b*a/(x*2);
	}
	else{
		kaku=(a*a*b-x)*2/(a*a*a);
	}
	printf("%.10f\n",to_deg(atan(kaku)));
//	cout<<to_deg(atan(kaku))<<endl;

}

Measured memory_bytes: 512
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
p = inpl()
q = inpl()
p = tuple(p)
q = tuple(q)

a = 0
b = 0
for i,num in enumerate(itertools.permutations(range(1,n+1))):
    if p == num:
        a = i+1
    if q == num:
        b = i+1
print(abs(a-b))

Measured memory_bytes: 66156
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	int n; cin >> n;
	int ans;
	if(n % 2 == 0) ans = n/2;
	else ans = n/2+1;
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

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

    int sum = 0, ab = abs(L), del = L;
    for (int i = 0 ; i < N ; i++)
    {
        sum += L + i;
        if (ab > abs(L + i)) {
            ab = abs(L + i);
            del = L + i;
        }
    }
    cout<<(del > 0 ? sum - del : sum - del)<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var A = ReadLongs();
            var sum = 0D;
            foreach (var a in A)
            {
                sum += 1D / a;
            }
            return 1D / sum;
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  vector<ll> cnt(n, 0);
  REP(i, n) {
    ll a;
    cin >> a;
    a--;
    cnt[a]++;
  }
  // s[x] = \sum_{i=0}^{n-1} min(cnt[i],x)
  vector<ll> s(n + 1, 0);
  // s[x+1] = s[x] + (x<cnt[p]を満たすpの個数)
  sort(ALL(cnt));
  REP(x, n) {
    auto it = lower_bound(ALL(cnt), x + 1);
    ll diff = cnt.end() - it;
    s[x + 1] = s[x] + diff;
  }
  FOR(t, 1, n + 1) {
    ll ok = 0, ng = n + 1;
    while (ok + 1 < ng) {
      ll x = (ok + ng) / 2;
      if (t * x <= s[x])
        ok = x;
      else
        ng = x;
    }
    cout << ok << endl;
  }
}

Measured memory_bytes: 5504
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];


int main(){
    int N, M;
    cin >> N >>M;
    if(N ==M)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

struct Node {
    int id;
    int parent;
    int left;
    int right;
};

static int FindRoot(const struct Node nodes[], int n) {
    int i;

    for ( i = 0; i < n; i++ ) {
        if ( nodes[i].parent == -1 ) {
            return i;
        }
    }

    return -1;
}

static void WalkPreorder(int root, const struct Node nodes[]) {

    printf(" %d", nodes[root].id);
    if ( nodes[root].left != -1 ) {
        WalkPreorder(nodes[root].left, nodes);
    }
    if ( nodes[root].right != -1 ) {
        WalkPreorder(nodes[root].right, nodes);
    }

    return;
}

static void WalkInorder(int root, const struct Node nodes[]) {

    if ( nodes[root].left != -1 ) {
        WalkInorder(nodes[root].left, nodes);
    }
    printf(" %d", nodes[root].id);
    if ( nodes[root].right != -1 ) {
        WalkInorder(nodes[root].right, nodes);
    }

    return;
}

static void WalkPostorder(int root, const struct Node nodes[]) {

    if ( nodes[root].left != -1 ) {
        WalkPostorder(nodes[root].left, nodes);
    }
    if ( nodes[root].right != -1 ) {
        WalkPostorder(nodes[root].right, nodes);
    }
    printf(" %d", nodes[root].id);

    return;
}

int main(void) {
    int n, i;
    struct Node* nodes;

    scanf("%d\n", &n);
    nodes = malloc(sizeof(struct Node) * n);
    for ( i = 0; i < n; i++ ) {
        nodes[i].parent = -1;
    }

    for ( i = 0; i < n; i++ ) {
        int id, left, right;
        scanf("%d %d %d\n", &id, &left, &right);

        nodes[id].id = id;
        nodes[id].left = left;
        nodes[id].right = right;

        if ( left != -1 ) {
            nodes[left].parent = id;
        }
        if ( right != -1 ) {
            nodes[right].parent = id;
        }
    }

    int root = FindRoot(nodes, n);
    printf("Preorder\n");
    WalkPreorder(root, nodes);
    printf("\n");

    printf("Inorder\n");    
    WalkInorder(root, nodes);
    printf("\n");

    printf("Postorder\n");
    WalkPostorder(root, nodes);
    printf("\n");
    
    free(nodes);

    return 0;
}



Measured memory_bytes: 2144
S = input()

ans = 0
for i in range(len(S)):
    for j in range(i, len(S)):
        sub_s = S[i:j+1]
        is_acgt = True
        for s in sub_s:
            if s == "A" or s == "C" or s == "G" or s == "T":
                continue
            else:
                is_acgt = False
        if is_acgt:
            ans = max(ans, len(sub_s))

print(ans)


Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;

int i = 1;
while(1) {
int x = i;

if(x % 3 == 0){
cout<<" "<<i;
}
else {
while(1){
if(x % 10 == 3){
cout<<" "<<i;
break;
}
x /= 10;
if(x == 0) break;
}
}

if(++i > n) break;
}
cout<<endl;

return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>
long long int sgn(long long int a) {
    return a >= 0 ? 1 : -1;
}
int main(void) {
    long long int a, b;
    scanf("%lld%lld", &a, &b);
    if(a == 0 || b == 0 || sgn(a) != sgn(b))
        puts("Zero");
    else if(sgn(a) == 1)
        puts("Positive");
    else if(a == b)
        puts("Negative");
    else
        puts((b - a) % 2 ? "Positive" : "Negative");
    return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#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 sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,x;cin>>n>>x;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll res=max((ll)0,a[0]-x);
    a[0]-=res;
    rep(i,n){
        if(i==0)continue;
        ll buf=max((ll)0,(a[i]+a[i-1]-x));
        res+=buf;
        a[i]-=buf;
    }
    cout<<res<<endl;
}


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

using namespace std;
int main(){
  ll n,k;
  std::cin >> n>>k;
  std::vector<ll> arr(100001,0);
  rep(i,n){
    int a,b;
    std::cin >> a>>b;
    arr[a]+=b;
  }

  ll now=0;
  rep(i,100001){
    now+=arr[i];
    if(now>=k){
      std::cout << i << '\n';
      return 0;
    }
  }



  return 0;
}


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

const ll rh_mod = 10000000000000061;
const ll rh_b = 1009;

class rolling_hash {
	const int n;
	vector<ll> R, H;
public:
	rolling_hash(const string& s)
		: n(s.size()), R(n + 1), H(n + 1) {
		R[0] = 1;
		for (int i = 0; i < n; i++) {
			R[i + 1] = (__int128)R[i] * rh_b % rh_mod;
			H[i + 1] = ((__int128)H[i] * rh_b + s[i]) % rh_mod;
		}
	}
	ll get(int l, int r) {
		assert(0 <= l && l <= r && r <= n);
		return (H[r] - (__int128)H[l] * R[r - l] % rh_mod + rh_mod) % rh_mod;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	string T, P;
	cin >> T >> P;
	int n = T.size(), m = P.size();
	rolling_hash rh(T);
	ll h = rolling_hash(P).get(0, m);
	for (int i = 0; i + m <= n; i++) if (rh.get(i, i + m) == h) {
		printf("%d\n", i);
	}
	return 0;
}



Measured memory_bytes: 19728
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1LL << 60;

ll A, B, C, K;

int main() {
    cin >> A >> B >> C >> K;

    if (A == B && B == C) {
        cout << 0 << endl;
        return 0;
    }

    if (abs(A - B) > 1e18) {
        cout << "Unfair" << endl;
        return 0;
    }

    if (K % 2 == 0) {
        cout << A - B << endl;
    } else {
        cout << B - A << endl;
    }
    // rep(i, K) {
    //     ll before_A = A, before_B = B, before_C = C;

    //     A = before_B + before_C;
    //     B = before_A + before_C;
    //     C = before_A + before_B;

    //     if (abs(A - B) > 1e18) {
    //         cout << "Unfair" << endl;
    //         return 0;
    //     }
    // }

    // cout << A - B << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int xcomp(vector<LL>& a, vector<LL>& b) {
	return a[0] < b[0];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

LL N, M;

bool isall = false;

vector<vector<LL>> graph(100001, vector<LL>(0));

vector<LL> tuuka(100001, 0);//0まだ1白2黒

vector<LL> white(0);
vector<LL> black(0);

void dfs(LL vertex,bool iswhite) {
	if (tuuka[vertex] == 0) {
		//そうさ
		if (iswhite) {
			tuuka[vertex] = 1;
			white.push_back(vertex);
		}
		else {
			tuuka[vertex] = 2;
			black.push_back(vertex);
		}

		REP(i, graph[vertex].size()) {
			dfs(graph[vertex][i], !iswhite);
		}
	}
	else {
		if (tuuka[vertex] == 1 && iswhite == false) {
			isall = true;
		}
		if (tuuka[vertex] == 2 && iswhite == true) {
			isall = true;
		}
	}
}

int main() {
	cin >> N >> M;
	REP(i, M) {
		LL A, B;
		cin >> A >> B;
		graph[A].push_back(B);
		graph[B].push_back(A);
	}

	dfs(1, true);

	if (isall) {
		cout << N*(N - 1) / 2 - M << endl;
	}
	else {
		cout << white.size()*black.size() - M << endl;
	}
}

Measured memory_bytes: 8956
import java.util.Scanner;

class Main {

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

        int x = scan.nextInt();
        int y = scan.nextInt();
        int i;

        while (x != 0 || y != 0) {
            if (x > y) {
                i = x;
                x = y;
                y = i;

            }
            System.out.println(x + " " + y);

            x = scan.nextInt();
            y = scan.nextInt();

        }
    }
}


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

int main() {
    ll n;
    ll d;
    cin >> n >> d;
    ll x, y;
    ll pp, qq, aa;
    int ans = 0;
    rep (i, n) {
        cin >> x >> y;
        pp = x * x;
        qq = y * y;
        if (d*d >=  pp + qq) ans++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// mint N;

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
// combination c(N);
// mint ans = c(N,n);
// cout << ans.x << endl;

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

int main(){
  ll N,K;
  cin >> N >> K;
  combination c(N-K+1);
  combination c2(K-1);
  for(ll i=1; i<=K; i++){
    mint ans1,ans2;
    ans1 = c(N-K+1,i);
    ans2 = c2(K-1, i-1);
    cout << (ans1.x*ans2.x)%mod << endl;
  }

  return 0;
}


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

int main() {
	int n,k,h,i,x,y;
	vector <int> v;
	cin >> n >> k;
	for(i=0;i<n;i++){cin>>h;v.push_back(h);}
	sort(v.rbegin(),v.rend());
	x = 1; y = v[0];
	while(y-x>0){
		h = 0;
		int m = (y+x)/2;
		for(i = 0; i < n; i++)h += (v[i]+m-1)/m - 1;
		if(h>k)x = m+1;
		else y = m;
	}
	cout << x << '\n';
}

Measured memory_bytes: 4252
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll x,y,tmp;
  cin >> x >> y;
  tmp = y - 2*x;
  if(tmp>=0&&tmp%2==0){
    ll sb = tmp/2;
    if(sb<=x){
      cout << "Yes\n";
    }else{
      cout << "No\n";
    }
  }else{
    cout << "No\n";
  }
}


Measured memory_bytes: 3636
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
tree=[[] for i in range(n+1)]
for i in range(n-1):
    a,b,c=mp()
    tree[a].append([a,b,c])
    tree[b].append([b,a,c])
ans=[-1]*(n+1)
ans[1]=0
que=deque()
que.append(tree[1])
while len(que):
    q=que.popleft()
    for x,y,z in q:
        if ans[y]==-1:
            ans[y]=(ans[x]+z)%2
            que.append(tree[y])
print(*ans[1:],sep="\n")

Measured memory_bytes: 106780
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long q = in.nextLong();
			long h = in.nextLong();
			long s = in.nextLong();
			long d = in.nextLong();
			double n = in.nextDouble();

			long min2_00 = Math.min(Math.min(q*8, h*4), Math.min(s*2, d*1));
			long min1_00 = Math.min(Math.min(q*4, h*2), s*1);
			long min0_50 = Math.min(q*2, h*1);
			long min0_25 = q;

			long sum = 0;
			while (n-2>=0) {
				n = n-2;
				sum += min2_00;
			}
			while (n-1>=0) {
				n = n-1;
				sum += min1_00;
			}
			while (n-0.5>=0) {
				n = n-0.5;
				sum += min0_50;
			}
			while (n-0.25>=0) {
				n = n-0.25;
				sum += min0_25;
			}

			out.println(sum);


		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21972
#include<stdio.h>
int main()
{
    int n;
    double a[50],b,sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%lf",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
            {
                int t=a[i];
                a[i]=a[j];
                a[j]=t;
            }
        }
    }
    b=a[0];
    for(int i=1;i<n;i++)
    {
        sum=(a[i]+b)/2.0;
        b=sum;
    }
    printf("%lf",sum);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
  int n;cin>>n;
  ll a[n];
  ll num[n+1];
  rep(i,0,n){
  	cin>>a[i];
    num[a[i]]=i+1;
  }
  set<ll> st;
  st.insert(0);
  st.insert(n+1);
  ll ans=0;
  rep(i,1,n+1){
    ll p=num[i];
  	auto itr=st.lower_bound(p);
    ll g=*itr;
    itr--;
    ll f=*itr;
    ans+=(g-p)*(p-f)*i;
    st.insert(p);
  }
  cout<<ans<<endl;
}

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

const int MOD = 1000000007;

void combination(int n, vector<vector<long long> >& comb)
{
    comb.assign(n+1, vector<long long>(n+1, 0));
    for(int i=0; i<=n; ++i){
        comb[i][0] = 1;
        for(int j=1; j<=i; ++j){
            comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
            comb[i][j] %= MOD;
        }
    }
}

int main()
{
    vector<vector<long long> > comb; // 組み合わせ
    combination(1000, comb);

    vector<long long> factorial(1001, 1); // 階乗
    for(int i=1; i<=1000; ++i)
        factorial[i] = (factorial[i-1] * i) % MOD;

    vector<long long> pow10(1001, 1); // 10のべき乗
    for(int i=1; i<=1000; ++i)
        pow10[i] = (pow10[i-1] * 10) % MOD;

    vector<long long> select(1001, 1); // [i] : i個の要素からi個以下の要素を選び、並び替える場合の数
    for(int i=1; i<=1000; ++i){
        for(int j=1; j<=i; ++j){
            select[i] *= j;
            ++ select[i];
            select[i] %= MOD;
        }
    }

    //////////////////////////////////////////////////////////////////////

    int n;
    cin >> n;

    vector<int> x(5);   // [i] : i桁の数字の個数
    vector<int> sum(5); // [i] : i桁の数字の合計値
    for(int i=0; i<n; ++i){
        int a;
        cin >> a;
        
        int b = a;
        int len = 0;
        while(b > 0){
            ++ len;
            b /= 10;
        }
        ++ x[len];
        sum[len] += a;
    }

    int m = 1;
    for(int i=0; i<5; ++i)
        m *= x[i] + 1;

    long long ret = 0;
    for(int i=0; i<m-1; ++i){
        int tmp = i;
        vector<int> y(5);
        int num = 0;
        int len = 0;
        for(int i=0; i<5; ++i){
            y[i] = tmp % (x[i] + 1);
            num += y[i];
            len += y[i] * max(1, i);
            tmp /= (x[i] + 1);
        }

        for(int j=1; j<5; ++j){
            if(x[j] == 0)
                continue;
            if(y[j] + 1 > x[j])
                continue;

            long long ret2 = 1;
            for(int k=0; k<5; ++k){
                if(j == k)
                    ret2 *= comb[x[k]-1][y[k]];
                else
                    ret2 *= comb[x[k]][y[k]];
                ret2 %= MOD;
            }

            ret2 *= factorial[num];
            ret2 %= MOD;

            ret2 *= pow10[len];
            ret2 %= MOD;

            if(x[0] - y[0] > 0){
                ret2 *= (select[n-num-1] - select[n-num-2] + MOD);
                ret2 %= MOD;
            }else{
                ret2 *= select[n-num-1];
                ret2 %= MOD;
            }

            ret += ret2 * sum[j];
            ret %= MOD;
        }
    }

    cout << ret << endl;

    return 0;
}

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

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
  int i,h;

  h= (h1(getKey(str)) + i * h2(getKey(str))) % M;

    /* your task */

  for(i=0;i<14;i++){
    h= (h1(getKey(str)) + i * h2(getKey(str))) % M;
    if(strcmp( H[h], str)==0) return 1;
  }
  return 0;
  
}

int insert(char str[]){
    /* your task */
  int i;
  if(find(str)) return 0;
  for(i=0;i<14;i++){
    if(H[ (h1(getKey(str)) + i * h2(getKey(str))) % M ][0]=='\0'){
      strcpy(H[ (h1(getKey(str)) + i * h2(getKey(str))) % M ],str);
      return 1;
    }
  }
  return 0;

}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 14280
import itertools
import math

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

n = []
for i in range(N):
    n.append(i)
    
c = list(itertools.permutations(n))

total = 0
for i in range(len(c)):
    x = xy[c[i][0]][0]
    y = xy[c[i][0]][1]
    dist = 0
    for j in range(1,len(c[i])):
        tmp_x = xy[c[i][j]][0]
        tmp_y = xy[c[i][j]][1]
        dist += math.sqrt((x - tmp_x) ** 2 + (y - tmp_y) ** 2)
        x = tmp_x
        y = tmp_y
    total += dist

print(total/len(c))



Measured memory_bytes: 47084
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long N,A,ans=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A;
		while(A%2==0){
			A=A/2;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

int main()
{
 vector<int > a(3);
  cin >> a[0] >> a[1] >> a[2];
  
  sort(a.begin(), a.end());
  if(a[0] == 5 && a[1] == 5 && a[2] == 7)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int two(int64_t x) {
    int res = 0;
    while(x % 2 == 0) {
        x /= 2;
        res++;
    }
    return res;
}

int five(int64_t x) {
    int res = 0;
    while(x % 5 == 0) {
        x /= 5;
        res++;
    }
    return res;
}

int main(void) {
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) {
        string s;
        cin >> s;
        if(s.find('.') == string::npos) {
            A[i] = stoll(s) * 1'000'000'000;
        } else {
            int d = s.size() - s.find('.');
            s += string(10-d, '0');
            s.erase(s.find('.'), 1);
            A[i] = stoll(s);
        }
        // cerr << A[i] << endl;
    }

    map< pair<int,int>, int64_t> mp;
    for(int i=0; i<N; i++) {
        // auto p = prime_factor(A[i]);
        mp[make_pair(two(A[i]), five(A[i]))]++;
    }

    int64_t ans = 0;
    for(int i=0; i<N; i++) {
        int t = two(A[i]);
        int f = five(A[i]);
        // auto p = prime_factor(A[i]);
        for(auto [key, val]: mp) {
            if(t + key.first >= 18 && f + key.second >= 18) {
                ans += val;
            }
        }
        if(t >= 9 && f >= 9) --ans;
    }

    cout << ans/2 << endl;
    return 0;
}


Measured memory_bytes: 4776
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func bfs(s []string, cost [][]int, h, w, x, y int) {
	ways := [][]int{{0, 1}, {1, 0}, {0, -1}, {-1, 0}}
	for _, way := range ways {
		nextx, nexty := x+way[0], y+way[1]
		// 進める場合
		if (0 <= nextx && nextx < w && 0 <= nexty && nexty < h) && s[y][x] == '.' {
			if cost[y][x]+1 < cost[nexty][nextx] {
				cost[nexty][nextx] = cost[y][x] + 1
				bfs(s, cost, h, w, nextx, nexty)
			}
		}
	}
}

func fillSlice(s [][]int, n int) {
	for i := range s {
		for j := range s[i] {
			s[i][j] = n
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	h, w := nextInt(), nextInt()
	s := make([]string, h)
	for i := range s {
		s[i] = next()
	}

	ans := 0
	cost := make([][]int, h)
	for i := range cost {
		cost[i] = make([]int, w)
	}

	for i := 0; i < h*w; i++ {
		fillSlice(cost, h*w)
		cost[i/w][i%w] = 0
		bfs(s, cost, h, w, i%w, i/w)
		for j := 0; j < h*w; j++ {
			if i == j || s[i/w][i%w] == '#' || s[j/w][j%w] == '#' {
				continue
			}
			ans = max(ans, cost[j/w][j%w])
		}
	}

	puts(ans)
}


Measured memory_bytes: 1024
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k; cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (i >= k && a[i - k] < a[i]) cout << "Yes" << endl;
        else if (i >= k) cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
	ll k, a, b;
	cin >> k >> a >> b;
	ll num = 1;
	if(a + 2 <= b){
		for(int i = 0; i < k; i++){
			if(num >= a && i!=k-1){
				num+=b-a;
				i++;
			}
			else num++;
		}
		cout << num << endl;
	}
	else{
		cout << k + 1 << endl;
	}
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> L(2 * N);
    for (auto & el : L) cin >> el;
    sort(L.begin(), L.end());
    int cum = 0;
    for (int i = 0; i < 2 * N; i += 2) cum += L[i];
    cout << cum << endl;
    return 0;
}

Measured memory_bytes: 256
/* ***************************************
Author        :Scau.ion
Created Time  :2016/10/15 20:14:35 UTC+8
File Name     :ion.cpp
*************************************** */

#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

using namespace std;

const int maxn=100010;

char s[maxn];

int main()
{
	scanf("%s",s);
    int n=strlen(s);
    int sum=0;
    for (int j=0;j<n;++j)
    {
        if (s[j]=='g') ++sum;
        else --sum;
    }
    sum/=2;
    printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Set<Integer> s1 = new HashSet<>();
        Set<Integer> sn = new HashSet<>();

        for (Integer i=0; i<m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();

            if (a == 1) {
                s1.add(b);
            }
            if (b == n) {
                sn.add(a);
            }            
        }
        s1.retainAll(sn);
        if (s1.isEmpty()) {
            System.out.println("IMPOSSIBLE");
        } else {
            System.out.println("POSSIBLE");
        }
    }
}


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

using namespace std;
using ll = long long;

int main() {
    ll n,d = 0;
    cin >> n >> d;
    ll x = 0;
    ll y = 0;
    ll cnt = 0;
    for(ll i = 0;i < n;i++){
        cin >> x >> y;
        if(x * x + y * y <= d * d){
            cnt++;
        }
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 3632
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# strlist = "abcdefghijklmnopqrstuvwxyz"
x = int(input())

jpy500 = 0
jpy5 = 0

jpy500 = x//500
x -= 500*jpy500
jpy5 = x//5

ans = jpy500*1000 + jpy5*5
print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
unordered_set<int> to[maxn];
int uf[maxn];
int find(int x){
	if(x == uf[x]) return x;
	return uf[x] = find(uf[x]);
}
using ii = pair<int,int>;
map<ii, int> c_edges;
queue<ii> q;
void upd_edge(int u, int v, int d){
	if(u == v) return;
	if(u > v) swap(u, v);
	ii e = {u, v};
	int cur_c = c_edges[e];
	cur_c += d;
	c_edges[e] = cur_c;
	if(cur_c == 2) q.push(e);
}
int join(int u, int v){
	u = find(u);
	v = find(v);
	if(u == v) return false;
	if(to[u].size() < to[v].size()) swap(u, v);
	to[u].erase(v);
	to[v].erase(u);
	for(int s : to[v]){
		upd_edge(v, s, -1);
		to[u].insert(s);
		to[s].erase(v);
		to[s].insert(u);
		upd_edge(u, s, 1);
	}
	to[v].clear();
	uf[v] = u;
	return true;
}
int main(){
	int n; cin >> n;
	iota(uf, uf + maxn, 0);
	for(int rot = 0; rot < 2; rot++){
		for(int i = 0; i < n - 1; i++){
			int u, v; cin >> u >> v;
			upd_edge(u, v, 1);
			to[u].insert(v);
			to[v].insert(u);
		}
	}
	for(int i = 0; i < n - 1; i++){
		if(q.empty()){
			cout << "NO" << endl;
			return 0;
		}
		int u, v;
		tie(u, v) = q.front(); q.pop();
		upd_edge(u, v, -1);
		upd_edge(u, v, -1);
		join(u, v);
	}
	cout << "YES" << endl;
	return 0;
}


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

#define SWAP(A, B) {int tmp = (B); (B) = (A); (A) = (tmp);}

int main() {
	char word[100][31];
	int pagenum[100];
	int sortnum[100];
	int count;

	for (int i = 0; i < 100; i++)
		sortnum[i] = i;

	for (count = 0; cin >> word[count] >> pagenum[count] != NULL; count++);

	for (int i = 0; i < count; i++) {
		for (int j = 0; j < count - i - 1; j++) {
			if (strcmp(word[sortnum[j]], word[sortnum[j+1]]) > 0)
				SWAP(sortnum[j], sortnum[j+1]);
		}
	}

	for (int i = 0; i < count; i++) {
		if (strcmp(word[sortnum[i]], word[sortnum[i+1]]) == 0) {
			int j, flag = 0;
			for (j = i
				; j < count - 1 && strcmp(word[sortnum[j]], word[sortnum[j+1]]) == 0
				; j++) 
			{
				if (pagenum[sortnum[j]] > pagenum[sortnum[j+1]]) {
					SWAP(sortnum[j], sortnum[j+1]);
					flag = 1;
				}
			}
			if (flag)
				i--;
			else
				i = j;
		}
	}

	for (int i = 0; i < count; i++) {
		cout << word[sortnum[i]] << endl;
		if (strcmp(word[sortnum[i]], word[sortnum[i+1]]) == 0) {
			for (; i < count && strcmp(word[sortnum[i]], word[sortnum[i+1]]) == 0; i++) {
				cout << pagenum[sortnum[i]] << ' ';
			}
		}
		cout << pagenum[sortnum[i]] << endl;
	}
	return 0;
}

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

using namespace std;

int in(){ int a; cin >> a; return a; }
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main(){
  ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0); cerr.tie(0);
  int n = in();
  vector<pair<int, int>> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end());
  for(int i = 0; i < n; i++){
    cout << a[i].second + 1 << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3860
K = int(input())
A, B = map(int, input().split())
if A <= K * (A // K) + K and K * (A // K) + K <= B:
    print("OK")
else:
    if A <= K * (A // K) and K * (A // K) <= B:
        print("OK")
    else:
        print("NG")


Measured memory_bytes: 61584
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	vector<int> v(n);
	long long t;
	long long min = 1000000000000000;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 1; i <= 100; i++) {
		t = 0;
		for (int j = 0; j < n; j++) {
			t += (v[j]-i)*(v[j] - i);
		}
		if (t < min) {
			min = t;
		}
	}
	cout << min << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e5;
struct edge{
	int u,v;
	ll c;
	edge(int u=-1,int v=-1,ll c=0):u(u),v(v),c(c){}
	bool operator <(const edge &e)const{
		return c<e.c;
	}
};
typedef pair<ll,int> P;
edge E[MAX_N<<1];
int N,M;
int par[MAX_N],ran[MAX_N];

int fpar(int v){
	if (v==par[v]){
		return v;
	}
	return par[v]=fpar(par[v]);
}
bool same(int u,int v){
	u=fpar(u);
	v=fpar(v);
	return u==v;
}
void unite(int u,int v){
	u=fpar(u);
	v=fpar(v);
	if (u!=v){
		if (ran[u]<ran[v]){
			par[u]=v;
		}else{
			par[v]=u;
			if (ran[u]==ran[v]){
				ran[u]++;
			}
		}
	}
}
int main(){
	cin>>N;
	M=0;
	{
		vector<P> vx,vy;
		REP(i,N){
			ll x,y;
			cin>>x>>y;
			vx.push_back(P(x,i));
			vy.push_back(P(y,i));
		}
		sort(vx.begin(),vx.end());
		sort(vy.begin(),vy.end());
		REP(i,N-1){
			E[M++]=edge(vx[i].second,vx[i+1].second,vx[i+1].first-vx[i].first);
			E[M++]=edge(vy[i].second,vy[i+1].second,vy[i+1].first-vy[i].first);
		}
		sort(E,E+M);
	}
	REP(v,N){
		par[v]=v;
		ran[v]=0;
	}
	ll ans=0;
	REP(i,M){
		edge e=E[i];
		if (!same(e.u,e.v)){
			unite(e.u,e.v);
			ans+=e.c;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6756