akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll INF=1e18;




// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

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

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(10005);


//nPk
 mint f(int n, int k) {
    if (n < 0) return 0;
    // nPk = nCk * k!
    mint res = comb(n,k);
    res *= comb.fact[k];
    return res;
}




//組み合わせの数nCrを計算
   int calcNumOfCombination(int n, int r){
       int num = 1;
       for(int i = 1; i <= r; i++){
           num = num * (n - i + 1) / i;
       }
       return num;
   }

mint dp[55][55][2600];
int main() {
  ll n,K;
  cin>>n>>K;
  dp[0][0][0]=1;
  rep(i,n){
    rep(j,i+1)rep(k,2500){
      dp[i+1][j][k+j*2]+=dp[i][j][k];

      dp[i+1][j][k+j*2]+=dp[i][j][k]*j*2;

      dp[i+1][j+1][k+j*2+2]+=dp[i][j][k];

      if(j>0){
        dp[i+1][j-1][k+j*2-2]+=dp[i][j][k]*j*j;
      }
    }

  }
cout<<dp[n][0][K];
}


Measured memory_bytes: 65236
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
char s[maxn];
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
	//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
	gbtb;
	cin>>n;
	cin>>s;
	int cntr=0;
	int cntb=0;
	rep(i,0,n)
	{
		if(s[i]=='B')
		{
			cntb++;
		}else
		{
			cntr++;
		}
	}
	if(cntr>cntb)
	{
		cout<<"Yes"<<endl;
	}else
	{
		cout<<"No"<<endl;
	}
	
	
	
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



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

int main(void)
{
 
  int a[3][3];
  scanf("%d %d %d",&a[0][0],&a[0][1],&a[0][2]);
  scanf("%d %d %d",&a[1][0],&a[1][1],&a[1][2]);
  scanf("%d %d %d",&a[2][0],&a[2][1],&a[2][2]);

 
  int res[3][3]={{0,0,0},{0,0,0},{0,0,0}};


  int n;
  scanf("%d",&n); 

int bn;
 for(int i=0;i<n;i++){
     scanf("%d",&bn);
     
     for(int p=0;p<3;p++){
         for(int q=0;q<3;q++){
             if(a[p][q]==bn){
                 res[p][q]=1;
             }
         }
     }
 }

//Bingo判定

//横
for(int i=0;i<3;i++){
if(res[i][0]+res[i][1]+res[i][2]==3){
    printf("Yes");
    return 0;
}
}


//縦
for(int i=0;i<3;i++){
if(res[0][i]+res[1][i]+res[2][i]==3){
    printf("Yes");
    return 0;
}
}

//斜め
if(res[0][0]+res[1][1]+res[2][2]==3||res[2][0]+res[1][1]+res[0][2]==3){
    printf("Yes");
    return 0;
}

printf("No");
  return 0;
}


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

vector<string> c;

int cntB(int bh, int bw) {
    int cnt = 0;
    for (int i = 0; i < c.size(); ++i) {
        if (bh & (1 << i)) continue;
        for (int j = 0; j < c[i].size(); ++j) {
            if (bw & (1 << j)) continue;
            if (c[i][j] == '#') cnt++;
        }
    }
    return cnt;
}

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    c.resize(h);
    for (int i = 0; i < h; ++i) {
        cin >> c[i];
    }
    int ans = 0;
    for (int b1 = 0; b1 < (1 << h); ++b1) {
        for (int b2 = 0; b2 < (1 << w); ++b2) {
            if (cntB(b1, b2) == k) ans++;
        }
    }
    cout << ans << endl;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string s;cin >> s;
    int a = 0;
    int b = 0;
    int n = s.size();
    inc(i, 0, n){
        if(i%2 == 0){
            if(s[i] == '1'){
                a++;
            }
            if(s[i] == '0'){
                b++;
            }
        }else{
            if(s[i] == '1'){
                b++;
            }
            if(s[i] == '0'){
                a++;
            }
        }
    }
    cout << min(a, b) << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int A[2010];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int MOD = 1e9 + 7;
    int n, k;;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> A[i];
    }
    int answer = 0;
    for (int i = 1; i <= n; ++i) {
        int cnt = 0;
        for (int j = i + 1; j <= n; ++j) {
            if (A[i] > A[j]) {
                ++cnt;
            }
        }
        int x = (1LL * k * (k + 1) / 2) % MOD;
        answer = (0LL + answer + (1LL * cnt * x) % MOD) % MOD;
        cnt = 0;
        //cout << answer << '\n';
        for (int j = 1; j < i; ++j) {
            if (A[i] > A[j]) {
                ++cnt;
            }
        }
        x = (1LL * (k - 1) * (k) / 2) % MOD;
        answer = (0LL + answer + (1LL * cnt * x) % MOD) % MOD;
        //cout << answer << '\n';
    }
    cout << answer;
}


Measured memory_bytes: 3668
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  string s,t;cin>>s>>t;
  ans1(s.size()+1==t.size()&&s==t.substr(0,s.size()));
  return 0;
}

Measured memory_bytes: 3608
#include <algorithm>

#include <bitset>

#include <tuple>

#include <cstdint>

#include <cstdio>

#include <cctype>

#include <assert.h>

#include <stdlib.h>

#include <stdio.h>

#include <cassert>

#include <cfloat>

#include <climits>

#include <cmath>

#include <complex>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <limits>

#include <map>

#include <memory>

#include <queue>

#include <random>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>

#include <math.h>
using namespace std;
int main() {
	char a;
	cin >> a;
	string big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	bool b = false;
	for (int i = 0; i < 26; i++) {
		if (big.at(i) == a) {
			b = true;
		}
	}
	if (b) {
		cout << "A" << endl;
	}
	else {
		cout << "a" << endl;
	}
}


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

int main(void)
{
    int rn, gn, bn, n;
    int n1, n2;
    int count = 0;
    cin >> rn >> gn >> bn >> n;

    for (int r = 0; r <= 3000; r++) {
        n1 = r * rn;
        if (n1 > n) break;
        for (int g = 0; g <= 3000; g++) {
            n2 = n1 + g * gn;
            if (n2 > n) break;
            if ((n2 - n) % bn == 0) count++;
        }
    }

    cout << count << endl;

    return 0;
}



Measured memory_bytes: 256
use input::{Input, ReadMode};

fn main() {
    let mut input = Input::new(ReadMode::Line);

    let n = input.parse();
    let m = input.parse();
    let h = (0..n).map(|_| input.parse()).collect::<Vec<u64>>();
    let mut v = vec![Vec::new(); n];

    for _ in 0..m {
        let a: usize = input.parse();
        let b: usize = input.parse();
        v[a - 1].push(b - 1);
        v[b - 1].push(a - 1);
    }

    let mut ans = 0;
    for i in 0..n {
        let x = &h[i];
        let mut ok = true;
        for j in v[i].iter() {
            if x <= &h[*j] {
                ok = false;
                break;
            }
        }
        if ok {
            ans += 1;
        }
    }

    println!("{}", ans);
}

#[allow(dead_code)]
pub mod input {
    use std::io::{BufRead, Read};

    pub enum ReadMode {
        Full,
        Line,
    }

    pub struct Input<'a> {
        lock: std::io::StdinLock<'static>,
        iter: Option<std::str::SplitAsciiWhitespace<'a>>,
        mode: ReadMode,
    }

    impl<'a> Input<'a> {
        fn naive_read(&mut self) -> Option<std::str::SplitAsciiWhitespace<'a>> {
            let mut s = Box::leak(Box::new(String::new()));
            let res = match self.mode {
                ReadMode::Full => self.lock.read_to_string(&mut s),
                ReadMode::Line => self.lock.read_line(&mut s),
            };
            res.ok().expect("failed to read");
            Some(s.split_ascii_whitespace())
        }
        pub fn new(mode: ReadMode) -> Self {
            let lock = Box::leak(Box::new(std::io::stdin())).lock();
            let iter = None;
            Self { lock, iter, mode }
        }
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            self.lock.read_line(&mut s).ok().expect("failed to read");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            match &mut self.iter {
                Some(iter) => {
                    let x = match iter.next() {
                        Some(x) => x,
                        None => {
                            self.iter = self.naive_read();
                            self.iter.as_mut().unwrap().next().expect("reached EOF")
                        }
                    };
                    x.parse().ok().expect("failed to parse")
                }
                None => {
                    self.iter = self.naive_read();
                    self.parse()
                }
            }
        }
    }
}


Measured memory_bytes: 15740
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <map>
#include <cassert>
#include <sstream>
#include <numeric>
#include <regex>
#include <cctype>
#include <utility>
#include <stdio.h>
#include <set>
#include <queue>
#include <deque>

typedef long long ll;

#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define MOD 1000000007
#define pb push_back
#define llnums vector<ll>
#define FOR(i,n) for(int i{0}; i < n; ++i)

using namespace std;

int main(void) { // A.cpp
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  set<int> u;
  int a, b, c; cin >> a >> b >> c;
  u.insert(a);u.insert(b);u.insert(c);
  cout << u.size() << '\n';
  return 0;
}









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

int main() {

  int s1s2s3,d1,d2,d3;
  cin >> s1s2s3;
  d1=s1s2s3/100;
  d2=(s1s2s3/10)%10;
  d3=s1s2s3%10;
  cout << d1+d2+d3 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    scan.nextLine();
    int[] AArray = new int[N];
    int[] BArray = new int[N - 1];

    for (int i = 0; i < N - 1; i++) {
      BArray[i] = scan.nextInt();
    }
    AArray[0] = BArray[0];
    for (int i = 1; i < N; i++) {
      AArray[i] = BArray[i - 1];
      if (i == N - 1) {
        break;
      }
      if (AArray[i] > BArray[i]) {
        AArray[i] = BArray[i];
      }
    }

    long result = 0;
    for (int i = 0; i < N; i++) {
      result += AArray[i];
    }
    System.out.println(result);

  }


}


Measured memory_bytes: 25172
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] x = new int[n];
		for (int i = 0; i < n; i++) x[i] = sc.nextInt();
		long cost = 0;
		long[] dp = new long[n];
		dp[0] = 0; dp[1] = Math.abs(x[1] - x[0]);
		for (int i = 2; i < n; i++) {
			dp[i] = Math.min(dp[i - 1] + Math.abs(x[i] - x[i - 1]), dp[i - 2] + Math.abs(x[i] - x[i - 2]));
		}
		System.out.println(dp[n-1]);
	}
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {

	int a, b, c;
	cin >> a >> b >> c;

	if (a == b && b == c)
		cout << "Yes";
	else
		cout << "No";
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int main(){
  int N,T,t[200200],X;

  cin>>N>>T;

  REP(i,N){
    cin>>t[i];
  }


  FOR(i,1,N){
    //間がT秒以上の時は、T秒加算
    if (t[i]-t[i-1] > T) {
      X += T;
    //間がT秒以下の時は、その間分加算
    } else {
      X += t[i]-t[i-1];
    }
  }

  //最後にT秒加算
  X += T;

  cout<<X<<endl;

  return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
//#pragma GCC target ("sse4")
#pragma optimize("fast-math")

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define endl '\n'
#define ull unsigned long long
#define si short int
#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define piii pair<pair<int, int>, int>
#define all(vec) (vec).begin(), (vec).end()
#define rall(vec) (vec).rbegin(), (vec).rend()
#define piiii pair<pair<int, int>, pair<int, int>>

void solve() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int now=0;
    while(true){
        if(now==0){
            c-=b;
            if(c<=0){
                cout<<"Yes";
                return;
            }
            now=1;
        }
        else{
            a-=d;
            if(a<=0){
                cout<<"No";
                return;
            }
            now=0;
        }
    }
}

void testcases(int n) {
    n = 1 - n;
    if (!n) cin >> n;
    for (int i = 0; i < n; i++) {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "r", stdin);
    //f=fopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w");
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w", stdout);

    unsigned int beg_time = clock();
    testcases(0);
    // 0 - no t, 1 - with t

    unsigned int end_time = clock();
    //cout << endl << endl << end_time - beg_time;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  string a,b,c;
  cin>>a>>b>>c;
  if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}


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

int h, w, k, cnt = 1, cnt2, cnt3;
char s[301][301];
int ans[301][301];
int main() {
	scanf("%d %d %d", &h, &w, &k);
	rep(i, h) {
		rep(j, w) {
			scanf("%c", &s[i][j]);
			if (s[i][j] == '\n') scanf("%c", &s[i][j]);
		}
	}
	rep(i, h) {
		cnt2 = 0;
		rep(j, w) if (s[i][j] == '#') ++cnt2;
		if (cnt2 == 0) continue;
		else if (cnt2 == 1) {
			rep(j, w) ans[i][j] = cnt;
			++cnt;
		}
		else {
			cnt3 = 0;
			rep(j, w) {
				if (s[i][j] == '#') {
					++cnt3;
					if (cnt3 == 2) {
						++cnt; cnt3 = 1;
					}
				}
				ans[i][j] = cnt;
				if (j == w - 1) ++cnt;
			}
		}
	}
	rep(i, h) {
		rep(j, w) {
			if ((ans[max(i - 1, 0)][j] == 0 || ans[min(i + 1, h - 1)][j] == 0) && ans[i][j] != 0) {
				for (int k = i - 1; k >= 0 && ans[k][j] == 0; --k) ans[k][j] = ans[i][j];
				for (int k = i + 1; k < h && ans[k][j] == 0; ++k) ans[k][j] = ans[i][j];
			}
		}
	}
	rep(i, h) {
		rep(j, w) {
			if (j < w - 1) printf("%d ", ans[i][j]);
			else printf("%d\n", ans[i][j]);
		}
	}
}


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

int main(){
  
  int a,b,c;
  cin >>a>>b>>c;
  if(b/a==c/a&&b%a!=0){
    cout << "NG"<<endl;
  }
  else{
    cout <<"OK" <<endl;
  }
}

Measured memory_bytes: 3608
/*****************************************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

#define   offcin        ios::sync_with_stdio(false)
#define   DEBUG         freopen("#.txt", "r", stdin)
#define   sigma_size    26
#define   lson          l,m,v<<1
#define   rson          m+1,r,v<<1|1
#define   slch          v<<1
#define   srch          v<<1|1
#define   ll            long long
#define   ull           unsigned long long
#define   lowbit(x)     (x&-x)

const int    INF    = 0x3f3f3f3f;
const ll     INFF   = 1e18;
const double pi     = acos(-1.0);
const double inf    = 1e18;
const double eps    = 1e-9;
const ll     mod    = 1e9+7;
const int    maxmat = 10;
const ull    BASE   = 133333331;

/*****************************************************/
inline void RI(int &x) {
      char c;
      while((c=getchar())<'0' || c>'9');
      x=c-'0';
      while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0';
}
inline ll bits(ll x) {
      return !x ? x : bits(x - lowbit(x)) + 1;
}
/*****************************************************/

int main(int argc, char const *argv[]) {
    int a, b;
    cin>>a>>b;
    a += b;
    while (a >= 24) a -= 24;
    cout<<a<<endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  int t = 0;
  int x = 0;
  int y = 0;
  
  int flag = 1;
  int s,u,v;
  
  for ( int i = 0; i < n; i++) {
    cin >> s >> u >> v;
    
    int t_diff = s-t;
    int dist = abs(x-u) + abs(y-v);
    
    if (t_diff < 0 || t_diff < dist || (t_diff % 2 - dist % 2) != 0){
      flag = 0;
      break;
    }
    x = u;
    y = v;
    t = s;
  }
    
  if (flag == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
p = list(map(int, input().split()))
s, d = list(map(lambda x, y: x + y * 1j, p[::2], p[1::2]))

ans = ""
for _ in range(2):
  v = d - s
  s = d
  d = s + v * 1j
  ans += " {:.0f} {:.0f}".format(d.real, d.imag)
print(ans[1:])


Measured memory_bytes: 3060
# 入力
D,N=map(int,input().split())

# D（=0,1,2）の値によって場合分け
if D==0:
  if N==100:
    print(101)
  else:
    print(N)

elif D==1:
  if N==100:
    print(10100)
  else:
    print(N*100)
else:
  if N==100:
    print(1010000)
  else:
    print(N*10000)


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


int main() {
  string S;
  cin >> S;
  
  string m_str = "ACGT";
  int cnt,ret_cnt = 0;
  for (char s :S) {
    if (m_str.find(s) != string::npos) {
      cnt++;
    } else {
      cnt = 0;
    }
    
    if (ret_cnt < cnt) {
      ret_cnt = cnt;
    }
  }
  cout << ret_cnt << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << 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...);
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

i = 1
A_2 = []
for a in A:
    A_2.append(a-i)
    i += 1

A_3 = sorted(A_2)

b = A_3[N//2]

i = 0
mini = 0
for a in A_3:
    mini += abs(A_3[i] - b)
    i += 1

print(mini)

Measured memory_bytes: 26128
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n,d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d, -1));
    REP(i,n) REP(j,d) cin >> x[i][j];
    vector<ll> a;
    int N = 1;

    while (N*N <= 50000) {
        a.push_back(N*N);
        ++N;
    }

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            ll sum = 0;
            for (int k = 0; k < d; ++k) {
                ll b = x[i][k]-x[j][k];
                b *= b;
                sum += b;
            }
            for (auto &&e: a) {
                if (e == sum) {
                    ans++;
                }
            }
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int x,y,a,b;
	cin>>x>>y>>a>>b;
	// vector<string> ans;
	// for (int i = x; i < a; i++){
	// 	ans.push_back('R');
	// }
	// for (int i = y; i < b; i++){
	// 	ans.push_back('U');
	// }
	// for (int i = x; i < a; i++){
	// 	ans.push_back('L');
	// }
	// for (int i = y; i < b; i++){
	// 	ans.push_back('D');
	// }

	// ans.push_back('D');
	// for (int i = x; i < a+1; i++){
	// 	ans.push_back('R');
	// }
	// for (int i = y-1; i < b; i++){
	// 	ans.push_back('U');
	// }
	// ans.push_back('L');
	// ans.push_back('U');
	// for (int i = a; i > x-1; i--){
	// 	ans.push_back('L');
	// }
	// for (int i = b+1; i > y; i--){
	// 	ans.push_back('D');
	// }
	// ans.push_back('R');
	// for(auto c:ans)
	// 	cout<<c;
	// cout<<endl;

	int dx = a-x, dy=b-y;
	cout<<string(dx,'R') << string(dy,'U');
	cout<<string(dx,'L') << string(dy,'D');
	cout<<'D'<< string(dx+1,'R')<<string(dy+1,'U')<<'L';
	cout<<'U'<<string(dx+1,'L')<<string(dy+1,'D')<<'R'<<endl;
	
	return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 998244353 //1000000007

class Comb{
public:
  ll *fac,*finv,*inv;
  Comb(){
    fac = new ll[1000001];
    finv = new ll[1000001];
    inv = new ll[1000001];
    fac[0] = 1;
    for(int i=1;i<1000001;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000001;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000001;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

ll jou(ll x,ll p){
  if(p == 0) return 1;
  if(p == 1) return x%MOD;
  ll temp = jou(x,p/2);
  temp = (temp*temp)%MOD;
  if(p%2 != 0) temp = (x*temp)%MOD;
  return temp;
}
int main(){
  ll n,m,k;
  cin >> n >> m >> k;
  ll ans = 0;
  Comb comb;
  for(int i=0;i<k+1;i++){
    ll temp = comb.calc(n-1,i);
    ll temp2 = jou(m-1,n-i-1);
    temp2 = (m*temp2)%MOD;
    ans += (temp*temp2)%MOD;
    ans %= MOD;
  }
  ans += 2*MOD;
  ans %= MOD;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 27084
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    private static final String BLANK = " ";

    public static void main(String[] args) {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        try {
            String input = in.readLine();

            String[] dataStr = input.split(BLANK);

            List<Integer> dataList = new ArrayList<Integer>();

            for (String str : dataStr) {
                dataList.add(Integer.valueOf(str));
            }

            List<Integer> resultList = mergeSort(dataList);

            StringBuilder resultBuilder = new StringBuilder();

            for (Integer result : resultList) {
                resultBuilder.append(result).append(BLANK);
            }

            resultBuilder.delete(resultBuilder.length() - 1,
                    resultBuilder.length());

            System.out.println(resultBuilder.toString());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static List<Integer> mergeSort(List<Integer> dataList) {

        if (dataList.size() == 1) {
            return dataList;
        }

        List<Integer> leftList = mergeSort(dataList.subList(0,
                dataList.size() / 2));
        List<Integer> rightList = mergeSort(dataList.subList(
                dataList.size() / 2, dataList.size()));

        int leftCnt = 0;
        int rightCnt = 0;
        List<Integer> resultList = new ArrayList<Integer>();

        for (int i = 0; i < leftList.size() + rightList.size(); i++) {

            if (rightCnt == rightList.size()) {
                resultList.add(leftList.get(leftCnt));
                leftCnt++;
            } else if (leftCnt == leftList.size()) {
                resultList.add(rightList.get(rightCnt));
                rightCnt++;
            } else if (leftList.get(leftCnt).compareTo(rightList.get(rightCnt)) > 0) {
                resultList.add(leftList.get(leftCnt));
                leftCnt++;
            } else {
                resultList.add(rightList.get(rightCnt));
                rightCnt++;
            }
        }

        return resultList;
    }
}

Measured memory_bytes: 16928
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if((a == b && a != c) || (a == c && a != b) || (b == c && b != a)){
        cout << "Yes";
    } else{
        cout << "No";
    }
    
    return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    String t = sc.next();
    StringBuilder sb = new StringBuilder();
    for(int i=0;i<n;i++) {
    	sb.append(s.charAt(i));
    	sb.append(t.charAt(i));
    }
    System.out.println(sb);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  vector<int> cnth(h,0); //水平方向のイチゴの数
  rep(i,h) {
    cin >> s[i];
    rep(j,w) {
      if (s[i][j] == '#') cnth[i]++;
    }
  }
  vector<P> hor; //水平方向のカット
  rep(i,h) {
    if (cnth[i] > 0) hor.emplace_back(P(i,cnth[i]));
  }
  if (cnth[h-1] == 0) { //最後の列にイチゴがない場合
    int temp = hor.back().second;
    hor.pop_back();
    hor.emplace_back(P(h-1,temp));
  }
  else hor.emplace_back(P(h-1,0));

  vector<vector<int> > ans(h, vector<int>(w));
  int idx = 0, cur = 1; //番号
  for (auto p : hor) {
    int hidx = p.first, maxcnt = p.second;
    int ichigocnt = 0;
    rep(x,w) {
      bool ichigo = false; //イチゴがあるかどうか
      for (int y = idx; y <= hidx && y < h; ++y) {
        if (s[y][x] == '#') {
          ichigocnt++;
          ichigo = true;
        }
        ans[y][x] = cur;
      }
      if (ichigo && (ichigocnt < maxcnt)) { //縦に切り分け
        ichigo = false;
        cur++; 
      }
    }
    idx = hidx+1;
    cur++;
  }
  rep(y,h) {
    rep(x,w) {
      cout << ans[y][x] << " ";
    }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 1280
int main(int argc, const char * argv[]) {
    
    int x,count = 1;
    
    while (1) {
        
        
        scanf("%d",&x);
        
        if (x == 0) {
            break;
        }
        
        printf("Case %d: %d\n",count,x);
        
        count++;
    }
    
    return 0;
}

Measured memory_bytes: 600
import java.util.*;
public class Main
{
	public static void main(String ar[])
	{
		Scanner ab=new Scanner(System.in);
		String a,b;
		a=ab.next();
		b=ab.next();
		a+=b;
		int i=Integer.valueOf(a);
		int c=(int)(Math.sqrt(i));
		if(c*c==i)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

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

using namespace std ;

const int MAX = 2e5 + 10 ;

int deg[MAX] ;
int n ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	for(int i = 2 ; i <= n ; ++i)
	{
		int x ;
		cin>>x ;
		deg[x]++ ;
	}
	for(int i = 1 ; i <= n ; ++i)
		cout<<deg[i]<<"\n" ;
	return 0 ;
}		

Measured memory_bytes: 4372
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
using namespace std;
int main()
{
    int n, k;
    string s;
    cin >> n >> k >> s;
    s[k - 1] += 32;
    cout << s << endl;
    return 0;
}

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

int main(){
	int h, w;
	long long mod= 1000000007;
	std::vector<std::string> mapList; 
	std::vector<std::vector<long long>> dpList;

	std::cin>>h>>w;
	mapList.resize(h);
	dpList.resize(h);

	for(int i=0; i<h; i++)
		dpList[i].resize(w, 0);

	for(int i=0; i<h; i++)
		std::cin>>mapList[i];

	dpList[0][0]=1;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(dpList[i][j]==0)
				continue;

			if(i+1<h && mapList[i+1][j]=='.')
				dpList[i+1][j]= (dpList[i][j]+ dpList[i+1][j])%mod;

			if(j+1<w && mapList[i][j+1]=='.')
				dpList[i][j+1]= (dpList[i][j]+ dpList[i][j+1])%mod;
		}
	}

	std::cout<<dpList[h-1][w-1]<<std::endl;

	return 0;
}

Measured memory_bytes: 9216
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back


#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64_t
#endif

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

int a[MAXN];
int kek1[MAXN];
int kek2[MAXN];


main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt();
    for (int i = 1; i <= n; i++) {
    	a[i] = readInt();
    }
    if (a[n] != 2) {
    	cout << -1;
    	return 0;
    }
    kek1[n] = 2;
    kek2[n] = 2;
    for (int i = n; i >= 1; i--) {		
		kek1[i - 1] = floor((kek1[i] + a[i] - 1) / a[i]) * a[i];
		kek2[i - 1] = floor(kek2[i] / a[i]) * a[i] + a[i] - 1;
    }
    if (kek1[0] > kek2[0]) {
    	cout << -1;
    	return 0;
    }
    cout << kek1[0] << ' ' << kek2[0];
    return 0;
}

Measured memory_bytes: 9216
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
l=[-1]*n
z=n*(n-1)//2
b=[input().split() for _ in range(m)]
c=[0]*(m-1)+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,0,-1):
  x,y=map(f,b[i])
  if x!=y:
    s,t=l[x],l[y]
    z-=s*t
    if s>t:
      l[x]=y
      l[y]+=s
    else:
      l[y]=x
      l[x]+=t
  c[i-1]=z
for x in c:
  print(x)

Measured memory_bytes: 39488
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

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

  ll n, m;
  cin >> n >> m;

  string a, b;
  rep(i, m) { a += to_string(n); }
  rep(i, n) { b += to_string(m); }

  if (a < b)
    cout << a << endl;
  else
    cout << b << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
//#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T>
using Pq = priority_queue<T>;
template <typename T>
using pQ = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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 <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

signed main() {
    INIT;
    cin >> N;
    vi t(N), v(N);
    cin >> t >> v;
    vector<pair<int, int>> tt;
    vi vv;
    int T = 0;
    vv.push_back(0);
    tt.push_back({0, 0});
    REP(i, N) {
        t[i] *= 2;
        v[i] *= 2;
        tt.push_back({T, T + t[i]});
        vv.push_back(v[i]);
        T += t[i];
    }
    vv.push_back(0);
    tt.push_back({T, T});
    dump(vv, tt);
    vi x(T + 1, INF);
    REP(i, N + 2) {
        REP(j, T + 1) {
            if (j < tt[i].first) {
                chmin(x[j], vv[i] + (tt[i].first - j));
            } else if (j < tt[i].second) {
                chmin(x[j], vv[i]);
            } else {
                chmin(x[j], vv[i] + (j - tt[i].second));
            }
        }
    }
    dump(x);
    double ans = 0;
    REP(i, T) {
        ans += (x[i] + x[i + 1]) / 2.0;
    }
    cout << ans / 4 << endl;
}

Measured memory_bytes: 3920
#include <cstdio>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;

const ll BASE = 1e9;

ll x[1010], y[1010];
string ans[1010];
int main() {
	int n;
	scanf("%d", &n);
	
	for(int i=0;i<n;i++){
		scanf("%lld %lld", &x[i], &y[i]);
		x[i] += BASE;
		y[i] += BASE;
	}

	for(int i=1;i<n;i++) {
		if((x[0]^y[0])%2 != (x[i]^y[i])%2) {
			puts("-1");
			return 0;
		}
	}

	int add=0;
	if(!((x[0]^y[0])&1)) {
		add = 1;
	}

	vector<ll> ds;
	ds.push_back(BASE+add);
	ds.push_back(BASE);

	for(int i=0;i<=32;i++) {
		ds.push_back(1ll<<i);
	}
	
	for(int i=0;i<n;i++) {
		ll cx = x[i], cy = y[i];

		ans[i] = "";
		ans[i] += "LD";
		cx += add;
		
		for(int j=0;j<32;j++) {
			// carry
			if((cx+cy)&2) {
				if(cx&1) {
					ans[i]+="R";
				}
				else {
					ans[i]+="U";
				}
			}
			// carry x -> carry만들어야함
			else {
				if(cx&1) {
					ans[i] += "L";
					cx++;
				}
				else {
					ans[i] += "D";
					cy++;
				}
			}
			cx>>=1;
			cy>>=1;
		}


		if(cx&1) {
			ans[i] += "R";
			cx--;
		}
		else {
			ans[i] += "U";
			cy--;
		}
	}

	printf("%d\n", ds.size());
	for(int i=0;i<ds.size();i++) {
		printf("%lld ", ds[i]);
	}
	puts("");
	for(int i=0;i<n;i++) {
		// printf("x[i]:%lld, y[i]:%lld\n", x[i], y[i]);

		ll cx=0, cy=0;
		for(int j=0;j<ds.size();j++){
			if(ans[i][j]=='R')
				cx += ds[j];
			else if(ans[i][j]=='L')
				cx -= ds[j];
			else if(ans[i][j]=='U')
				cy += ds[j];
			else if(ans[i][j]=='D')
				cy -= ds[j];
		}
		// printf("cx:%lld, cy:%lld\n", cx+BASE, cy+BASE);
		printf("%s\n", ans[i].c_str());
	}
	return 0;
}

/*
3
-1000000000 -999999999
-999999999 -999999996
-999999997 -1000000000
*/

Measured memory_bytes: 384
N,M = map(int,input().split())
Xs = list(map(int,input().split()))
if len(Xs) <= N:
    print(0)
else:
    Xs.sort()
    Xdivs = []
    for i in range(M-1):
        Xdivs.append(Xs[i+1]-Xs[i])
    Xdivs.sort()
    print(sum(Xdivs[:M-N]))

Measured memory_bytes: 13968
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

string s;
int main() {
	cin >> s;
	if (s == "Sunny")cout << "Cloudy" << endl;
	if (s == "Cloudy")cout << "Rainy" << endl;
	if (s == "Rainy")cout << "Sunny" << endl;
}




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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long 
#define sqr(x) ((x)*(x))
#define pi acosl(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
void solve(){
        int x;
        scanf("%d",&x);
        printf("%d\n",1-x);
}
int main(){
    int t=1;
    int T=1;
    while(t--){
        solve();
    }
}
/*
100
5
5 4
4 2
4 2 3
5 4 2 3 1
*/

Measured memory_bytes: 3824