akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
using namespace std;

int main(){
    long long n,m;cin>>n>>m;
    map<long long, bool> flags;
    for (long long i=1;i<=n;i++){
        flags[i] = false;
    }

    long long a_acc = 0;
    map<long long, long long> wa_counter;
    for (long long i=1;i<=n;i++){
        wa_counter[i] = 0;
    }


    for (long long i=0;i<m;i++){
        long long q;
        string ans;
        cin >> q >> ans;
        if (ans == "AC"){
            if (!flags[q]){
                a_acc++;
                flags[q] = true;
            }
        } else {
            if (!flags[q]){
                wa_counter[q]++;
            }
        }
    }
    long long w_acc = 0;
    for (auto item : flags){
        if (item.second){
            w_acc += wa_counter[item.first];
        }
    }
    cout << a_acc << " " << w_acc << endl;
    return 0;

}

Measured memory_bytes: 12800
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;

inline int read()
{
	int X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}

string s,t;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>s>>t;
    int ans=INF;
    for(int i=0;i<=s.size()-t.size();++i){
    	int cnt=t.size();
    	int pos=i;
    	for(int j=0;j<t.size();++j,++pos){
    		if(s[pos]==t[j]){
    			cnt--;
    		}
    	}
    	ans=min(ans,cnt);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3636
def dict_count(dict, key):
	if key in dict:
		dict[key] = dict[key]+1
	else:
		dict[key] = 1
	return dict
 
N = int(input())
divs = {}
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for n in range(2, N+1):
	for p in primes:
		while n%p==0:
			divs = dict_count(divs, p)
			n = n//p
		if p*p>n:
			break
	if n!=1:
		dict_count(divs, n)
result = 1
base = 10**9+7
for c in divs.values():
	result = (result*(c+1))%base
print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
#include <string>
#include <math.h>
#include <queue>

using namespace::std;


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

    vector <int> x(m);
 
    for(int i(0); i < m; ++i)
    {
        int l;
        cin >> l;
        x[i] = l;
    }

    sort(x.begin(), x.end());
    vector <int> sa(m-1);
    for(int i(0); i < m-1; ++i)
    {
        sa[i] = x[i+1] - x[i];
    }
    sort(sa.begin(), sa.end());

    int sum= 0;
    for(int i(0); i < m-1 - n + 1; ++i)
    {
        sum+=sa[i];
    }

    cout << sum << endl;
    

    return 0;
}

Measured memory_bytes: 1024
#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>;

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; }
const ll INF = 1LL << 60;

//---main---------------------------------------------
int main(){
    //main
    int N;
    cin >> N;

    int AC=0,WA=0,TLE=0,RE=0;
    string J;
    rep(i,N){
        cin >> J;
        if( J == "AC") AC++;
        if( J == "WA") WA++;
        if( J == "TLE") TLE++;
        if( J == "RE") RE++;
    }

    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;


    return 0;
}

Measured memory_bytes: 3596
const lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int,s)
intSub(s::SubString{String})=parse(Int,s)
intLine()=map(intSub,split(input()))
function main()
    x,y=intLine()
    if -2<x-y<2
        println("Brown")
    else
        println("Alice")
    end
end
main()

Measured memory_bytes: 110796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

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

bool p(string s)
{
    bool ok = true;
    REP(i, s.size())
    {
        if (s[i] != s[s.size() - 1 - i])
        {
            ok = false;
        }
    }
    return ok;
}

int main()
{
    string S;
    cin >> S;

    ll N = S.size();
    bool ok = p(S) and p(S.substr(0, (N - 1) / 2)) and p(S.substr((N + 3) / 2 - 1));
    if (ok)
    {
        OUT("Yes");
    }
    else
    {
        OUT("No");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
// #include <unordered_map>
#define vi vector <ull>
#define ii pair<ull,ull>
#define vii vector<ii>

#define seti set<ull>
#define mii map<ull,ull>
#define um unordered_map
#define ull long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MAX 100100
#define _ << " " <<

using namespace std;





void solve(){
	
	int n;
	cin >> n;
	int h[n][3];
	for(int i = 0 ; i < n; i++){
		cin >> h[i][0] >> h[i][1] >> h[i][2];
	}

	ull dp[n][3];

	for(int i = 0 ; i < n; i++){
		for(int j = 0; j < 3; j++){
			dp[i][j] = 0;
		}
	}

	for(int i = 0 ; i < 3; i++){
		dp[0][i] = h[0][i];
	}	



	for(int i = 1; i < n; i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				if(k != j){
					dp[i][j] = max(dp[i][j], dp[i-1][k]+h[i][j]);
				}
			}
		}
	}

	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
	
}


int main(){
	// freopen("data.in", "r", stdin);
	// freopen("data.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ull q;
	// cin >> q;
	q = 1;
	for(ull i = 0; i < q; i++){
		// cout << "Case #" << i+1 << ":" << endl;

		solve();
		// cout << endl;
	}

	

	return 0;
}


Measured memory_bytes: 3840
S = int(input())
MOD = 10 ** 9 + 7

DP = [0] * (2000+1)
DP[0]
 
DP[3]=1
for i in range(4,2001):
    DP[i]=DP[i-1]+DP[i-3]

print(DP[S]%(10**9+7))  

Measured memory_bytes: 8944
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int R,G,B,N; cin >> R >> G >> B >> N;
    int ans = 0;
    for(int i = 0; i <= N; i += R) {
        for(int j = 0; j <= N-i; j += G) {
            int rest = N - (i+j);
            if(rest%B == 0) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


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

int main(){

	int i, n, pt = 0, ph = 0, cmp;
	char ct[1000], ch[1000];

	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%s %s", ct, ch);
		cmp = strcmp(ct, ch);
		if(cmp < 0){
			ph += 3;
		} else if(cmp == 0){
			pt++;
			ph++;
		} else {
			pt += 3;
		}
	}
	printf("%d %d\n", pt, ph);
	


	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
int main(){
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	int a,b;
	cin>>a>>b;
	if(a%b==0){
		cout<<a/b;
	}
	else{
		cout<<a/b+1;
	}

}


Measured memory_bytes: 256
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    count = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            k = x - i - j
            if j < k and k <= n:
                count += 1
    print(count)
        


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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<bool>> K(N, vector<bool>(M, false));
    for (int i = 0; i < N; i++) {
        int Ki;
        cin >> Ki;
        for (int j = 0; j < Ki; j++) {
            int Aij;
            cin >> Aij;
            K[i][Aij - 1] = true;
        }
    }
    int ans = 0;
    for (int i = 0; i < M; i++) {
        bool flag = true;
        for (int j = 0; j < N; j++) {
            if (K[j][i] == false) {
                flag = false;
                break;
            }
        }
        if (flag == true) ans++;
    }

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

max_num = max(A)
max_i = A.index(max_num)
A.remove(max_num)
second_max = max(A)
new_list = [max_num for _ in range(N)]

new_list[max_i] = second_max
print(*[val for sublist in new_list for val in sublist], sep='\n')

Measured memory_bytes: 52824
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    
    int a =scan.nextInt();
    int b =scan.nextInt();
    int c =scan.nextInt();

    if(a>b && a>c){
        if(b>c){
            System.out.printf("%d %d %d\n",c,b,a);
        }else{
            System.out.printf("%d %d %d\n",b,c,a); 
        }
    }else if(b>a && b>c){
        if(a>c){
            System.out.printf("%d %d %d\n",c,a,b);
        }else{
            System.out.printf("%d %d %d\n",a,c,b); 
        }   
    }else if(c>a && c>b){
        if(a>b){
            System.out.printf("%d %d %d\n",b,a,c);
        }else{
            System.out.printf("%d %d %d\n",a,b,c); 
        }
    }
    }
}


Measured memory_bytes: 26240
import java.util.Scanner;

public class Main {

	/** 正直者 */
	private static final String HONEST = "H";
	/** 嘘つき */
	private static final String DISHONEST = "D";

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			String a = scanner.next(), b = scanner.next();
			System.out.println((HONEST.equals(a) ? b : reverse(b)));
		}
	}

	/**
	 * @param input
	 * @return inputの反対
	 */
	private static String reverse(String input) {
		return (HONEST.equals(input) ? DISHONEST : HONEST);
	}
}


Measured memory_bytes: 35576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;


int main(){
    ll N;
  	cin>>N;
    set<string> S;
    for(int i=0; i<N; i++){
      	string T;
      	cin>>T;
      	S.insert(T);
    }
    cout<<S.size()<<endl;
}

Measured memory_bytes: 19224
fun main(args: Array<String>) {

    val N = readLine()!!.toInt()
    val ABCN = Array(N) { readLine()!!.split(" ").map(String::toInt) }

    val dp = Array(N) { IntArray(3) }

    dp[0][0] = ABCN[0][0]
    dp[0][1] = ABCN[0][1]
    dp[0][2] = ABCN[0][2]

    for (i in 1 until dp.size) {
        val a = dp[i - 1][0]
        val b = dp[i - 1][1]
        val c = dp[i - 1][2]

        dp[i][0] = Math.max(b, c) + ABCN[i][0]
        dp[i][1] = Math.max(a, c) + ABCN[i][1]
        dp[i][2] = Math.max(b, a) + ABCN[i][2]
    }

    println(dp[N - 1].max())
}


Measured memory_bytes: 71112
#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() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  
  map<int, int> mp;
  rep(i, n) ++mp[a[i]];
  int ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    int f = (*itr).first;
    int s = (*itr).second;
    if (s >= f) ans += s - f;
    else ans += s; 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8276
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
        out << '(' << p.first << ',' << p.second << ')';
            return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
        in >> p.first >> p.second;
            return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
        for (T &x : v)
                    in >> x;
            return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
        for (const vector<T> &x : v)
                    out << x << '\n';
            return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
        for (const T &x : v)
                    out << x << ' ';
            return out;
}

template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
        for (const T &x : s)
                out << x << ' ';
            return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.00000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main()
{
    fast();
    ll n,m;
    cin>>n>>m;
    vi x(n),y(m);
    cin>>x>>y;
    
    ll y1=0;
    ll y2=0;
    
    for(ll i=0;i<m;i++)
    {
        y1+=i*y[i];
        y2+=(m-1-i)*y[i];
        
        y1%=mod;
        y2%=mod;
    }
    
    ll x1=0;
    ll x2=0;
    for(ll i=0;i<n;i++)
    {
        x1+=i*x[i];
        x2+=(n-1-i)*x[i];
        x1%=mod;
        x2%=mod;
    }
    
    ll ans=((x2+mod-x1)%mod)*((y2-y1+mod)%mod);
    
    cout<<ans%mod<<nl;
} 


Measured memory_bytes: 4796
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  map<char, int> amap;
  string S;
  for(int i=0;i<N;++i) {
    cin>>S;
    if(i==0) {
      for(int j=0;j<S.size();++j) {
        amap[S[j]]++;
      }
    }
    else {
      map<char, int> tmpmap;
      for(int j=0;j<S.size();++j) {
        tmpmap[S[j]]++;
      }
      for(char a='a';a<='z';++a) {
        amap[a] = min(amap[a], tmpmap[a]);
      }
    }
  }
  string ans;
  for(char a='a';a<='z';++a) {
    for(int i=0;i<amap[a];++i) {
      ans.push_back(a);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3592
n, K = map(int, input().split())
R, S, P = map(int, input().split())
t = input()

hands = ["any"]*n

for i in range(n):
  if i-K < 0 or hands[i-K] != t[i]:
    hands[i] = t[i]
    
score = 0
for h in hands:
  if h == "r":
    score += P
  elif h == "s":
    score += R
  elif h == "p":
    score += S
print(score)

Measured memory_bytes: 77216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll k,a,b;
    cin>>k;
    cin>>a>>b;
    rep(a,i,b+1){
        if(i%k==0){
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
}

Measured memory_bytes: 3644
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
bitset<301>AA[301];
int main(){
    MOD=998244353;
    int n,m;
    R(n,m);
    REP(i,n){
        REP(j,m){
            int x; R(x);
            if(x)AA[i][j]=1;
        }
    }
    int now=0;
    LL all=1,zero=1;
    REP(i,n)all=all*2%MOD;
    REP(i,m){
        if(now>=n)break;
        REPP(j,now,n){
            if(AA[j][i]){
                if(j!=now)swap(AA[j],AA[now]);
                break;
            }
        }
        if(!AA[now][i])continue;
        REP(j,n){
            if(j==now)continue;
            if(AA[j][i])AA[j]^=AA[now];
        }
        now++;
    }
    REP(i,n-now)zero=zero*2%MOD;
    ADD(all,-zero);
    LL two=1;
    REP(i,m-1)two=two*2%MOD;
    W(all*two%MOD);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repv(i,a,b) for(ll i=b-1;i>=a;i--)
#define MAXN 300005
#define endl "\n"
 
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;}
 
int dp[3005][3005];
string s,t;
char s1[3005],t1[3005];
 
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>s>>t;
    // string q=t;
    // if(s.size()<t.size())
    for(int i=0;i<s.size();i++) s1[i+1]=s[i];
    for(int i=0;i<t.size();i++) t1[i+1]=t[i];
    for(int i=1;i<=s.size();i++)
    {
        for(int j=1;j<=t.size();j++)
        {
            if(s1[i]==t1[j])
                dp[i][j]=dp[i-1][j-1]+1;
            else 
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int i=s.size(),j=t.size();
    string p="";
    while(i>0 && j>0)
    {
        if(s1[i]==t1[j])
        {
            p=s1[i]+p;
            i--;j--;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1]) i--;
            else j--;
        }
    }
    cout<<p<<endl;
}

Measured memory_bytes: 35584
n = int(input())
for x in range(1, 3501):
  for y in range(1, 3501):
    t = 4 * x * y - n * y - n * x
    if(t <= 0):
      continue
    if((n * x * y) % t == 0):
      print(x, y, (n * x * y) // t)
      exit(0)

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

// Data structures.
struct Point {
    double x, y;
    Point(double x = 0, double y = 0) : x(x), y(y) {}
    Point(const Point& p) : x(p.x), y(p.y) {}

    Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); }
    Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
    Point operator*(double k) const { return Point(k * x, k * y); }
    Point operator/(double k) const { return Point(x / k, y / k); }

    bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; }
    bool operator==(const Point& p) const { return fabs(x - p.x) < 1e-10 && fabs(y - p.y) < 1e-10; }

    static double norm(const Point& p) { return sqrt(p.x * p.x + p.y * p.y); }
    static double dot(const Point& p1, const Point& p2) { return p1.x * p2.x + p1.y * p2.y; }
    static double cross(const Point& p1, const Point& p2) { return p1.x * p2.y - p1.y * p2.x; }
};

struct Segment {
    Point s, t;
};

double distance(const Segment& s, const Point& p) {
    return abs(Point::cross(s.t - s.s, p - s.s)) / Point::norm(s.t - s.s);
}

Point cross_point(const Segment& s1, const Segment& s2) {
    double ds = distance(s1, s2.s);
    double dt = distance(s1, s2.t);
    return s2.s + (s2.t - s2.s) * ds / (ds + dt);
}

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

    int q;
    cin >> q;

    rep(i, 0, q) {
        Segment s1, s2;
        cin >> s1.s.x >> s1.s.y >> s1.t.x >> s1.t.y;
        cin >> s2.s.x >> s2.s.y >> s2.t.x >> s2.t.y;
        Point p = cross_point(s1, s2);
        printf("%.10f %.10f\n", p.x, p.y);
    }

    return 0;
}


Measured memory_bytes: 3292
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

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};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int K, T;
	cin >> K >> T;
	
	Vec< int > a(T);
	for_(i,0,T) cin >> a[i];
	
	sort(allof(a), greater< int >());
	
	int i = 0, j = 1;
	while (j < T) {
		if (a[i] >= a[j]) {
			a[i] -= a[j];
			a[j] = 0;
		} else {
			a[j] -= a[i];
			a[i] = 0;
		}
		while (a[i] == 0) ++i;
		++j;
	}
	
	int ans = 0;
	for_(i,0,T) if (a[i] != 0) {
		ans += a[i] - 1;
		break;
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//


Measured memory_bytes: 256
s=input()

length=len(s)

s1=''
s2=''
count1=0
count2=0

for i in range(int(length/2)):
    s1+='10'
if int(length%2)==1:
    s1+='1'

for i in range(int(length/2)):
    s2+='01'
if int(length%2)==1:
    s2+='0'




for i in range(length):
    if s[i]!=s1[i]:
        count1+=1
        
for i in range(length):
    if s[i]!=s2[i]:
        count2+=1


print(min(count1,count2))


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

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

use std::cmp::{max, min};

fn main() {
  let a = read::<i32>();
  let b = read::<i32>();

  println!("{}", (a - 1) * (b - 1));
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    if(abs(a-b)<=x && abs(c-b)<=x || abs(a-c)<=x)
        cout<<"Yes\n";
    else
        cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
const long int NMAX = 100010, INF = 10000000023;
long int dp[NMAX];
long int a[NMAX];

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    cin >> a[i];
  }

  REP(i, n+1) {
    dp[i] = INF;
  }

  for (int i = 0; i < n; i++) {
    int j = 0;
    long int* p = lower_bound(dp, dp + n, a[i]);
    *p = a[i];
  }

  long int* p = lower_bound(dp, dp + n, INF);
  cout << p - dp << endl;
}

Measured memory_bytes: 2720
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
using VI = vector<long>;

long sum(long n) {
    long ret = 0;
    while (n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

long hoge(long n, long k) {
    for (int i = 0; i < k; i++) {
        n /= 10;
    }
    n -= 1;
    for (int i = 0; i < k; i++) {
        n *= 10;
        n += 9;
    }
    return n;
}

int main() {
    long n;
    cin >> n;
    
    long digits = long(floor(log10(n) + 1));
    long ans = sum(n);
    for (int i = 0; i < digits; i++) {
        ans = max(ans, sum(hoge(n, i)));
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);


int main(){
    IOS;
    ll n;cin>>n;
    vector<ll>v;
    f(i,0,120){
        ll x=pow(i,5);
        v.pb(x);
    }
    bool ok=0;
    f(i,0,v.size()){
        f(j,0,v.size()){
            if(v[i]+v[j]==n){cout<<i<<" "<<-j;ok=1;break;}
            if(v[j]-v[i]==n){cout<<j<<" "<<i;ok=1;break;}
            // if(v[j]-v[i]==n){cout<<j<<" "<<i;ok=1;break;}
            }
        if(ok)break;
    }
    return 0;  
} 





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

int N, M, X;
int C[20];
int A[20][20];
int ans = 20000000;

int main(){
  cin >> N >> M >> X;
  rep(i, N){
    cin >> C[i];
    rep(j, M){
      cin >> A[i][j];
    }
  }

  rep(bits, 1<<N){
    bool flag[N];
    rep(n, N){
      if (bits & (1<<n)) flag[n] = true;
      else flag[n] = false;
    }

    int sums = 0;
    rep(i, N){
      sums += flag[i] * C[i];
    }

    int Y[20];
    rep(i, 20) Y[i] = 0;
    rep(i, N){
      if (flag[i]){
        rep(j, M) Y[j] += A[i][j];
      }
    }

    bool ok = true;
    rep(j, M){
      if (Y[j] < X) ok = false;
    }
    if (ok) ans = min(ans, sums);
  }
  if (ans == 20000000) cout << "-1" << endl;
  else cout << ans << endl;
}


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

using namespace std;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int N;
    long long K;
    cin >> N >> K;

    vector<int> a(N+1);
    vector<vector<int> > table(64, vector<int>(N+1, -1));

    for(int i = 1; i <= N; ++i){
        cin >> a[i];
        table[0][i] = a[i];
    }

    for(int k = 0; k < 63; ++k){
        for(int i = 1; i <= N; ++i){
            if(table[k][i] == -1){
                table[k+1][i] = -1;
            }else{
                table[k+1][i] = table[k][table[k][i]];
            }
        }
    }

    int res = 1;

    for(int k = 63; k >= 0; --k){
        if(1ll << k & K){
            res = table[k][res];
        }
    }

    cout << res << '\n';

}

Measured memory_bytes: 54888
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

vector<ll> s;
bool bx[110000];
int main() {
    ll n, ax = 0;
    cin >> n;
    s.resize(n);
    REP(i, n){
        cin >> s[i];
        if(i >= 2) ax ^= s[i];
    }
    if(s[1] + s[0] - ax < 0 or (s[1] + s[0] - ax) % 2 == 1){
        cout << -1 << endl;
        return 0;
    }
    ll x = (s[1] + s[0] - ax) / 2;
    ll a = 0, b = 0;
    ll t = s[0] + s[1] - 2 * x;
    REP(i, 60){
        if((x & (1ll << i)) and (t & (1ll << i))){
            cout << -1 << endl;
            return 0;
        }
    }
   // cout << x << " " << t << " " << ax<< endl;
    ll need[80] = {};
    REP(i, 60){
        if ((x & (1ll << i))) need[i] += 1ll << i;
        need[i + 1] += need[i];
    }
    REPR(i, 60){
        if((x & (1ll << i))){
            a += 1ll << i;
            b += 1ll << i;
        }
        else if((t & (1ll << i))){
            if(a + need[i] + (1ll << i) <= s[0]) a += 1ll << i;
            else b += 1ll << i;
        }
        //cout << a << " " << b << endl;
    }
    bool ok = true;
    if (a + b != s[0] + s[1]) ok = false;
    if (a > s[0]) ok = false;
    if (a == 0) ok = false;
    if ((a xor b xor ax) != 0) ok = false;
    cout << (ok ? s[0] - a : -1) << endl;
}


Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int x, a, b,c,ans=0;
    cin >> a>> b >> c>>x;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (500 * i + 100 * j + 50 * k == x) ans++;
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
class SegTreeBool():
    def segFunc(self, x, y):
        return x + y
    def searchIndexFunc(self, val):
        return val > 0
    def __init__(self, ide, init_val):
        n = len(init_val)
        self.ide_ele = ide
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segFunc(self.seg[2*i+1],self.seg[2*i+2])
    def update(self, idx, val):
        idx += self.num-1
        self.seg[idx] = val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def query(self, begin, end):
        if end <= begin:
            return self.ide_ele
        begin += self.num-1
        end += self.num-2
        res = self.ide_ele
        while begin + 1 < end:
            if begin&1 == 0:
                res = self.segFunc(res, self.seg[begin])
            if end&1 == 1:
                res = self.segFunc(res, self.seg[end])
                end -= 1
            begin = begin//2
            end = (end-1)//2
        if begin == end:
            res = self.segFunc(res, self.seg[begin])
        else:
            res = self.segFunc(self.segFunc(res, self.seg[begin]), self.seg[end])
        return res
    def getLargestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R)//2
            if self.searchIndexFunc(self.query(P, R)):
                L = P
            else:
                R = P
        return L
    def getSmallestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R+1)//2
            if self.searchIndexFunc(self.query(L, P)):
                R = P
            else:
                L = P
        return L

def main():
    n, q = map(int, input().split())
    qry = [list(map(int, input().split())) for _ in range(q)]
    ans = (n-2)**2
    m1, m2 = n, n
    segbool1 = SegTreeBool(0, [0]*n)
    segbool2 = SegTreeBool(0, [0]*n)
    ms1 = [n]*n
    ms2 = [n]*n
    for ptn, idx in qry:
        if ptn == 1:
            tmp = None
            if segbool1.query(0, idx) == 0:
                tmp = m2 - 2
            else:
                pt = segbool1.getLargestIndex(0, idx)
                tmp = ms1[pt]
            ans -= tmp
            ms1[idx] = tmp
            segbool1.update(idx, 1)
            if idx < m1:
                m1 = idx
        else:
            tmp = None
            if segbool2.query(0, idx) == 0:
                tmp = m1 - 2
            else:
                pt = segbool2.getLargestIndex(0, idx)
                tmp = ms2[pt]
            ans -= tmp
            ms2[idx] = tmp
            segbool2.update(idx, 1)
            if idx < m2:
                m2 = idx
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 118560
n=int(input())
ab=[]
p=[-1 for i in range(n+1)]
edge={}
G=[[] for i in range(n+1)]
used=[0 for i in range(n+1)]
for i in range(n-1):
    ab.append(list(map(int,input().split())))
    G[ab[i][0]].append(ab[i][1])
    G[ab[i][1]].append(ab[i][0])

max_n=0

for i in range(n+1):
    tmp=len(G[i])
    if tmp>max_n:
        max_n=tmp
        top=i

queue=[]
queue.append(top)

while len(queue)>0:
    num=queue.pop(0)
    used[num]=1
    color=1
    for i in range(len(G[num])):
        if used[G[num][i]]==0:
            if p[num]==color:
                color+=1
                edge["{},{}".format(num,G[num][i])]=color
                edge["{},{}".format(G[num][i],num)]=color
                p[G[num][i]]=color
                queue.append(G[num][i])
            else:
                edge["{},{}".format(num,G[num][i])]=color
                edge["{},{}".format(G[num][i],num)]=color
                p[G[num][i]]=color
                queue.append(G[num][i])
            color+=1

print(max_n)
for i in range(n-1):

    print(edge["{},{}".format(ab[i][0],ab[i][1])])

        




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

using namespace std;
typedef long long ll;
#define mp make_pair
const int INF = 1e9;

const int N = 1e5 + 10;
int a[N];

int main() {
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);	
	int n, min_a = INF, max_a = -INF;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		min_a = min(min_a, a[i]);
		max_a = max(max_a, a[i]);
	}
	if (max_a - min_a > 1) {
		cout << "No" << endl;
		return 0;
	}
	if (max_a == min_a) {
		if (max_a == n - 1 || 2 * max_a <= n) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
		return 0;
	}
	int un = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == min_a)
			un++;
	}
	int s = max_a - un;
	if (s <= 0 || un + 2 * s > n) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;

int main(){
    string s;cin>>s;
    int n=s.size(),ans=0;
    bool a=true;
    rep0(i,n){
        rep1(j,n-i+1){
            string t=s.substr(i,j);
            int l=t.size();
            a=true;
            rep0(k,l){
                if(t[k]!='A' && (t[k]!='C' && (t[k]!='T' && t[k]!='G'))){
                    a=false;
                }
            }
            if(a){
                ans=max(ans,l);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
signed main(){
  int n,c=1,k=0;
  cin>>n;
  while(c<n&&c<10)cout<<c<<endl,c++;
  int m=9,x=10;
  while(c<=n){
    m+=x;
    cout<<m<<endl;
    k=m+x;
    int y=0;
    while(k>0){
      y+=k%10;
      k/=10;
    }
    k=m+x*10;
    int b=0;
    while(k>0){
      b+=k%10;
      k/=10;
    }
    if((m+x*10)*y<=(m+x)*b) x*=10;
    c++;
  }
}

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

using namespace std;
#define ll long long int
#define rep(i,n) for(i=0;i<(n);i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
typedef pair< ll, ll > lpair;

bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    if(a.ff == b.ff)
        return (a.ss < b.ss);
    return (a.ff < b.ff);
}

vector< ll > prime(1000005,1);
void p()
{
    ll i,j;
    for(i=2;i<=1000000;i++)
    {
        if(prime[i] == 1)
        {
            for(j = 2*i;j<=1000000;j+=i) prime[j] = 0;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,w,i,j;
    cin>>n>>w;
    vector< ll > weight(n+1),value(n+1);
    rep(i,n)
    {
        cin>>weight[i+1]>>value[i+1];
    }

    ll dp[n+1][w+1];

    for(i = 0;i<=n;i++) dp[i][0] = 0;
    for(i = 0;i<=w;i++) dp[0][i] = 0;

    for(i = 1;i<=n;i++)
    {
        for(j = 1;j<=w;j++)
        {
            dp[i][j] = dp[i-1][j];
            if(j-weight[i] >= 0) dp[i][j] = max(dp[i][j],dp[i-1][j-weight[i]] + value[i]);
        }
    }

    cout<<dp[n][w]<<endl;

    return 0;
}

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

using namespace std;
using ll = long long;
constexpr ll mod = 1e9+7;
constexpr ll md = mod;
constexpr ll inf = 1e15;
int main(){
    ll h,w,x,y;
    cin>>w>>h>>x>>y;
    cout <<setprecision(10) << fixed <<  w*h/2.0 << " " << (x*2 == w and y*2 == h)  << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl "\n"
#define p_b push_back
#define fastIO ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
template <class T> 
using _ost = tree<
		T, 
		null_type, 
		less<T>, 
		rb_tree_tag, 
        tree_order_statistics_node_update>;
// char alphabet[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
void swap(int* a,int* b){
    int temp = *a;
    *a=*b;
    *b=temp;
}
int32_t main(){
 	fastIO;
 	int n,k;cin>>n>>k;
 	cout<<min(k-(n%k),n%k)<<endl;
} 	

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
ab = []
m.times do
  ab.push gets.split.map(&:to_i)
end
h = Array.new(n+1).map { Array.new([]) }
ab.each do |ij|
  h[ij.first].push ij.last
  h[ij.last].push ij.first
end
puts (h[1] & h[n]).empty? ? 'IMPOSSIBLE' : 'POSSIBLE'


Measured memory_bytes: 36880
/* 
author: Hayato Kawakita
date: 2020/06/29 19:20
vertict: AC
URL:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1150&lang=ja
所要時間:20分
やるだけ。スタートからdijkstra法のように調べるだけ。右足、左足の状態を分けていることに注意。
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
typedef array<int, 4> V;

//inputs
int w, h;
char s[65][35];
//distance from start {y, x, is_right_foot}
int d[65][35][2];

void init() {
  rep(i, 65) rep(j, 35) rep(k, 2) d[i][j][k] = inf;
}

void solve() {
  priority_queue<V, vector<V>, greater<V>> pq;
  //start
  rep(i, h) {
    rep(j, w) {
      if (s[i][j] == 'S') {
        rep(k, 2) {
          d[i][j][k] = 0;
          pq.push({0, i, j, k});
        }
      }
    }
  }
  while (pq.size()) {
    V res = pq.top();
    pq.pop();
    int y = res[1], x = res[2], t = res[3];
    //visited
    if (res[0] > d[y][x][t]) continue;
    //次の状態を全て調べるだけ
    FOR(i, 1, 4) {
      int nx = (t == 0 ? x + i : x - i);
      if (nx < 0 || nx >= w) break;
      FOR(j, -3 + i, 4 - i) {
        int ny = y + j;
        if (ny < 0 || ny >= h) continue;
        if (s[ny][nx] == 'X' || s[ny][nx] == 'S') continue;
        if (s[ny][nx] == 'T') {
          cout << d[y][x][t] << '\n';
          return;
        }
        if (chmin(d[ny][nx][t ^ 1], d[y][x][t] + s[ny][nx] - '0')) {
          pq.push({d[ny][nx][t ^ 1], ny, nx, t ^ 1});
        }
      }
    }
  }
  //impossible
  cout << -1 << '\n';
  return;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  while (cin >> w >> h, w) {
    init();
    rep(i, h) rep(j, w) cin >> s[i][j];

    solve();
  }



  




  
  return 0;
}


Measured memory_bytes: 3172
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

s = 0
sabun = []

s += a
sabun.append((10 - a % 10) % 10)
s += b
sabun.append((10 - b % 10) % 10)
s += c
sabun.append((10 - c % 10) % 10)
s += d
sabun.append((10 - d % 10) % 10)
s += e
sabun.append((10 - e % 10) % 10)

s += sum(sabun) - max(sabun)
print(s)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, m;
vector<int> v,vv;

//コンビネーション
//けんちょんさんありがとう
const int MAX = 101010, MOD = INF;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long C(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
////

int main(){
	cin >> n >> m;
	
	for(i64 i = 2; i*i <= m; ++i){
		int cnt = 0;
		while(m % i == 0){
			m /= i;
			cnt++;
			v.push_back(i);
		}
		vv.push_back(cnt);
	}
	if(m != 1){v.push_back(m); vv.push_back(1);}
	
	i64 ans = 1;
	COMinit();
	for(int i = 0; i < vv.size(); i++){
		ans *= C(vv[i]+n-1, vv[i]);
		ans %= INF;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int m=0,n,aa[220000],a,b,cnt=0;
pair<int,int> p[220000];
string s,ss[110000];
char c;
signed main(){
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

Measured memory_bytes: 1152
import java.io.*;
import java.math.*;

public class Main {
	public static void main(String args[]) throws IOException{
		String str[] = new String[2];
		double x = 0, y = 0, angle = 0, deg = 0;
		int step = 0;
		
		BufferedReader input =
				new BufferedReader(new InputStreamReader(System.in));
		while(true){
			str = input.readLine().split(",");
			step = Integer.parseInt(str[0]);
			deg = Double.parseDouble(str[1]);
			
			x += step * Math.sin(Math.toRadians(angle));
			y += step * Math.cos(Math.toRadians(angle));
			
			angle += deg;
			
			if(str[0].equals("0") && str[1].equals("0")){
				System.out.println((int)x + "\n" +(int) y);
				break;
			}
		}
	}
}

Measured memory_bytes: 16924
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=998244353;
const int N=262150;
int n;
int p[N],f[N];
inline ll qpow(ll x,int k,ll r=1){
	for(;k;k>>=1,x=x*x%mod) if(k&1) r=r*x%mod;
	return r;
}
inline void fwt(int *a,int len,int opt){
	for(int i=1;i<len;i<<=1) for(int j=0;j<len;j+=i<<1) for(int k=0;k<i;++k){
		int x=a[j+k],y=a[j+k+i];
		a[j+k]=(x+y)%mod; a[j+k+i]=(x-y+mod)%mod;
	}
	if(~opt) return ;
	int inv=qpow(len,mod-2);
	for(int i=0;i<len;++i) a[i]=1ll*a[i]*inv%mod;
}
int main(){
	scanf("%d",&n); int len=1<<n,sum=0;
	for(int i=0;i<len;++i) scanf("%d",&p[i]),sum+=p[i]; sum=qpow(sum,mod-2);
	for(int i=0;i<len;++i) p[i]=1ll*p[i]*sum%mod; (p[0]+=mod-1)%=mod;
	for(int i=0;i<len;++i) f[i]=mod-1; (f[0]+=len)%=mod;
	fwt(f,len,1); fwt(p,len,1); sum=0;
	for(int i=1;i<len;++i) f[i]=f[i]*qpow(p[i],mod-2)%mod,(sum+=f[i])%=mod;
	f[0]=mod-sum; fwt(f,len,-1);
	for(int i=0;i<len;++i) printf("%d\n",f[i]);
	return 0;
}

Measured memory_bytes: 5764
def insertionSort(arr): 
  
    # Traverse through 1 to len(arr) 
    for i in range(1, len(arr)): 
  
        key = arr[i] 
        j = i - 1
        
        while j >=0 and key < arr[j] : 
                arr[j+1] = arr[j] 
                j -= 1
        arr[j+1] = key
        
        print(' '.join(map(str, numbers)))

_ = input()
numbers = list(map(int, input().split()))
print(' '.join(map(str, numbers)))
insertionSort(numbers)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
int A,B,C,X,Y;
int counts(int A,int B,int C,int X,int Y)
{
    if(X==(min(X,Y)))
    {
        return (Y-(min(X,Y)))*B;
    }
    else
    {
        return (X-(min(X,Y)))*A;
    }
}
int main()
{
    scanf("%d %d %d %d %d",&A,&B,&C,&X,&Y);
    int ans1=max(X,Y)*2*C;
    int ans2=min(X,Y)*2*C+counts(A,B,C,X,Y);
    int ans3=A*X+B*Y;
    printf("%d\n",min(min(ans1,ans2),ans3));
}


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

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

ll N,M;

void solve(){
    ll ans;

    if(N == 1 && M == 1)
        ans = 1;
    else if(M == 1){
        ans = N-2;
    } else {
        ans = (N-2)*(M-2);
    }

    cout << ans << endl;
}

int main(){
    cin >> N >> M;

    if(N < M) swap(N,M);

    solve();
}


Measured memory_bytes: 256