akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
	int n,sum;
	char str[1000];

	for( ; ; ){
		sum=1150;
		fgets(str,sizeof(str),stdin);
		sscanf(str,"%d",&n);
		if(n==-1) break;
		if(n>30){sum += (n - 30)*160; n = 30;}
		if(n>20){sum += (n - 20)*140; n = 20;}
		if(n>10) sum += (n - 10)*125;
		printf("%d\n",4280-sum); 
	} 
	return 0;
}			

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;;

int main() {
  int n, m;  cin >> n >> m;
  vector<int> r(n, INF);
  for(int i=0; i<m; i++){
    int a, b;  cin >> a >> b;
    --a; --b;  // 0 <= i < n  の区間に正規化
    r[a] = min(r[a], b);  // aからスタートする点の中で一番先にゴールする点を格納
  }

  int x = INF, ans = 0;
  for(int i=0; i<n; i++){
    if (x == i) x = INF, ans++;  // 下で格納した点が来て、ゴールになった場合リセットしてまた一番近いゴールを格納し始める
    x = min(x, r[i]);  // iからスタートする点があれば、その中で一番先にゴールするときの点を格納してる
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3764
package main

import "fmt"

func main() {
	var a, b, c, d, e, k int
	fmt.Scan(&a, &b, &c, &d, &e, &k)

	if e-a <= k && d-a <= k && c-a <= k && b-a <= k {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
#define pw(x) (1LL<<(x))
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to kth largest, order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define NEWL EVAL({cout << '\n';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 3;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
#define DIE EVAL({cout << -1 << '\n'; exit(0);})
//------------------------------------------------------------------------------------------------------

const int N = 1e5 + 10;

string s[2];
int pref[2][N];

void compute_pre() {
    REP(which, 2) {
        pref[which][0] = (s[which][0] == 'A' ? 1 : 2);
        FOR(i, 1, s[which].size()) {
            pref[which][i] = msum(pref[which][i-1], (s[which][i] == 'A' ? 1 : 2));
        }
    }
}

int getsum(int l, int r, int which) {
    int ret = pref[which][r];
    if(l > 0) {
        ret = mdif(ret, pref[which][l-1]);
    }
    return ret;
}

int main() {
    cin >> s[0] >> s[1];
    compute_pre();
    int q; cin >> q;
    while(q--) {
        int ls, rs, lt, rt;
        cin >> ls >> rs >> lt >> rt;
        ls--, rs--, lt--, rt--;
        cout << (getsum(ls, rs, 0) == getsum(lt, rt, 1) ? "YES\n" : "NO\n");
    }
}






























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

using namespace std;

void failure () {
  cout << "IMPOSSIBLE" << endl;
  exit(0);
}

const int MAX_N = 1e3 + 5;
const int MAX_X = 5e3 + 5;

vector<int> adj [MAX_N];
int cap [MAX_N];
int dp [MAX_N];

int knap [MAX_X];

void dfs (int u) {
  for (int nxt : adj[u]) {
    dfs(nxt);
  }

  int bothw = 0;
  int minw = 0;
  vector<int> switches;
  for (int nxt : adj[u]) {
    bothw += dp[nxt];
    minw += min(dp[nxt] - cap[nxt], cap[nxt]);
    switches.push_back(max(dp[nxt] - cap[nxt], cap[nxt]) -
                       min(dp[nxt] - cap[nxt], cap[nxt]));
  }

  if (minw > cap[u]) {
    failure();
  }

  for (int i = 0; i <= cap[u]; i++) {
    knap[i] = 0;
  }

  knap[minw] = 1;
  for (int p : switches) {
    for (int i = cap[u] - p; i >= 0; i--) {
      if (knap[i]) knap[i + p] = 1;
    }
  }

  int ans = bothw - minw;
  for (int i = 0; i <= cap[u]; i++) {
    if (knap[i]) {
      ans = bothw - i;
    }
  }

  dp[u] = cap[u] + ans;
}

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;

    adj[p].push_back(i);
  }

  for (int i = 1; i <= n; i++) {
    cin >> cap[i];
  }
  
  dfs(1);

  cout << "POSSIBLE" << endl;
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
//gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T> //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) //最大値更新 返り値はbool
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) //最小値更新 返り値はbool
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

    int n, cnt = 0, ans = 0;
    cin >> n;
    vector<int> x(n);

    rep(i, 0, n)
    {
        cin >> x[i];
        if (x[i] < 0)
            ++cnt;
    }

    if (cnt % 2 == 0)
    {
        arep(i, x)
        {
            ans += abs(i);
        }
        cout << ans << '\n';
    }
    else
    {
        cnt = INF;
        arep(i, x)
        {
            ans += abs(i);
            chmin(cnt, abs(i));
        }
        cnt = 2 * cnt;
        cout << ans - cnt << '\n';
    }

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
using namespace std;

const int N = 1e6 + 5;
int fl[N];
int n;
void seive() {
	for (int i = 1000003; i >= 2; i--) {
		for (int j = 2 * i; j <= 1000003; j = j + i) {
			fl[j] = i;
		}
	}
}

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

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

	int g = a[0];
	for (int i = 1; i < n; i++) {
		g = __gcd(g, a[i]);
	}

	seive();
	//for (int i = 2; i <= 100; i++) {
	//	cout << i << " " << fl[i] << '\n';
	//}
	set<int> st;
	set<int> :: iterator itr;
	int fg = 0;
	for (int i = 0; i < n; i++) {
		set<int> st1;
		st1.clear();
		if (a[i] == 1) continue;
		while (true) {
			if (fl[a[i]] == 0) { //cout << a[i] << " ";
				st1.insert(a[i]);
				break;
			}
			else {
				st1.insert(fl[a[i]]); //cout << fl[a[i]] << " ";
				a[i] = a[i] / fl[a[i]];
			}
		}

		for (itr = st1.begin(); itr != st1.end(); itr++) {
			if (st.find(*itr) != st.end()) {
				fg = 1;
				break;
			}
			else {
				st.insert(*itr);
			}
		}
		//cout << '\n';
	}
	
	if (fg == 0) {
		cout << "pairwise coprime\n";
	}
	else if (g == 1) {
		cout << "setwise coprime\n";
	}
	else {
		cout << "not coprime\n";
	}


	

}

Measured memory_bytes: 14636
#pragma gcc optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define pb(n) push_back(n)
#define endl '\n'
#define P(x)  cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, count = 0; string s; char c; bool flg;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  IN(s);
  s[3] = '8';
  OUT(s);
}


Measured memory_bytes: 256
a = []
cnt = 0
for i in 0..4
  a[i] = gets.to_i
  if a[i] % 10 == 0
    cnt += 1
  end
end
a.sort!{|a, b| b % 10 <=> a % 10}
time = 0
for i in 0..4
  if i == 5-cnt-1 || a[i] % 10 == 0
    time += a[i]
  else
    time += (a[i] / 10 + 1) * 10
  end
end
puts time

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n,m;
ll x[100010];

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

  cin>>n>>m;
  rep(i,m)cin>>x[i];
  sort(x,x+m);

  vector<ll> d;
  rep(i,m-1){
    d.push_back(x[i+1]-x[i]);
  }
  sort(all(d));

  ll res=0;
  rep(i,m-n)res+=d[i];
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	cin >>n;
	printf("%d:",n);
	int cnt=1;
	while(n!=1){
		for(cnt=2;cnt<=sqrt(n);cnt++){
			if(n%cnt==0){
				printf(" %d",cnt);
				n/=cnt;
				break;
			}
		}
		if(cnt>sqrt(n)){
			printf(" %d\n",n);
			n=1;
		}
	}
}


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

#define REP(i,n) for(long long 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)

using ll = long long;
#define INF 1e9

int H, W;
vector<vector<int>> a;
vector<pair<int, int>> ans;
int main(){
  cin >> H >> W;
  a.resize(H, vector<int>(W));
  REP(i, H){
    REP(j, W){
      cin >> a[i][j];
    }
  }
  REP(i, H){
    if(i % 2){
      REPR(j, W-1){
        if(i == H-1 && j == 0) continue;
        if(a[i][j] % 2){
          ans.push_back(make_pair(i+1, j+1));
          if(j != 0){
            a[i][j-1]++;
            ans.push_back(make_pair(i+1, j));
          }
          else{
            ans.push_back(make_pair(i+2, j+1));
            a[i+1][j]++;
          }
        }
      }
    }
    else{
      REP(j, W){
        if(i == H-1 && j == W-1) continue;
        if(a[i][j] % 2){
          ans.push_back(make_pair(i+1, j+1));
          if(j != W-1){
            a[i][j+1]++;
            ans.push_back(make_pair(i+1, j+2));
          }
          else{
            a[i+1][j]++;
            ans.push_back(make_pair(i+2, j+1));
          }
        }
      }
    }
  }
  cout << ans.size()/2 << endl;
  REP(i, ans.size()){
    if(i % 2){
      cout << ans[i].first << " " << ans[i].second << endl;
    }
    else{
      cout << ans[i].first << " " << ans[i].second << " ";
    }
  }
  return 0;
}


Measured memory_bytes: 5232
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	int n,m;
	cin >> n >> m;
	map<int,int> mi;
	rep(i,m){
		int a,b;
		cin >> a >> b;
		mi[a]++;
		mi[b]++;
	}
	rep(i,n){
		P(mi[i+1]);
	}
}

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


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        long sum = 0;
        int num = 1;
        while(count != n){
            if(num%3==0&&num%5==0){

            }else if(num%5==0){

            }else if(num%3==0){

            }else{
                sum += num;
            }
            num++;
            count++;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 35788
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define dump(ary) for (auto &a : ary) cout << a << ' '; cout << endl
int divup(int x, int y) {
    if (x < 0 || y <= 0) return 0;
    return (x + y - 1) / y;
}
int main() {
    int N; cin >> N;
    vector<int> A(N), B(N);
    for (auto &a : A) cin >> a;
    for (auto &b : B) cin >> b;
    Int ans = 0;
    stack<int> S;
    auto check = [&](int i) {
        int& prev = B[(i-1+N)%N];
        int& curr = B[i];
        int& next = B[(i+1)%N];
        if (curr > A[i] && prev < curr && curr > next) {
            S.push(i);
        }
    };
    for (int i = 0; i < N; i++) {
        check(i);
    }
    while (!S.empty()) {
        int i = S.top();
        S.pop();
        int& prev = B[(i-1+N)%N];
        int& curr = B[i];
        int& next = B[(i+1)%N];
        int k = divup(curr - max({prev, next, A[i]}), prev + next);
        curr -= k * (prev + next);
        ans += k;
        if (curr < A[i]) {
            ans = -1;
            break;
        }
        check((i+1)%N);
        check(i);
        check((i-1+N)%N);
    }
    if (A == B) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

#n = int(input)
#h,w = [int(i) for i in readline().split()]
#n,*w = [int(i) for i in read().split()]

n = int(input())

res = []
for i in range(n):
    x,l = [int(i) for i in readline().split()]
    res.append((x-l,x+l))

from operator import itemgetter
res.sort(key=itemgetter(1))

#print(res)

ans = 0
now = res[0][0] - 10
for l,r in res:
    if now <= l:
        ans += 1
        now = r
    

print(ans)








Measured memory_bytes: 18300
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.nextLine());
    int B = Integer.parseInt(sc.nextLine());
    int C = Integer.parseInt(sc.nextLine());
    int X = Integer.parseInt(sc.nextLine());
    
    int ans = 0;
    for(int i = 0; i <= A; i++){
      for(int j = 0; j <= B; j++){
        for(int k = 0; k <= C; k++){
          if(i*500 + j*100 + k*50 == X){
            ans++;
          }
        }
      }
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define f first
#define int long long
#define pb push_back

int dp[3005][3005];
string s, t;


int cal_seq(int index_1, int index_2) {

       if (index_1 <= 0 || index_2 <= 0 )     return 0;

       if (dp[index_1][index_2] != -1)       return dp[index_1][index_2];

       if (s[index_1 - 1] == t[index_2 - 1])
              dp[index_1][index_2] = max(dp[index_1][index_2], 1 + cal_seq(index_1 - 1, index_2 - 1));

       else dp[index_1][index_2] = max(cal_seq(index_1 - 1 , index_2), cal_seq(index_1, index_2 - 1));
       return dp[index_1][index_2];

}

void solve() {
       cin >> s >> t;
       memset(dp, -1, sizeof(dp));
       cal_seq(s.length(), t.length());
       vector<char> ans;
       int index_1 = s.length(), index_2 = t.length();

       while (index_1 >= 0 && index_2 >= 0) {
              if (index_1 == 0 || index_2 == 0)  break;
              if (s[index_1 - 1] == t[index_2 - 1])  ans.pb(s[index_1 - 1]), index_1--, index_2--;
              else if (dp[index_1 - 1][index_2] >= dp[index_1][index_2 - 1])      index_1--;
              else index_2--;
       }
       reverse(ans.begin(), ans.end());
       for (auto i : ans)      cout << i;
}




signed main()
{
#ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("o.txt", "w", stdout);
#endif

       solve();
}

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

int main() {
  int D, N, S = 1;
  cin >> D >> N;
  for(int i=0; i<D; ++i) S *= 100;
  if(N <= 99) cout << S*N << endl;
  else cout << S*101 << endl;
  return 0;
}

Measured memory_bytes: 256
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

a,b=map(int,input().split())
ans=0
for i in range(a,b+1):
    s=str(i)
    for j in range(len(s)//2):
        if s[j]!=s[-1-j]:
            break
    else:
        ans+=1
print(ans)

Measured memory_bytes: 74500
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int Q=sc.nextInt();
		UnionFind uft=new UnionFind(N);
		for(int i=0; i<Q; i++) {
			int com=sc.nextInt();
			int x=sc.nextInt();
			int y=sc.nextInt();
			if(com==0) {
				uft.union(x,y);
			}
			else {
				if(uft.same(x,y)) {
					pl(1);
				}
				else {
					pl(0);
				}
			}
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	public static class UnionFind{
		int[] par; //

		public UnionFind(int n){
			par = new int[n];
			for(int i = 0; i < n; i++){ par[i] = -1; }
		}

		public int find(int x){
			if(par[x] < 0){
				return x;
			}else{
				return par[x] = find(par[x]);
			}
		}

		public boolean union(int x, int y){
			x = find(x);
			y = find(y);

			if(x != y){
				if(par[y] < par[x]) {  // 多い方が根になるようにスワップする.
					int tmp = x; x = y; y = tmp;
				}
				par[x] += par[y];
				par[y] = x;
				return true;
			}else{
				return false;
			}
		}

		public boolean same(int x, int y){
			return find(x) == find(y);
		}

		public int size(int x){
			return -par[find(x)];
		}
	}
}


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

int main(){
double n;
cin>>n;
ll ans=10000000000000;
for (int i = 1; i <= sqrt(n); i++)
{
  /* code */
  if (fmod(n,i)==0)
  {
    /* code */
    ll ans2=i+n/i-2;
  ans=min(ans,ans2);
  }
  
  

}
cout<<ans<<endl;



}

Measured memory_bytes: 256
#include<stdio.h>
int a[100001],b[100001];
int ans;
int max(int x,int y){
	if(x>y)return x;
	return y;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int v;
		scanf("%d",&v);
		if(i%2==0)a[v]++;
		else b[v]++;
	}
	int a1=0,a2=0,b1=0,b2=0;
	for(int i=1;i<=100000;i++){
		if(a[a1]<a[i]){
			a2=a1;
			a1=i;
		}
		else if(a[a2]<a[i])a2=i;
		if(b[b1]<b[i]){
			b2=b1;
			b1=i;
		}
		else if(b[b2]<b[i])b2=i;
	}
	if(a1==b1)ans=n-max(a[a1]+b[b2],a[a2]+b[b1]);
	else ans=n-(a[a1]+b[b1]);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2516
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using V = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 10e9+7LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

vector<ll> dp[13];

void solve()
{
    IN(k);
    reps(i, 1, 10)
    {
        dp[0].push_back(i);
    }
    reps(i, 1, 12)
    {
        for (auto x : dp[i-1])
        {
            if (x % 10 == 0)
            {
                dp[i].push_back(x * 10);
                dp[i].push_back(x * 10 + 1);
            }
            else if (x % 10 == 9)
            {
                dp[i].push_back(x * 10 + 8);
                dp[i].push_back(x * 10 + 9);
            }
            else
            {
                dp[i].push_back(x * 10 + x % 10 - 1);
                dp[i].push_back(x * 10 + x % 10);
                dp[i].push_back(x * 10 + x % 10 + 1);
            }
        }
    }
    vector<ll> v;
    rep(i, 12)
    {
        for (auto x : dp[i])
        {
            v.push_back(x);
        }
    }
    sort(all(v));
    cout << v[k-1] << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 42788
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


bool same(string s,string w){
    assert(s.size()==w.size());
    vector<ll> count(30,0);
    for(int i=0;i<s.size();i++){
        count[s[i]-'a']++;
        count[w[i]-'a']--;
    }
    for(int i=0;i<30;i++){
        if(count[i]!=0){return false;}
    }
    return true;
}



int main(){
    ll h,w;
    cin>>h>>w;
    vector<string> S;
    for(int i=0;i<h;i++){
        string s;
        cin>>s;
        S.push_back(s);
    }
    bool j=true;
    bool used=h%2;
    used=!used;
    for(int i=0;i<h/2;i++){
        bool done=false;
        for(int t=i+1;t<h;t++){
            if(same(S[i],S[t])){swap(S[h-1-i],S[t]); done=true; break;}
        }
        if(!done){
            if(!used){
                swap(S[h/2],S[i]);
                used=true;
                i--;
            }
            else{
                j=false;
                break;
            }
        }
    }
    used=w%2;
    used=!used;
    vector<string> T(w);
    for(int i=0;i<h;i++){
        for(int t=0;t<w;t++){
            T[t].push_back(S[i][t]);
        }
    }
    for(int i=0;i<w/2;i++){
        bool done=false;
        for(int t=i+1;t<w;t++){
            if(same(T[i],T[t])){swap(T[w-1-i],T[t]); done=true; break;}
        }
        if(!done){
            if(!used){
                swap(T[w/2],T[i]);
                used=true;
                i--;
            }
            else{
                j=false;
                break;
            }
        }
    }
    j=true;
    for(int i=0;i<w;i++){
        //cout<<T[i]<<endl;
        for(int t=0;t<h;t++){
            if(T[i][t]!=T[w-1-i][h-1-t]){j=false;}
        }
    }
    cout<<(j?"YES":"NO")<<endl;
    
    
    return 0;
}

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

int main(){
    int a, b, c, tmp;
    cin >> a >> b >> c;
    
    if (a > b){
        tmp = a;
        a = b;
        b = tmp;
    }
    if (b > c){
        tmp = b;
        b = c;
        c = tmp;
    }
    if (c > a){
        tmp = c;
        c = a;
        a = tmp;
    }
    cout << a*10 + b + c << endl;
}


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

int main(void){
  
    int N,A;
    cin >> N;
    vector<vector<int>> vv(N);
    for(int i=0;i<N-1;i++){
        cin >> A;
        vv[A-1].push_back(i+1);
    }
    
    for(int i=0;i<N;i++){
        cout << vv[i].size() << endl;
    }
}

Measured memory_bytes: 14316
// AtCoder Regular Contest 078
// C - Splitting Pile

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;


const int MAX_N = 200000;
const ll INF = (ll)1e17;

int N;
ll a[MAX_N];

int main() {

    ll sum, tmp, ans;

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

    tmp = a[0];
    ans = abs(tmp - (sum - tmp));
    for (int i = 1; i < N - 1; i++) {
        tmp += a[i];
        ans = min(ans, abs(tmp - (sum - tmp)));
    }

    cout << ans << endl;

    return 0;

}





Measured memory_bytes: 1792
<?php

fscanf(STDIN,"%d %d",$n,$d);

$result=0;
for($i=0;$i<$n;$i++){
    fscanf(STDIN,"%d %d",$x,$y);
    $D = sqrt($x*$x+$y*$y);
    if($D<=$d){
        $result++;
    }
}

echo $result."\n";



Measured memory_bytes: 16220
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int x,y,z;
    for (int n=1; n<=N; ++n) {
        int s=0;
        int m = sqrt(n);
        for (int x=1; x<=m; ++x) {
        for (int y=1; y<=m; ++y) {
        for (int z=1; z<=m; ++z) {
            if (x*x+y*y+z*z+x*y+y*z+z*x == n) {
                ++s;
            }
        }
        }
        }
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define pb push_back
using namespace std;	

const int N=205;
typedef long long int lint;


int main()
{
	int n;
	scanf("%d",&n);
	pair <int,int> d[n+5];
	for (int i = 0; i < n; ++i)
	{
		scanf("%d %d",&d[i].first,&d[i].second);
	}
	double sum=0;
	for (int i = 0; i < n; ++i)
	for (int j = i+1; j < n; ++j)
		sum += sqrt((d[i].first-d[j].first)*1ll*(d[i].first-d[j].first) + (d[i].second-d[j].second)*1ll*(d[i].second-d[j].second) ) ;
	printf("%.12lf",2*(n-1) * sum / (n * (n-1)));
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			int[] as = new int[N];
			int[] bs = new int[N];
			int[] cs = new int[N];
			
			for(int i = 0; i < N; i++) {
				as[i] = sc.nextInt() - 1;
			}
			for(int i = 0; i < N; i++) {
				bs[i] = sc.nextInt();
			}
			for(int i = 0; i < N - 1; i++) {
				cs[i] = sc.nextInt();
			}
			
			int score = bs[as[0]];
			for(int i = 1; i < N; i++) {
				final int prev = as[i - 1];
				final int curr = as[i];
				
				score += bs[curr] + (prev + 1 == curr ? cs[prev] : 0);
			}
			
			System.out.println(score);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>



typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())


template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;
const ll inf=1001002003004005006;



int main(){
    int n; ll sum=0;
    cin>>n;
    vector<int> v(n);
    rep(i,n){
        int a;
        cin>>a;
        v[i]=a;
        sum+=a;
    }
    //cout<<sum;
    ll tmp=0;
    ll ans=inf;
    for(int i=0;i<n-1;i++){
        tmp+=v[i];
        ans=min(ans,abs(sum-tmp*2));
    }
    cout<<ans;
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

int main(){

  int i,X,Y,Z;
  string S,T,U;
  
  //cin>>S>>T;
  cin>>X>>Y>>Z;
  //cin>>U;

  //  cout<<S<<endl;
  
  cout<<Z<<' '<<X<<' '<<Y<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    if(S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
N,K = map(int,input().split())
td = [tuple(map(int,input().split())) for i in range(N)]

td = [(x[0]-1,x[1]) for x in td]
td.sort(key=lambda x:-x[1])

t = [-1]*N
for i in range(N):
    t[td[i][0]] = 0
tdK = td[:K]
for i in range(K):
    t[tdK[i][0]] = 1

t_used = [i for i in range(N) if t[i]==1]
t_not_used = [i for i in range(N) if t[i]==0]

d_top = [0]*N
d_top_candi = [0]*N
d_rest = []
d_candi = []

for i in range(K):
    if d_top[td[i][0]] == 0:
        d_top[td[i][0]] = td[i][1]
    else:
        d_rest.append(td[i][1])
for i in range(K,N):
    if t[td[i][0]] == 0:
        if d_top_candi[td[i][0]] == 0:
            d_top_candi[td[i][0]] = 1
            d_candi.append(td[i][1])
l = len(t_used)
s = sum(d_top)
d_rest.sort()
d_candi.sort(key=lambda x:-x)

d_rest_cum = list(accumulate(d_rest))
d_candi_cum = list(accumulate(d_candi))

if len(d_rest) == 0:
    print(l**2 + s)
else:
    s += d_rest_cum[-1]
    ans = l**2 + s
    for k in range(min(len(d_rest),len(d_candi))):
        ans = max((l+k+1)**2 + s + d_candi_cum[k] - d_rest_cum[k],ans)

    print(ans)

Measured memory_bytes: 77272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	string s; cin >> s;
	deque<char> d;
	for (auto &e : s)
		d.push_back(e);

	ll res{0};
	while (d.size() > 1)
	{
		char f = d.front();
		char b = d.back();

		if (f == 'x' && b != 'x')
		{
			++res;
			d.push_back('x');
		}
		else if (f != 'x' && b == 'x')
		{
			++res;
			d.push_front('x');
		}

		f = d.front();
		b = d.back();
		if (f == b)
		{
			d.pop_front();
			d.pop_back();
		}
		else
		{
			res = -1;
			break;
		}
	}

	std::cout << res << std::endl;
}

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

int main(){
    int N;
    cin>>N;
    
    vector<int> A(N);
    int x=0;
    rep(i,N){
        int a;
        cin>>a;
        A[i]=a;
        x^=a;
    }
    
    rep(i,N)cout<<(x^A[i])<<endl;
}

Measured memory_bytes: 4048
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		System.out.println((Integer.parseInt(s[0]) - 1) * (Integer.parseInt(s[1]) - 1));
	}
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define ll long long
#define M 1000000007
#define mp make_pair
#define pb push_back
#define p(k) printf("%d ",k)
#define pl(k) printf("%lld ",k)
#define pn(k) printf("%d\n",k)
#define pln(k) printf("%lld\n",k)
#define ps(str) printf("%s",str)
#define s(k) scanf("%d",&k)
#define sl(k) scanf("%lld",&k)
#define ss(str) scanf("%s",str)
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define ppi pair<int,int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ft first
#define sd second
#define count(x) __builtin_popcount(x)

using namespace std;

void test_case(){
	int n,i,j,mask;
	s(n);
	int a[n][n];
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			s(a[i][j]);
		}
	}
	vector<int>dp((1<<n)+5,0);
	dp[0] = 1;
	for(mask=1;mask<(1<<n);mask++){
		dp[mask] = 0;
		i = count(mask)-1;
		for(j=0;j<n;j++){
			if(mask & (1<<j) && a[i][j]==1){
				//~ p(dp[mask^(1<<j)]);pn(mask^(1<<j));
				dp[mask] = (dp[mask]+dp[mask^(1<<j)])%M;
			}
		}
		//~ pn(dp[mask]);
	}
	pn(dp[(1<<n)-1]);
	return ;
}
signed main(){
	int t;
	t = 1;
	//~ s(t);
	while(t--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 8448
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long int ll;
int N;
ll A[2000];
ll dp1[2000][2000];
ll dp2[2000][2000];
int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)scanf("%lld",&A[i]);
	for(int i=0;i<N;i++)dp1[i][0]=A[i];
	for(int j=1;j<N;j++){
	//from i to (i+j)&N
		if(j&1){
			for(int i=0;i<N;i++){
			//dp1[i][j-1]
				if(A[(i+N-1)%N]>A[(i+j)%N]){
					dp2[(i+N-1)%N][j]=max(dp1[i][j-1],dp2[(i+N-1)%N][j]);
				}
				else{
					dp2[i][j]=max(dp1[i][j-1],dp2[i][j]);
				}
			}
		}
		else{
			for(int i=0;i<N;i++){
			//dp2[i][j-1]
				dp1[i][j]=max(dp2[i][j-1]+A[(i+j)%N],dp1[i][j]);
				dp1[(i+N-1)%N][j]=max(dp2[i][j-1]+A[(i+N-1)%N],dp1[(i+N-1)%N][j]);
			}
		}
	}
	/*
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(i&1)printf("%lld ",dp2[j][i]);
			else printf("%lld ",dp1[j][i]);
		}
		printf("\n");
	}*/
	ll ans=0;
	for(int i=0;i<N;i++)ans=max(ans,dp1[i][N-1]);
	for(int i=0;i<N;i++)ans=max(ans,dp2[i][N-1]);
	printf("%lld\n",ans);
}

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

using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
//#define int int64_t
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = (int) (1e9) + 7;

int tc, q;
map<int, int> factorize(long long n)
{
    map<int, int> factors;
    int count = 0;

    while (!(n % 2)) {
        n >>= 1;
        count++;
    }

    if(count)factors[2] = count;

    for (long long i = 3; i <= sqrt(n); i += 2) {
        count = 0;
        while (n % i == 0) {
            count++;
            n = n / i;
        }
        if (count)
            factors[i] = count;
    }

    if (n > 2)
        factors[n] = 1;
    return factors;
}



void _() {
    ll n, m;
    cin >> n >> m;
    string s,t;
    cin >> s >>t;
    ll l = n*m/ __gcd(n, m);
    for (int i = 0; i < __gcd(n, m); ++i) {
        if(s[i*n/__gcd(n,m)] != t[i*m/__gcd(n,m)]){
            cout << -1 ;return;
        }
    }
    cout << l;

};

#undef int
int main() {
#if __MINGW32__
    freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Input.txt", "r", stdin);
    freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Output.txt", "w", stdout);

#endif

    _();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>

using namespace std;
int main(void){
    int a, b;
    cin >> a >> b;
    
    int d = a / b;
    int r = a % b;
    double f = (double)a / (double)b;
    
    cout << fixed;
    cout << d << " " << r << " " << setprecision(8) << f << endl;
    
    return 0;
}



Measured memory_bytes: 3288
integer(8) :: n,m,c,ans=0,p
integer(8),allocatable,dimension(:) :: B,A
read*,n,m,c
allocate(B(m),A(m))
read(*,*)(B(i),i=1,m)
do i = 1,n
    read(*,*)(A(j),j=1,m)
    p = sum(A*B) + c
    if(p>0)then
        ans = ans + 1
    endif
enddo
write(*,'(i0)')ans
end

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;

ll a[100005];
int main(){
	ll t;
    for(ll i=1;i<=5;i++){
    	ll j;
		cin>>j;
    	if(j==0)cout<<i;
	}
    	
    
	
	
	
	
    
}

Measured memory_bytes: 3644
import java.util.*;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String args[]) {

        int a = sc.nextInt();
        int b = sc.nextInt();

        int ans = 0;
        if (a==b) ans = 2 * a;
        else ans = 2 * (a > b ? a : b) -1;

        System.out.println(ans);

    }

}


Measured memory_bytes: 23764
X=int(input())

d5=[0]*(10001)
for i in range(10001):
    d5[i]=i**5


for i in range(10001):
    for j in range(10001):
        ans1=d5[i]-d5[j]
        if ans1==X:
            print(i,j)
            exit()
        ans2=d5[i]+d5[j]
        if ans2==X:
            print(i,(-1)*j)
            exit()

Measured memory_bytes: 9560
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
double w,h,x,y;
int main()
{
	cin>>w>>h>>x>>y;
	if(x==w/2&&y==h/2)
	{
		cout<<w*h/2<<" "<<1;
	}
	else
	{
		cout<<w*h/2<<" "<<0;
	}
}

Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)
	n, _ := nextInt()

	p1 := 0
	p2 := 0
	for i := 0; i < n; i++ {
		w1 := nextString()
		w2 := nextString()

		if w1 > w2 {
			p1 += 3
		} else if w1 == w2 {
			p1++
			p2++
		} else {
			p2 += 3
		}
	}
	fmt.Println(p1, p2)
}



Measured memory_bytes: 1092
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
const int maxx = 1005;
ll q, t, n, m, k, ans, a[maxn], b[maxn], f[maxx][maxx];
priority_queue<ll> pr;
string s, str;
char ss[maxx][maxx];
map<ll, ll> mp;
void sol()
{
    cin >> n;
    ll mx = 1e16;
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i];
    }
    for(int i = n - 1; i >= 0; i--)
    {
        for(int j = i; j >= 0; j --)
        {
            if(i == n - 1)f[i][j] = (j == 0 ? a[i] : 0);
            else
                f[i][j] = min(a[i] + f[i+1][a[i] > 100 ? j + 1 : j], j > 0 ? f[i+1][j-1] : mx);
        }
    }
    cout << f[0][0];
}
void test()
{
    cin >> n >> k >> s;
    t = 1;
    ans = 0;
    m = 0;
    s = " " + s;
    mp[0] = 1;
    for(int i = n; i > 0; i --)
    {
        m += (s[i] - '0') * t;
        //cout << t<<" ";
        m %= k;
        t *= 10;
        t %= k;
        ans += mp[m];
        ++mp[m];
    }
    if(k == 2 || k == 5)
    {
        ans = 0;
        for(int i = n; i > 0; i --)
        {
            if( (s[i] - '0') % k == 0)
            {
                ans += i;
            }
        }
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    test();
}


Measured memory_bytes: 1104
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
#define ms(a,b) memset(a,b,sizeof(a))

bool ma[55][55];
int n,m;
/*int dfs(int x)
{
    for(int i=1;i<=n;i++){
        if(ma[x][i] &&vis[i]==0){vis[i]=1;cnt++;dfs(i);}
    }
}
int solve(int x,int y)
{
    memset(vis,0,sizeof(int)*(n+1));
    ma[x][y]=0;
    ma[y][x]=0;
    vis[1]=1;cnt=1;
    dfs(1);
    ma[x][y]=1;
    ma[y][x]=1;
    if(cnt==n) return false;
    else return true;
}*/
bool solve()
{//判断图是否连通
    bool vis[55]={0};
    queue<int>q;
    q.push(1);
    int cnt=0;
    while(!q.empty()){
        int f=q.front();q.pop();
        if(vis[f]==1) continue;
        cnt++;
        vis[f]=1;
        for(int i=1;i<=n;i++){
            if(ma[f][i] && !vis[i]) q.push(i);
        }
    }
    if(cnt==n) return false;
    else return true;
}
int main()
{
    //ios::sync_with_stdio(0);cin.tie(0);
    int a[55],b[55];
    while(~scanf("%d%d",&n,&m)){
        memset(ma,0,sizeof(ma));
        for(int i=1;i<=m;i++){
            scanf("%d%d",&a[i],&b[i]);
            ma[a[i]][b[i]]=1;
            ma[b[i]][a[i]]=1;
        }
        int ans=0;
        for(int i=1;i<=m;i++){
            int x=a[i],y=b[i];
            ma[x][y]=0;ma[y][x]=0;
            if(solve()) ans++;
            ma[x][y]=1;ma[y][x]=1;
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

def calc_divisors(n):
  divisors = []
  for i in range(1, n//2+1):
    if n % i == 0:
      divisors.append(i)
  divisors.append(n)
  return divisors

res = 0
for i in range(1,N+1):
  if i == 1:
    continue
  if i % 2 == 0:
    continue
  divisors = calc_divisors(i)
  if len(divisors) == 8:
    res += 1
  
print(res)


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

int ctoi(char c){
  return c - '0';
}

int main(){
  string A, B;
  cin >> A >> B;
  int judge = 0;
  if(A.size() > B.size()) judge = 1;
  else if(A.size() < B.size()) judge = -1;
  else{
    int a = A.size();
    for(int i = 0; i < a; i++){
      if(ctoi(A.at(i)) > ctoi(B.at(i))){
        judge = 1;
        break;
      }
      else if(ctoi(A.at(i)) < ctoi(B.at(i))){
        judge = -1;
        break;
      }
    }
  }
    
  if(judge == 1) cout << "GREATER" << endl;
  else if(judge == 0) cout << "EQUAL" << endl;
  else cout << "LESS" << endl;
}

Measured memory_bytes: 256
N=int(input())
a=list(map(int, input().split()))
total=0
for i in range(1,N):
  add=abs(a[i]-a[i-1])
  total=total+add if a[i]<a[i-1] else total
  a[i]=a[i]+add if a[i]<a[i-1] else a[i]

print (total)

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

int main() {
  int r, g, b;
  cin >> r >> g >> b;

  if ((r * 100 + g * 10 + b) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256