akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    """
    n個の要素を0 ~ n - 1の番号で管理する。以下の属性およびメソッドを持つ。

    parents
    各要素の親要素の番号を格納するリスト
    要素が根（ルート）の場合は-(そのグループの要素数)を格納する

    find(x)
    要素xが属するグループの根を返す

    union(x, y)
    要素xが属するグループと要素yが属するグループとを併合する

    size(x)
    要素xが属するグループのサイズ（要素数）を返す

    same(x, y)
    要素x, yが同じグループに属するかどうかを返す

    members(x)
    要素xが属するグループに属する要素をリストで返す

    roots()
    すべての根の要素をリストで返す

    group_count()
    グループの数を返す

    all_group_members
    {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す

    __str__()
    print()での表示用
    ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
    """


n, m = (int(x) for x in input().split())
L = [set() for _ in range(n)]
for i in range(n):
    k, *arg = (int(x) for x in input().split())
    L[i].update(set(arg))

ANS = L[0]
uf = UnionFind(n)
for _ in range(100):
    for i in range(1, n):
        if ANS & L[i]:
            ANS |= L[i]
            uf.union(0, i)
    for i in reversed(range(1, n)):
        if ANS & L[i]:
            ANS |= L[i]
            uf.union(0, i)

if uf.group_count() == 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 136380
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;
bool can(int max,int num2,vector<int>a,int num1){
    vector <int> m2;m2.push_back(0);
    for(int i=0;i<num1;i++) {
        if(a[i]+*(m2.end()-1)<=max) *(m2.end()-1)+=a[i];
        else m2.push_back(a[i]);
    }
     return (m2.size()<=num2);
}
int main()
{
    int num1,num2,tmp,max_;
    cin>>num1>>num2;
    vector<int> m,m3,copy;
    for(int i=0;i<num1;i++) {cin>>tmp;m.push_back(tmp);}
    copy=m;
    sort(copy.begin(),copy.end());
    if(copy[num1-1]>accumulate(m.begin(),m.end(),0)/num2)
    {max_=copy[num1-1];if(can(max_,num2,m,num1)) {cout<<max_<<endl;return 0;}}
    else max_=accumulate(m.begin(),m.end(),0)/num2;
    //cout<<"max_"<<max_<<endl;
    //cout<<"start:"<<start<<"end:"<<end<<endl;
    int a=max_,b=max_+copy[num1-1],mid=a;
    while(a!=b){
        mid=(a+b)/2;
        if(can(mid,num2,m,num1)) b=mid;
        else a=mid+1;
    }
    cout<<a<<"\n";
    }



Measured memory_bytes: 4736
#include <stdio.h>
#include <math.h>

int h[2*123456];
int n;

int main()
{
	int i,j;
	int count = 0;
	while(1){
		scanf("%d", &n);
		if(n == 0) break;
		if(n == 1){
			printf("%d\n", 1);
			continue;
		}
		for (i = 1; i < 2*n;i++)
		{
			h[i] = i;
		}
		h[0] = 0;
		h[1] = 0;
		i = 2;
		while(i < sqrt(2*n)){
			for(j = 2*i; j < 2*n; j += i){
				h[j] = 0;
			}
			j = i+1;
			while(h[j] == 0) j++;
			i = h[j];
		}
		count = 0;
		for(i = n+1; i < 2*n; i++){
			if(h[i] != 0) count++;
		}
		printf("%d\n", count);
	}
	return 0;
}

Measured memory_bytes: 1992
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp
{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x)
{
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue()
{
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b)
{
    return a < b ? a : b;
}

int main()
{
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d",&n,&q);

    for(i = 1;i <= n;i++) {
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }
    head = 1; tail = n + 1;

    while(head != tail) {
        u = dequeue();
        c = min(q,u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0) enqueue(u);
        else {
            printf("%s %d\n", u.name,elaps);
        }
    }
    return 0;
}



Measured memory_bytes: 12888
N = int(input())
wi = [[] for i in range(N)]
for i in range(N):
    wi[i].append([i,1])
    for j in range(int(input())):
        x,y = map(int,input().split())
        wi[i].append([x-1,y])
ans = 0
for i in range(2**N):
    flag = False
    hoge = 0
    witnes = [0]*N
    for j in range(N):
        if i>>j & 1 == 1:
            hoge += 1
            for x,y in wi[j]:
                if i >> x & 1 != y:
                    flag = True
                    break
        if flag:
            break
    if not flag:
        ans = max(ans,hoge)
print(ans)

Measured memory_bytes: 42352
#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 n;
    cin>>n;
    vector<ll>a(n);
    rep(0,i,n)cin>>a[i];
    ll M=a[0],ans=0;
    rep(0,i,n){
        ans+=max(M-a[i],(ll)0);
        M=max(M,a[i]);
    }
    cout<<ans<<endl;
}


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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i, N) cin >> d[i];
    sort(d.begin(), d.end());
    cout << d[N / 2] - d[N / 2 - 1] << endl;
}

Measured memory_bytes: 640
N = int(input())
D = sorted([int(x) for x in input().split()])
M = int(input())
T = sorted([int(x) for x in input().split()])
j = 0
for i in range(len(D)):
    if j == len(T):
        break
    if D[i] == T[j]:
        j += 1
print("YES" if j == len(T) else "NO")


Measured memory_bytes: 33784
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    if a[i]>b[i]: ans+=b[i]
    elif a[i]+a[i+1]>b[i]:
        ans+=b[i]
        a[i+1] = a[i+1]-(b[i]-a[i])
    else:
        ans+=a[i]+a[i+1]
        a[i+1]=0
print(ans)

Measured memory_bytes: 19156
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <map>

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)
#define all(c) begin(c),end(c)
 
template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const long long INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9; 

// 多次元配列を作る
// vector<vector<int>> vn(n, vector<int>(3, 0));

// 多次元配列の dump
// for (vector<int> v : vn) {
//     cout << v;
// }

// printf("%d\n", n);
// printf("%lld\n", n);

int main(void){
    int n, m;
    scanf("%d", &n);
    scanf("%d", &m);
    // printf("%d ", n);
    // printf("%d\n", m);
    map<int, bool> mp; 
    REP (i, m) {
        mp[i + 1] = true;
    }

    // printf("\n");
    // for (const auto &p : mp) {
    //     std::cout << "m[" << p.first << "] = " << p.second << '\n';
    // }
    // printf("\n");

    REP (i, n) {
        // printf("%s", "======\n");
        int k;
        scanf("%d", &k);
        // printf("%d: ", k);
        map<int, bool> lmp; 
        REP (j, k) {
            int l;
            scanf("%d", &l);
            // printf("%d ", l);
            lmp[l] = true;
        }

        // printf("\n");
        // for (const auto &p : lmp) {
        //     std::cout << "m[" << p.first << "] = " << p.second << '\n';
        // }
        // printf("\n");
        REP (j, m) {
            if ((lmp.find(j + 1) == lmp.end())) {
                // printf("deleted: %d \n", j + 1);
                mp[j + 1] = false;
            }
        }
        // printf("\n");
    }

    // printf("\n");
    int cnt = 0;
    for (const auto &p : mp) {
        if (p.second == true) {
            ++cnt;
        }
    }
    printf("%d", cnt);

    return 0;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define allof(v) (v).begin(), (v).end()

#define INF 1ll<<60

li n;
vector<pair<li, li>> edge[100100];

li table[100100];

inline void dfs(li now, li now_distance, li from) {
	table[now] = now_distance;
	for (auto && e : edge[now]) {
		if (e.first == from) {
			continue;
		}
		dfs(e.first, now_distance + e.second, now);
	}
}

int main(void)
{
	cin >> n;
	rep(i, n - 1) {
		li a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		edge[a].push_back({b, c});
		edge[b].push_back({a, c});
	}

	li q, k;
	cin >> q >> k;
	k--;
	dfs(k, 0, -1);

	rep(i, q) {
		li x, y;
		cin >> x >> y;
		x--;
		y--;
		cout << table[x] + table[y] << endl;
	}


	return 0;
}

Measured memory_bytes: 13056
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    string s;
    cin>>s;
    ll sum = n;

    ll i = 0;
    while (i < s.size())
    {
        if (s[i] == s[i + 1])
        {
            sum--;
            // s.erase(i + 1);
            
        }
        i++;
    }

    cout << sum << endl;
}

Measured memory_bytes: 512
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

const INF: i64 = 1 << 60;
#[fastout]
fn main() {
    input! {
    n:usize,k:usize,c:i64,
    s:Chars,
     }

    let mut left = Vec::new();
    let mut right = Vec::new();
    let mut prev = -INF;
    for (i, &now) in s.iter().enumerate() {
        let i = i as i64;
        if left.len() >= k {
            break;
        }
        if now == 'o' {
            if i - prev > c {
                prev = i;
                left.push(i);
            }
        }
    }
    let mut prev = INF;
    for (i, &now) in s.iter().enumerate().rev() {
        let i = i as i64;
        if right.len() >= k {
            break;
        }
        if now == 'o' {
            if prev - i > c {
                prev = i;
                right.push(i);
            }
        }
    }
    right.sort();
    for (i, &l) in left.iter().enumerate() {
        if right[i] == l {
            println!("{}", l + 1);
        }
    }
}


Measured memory_bytes: 6160
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N, K;
    cin >> N >> K;
    VI d(K);
    VVI A(K);
    REP(i, K) {
        cin >> d[i];
        A[i] = VI(d[i]);
        REP(j, d[i]) {
            cin >> A[i][j];
        }
    }

    set<int> se;
    REP(i, K) {
        FORE(e, A[i]) se.emplace(e);
    }

    cout << N - se.size() << endl;
}


Measured memory_bytes: 3644
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF32		INT32_MAX
#define	INF64		INT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// main function
int main()
{
	string S = "";
	string ret = "TBD";
	ll y = 0;
	ll m = 0;
	ll d = 0;

	cin >> S;

	sscanf(S.c_str(), "%d/%d/%d", &y, &m, &d);

	if (y < 2019) {
		ret = "Heisei";
	}
	else if (y == 2019) {
		if (m < 4) {
			ret = "Heisei";
		}
		else if (m == 4) {
			if (d <= 30) {
				ret = "Heisei";
			}
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <utility>
#include <set>
#include <bitset>
#include <vector>
#define pi acos(-1.0)
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fLL
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=5e5+5;
int min3(int a,int b,int c)
{
    return min(min(a,b),c);
}
int max3(int a,int b,int c)
{
    return max(max(a,b),c);
}
int gcd(int x, int y)
{
    if(y==0)return x;
    return gcd(y, x%y);
}
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int main()
{
    int a[10];
    scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]);
    sort(a,a+4);
    if(a[0]==1 && a[1]==4 && a[2]==7 && a[3]==9)printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision; // int64_tは9*10^18まで

int main() {
  int n, l=0, r=0, tmp1=0, tmp2=0;
  string s;
  cin >> n >> s;
  for(int i=0; i<n; i++){
    if(s[i]=='(') l++;
    else r++;
    if(r-l>tmp1) tmp1=r-l;
    if(l-r>tmp2) tmp2=l-r;
  }
  for(int i=0; i<max(r-l, tmp1); i++) {
    cout << '(';
    l++;
  }
  cout << s;
  for(int i=0; i<l-r; i++) cout << ')';
}

Measured memory_bytes: 3596
use itertools::Itertools;
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n: usize,
        a: [usize; n-1]
    }

    let mut a_v = vec![0; n];
    for v in a {
        a_v[v - 1] += 1;
    }
    
    let ans = a_v.iter().take(n).join("\n");
    print!("{}" , ans);
}

Measured memory_bytes: 5584
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<int>w(N + 2);
	string s;
	cin >> s;
	s = '0' + s + '0';
	for (int i = 1; i <= N + 1; i++) {
		w[i] += w[i - 1];
		if (s[i] == 'W') w[i]++;
	}
	int ans = MOD;
	for (int i = 1; i <= N; i++) {
		int box = 0;
		box += w[i - 1];
		box += N - i;
		box -= w[N] - w[i];
		ans = min(ans, box);
	}
	cout << ans << endl;
	return 0;
}


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

q = ['a']
for i in range(n-1):
    nq=[]
    for j in q:
        stop=ord(max(j))+2

        for k in range(ord('a'),stop):
            nq.append(j+chr(k))
        q=nq

for i in q:
    print(i)

Measured memory_bytes: 12988
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,y;
  cin >> x >> y;
  if( y % 2 ) {
    cout << "No" << '\n';
    return 0;
  }
  int y2 = y / 2;
  int b = y2 - x;
  int a = x - b;
  if( b < 0 || a < 0 ){
    cout << "No" << '\n';
    return 0;
  }
  if( a * 2 + b * 4 == y ) {
    cout << "Yes" << '\n';
  }
  else {
    cout << "No" << '\n';
  }
  return 0;
}



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

int n, val, cnt;
set<int> s;

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) {
		scanf("%d", &val);
		if(s.find(val) == s.end())
			s.insert(val);
		else 
			s.erase(val);
	}
	printf("%d\n", (int) s.size());
}

Measured memory_bytes: 4864
N = int(input())
X = list(map(int,input().split()))
X.sort()
min = 10**100

for i in range(X[0],X[N-1]+1):
    ans = 0
    for j in range(N):
        ans += (X[j]-i)**2
    if ans < min:
        min = ans
    
print(min)

Measured memory_bytes: 38640
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

def main():
    a1, a2, a3 = [int(_) for _ in input().split()]
    print(max(a1, a2, a3) - min(a1, a2, a3))

main()


Measured memory_bytes: 5056
N = int(input())
A = [int(input()) for i in range(N)]
dic = {}
for i in A:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
ans = 0
for i in dic.keys():
    if dic[i] % 2 == 1:
        ans += 1
print(ans)

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
vector<int> graph[200005];
int main()
{
    int n,m;
    cin >> n >> m;
    int a, b;
    rep(i,m)
    {   
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    queue<int> dest;
    for (auto i : graph[1])
    {
        dest.push(i);
    }
    queue<int> dest2;
    while(!dest.empty())
    {
        int s = dest.front();
        dest.pop();
        for (auto i : graph[s])
        {
            dest2.push(i);
        }
    }
    while (!dest2.empty())
    {
        int s = dest2.front();
        dest2.pop();
        if(s==n)
        {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

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

int main() {
  
  int64_t N; cin >> N;
  
  int64_t ans = N + 1;
  
  for (int64_t i = 1; i * i <= N; i++) {
    
    if (N % i != 0) continue;
    
    int64_t tmp = i + N / i - 2;
    
    ans = min(ans, tmp);
    
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int w=0,x=0;char ch=0;
	while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return w?-x:x;
}
int n,a[10080]={},sum=0;
int main()
{
	n=read();
	n*=2;
	for(int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1);
	for(int i=n;i>=0;i-=2)
	{
		sum+=min(a[i],a[i-1]);
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

bool vis[100][100]={};
bool win[100][100]={};

bool dfs(ll x, ll y)
{
    if(vis[x][y]) return win[x][y];

    bool ret=false;

    for(ll i=1; 2*i<=x; ++i) ret |= !dfs(x-2*i,y+i);
    for(ll i=1; 2*i<=y; ++i) ret |= !dfs(x+i,y-2*i);

    vis[x][y]=true;
    return win[x][y]=ret;

}

void test()
{
    win[0][0]=win[1][0]=win[0][1]=false;
    vis[0][0]=vis[1][0]=vis[0][1]=true;

    rep(i,50)
    {
        rep(j,50) printf("%c", "XO"[dfs(i,j)]);
        printf("\n");
    }
}

int main()
{
    // test();

    ll x,y;
    cin >>x >>y;
    cout << (abs(x-y)<=1?"Brown":"Alice") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
LL T;
LL Gcd(LL a,LL b) {
	if(b==0) return a;
	return Gcd(b,a%b);
}
int main() {
	scanf("%d",&T);
	for(int i=1;i<=T;i++) {
		LL a,b,c,d;bool flag=true;
		scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
		if(b>d||a<b) {
			printf("No\n");
			continue;
		}
		if(c>=b) {
			printf("Yes\n");
			continue;
		}
		LL x=a%b,y=Gcd(d,b);
		LL k1=x;
		LL k2=(x+y)%b;
		LL delta=k2-k1;
		if(c<k1||c<k2)
			flag=false;
		else if(delta==0)
			flag=true;
		else if(delta>0) {
			if(k1+(c-k1+delta)/delta*delta<b)
				flag=false;
		}
		else {
			LL you=(k1+delta-1)/delta*delta-k1;
			if(you>0&&b-you>c)
				flag=false;
		}
		if(flag) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}
//(c,b)

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll dp[100010];

int main(void){
    ll n;
    cin>>n;
    vector<ll>a(n),ans;
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++){
        auto itr=upper_bound(ans.begin(),ans.end(),a[i],greater<ll>());
        if(itr==ans.end())ans.push_back(a[i]);
        else *itr=a[i];
    }
    cout<<ans.size()<<endl;
    return 0;
}

Measured memory_bytes: 2296
#include<iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int H[N];
  for(int i=0; i<N; i++){
    cin >> H[i];
  }
  int dp[N], count=1;
  dp[0] = H[0];
  for(int i=1; i<N; i++){
    dp[i] = max(dp[i-1], H[i]);
    if(dp[i-1] <= H[i])
      count++;
  }
  cout << count;
  return 0;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) REP(i,(vec).size()) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    string w;
    cin >> w;
    unordered_map<char, int> m;
    REP(i, w.length()) {
        m[w[i]]++;
    }

    REP(i, m.size()) {
        if (m[i] % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
n, x, m = map(int, input().split())
g = x * 1
ans = x
arr = []
res = set([])
roop = (0, 0)
k = 0
for i in range(m + 1):
	tmp = x ** 2 % m
	if tmp in res:
		roop = (i, tmp)
		break
	res.add(tmp)
	arr.append(tmp)
	ans += tmp
	x = tmp

for i, y in enumerate(arr):
	if y == roop[1]:
		k = i
		break

ini = sum(arr[:k])
mul = ans - ini - g
t, v = divmod(n - k - 1, roop[0] - k)
print(g + ini + mul * t + sum(arr[k:k + v]))


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

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

void Main() {
    int N;
    string S;
    cin >> N >> S;
    vector<int> R, G;
    set<int> B;
    rep(i, N){
        if (S[i] == 'R'){R.push_back(i);}
        if (S[i] == 'G'){G.push_back(i);}
        if (S[i] == 'B'){B.insert(i);}
    }
    ll ans = R.size() * G.size() * B.size();
    for (auto r : R){for (auto g : G){
        if ( (r + g) % 2 == 0){
            int k = (r + g) / 2;
            if (B.find(k) != B.end()){ans -= 1;}
        }
        if (0 <= (2 * g - r) < N){
            if (B.find(2 * g - r) != B.end()){ans -= 1;}
        }
        if (0 <= (2 * r - g) < N){
            if (B.find(2 * r - g) != B.end()){ans -= 1;}
        }
    }}
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3724
from functools import lru_cache
from sys import setrecursionlimit
setrecursionlimit(10000)
N = input()
K = int(input())

@lru_cache()
def f(n, k):
    if k == 0:
        return 1
    if len(n) == 1:
        if k == 1:
            return int(n)
        else:
            return 0
    m = int(n[-1])
    return f(n[:-1], k) + f(n[:-1], k - 1) * m + f(str(int(n[:-1]) - 1), k - 1) * (9 - m)

print(f(N, K))

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << "(i) " <<  i << endl
using namespace std;
int n;
int f, l;
int solve();
int sum(int n){
    return (n * (n + 1) / 2);
  }

int main(){
  cin >> n;
  while(n != 0){
    solve();
    cout << f << " " << l << endl;
    cin >> n;
 }
 return 0;
}

int solve(){
    int st = sqrt(2 * n);
    //cout  << "st " << st << endl;
    int num = st;
    int t = n - sum(st);
    REPB(i,st){
      if(t % num == 0 && t >= 0){
        l = num;
        f = t / num + 1;
        //cout << "sum " <<  sum(num) << endl;
        return 0;
    }
        t += st;
        st--;
        num--;
      }
  }


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 100005;

class TaskE {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		int n;
		cin >> n;
		vector<int> h(n+1);
		for(int i = 1; i <= n; i++){
			cin >> h[i];
		}
		long long ans = 0;
		map<int,int> mp;
		for(int i = 1; i <= n; i++){
			int val = i - h[i];
			ans += mp[val];
			mp[h[i] + i]++;
		}
		cout << ans << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskE solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 21112
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2010;
int n;
char a[maxn], b[maxn];
int ans;
bool has_one[maxn][maxn];
int sufmax[maxn];
int one4left[maxn], one4right[maxn];

inline int toleft(int x, int offset) {
	return (x - offset + n) % n;
}

inline int toright(int x, int offset) {
	return (x + offset + n) % n;
}

void gao(bool dir) {
	auto g = [=](int x, int k) {
		return dir ? toright(x, k) : toleft(x, k);
	};
	for (int d = 0; d < n; ++d) {
		vector<pair<int, int>> xy;
		int flip = 0;
		for (int i = 0; i < n; ++i) {
			if (a[i] != b[g(i, d)]) {
				++flip;
				if (dir ? !has_one[i][g(i, d)] : !has_one[g(i, d)][i]) {
					xy.push_back(make_pair(one4left[dir ? i : g(i,d)], one4right[dir ? g(i,d) : i]));
				}
			}
		}
		sort(xy.begin(), xy.end());
		sufmax[xy.size()] = 0;
		for (int i = static_cast<int>(xy.size()) - 1; i >= 0; --i) {
			sufmax[i] = max(sufmax[i+1], xy[i].second);
		}
		int minlr = sufmax[0];
		for (int i = 0; i < xy.size(); ++i) {
			minlr = min(minlr, xy[i].first + sufmax[i+1]);
		}
		//cout << flip << ' ' << minlr << ' ' << d << ' ' << xy.size() << endl;
		ans = min(ans, flip + minlr * 2 + d);
	}
}

int main() {
	while (~scanf("%s%s", a, b)) {
		n = strlen(a);
		bool b_has_one = false;
		for (int i = 0; i < n; ++i) {
			if (b[i] == '1') {
				b_has_one = true;
				break;
			}
		}
		if (b_has_one == false) {
			bool a_has_one = false;
			for (int i = 0; i < n; ++i) {
				if (a[i] == '1') {
					a_has_one = true;
					break;
				}
			}
			printf("%d\n", a_has_one ? -1 : 0);
			continue;
		}
		for (int i = 0; i < n; ++i) {
			has_one[i][i] = (b[i] == '1');
			for (int j = toright(i, 1), cnt = 1; cnt < n; ++cnt, j = toright(j, 1)) {
				has_one[i][j] = (has_one[i][toleft(j, 1)] || b[j] == '1');
			}
		}
		int t;
		for (int i = 0; i < n; ++i) {
			if (b[i] == '1') {
				t = i;
				break;
			}
		}
		for (int i = t, cnt = 0; cnt < n; ++cnt, i = toright(i, 1)) {
			one4left[i] = (b[i] == '1' ? 0 : one4left[toleft(i, 1)] + 1);
		}
		for (int i = t, cnt = 0; cnt < n; ++cnt, i = toleft(i, 1)) {
			one4right[i] = (b[i] == '1' ? 0 : one4right[toright(i, 1)] + 1);
		}
		ans = 1e6;
		gao(true);
		gao(false);
		assert(ans != 1e6);
		printf("%d\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Long A = sc.nextLong();
    Long B = sc.nextLong();
    Long K = sc.nextLong();
    if (A >= K) {
      A -= K;
      System.out.println(A + " " + B);
    } else if (A + B - K >= 0) {
      System.out.println(0 + " " + (A + B - K));
    } else {
      System.out.println(0 + " " + 0);
    }
  }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define nl cout<<"\n"
#define endl "\n"
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c.size())
#define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++)
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define f first
#define s second

inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a; a%=b;return gcd(b,a);}
ll power(ll x, ll y){if(y == 0) return 1; ll a = power(x,y/2);if (y % 2 == 0) return a * a; else return x * a * a; }
ll powermod(ll x, ll ex , ll md) {ll ans = 1ll;while (ex > 0) {if (ex & 1ll) ans = (ans * x) % md; ex >>= 1ll;x = (x * x) % md;}return ans;}

const ll inf = 1e18 + 9;
const ll mod = 1e9 + 7;
const ld PI = acos(-1);
const ld eps = 1e-9;

const ll N = 2e5 + 11;
ll n , a[N] ;
void solve(){
    cin >> n;
    rep(i , n) cin >> a[i];
    sort(a , a + n , greater<ll>());
    ll ans = 0;
    ll ct =0 ;
    for(ll i = 0 ; i < n; i++){
        if(ct == n - 1 || ct == n){
            if(ct == n) ans -= a[i - 1];
            break;
        }
        if(i == 0) ans += a[0] , ct++;
        else ans += a[i] + a[i] , ct += 2;
    }
    cout << ans << endl;
}
int main(){
    IOS;
    cout << fixed << setprecision(20);
    ll NTC = 1;
    // cin >> NTC;
    ll PTC = 0;
    while(PTC++ < NTC){
        // cout << "Case #" << PTC << ":" << ' ';
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 5364
#include<stdio.h>

int main(void)
{
  char S[100001];
  scanf("%s",S);

  int counta = 0;
  int countb = 0;
  int i;
  for(i = 0; S[i] != '\0'; i++)
  {
    if(S[i] == '1')  counta++;
    else countb++;
  }
  int ans=0;
  
  ans = (counta>=countb)? countb: counta;
  printf("%d",2*ans);
  return 0;
}


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

int main(){
  ll n;
  cin >> n;
  vector<vector<ll>>a(n,vector<ll>(2));
  for(int i=0; i<n; i++){
    cin >> a[i][0];
    a[i][1]=i+1;
  }
  
  sort(a.begin(),a.end());
  for(int i=0; i<n; i++){
    a[i][0]=i+1;
  }
  
  ll count=0;
  for(int i=0; i<n; i++){
    ll x=a[i][0]%2,y=a[i][1]%2;
    if(x!=y)count++;
  }
  
  cout << count/2 << endl;
  
  
}
  
  
  
  


Measured memory_bytes: 5760
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
l = 1
r = n
for i in range(m):
    ll, rr = na()
    l = max(l, ll)
    r = min(r, rr)
if l > r:
    print(0)
else:
    print(r-l+1)


Measured memory_bytes: 3316
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
  int h,i,j;
  int n,m;
  while(cin>>n>>m,n||m){
    vector<int> a[100];
    for(i=0;i<n;++i){
      int p;
      do{
	cin>>p;
	if(p)
	  a[i].push_back(p);
      }while(p);
    }
    int b[100]={},c[100]={};
    queue<int> d;
    int ct=0;
    for(i=0;i<m;++i){
      h=0;
      for(j=0;j<n;++j){
	if(b[j]%2){
	  if(d.front()==j){
	    c[j]=(c[j]+1)%a[j][b[j]];
	    if(c[j]==0){
	      b[j]=(b[j]+1)%a[j].size();
	      h=1;
	    }
	  }else{
	    ct++;
	  }  
	}else{
	  c[j]=(c[j]+1)%a[j][b[j]];
	  if(c[j]==0){
	    ++b[j];
	    d.push(j);
	  }
	}
      }
      if(h)
	d.pop();
    }
    cout<<ct<<endl;
  }
  return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.nextInt();
        int l = sc.nextInt();

        var list = new List<int>();
        for (int i = 1; i <= n; i++)
        {
            list.Add(l + i - 1);
        }
        int sum = list.Sum();

        int ans = 0;
        int gap = int.MaxValue;
        for (int i = 0; i < n; i++)
        {
            if (Math.Abs(list[i]) < gap)
            {
                gap = Math.Abs(list[i]);
                ans = sum - list[i];
            }
        }
        Console.WriteLine(ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13268
//
//  main.cpp
//  AOJ1180
//
//  Created by aki33524 on 2014/07/08.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int A, L;

void solve(){
    vector<int> vec;
    vec.push_back(A);
    
    for(int i=0; i<=20; i++){
        int al = vec[vec.size()-1];
        vector<int> digits(L);
        
        for(int j=0; j<L; j++){
            digits[j] = al%10;
            al /= 10;
            if(al == 0)
                break;
        }
        sort(digits.begin(), digits.end());
        
        int maxa = 0, mina = 0;
        int base = 1;
        for(int j=0; j<L; j++){
            maxa += base * digits[j];
            mina += base * digits[L-j-1];
            base *= 10;
        }
        vec.push_back(maxa - mina);
    }
    
    int n = vec.size();
    for(int i=0; i<n; i++){
        for(int j=0; j<i; j++){
            if(vec[i] == vec[j]){
                cout << j << " " << vec[j] << " " << i-j << endl;
                return;
            }
        }
    }
}

int main(int argc, const char * argv[])
{
    while(cin>>A>>L, A|L){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1220
import sys
input = sys.stdin.readline
s = input().strip()
t = input().strip()
chk = [[] for i in range(26)]
ma = [0]*26
ex = [False]*26
for i,si in enumerate(s):
  num = ord(si)-97
  chk[num].append(i+1)
  if not ex[num]:
    ex[num] = True
  ma[num] = i+1
  
import math,bisect
now = 0
ans = 0
l = len(s)
for i,ti in enumerate(t):
  ans += 1
  j = i+1
  n = ord(ti)-97
  if not ex[n]:
    ans = -1
    break
  if ans > now*l + ma[n]:
    now = math.ceil((ans-ma[n])/l)
  ind = bisect.bisect_left(chk[n],ans-now*l)
  ans = chk[n][ind] + now*l
print(ans)

Measured memory_bytes: 7624
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

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

int N, MOD;
std::vector<std::vector<int>> G;
std::vector<std::vector<ll>> dp;

ll dfs(const int v, const int p = -1) {
  ll res = 1;
  rep(i, sz(G[v])) {
    if ( G[v][i] == p ) continue;
    dp[v][i] = dfs(G[v][i], v);
    res *= (dp[v][i] + 1 ) % MOD;
    res %= MOD;
  }
  return res % MOD;
}

void rev(const int v, const int p = -1, const ll add = 0) {
  rep(i, sz(G[v])) {
    if (G[v][i] == p) {
      dp[v][i] = add;
      break;
    }
  }

  const int deg = G[v].size();
  std::vector<ll> l(deg), r(deg);
  for (int i = 0; i < deg; ++i) r[i] = ((l[i] = (dp[v][i] + 1)) %= MOD);
  for (int i = 1; i < deg; ++i) (l[i] *= l[i - 1]) %= MOD;
  for (int i = deg - 2; 0 <= i; --i) (r[i] *= r[i + 1]) %= MOD;

  for (int i = 0; i < deg; ++i) {
    if (G[v][i] == p) continue;
    ll add_c = 1;
    if (i != 0) (add_c *= l[i - 1]) %= MOD;
    if (i != deg - 1) (add_c *= r[i + 1]) %= MOD;
    rev(G[v][i], v, add_c);
  }
  return;
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::cin >> N >> MOD;
  G.resize(N);
  rep(i,N-1) {
    int x, y; std::cin >> x >> y; x--, y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  dp.resize(N);
  rep(i,N) dp[i].assign(sz(G[i]), 0);

  dfs(0);
  rev(0);

  rep(v,N) {
    ll ans = 1;
    for (ll add : dp[v]) (ans *= (add + 1)) %= MOD;
    std::cout << ans << std::endl;
  }
  return 0;
}


Measured memory_bytes: 22272
tmp = list(map(int, input().split()))
N, M, C = tmp[0], tmp[1], tmp[2]
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
cnt = 0
for i in range(N):
  sum = 0
  for j in range(M):
    sum += A[i][j] * B[j]
  sum += C
  if sum > 0:
    cnt += 1
print(cnt)

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
import java.lang.Math.*;

class Main{

    static String[] mData = new String[1000];
    static int[][] dp = new int[1000][1000];

    static int H;
    static int W;

    static final int m = 1000000007;

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
    
        H = sc.nextInt();
        W = sc.nextInt();

               

        for(int i = 0; i < H; i++){
            mData[i] = sc.next();
        }
        boolean flag = true;
        for(int i = H - 1; i > -1; i--){
            if( mData[i].charAt(W-1) != '#' && flag ){
               dp[i][W-1] = 1;         
            }
            else{
                flag = false;
                dp[i][W-1] = 0;
            }
        }
        flag = true;
        for(int j = W - 1; j > -1; j--){
            if( mData[H-1].charAt(j) != '#' && flag ){
               dp[H-1][j] = 1;  
            }
            else{
                flag = false;
            }
        }

        for(int i = H - 2; i >= 0; i--){
            for(int j = W - 2; j >= 0; j--){
                if( mData[i].charAt(j) == '#' ){
                    dp[i][j] = 0;
                }
                else{
                    dp[i][j] = (dp[i+1][j] + dp[i][j+1]) % m;
                }
            }
        }        
        System.out.println( dp[0][0] );
    }
}


Measured memory_bytes: 35216
// https://atcoder.jp/contests/aising2020/tasks/aising2020_b
#include<bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		if (tmp%2!=0 && (i+1)%2!=0) {
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3616
use std::io;
use std::cmp::Ordering;

fn main() {
  let stdin = io::stdin();
  let mut buf = String::new();
  stdin.read_line(&mut buf).unwrap();
  let mut iter = buf.trim()
    .split_whitespace()
    .map(|x| x.parse::<i32>().unwrap());
  let a = iter.next().unwrap();
  let b = iter.next().unwrap();

  let bin = match a.cmp(&b) {
    Ordering::Less    => "<",
    Ordering::Equal   => "==",
    Ordering::Greater => ">"
  };

  println!("a {} b", bin);
}


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


int main() {
  double L;
  cin >> L;
  cout << fixed << setprecision(10);
  double s;
  double t;
  t = 1;
  
  s = L / 3;
  for(int i = 0; i < 3; i++){
    t *= s;
  }
  
  cout << t;
  
  return 0;
}

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

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int n;
  cin>>n;
  int ans=0;
  vector<int> data(n);
  ff(i,0,n){
    cin>>data.at(i);
  }
  int pre;
  ff(i,0,n){
    ff(j,0,n){
      if(i==j){
        break;;
      }
      pre=data.at(i)*data.at(j);
      ans+=pre;
    }
  }
  cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
def fnSolv():
  input()
  s = input()
  sP = "0"
  iRet = 0
  for s0 in s:
    if s0 != sP:
      iRet += 1
    sP = s0
  print(iRet)
if __name__ == '__main__':
  fnSolv()

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

int main(){
    int S, W;
    cin >> S >> W;

    if (W >= S){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636