akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
const int MAXN = 1e5 + 10;
 
int N, M;
int C[MAXN];
 
int main()
{
	cin >> N >> M;
	for(int i = 1; i <= M; i++)
	{
		int u, v;
		cin >> u >> v;
		C[u]++, C[v]++;
	}
 
	for(int i = 1; i <= N; i++)
		if(C[i] & 1)
		{
			cout << "NO" << endl;
			return 0;
		}
 
	cout << "YES" << endl ;
 
	return 0;
}
 

Measured memory_bytes: 640
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1001001001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}



int main() {
    int N;cin >> N;
    int K;cin >>K;
    vector<int> retu(N);
    int ans = 0;
    for(int i = 0;i<N;i++) cin >> retu.at(i);
    for(int i = 0;i<N;i++){
        ans += min(abs(retu.at(i)-0),abs(retu.at(i)-K))*2;
    }
    cout << ans << endl;
    // PLEASE GIVE ME THE "ACCEPTED" !
}

Measured memory_bytes: 256
EPS = 0.0001
while True:
    try:
        a = list(map(float, input().split()))
        dd = a[0]*a[4]-a[3]*a[1]
        d1 = a[2]*a[4]-a[5]*a[1]
        d2 = a[0]*a[5]-a[3]*a[2]
        print("{0:.3f} {1:.3f}".format(d1/dd+EPS, d2/dd+EPS))
    except EOFError:
        break



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

int sx, sy, tx, ty;
int main()
{
	int i;
	cin >> sx >> sy >> tx >> ty;
	for (i = 0; i < ty - sy; i++) printf("U");
	for (i = 0; i < tx - sx; i++) printf("R");
	for (i = 0; i < ty - sy; i++) printf("D");
	for (i = 0; i < tx - sx; i++) printf("L");
	printf("L");
	for (i = 0; i <= ty - sy; i++) printf("U");
	for (i = 0; i <= tx - sx; i++) printf("R");
	printf("DR");
	for (i = 0; i <= ty - sy; i++) printf("D");
	for (i = 0; i <= tx - sx; i++) printf("L");
	printf("U\n");
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    s, t = gete(), gete()

    ans = 0
    for i in range(len(s)):
        if s[i] != t[i]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9684
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let sum = input
        .split_whitespace()
        .map(|s| s.parse::<i32>().unwrap())
        .sum::<i32>();
    let ans = if sum >= 22 { "bust" } else { "win" };
    println!("{}", ans);
}


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

int main(){
   int s,w;
   cin >> s >> w;
   if(w>=s) cout << "unsafe" << endl;
   else  cout << "safe" << endl;
   return 0;  
}

Measured memory_bytes: 3632
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

long long s;

int main() {

	scanf("%lld", &s);

	long long x1 = 0;
	long long y1 = 0;
	long long x2 = (long long) 1e9;
	long long y2 = 1;
	long long x3 = -1;
	long long y3 = -1;

	if (s % x2 == 0) {
		y3 = s / x2;
		x3 = 0;
	} else {
		y3 = s / x2 + 1;
		x3 = x2 * y3 - s;
	}

	long long area = x1 * y2 + x2 * y3 + x3 * y1 - y1 * x2 - y2 * x3 - y3 * x1;

	printf("%lld %lld %lld %lld %lld %lld\n", x1, y1, x2, y2, x3, y3);

	return 0;

}

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

long long int ar[100005];
int n,k;
long long int dp[100005];

long long int solve(int x){
    if(x >= n-1)
        return 0;
    if(dp[x] != INT_MAX)
        return dp[x];
    for(int j=1;j<=k;j++)
        dp[x] = min( dp[x] , (abs(ar[x+j]-ar[x]) + solve(x+j)));
    return dp[x];
}

int main(){
    cin >> n >> k;
    for(int i=0;i<100005;i++)
        dp[i] = INT_MAX;
    for(int i=0;i<n;i++)
        cin >> ar[i];
    for(int i=n;i<=n+k;i++)
        ar[i] = INT_MAX;
    cout << solve(0) << endl;
}


Measured memory_bytes: 6528
#include<stdio.h>
#include<iostream>
#include<bitset>
#include<vector>

///using namespace std;


int main(void) {
	int x;
	std::cin >> x;

	if (x < 1200)
		std::cout << "ABC" << std::endl;
	else
		std::cout << "ARC" << std::endl;

	system("pause");
}



Measured memory_bytes: 504
#include <iostream>
#include <cstdlib>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <cstdio>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define irep(i, a) for (int i = 1; i <= a; i++)
#define mp make_pair
#define pb push_back
#define P pair<int, int>
#define ll long long

int n,k;

int main()
{
  cin>>n>>k;
  cout<<n-k+1<<endl;


    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; string S; cin >> N >> S;
    for (int i = 0; i < N; ++i) {
        string T = S.substr(0, i + 1);
        T += T;
        if (S == T) {
            printf("%s\n", "Yes");
            break;
        }
        if (i == N - 1) printf("%s\n", "No");
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long 
#define lli long long int
#define vpl vector < pair < ll,ll > >
#define vll vector < ll >
#define pll pair <ll,ll>
#define mll map< ll,ll >
#define ins insert
#define mkp make_pair
#define pb push_back
#define beg() begin()
#define  fi first
#define sec second
#define rev(s) reverse(s.begin(), s.end())
#define srt(v) sort(v.begin(),v.end())
#define mem(a,b) memset(a,b,sizeof(a))
#define cn(a) cout<<a<<"\n"
#define cp(a) cout<<a
#define cs(a) cout<<a<<" "
#define fr(a,n,i) for(ll i=a; i<n; i++ )
#define frn(a,n,i) for(ll i=a; i>=n; i--)
#define fre(a,n,i) for(ll i=a; i<=n; i++)

using namespace std;
ll mod=1e9 +7;
bool comp(pll p,pll q)
{
    if(p.first!=q.first)
    return p.first<q.first;
    else
    return p.second>q.second;
}
ll power(ll a,ll n)
{
	ll res=1;
 
	while(n){
		if(n%2)
		res=(res*a);
		a=(a*a);
		n/=2;
	}
  return res;
}

void dfs(ll i, vll ad[],ll c,vll &d, ll v[], map <pll,vll> &m)
{
    v[i]=1;
  // cs(i);
    fr(0,ad[i].size(),j)
     {  //cs(ad[i][j]);
     if(find(m[{i,ad[i][j]}].begin(),m[{i,ad[i][j]}].end(),c)!=m[{i,ad[i][j]}].end())
     {
     d[ad[i][j]]=1;
     if(!v[ad[i][j]])
     dfs(ad[i][j],ad,c,d,v,m);
     }
    
   
      }
}

int32_t main()
{
    fast;
   ll n,c,k,ans=0;
   cin>>n>>c>>k;
   ll a[n];
   fr(0,n,i)
  cin>>a[i];
  
  sort(a,a+n);
  
  fr(0,n,i)
  { ll x=a[i],cn=0;
      while(i<n && a[i]<=x+k && cn<c)
      {
          i++; cn++;
      }
      i--;
      
      
      ans++;
      
  }
  
   cp(ans);
   

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define ind(a) scanf("%d", &a)
#define inlld(a) scanf("%lld", &a)
#define ind2(a, b) scanf("%d%d", &a, &b)
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
#define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

using namespace std;

const int N=2e5+5;
const int MOD=1e9+7;

typedef long long ll;
typedef long double ld;

ll n, height[N], value[N], bit[N];

void upd(ll x, ll val)
{
    for(;x<=n; x+=x&-x)
        bit[x]=max(bit[x], val);
}

ll query(ll x)
{
    ll ret=0;
    for(; x>=1; x-=x&-x)
        ret=max(ret, bit[x]);
    return ret;
}

int main() 
{
    inlld(n);
    for(ll a=1; a<=n; a++)
        inlld(height[a]);
    for(ll a=1; a<=n; a++)
        inlld(value[a]);
    ll ans=0;
    for(ll a=1; a<=n; a++)
    {
        ll maxi_here=query(height[a]);
        ans=max(ans, maxi_here+value[a]);
        upd(height[a], maxi_here+value[a]);
    }
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  int H,N;cin>>H>>N;
  vi A(N),B(N);
  rep(i,N)cin>>A[i]>>B[i];
  vvi dp(1001,vi(20001));
  rep(i,N+1){
    rep(j,20001){
      dp[i][j] = 100000001;
    }
  }
  rep(i,N+1)dp[i][0]=0;
  rep(i,N){
    rep(j,20001){
      if(j<A[i])dp[i+1][j]=dp[i][j];
      else dp[i+1][j]=min(dp[i][j],dp[i+1][j-A[i]]+B[i]);
    }
  }
  int ans=100000001;
  for(int i=H;i<H+10000;i++ ){
    ans =min(dp[N][i],ans);
  }
  cout<<ans<<endl;
}





Measured memory_bytes: 81664
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    ll x, y;
    cin >> x >> y;
    if(x % y == 0)cout << -1 << endl;
    else cout << x << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;
u64 over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int a, b;
  cin >> a >> b;
  cout << (a-1)*(b-1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<limits.h>
using namespace std;

typedef long long LL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN=2e5+10;
LL a[57]={2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776,2199023255552,4398046511104,8796093022208,17592186044416,35184372088832,70368744177664,140737488355328,281474976710656,562949953421312,1125899906842624,2251799813685248,4503599627370496,9007199254740992,18014398509481984,36028797018963968,72057594037927936,144115188075855872};

LL find(LL h){
    for(int i=0;i<56;++i){
        if(h<a[i])
            return a[i]-1;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    LL h;
    cin>>h;
    cout<<find(h)<<endl;
    return 0;
}


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

typedef long long int64;

int main(void) {
  int n;
  std::cin >> n;
  int x = n >> 1;
  std::cout << std::fixed << std::setprecision(10) << 1.0 - (double)(x) / n << std::endl;
  return 0;
}


Measured memory_bytes: 256
#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 ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=105;
bitset<N*N> dp;
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,x;
  cin>>n;
  dp.reset();
  dp.set(0);
  rep(i,1,n+1)
    {
      cin>>x;
      dp|=(dp<<x);
    }
  repv(i,1,N*N)
    if(dp.test(i) && i%10!=0)
      {
	cout<<i<<endl;
	return 0;
      }
  cout<<0<<endl;
  return 0 ;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<string>
#include<utility>
#include<iomanip>
#include<bitset>
#include<math.h>
using namespace std;
 
 
int main(){
 
	int n;
	cin >> n;
	string s;
	cin >> s;
	if(n < 3200){
		cout << "red" << endl;
	}else{
		cout << s << endl;
	}

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;
typedef long long ll; 

ll mod = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	vector<string> s(n);
	for(int i=0;i<n;i++){
		cin >> s[i];
		sort(s[i].begin(),s[i].end());
	}
	ll ans = 0;
	sort(s.begin(),s.end());
	map<string,int> m;
	for(int i=0;i<n;i++){
		if(m.count(s[i])){
			ans += m[s[i]];
			m[s[i]] += 1;
		}else{
			m[s[i]] = 1;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 13568
import  itertools as it

n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
cnt=[]
for i in range(1,n+1):
    cnt.append(i)
tmp=[]
for conbinations in it.permutations(cnt):
    tmp.append(list(conbinations))

print(abs(tmp.index(q)-tmp.index(p)))

Measured memory_bytes: 10228
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N=sc.nextInt();
    int num=0;
    for(int i=0; i<N; i++){
      int l=sc.nextInt(),r=sc.nextInt();
      num+=r-l+1;
    }
    System.out.println(num);
  }
}

Measured memory_bytes: 23656
L, R = [int(x) for x in input().split()]


res = 2018
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):

        tmp = (i * j) % 2019
        if tmp == 0:
            print(0)
            exit()
        if tmp < res:
            res = tmp

print(res)

Measured memory_bytes: 3060
// Problem : D - Built?
// Contest : AtCoder - AtCoder Beginner Contest 065
// URL : https://atcoder.jp/contests/abc065/tasks/arc076_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

vi dsu,sz;
void init_dsu(int n)
{
	incd(dsu,n+1);
	incd(sz,n+1);
	for(int i=0;i<=n;i++)
	dsu[i]=i,sz[i]=1;
}

int get_par(int x)
{
	if(dsu[x]==x) return x;
	return dsu[x]=get_par(dsu[x]);
}

void unite(int x,int y)
{
	int p1=get_par(x);
	int p2=get_par(y);
	if(p1!=p2)
	{
		sz[p1]+=sz[p2];
		dsu[p2]=p1;
	}
}

int MST(vector<pair<int,pii>> edges,int n)
{
	init_dsu(n+1);
	int cost=0;
	sort(all(edges));
	for(auto i:edges)
	{
		pii p=i.se;
		int x=get_par(p.f);
		int y=get_par(p.se);
		if(x!=y)
		{
			//cout<<x<<" "<<y<<" "<<i.f<<"\n";
			unite(x,y);
			cost+=i.f;
		}
	}
	return cost;
}

void solve()
{
int n;cin>>n;
vector<pair<int,pii>> edges;
vp v1,v2;
int point=1;
map<pii,int> mp;
for(int i=0;i<n;i++)
{
	int x,y;
	cin>>x>>y;
	if(mp.count({x,y}))continue;
	else
	{
		mp[{x,y}]=point++;
		v1.pb({x,point-1});
		v2.pb({y,point-1});
	}
}
sort(all(v1));
sort(all(v2));
for(int i=0;i<size(v1)-1;i++)
{
	edges.pb({v1[i+1].f-v1[i].f,{v1[i].se,v1[i+1].se}});
}
for(int i=0;i<size(v1)-1;i++)
{
	edges.pb({v2[i+1].f-v2[i].f,{v2[i].se,v2[i+1].se}});
}
cout<<MST(edges,point);
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 23736
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
#define rep(i, s, n) for(int i = s; i < n; i++)
#define ll long long 
long long N;

int ans = 0;

ll dfs(ll n, int three, int five, int seven) {
    if(N < n) {
        return 0;
    }
    else {
        if(three&&five&&seven) {
            ans += 1; 
        }
    }

    dfs(10*n+3, 1, five, seven);
    dfs(10*n+5, three, 1, seven);
    dfs(10*n+7, three, five, 1);
}

int main() {
    
    cin >> N;
    //count = 0;

    if(N < 357) {
        cout << 0 << endl;
        return 0;
    }

    dfs(0, 0, 0, 0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

LL t[11000000][3];

int main(){
	int n,m;
	LL i,j,k;
	LL a,b,c;
	const LL N=1e7;
	t[1][1]=1;
	for(i=2;i<=N;i++){
		if(t[i][0]==0){
			t[i][0]=i;
			t[i][1]=2,t[i][2]=1;
			for(j=i*i;j<=N;j+=i){
				if(t[j][0]==0)t[j][0]=i;
			}
		}else{
			a=t[i][0];
			if(t[i][0]==t[i/a][0]){
				t[i][2]=t[i/a][2]+1;
				b=t[i][2];
				t[i][1]=t[i/a][1]/b*(b+1);
			}else{
				t[i][2]=1;
				t[i][1]=t[i/a][1]*2;
			}
		}
	}
	cin>>n;
	a=0;
	for(i=1;i<=n;i++){
		a+=i*t[i][1];
	}
	cout<<a<<endl;
}

Measured memory_bytes: 238012
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int A;
    int B;
    int C;
    int N;
    
    cin >> A;
    cin >> B;

    if(A % (1 + 2 * B)==0)    cout << A / (1 + 2*B) << endl; 
    else cout << A / (1 + 2*B) + 1 << endl;    

}

Measured memory_bytes: 256
import java.util.Scanner;

 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s= in.next();
        String t= in.next();
        int s1=in.nextInt();
        int s2=in.nextInt();
        String u=in.next();
        if(u.equals(s)){
            s1--;

        }else{
            s2--;
        }
        System.out.println(s1 + " " + s2);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i < (n);++i)
typedef long long ll;
using namespace std;
 
int main(){
  int r;
  cin >> r;
  
  if(r<1200) cout << "ABC" << endl;
  else if(r<2800) cout <<"ARC" << endl;
  else cout << "AGC" << endl;
  
  return 0;
}


Measured memory_bytes: 256
N, H = map(int, input().split(' '))
a = []
b = []
for i in range(N):
    temp_a, temp_b = input().split(' ')
    a.append(int(temp_a))
    b.append(int(temp_b))
maxa = max(a)
c = [i for i in b if i > maxa]
sorted_b = sorted(b)[::-1]
i = 0
while(H > 0 and i != N):
    if maxa < sorted_b[i]:
        H -= sorted_b[i]
        i += 1
    else:
        break
left = 0
if H > 0:
    left = (H + maxa - 1) // maxa
print(i + left)


Measured memory_bytes: 13260
#include "bits/stdc++.h"
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/04  Problem: ABC 084 A / Link: http://arc084.contest.atcoder.jp/tasks/arc084_a  ----- */
/* ------問題------

今年もすぬけ祭の季節がやってきました。りんごさんは、まず手始めにすぬけ君召喚の儀式を執り行おうと思っています。 儀式には祭壇が必要で、祭壇は上部、中部、下部の
3 つのカテゴリーのパーツ1 つずつからなります。

祭壇の3 カテゴリーのパーツがそれぞれN 個ずつあります。
i 個目の上部のパーツのサイズはAi 、i 個目の中部のパーツのサイズはBi 、i 個目の下部のパーツのサイズはCi です。
祭壇を作るにあたっては、中部のパーツのサイズは上部のパーツのサイズより真に大きく、下部のパーツのサイズは中部のパーツのサイズより 真に大きくなければなりません。逆に、この条件を満たす任意の
3 つのピースを組み合わせて祭壇を作ることができます。

りんごさんが作ることのできる祭壇は何種類あるでしょうか。ただし、
2 つの祭壇が異なるとは、上部、中部、下部に使われるピースのうち 少なくとも1 つが異なることを言います。

-----問題ここまで----- */
/* -----解説等-----

真ん中からみればよい。
そうでなくて、K段あるときはDPをすればよい。
O(KNlogN)ぐらい。

----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VI a(N), b(N), c(N);
	FOR(i, 0, N)cin >> a[i];
	FOR(i, 0, N)cin >> b[i];
	FOR(i, 0, N)cin >> c[i];
	SORT(a);
	SORT(b);
	SORT(c);

	FOR(i, 0, N) {
		int anum = lower_bound(ALL(a), b[i]) - begin(a);
		int cnum = upper_bound(ALL(c), b[i]) - begin(c);
		if (anum >= 1 && cnum != N) {
			ans += anum*(N-cnum);
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define MOD 1000000007
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define OTP(s) cout<<s<<endl;
#define FOR(i,j,k,l) for(int i=j;i<k;i+=l)
#define REP(i,j) FOR(i,0,j,1)
inline ll add(ll a, ll b){a += b; if(a >= MOD)a -= MOD; return a;}
inline ll sub(ll a, ll b){a -= b; if(a < 0)a += MOD; return a;}
inline ll mul(ll a, ll b){return (ll)((ll) a * b %MOD);}
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

ll min(ll a,ll b)
{
    return a>b?b:a;
}
ll max(ll a,ll b)
{
    return a>b?a:b;
}

ll n,ar[300000];
int main()
{
    IOS 
    cin>>n;
    REP(i,n)
    {
        cin>>ar[i];
    }

    ll ind=1;
    REP(i,n)
    {
        if(ar[i]==ind)
        {
            ind++;
        }
    }
    if(ind==1)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<n-ind+1<<endl;
    }
    

}

Measured memory_bytes: 1792
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read2<T: std::str::FromStr>(n: i64) -> Vec<Vec<T>> {
    let mut v2 = Vec::new();
    for _ in 0..n {v2.push(read());}
    v2
}

fn main() {
    let t: Vec<i64> = read();
    let s: Vec<Vec<String>> = read2(t[0]);
    //let mut cards: Vec<(String, i64)> = s.iter().map(|si| {(si[0].clone(), si[1].parse().unwrap())}).collect();
    for suit in vec!["S", "H", "C", "D"] {
        for i in 1..14 {
            let mut has_card: bool = false;
            for si in &s {
                let si_num: i64 = si[1].parse().unwrap();
                if si[0] == suit && si_num == i {
                    has_card = true;
                    break;
                }
            }
            if !has_card {
                println!("{} {}", suit, i);
            }
        }
    }
}



Measured memory_bytes: 5028
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }
    
    sort(d.begin(), d.end());

    int ans = d[N/2] - d[N/2 - 1];

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

Measured memory_bytes: 640
number = int(input())
number_list = list(map(int, input().split()))

num = 0
for i in number_list:
    num += i

ex = num // number
cost_list = []

def cul(ex):
    cost = 0
    for i in number_list:
        cost += (ex - i)**2
    cost_list.append(cost)

cul(ex)
cul(ex+1)
cul(ex-1)

print(min(cost_list))


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n>=400&&n<=599)cout<<'8';
    else if(n>=600&&n<=799)cout<<'7';
    else if(n>=800&&n<=999)cout<<'6';
    else if(n>=1000&&n<=1199)cout<<'5';
    else if(n>=1200&&n<=1399)cout<<'4';
    else if(n>=1400&&n<=1599)cout<<'3';
    else if(n>=1600&&n<=1799)cout<<'2';
    else if(n>=1800&&n<=1999)cout<<'1';

}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

void f()
{
  int n,x,t;
  cin>>n>>x>>t;
  n=ceil(n*1.0/x);
  cout<<n*t<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3572
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


int main(){
	int n;
	
	while(cin>>n){
		if(n==0)break;
		
		for(int i=0;i<n;i++){
			int pm,pe,pj;
			cin>>pm>>pe>>pj;
			
			if(pm==100 || pe==100 || pj==100)puts("A");
			else if(pe+pm>=180)puts("A");
			else if(pe+pm+pj>=240)puts("A");
			else if(pe+pm+pj>=210)puts("B");
			else if(pe+pm+pj>=150 && (pe>=80 || pm>=80))puts("B");
			else puts("C");
		}
	}
	return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 
MOD = 10**9+7

N = int(inp())
A = [0] + list(map(int, inp().split()))

# A[i]余りが1: sum(A[i::i])が奇数
for i in range(N//2, 0, -1):
  A[i] = sum(A[i::i])&1
  
ans = [i for i, a in enumerate(A) if a]  

print(len(ans))
if len(ans) > 0:
  print(*ans)
  

Measured memory_bytes: 12700
S = input()

import itertools

equation_str = []

plus_add_position = []

for i in range(len(S)):
    plus_add_position.extend(list(itertools.combinations(range(len(S)-1), i)))

for v in plus_add_position:
    if v==tuple():
        equation_str.append(S)
    else:
        eq = S[0]
        for i in range(len(S)-1):
            if i in v:
                eq += '+' + S[i+1]
            else:
                eq+= S[i+1]
        equation_str.append(eq)

ans = 0
for eq in equation_str:
    term = list(map(int, eq.split('+')))
    ans += sum(term)

print(ans)

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

int main() {
  int n;
  cin >> n;
  // n = 2 * 1e3;

  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i];
    // l[i] = 1e3;
  }

  sort(l.begin(), l.end());

  int ans = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      for (int k = j + 1; k < n; k++) {
        if (l[k] >= l[i] + l[j]) break;
        if (l[j] < l[k] + l[i]) ans++;
      }
    }
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

void Swap(string *c1, string *c2) {
    string tmp = *c1;
    *c1 = *c2;
    *c2 = tmp;
}

// Compare Card
bool Less(string c1, string c2) {
    int n1 = c1[1] - '0';
    int n2 = c2[1] - '0';
    return n1 < n2;
}

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

    string A_B[n];
    string A_S[n];

    for (int i = 0; i < n; i++) {
        string tmp;
        cin >> tmp;
        A_B[i] = tmp;
        A_S[i] = tmp;
    }

    // Bubble sort
    // stable sort
    for (int i = 0; i < n; i++) {
        for (int j = n - 1; i < j; j--) {
            if (Less(A_B[j], A_B[j - 1])) {
                Swap(A_B + j - 1, A_B + j);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (i != n - 1) {
            cout << A_B[i] << " ";
        } else {
            cout << A_B[i] << endl;
        }
    }
    cout << "Stable" << endl;

    // Selection sort
    // NOT necessary stable
    for (int i = 0; i < n; i++) {
        int minj = i;
        for (int j = i + 1; j < n; j++) {
            if (Less(A_S[j], A_S[minj])) {
                minj = j;
            }
        }
        if (i != minj) {
            Swap(A_S + i, A_S + minj);
        }
    }
    for (int i = 0; i < n; i++) {
        if (i != n - 1) {
            cout << A_S[i] << " ";
        } else {
            cout << A_S[i] << endl;
        }
    }

    for (int i = 0; i < n; i++) {
        if (A_B[i] != A_S[i]) {
            cout << "Not stable" << endl;
            break;
        }
        if (i == n - 1) {
            cout << "Stable" << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc =new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int x=sc.nextInt();
		int[] a=new int[m];
		int l=0;
		int r=0;
		for(int i=0;i<m;i++) {
			a[i]=sc.nextInt();
		}
		
		for(int i=0;i<m;i++) {
			if(a[i]==x) {
				r=m-l-1;break;
			}
			else if(a[i]>x) {
				r=m-l;
				break;
			}
			l++;			
		}
		System.out.println(Math.min(r, l));
		
	}

}


Measured memory_bytes: 21844
# 入力
N=int(input())

l=[]
for i in range(N):
  l.append(int(input()))

# 降順にソートする
l.sort()
l.reverse()

# 餅の枚数（必ず1枚は置ける）
c=1

# 下にある餅の直径
d=l[0]

for x in l[1:]:
  # 下にある餅より直径が小さい場合は餅を置ける
  if x<d:
    # 下にある餅の直径の値を更新
    d=x
    # 枚数をインクリメント
    c+=1

# 枚数を出力
print(c)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, n) for(long i = x; i < n; i++)
#define erep(i, x, n) for(long i = x; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define show(ans)  cout << ans << endl;

long f[101][11];
long p[101][11];


int main() {long N;
cin >> N; long ans = -1e12;
erep(i, 1, N){
    erep(j, 1, 10){
        cin >> f[i][j];
    }
}
erep(i, 1, N){
    erep(j, 0, 10){
        cin >> p[i][j];
    }
}
rep(i, 1, (1 << 10)){
    vector<long> cnt(N+1, 0);
    erep(j, 0, 9){
        erep(k, 1, N){
            if(((i >> j) & 1) && f[k][j+1] == 1){
                cnt[k]++;
            }
        }
    }
    long tmp = 0;
    erep(j, 1, N){
        tmp += p[j][cnt[j]];
    }
    ans = max(ans, tmp);
}
show(ans);


  return 0;
 
}



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

static const int N = 100100;

using namespace std;

int div_roundout(int a, int b)
{
    return (a + b - 1) / b;
}

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

    int d, g;
    array<int, N> p, c;
    // vector<int> a, b;

    cin >> d >> g;
    for (int i = 0; i < d; i++)
    {
        cin >> p[i] >> c[i];
    }

    int min_np = 2000000000;

    for (int i = 0; i < pow(2, d); i++)
    {
        int now_np = 0, now_sc = 0;
        // 完答処理
        for (int j = 0; j < d; j++)
        {
            if (i & (1 << j))
            {
                now_np += p[j];
                now_sc += c[j] + 100 * (j + 1) * p[j];
            }
        }
        // 部分解答処理
        if (g > now_sc)
        {
            int part_i = -1;
            for (int j = 0; j < d; j++)
            {
                if (!(i & (1 << j)))
                    part_i = j;
            }

            int part_n = div_roundout(g - now_sc, (part_i + 1) * 100);
            if (part_n >= p[part_i])
                continue;
            now_sc += part_n * (part_i + 1) * 100;
            now_np += part_n;
        }

        min_np = min(now_np, min_np);
    }

    cout << min_np << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

ll gcd(ll n, ll m)
{
  if (n < m)
  {
    ll tmp = m;
    m = n;
    n = tmp;
  }
  if (m == 0)
  {
    return n;
  }
  return gcd(m, n % m);
}

ll lcm(ll n, ll m)
{
  ll g = gcd(n, m);
  return n * m / g;
}

int main()
{
  ll n, m;
  string s, t;
  cin >> n >> m;
  cin >> s >> t;

  ll l = lcm(n, m);
  for (ll i = 0; i * l < m * n; i++)
  {
    if (s[i * (l / m)] != t[i * (l / n)])
    {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << l << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
  int a, b, c, d;
  int l, r;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  l = a + b; r = c + d;
  if (l > r) printf("Left\n");
  else if (l == r) printf("Balanced\n");
  else printf("Right\n");

  return 0;
}


Measured memory_bytes: 128
n=int(input())
z=0
c=0
f=0
i=0;

while i<n:
    l=list(map(int,input().split()))
    a=l[0]
    b=l[1]
    if a==b:
        z=1
        c=c+1
        if c>=3:
            f=1
    else:
        c=0
        z=0
    
    i=i+1
if f:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9188
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <cstring>
#include <bitset>
#include <stack>
using namespace std;
#define MP make_pair
#define PB push_back
const int INF=1e9;
const int MOD=1e9+7;

int n,m,q,ans;
int dp[1000005],t[1000005][25],p1[25],p2[25],lst[1000005];

int main()
{
	cin>>n>>m>>q;
	n--;
	while (q--)
	{
		int x,y,z;
		cin>>x>>y>>z;
		y--;
		p1[x]|=(1<<y);
		p2[x]|=(1<<y)*z;
	}
	for (int i=0;i<(1<<n);i++)
	{
		lst[i]=-1;
		for (int j=0;j<n;j++) t[i][j]=-1;
		int id=0;
		for (int j=0;j<n;j++)
		{
			if (i&(1<<j))
			{
				if (j>0 && (!(i&(1<<(j-1))))) t[i][id]=i^(1<<(j-1))^(1<<j);
				id++;
			}
		}
		for (int j=n-1;j>=0;j--)
			if (!(i&(1<<j)))
			{
				lst[i]=i^(1<<j);
				break;
			}
	}
	dp[0]=1;
	for (int i=1;i<=m;i++)
	{
		for (int j=0;j<(1<<n);j++) if (lst[j]!=0) dp[lst[j]]=(dp[j]+dp[lst[j]])%MOD;
		for (int k=0;k<n;k++)
			for (int j=(1<<n)-1;j>=0;j--)
				if (t[j][k]!=-1) dp[t[j][k]]=(dp[t[j][k]]+dp[j])%MOD;
		for (int j=0;j<(1<<n);j++) if ((j&p1[i])!=p2[i]) dp[j]=0;
	}
	for (int i=0;i<(1<<n);i++) ans=(ans+dp[i])%MOD;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 59648
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var a = readline().split(" ").map(x => parseInt(x))
    var days = readline().split(" ").map(x => parseInt(x))
    var n = a[0]
    var m = a[1]
    var totalDays = days.reduce((a, b) => a + b)
    var res = n - totalDays
    if (0 <= res) print(res)
    else print('-1')
}


Measured memory_bytes: 30708
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
#define accum(x) accumulate((x).begin(), (x).end(), 0)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int COLORS = 8;

int main() {
  int n, a;
  cin >> n;
  vector<int> v(COLORS + 1);
  rep(i, 0, n) {
    cin >> a;
    if (1 <= a && a <= 399)
      v[0] = 1;
    else if (400 <= a && a <= 799)
      v[1] = 1;
    else if (800 <= a && a <= 1199)
      v[2] = 1;
    else if (1200 <= a && a <= 1599)
      v[3] = 1;
    else if (1600 <= a && a <= 1999)
      v[4] = 1;
    else if (2000 <= a && a <= 2399)
      v[5] = 1;
    else if (2400 <= a && a <= 2799)
      v[6] = 1;
    else if (2800 <= a && a <= 3199)
      v[7] = 1;
    else if (3200 <= a)
      v[8]++;
  }

  int ma = accum(v);
  int mi = 0;
  rep(i, 0, COLORS) mi += v[i];
  if (v[8] == n)
    cout << 1 << " " << ma << endl;
  else
    cout << mi << " " << ma << endl;
  return 0;
}


Measured memory_bytes: 3640
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())
    diff = abs(A - B)
    mov = V - W
    if mov <= 0:
        print("NO")
    elif mov * T < diff:
        print("NO")
    else:
        print("YES")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9192
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
/*mod逆元*/long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------ライブラリとか----------------

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

    int n,k; cin >> n >> k;
    VI a(n); REP(i,n) cin >> a[i];
    map<int,int> mp;
    REP(i,n) mp[a[i]]++;
    VI list; for(auto x : mp) list.push_back(x.second);
    SORT(list);
    int want = list.size() - k;
    int ans = 0; REP(i,want) ans += list[i];
    out(ans);

    return 0;
}

Measured memory_bytes: 16500
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}


ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
  ll a,b,c;
  
  cin>>a>>b>>c;
  
  if(4*a*b < (c-a-b)*(c-a-b)&& c >a+b) cout<<"Yes"<<endl;
  else cout <<"No"<<endl;
}
  

Measured memory_bytes: 256
#include <stack>
#include <cstdio>
#include <cstring>
using namespace std;

#define REP(i,n,m) for(int i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)

class Rect{public:int h;int pos;};

int w,h,ct[504][504];
char t[504][504];

void mkCT(void){
	rep(j,w){
		int count = 1;
		rep(i,h){
			if(t[i][j] == '*') count = 0;
			ct[i][j] = count++;
		}
	}
}

int calArea(void){
	mkCT();

	int res = 0;
	stack<Rect> s;

	rep(i,h)rep(j,w+1){
		Rect rect;
		rect.h = ct[i][j];
		rect.pos = j;

		if(s.empty()){
			s.push(rect);
		}
		else {
			Rect tmp = s.top();
			if(tmp.h < rect.h){
				s.push(rect);
			}
			else if(tmp.h > rect.h){
				int pre = -1;
				while(!s.empty() && s.top().h >= rect.h){
					tmp = s.top(); s.pop();
					pre = tmp.pos;
					res = max(res, tmp.h * (j - tmp.pos));
				}
				rect.pos = pre;
				s.push(rect);
			}
		}
	}

	return res;
}

int main(void){
	while(scanf("%d%d",&h,&w) && (h||w)){
		rep(i,h){
			scanf("%s",t[i]);
			ct[i][w] = 0;
		}
		printf("%d\n",calArea());
	}

	return 0;
}

Measured memory_bytes: 0