akhauriyash/Code-Regression huggingface dataset:
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//
// Prime
//

#[allow(dead_code)]
struct Primes {
    size: usize,
    v: Vec<u64>,
    primes: Vec<u64>,
}

#[allow(dead_code)]
impl Primes {
    fn new(size: usize) -> Primes {
        let qsize = ((size as f64).sqrt() as usize) + 1;
        let mut v = vec![0; size];
        let mut primes = Vec::new();
        for i in 2..size {
            if v[i] != 0 {
                continue;
            }
            primes.push(i as u64);
            if i <= qsize {
                let mut j = i * i;
                while j < size {
                    v[j] = 1;
                    j += i;
                }
            }
        }
        Primes { size, v, primes }
    }

    // (素数,べき) のVecを返す
    fn factorv(&self, xx: u64) -> Vec<(u64, usize)> {
        let mut x = xx;
        let mut v = Vec::new();
        for &i in &self.primes {
            let mut ct = 0;
            while x % i == 0 {
                x /= i;
                ct += 1;
            }
            if ct != 0 {
                v.push((i, ct));
                if x < i * i {
                    break;
                }
            }
        }
        if x != 1 {
            v.push((x, 1));
        }
        v
    }

    fn divisor(&self, xx: u64) -> Vec<u64> {
        let v = self.factorv(xx);
        let mut div = Vec::new();
        self.divisor2(&mut div, &v, 1);
        div.sort();
        div
    }

    fn divisor2(&self, div: &mut Vec<u64>, v: &[(u64, usize)], val: u64) {
        if v.len() == 0 {
            div.push(val);
        } else {
            let (prime, pow) = v[0];
            self.divisor2(div, &v[1..], val);
            let mut pp = 1;
            for _i in 1..=pow {
                pp *= prime;
                self.divisor2(div, &v[1..], val * pp);
            }
        }
    }
}

//#[proconio::fastout]
fn main() {
    input! {
        n: u64,
    }

    let p = Primes::new(1000001);
    /* n = (a*k+1)*k^b */

    // b == 0
    let v1 = p.divisor(n - 1);

    // b != 0
    let f = |&&x: &&u64| {
        let mut y = n;
        while x != 1 && y % x == 0 {
            y /= x;
        }
        y % x == 1
    };
    let v2 = p.divisor(n);

    let s: BTreeSet<_> = v1.iter().chain(v2.iter().filter(f)).collect();

    println!("{}", s.len() - 1);
}


Measured memory_bytes: 10548
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main(){
    int N,aj,aj1,minj,bj,bminj;
    bool q = true;
    cin >> N;
    string a[N],b[N],c_bub,c_sele;
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    for(int i=0;i<N;i++){
        b[i] = a[i];
    }
    //Bubble
    for(int i=0;i<N;i++){
        for(int j=N-1;j>i;j--){
            aj = a[j][1] - '0';
            aj1 = a[j-1][1] - '0';
            if(aj < aj1){
                c_bub = a[j];
                a[j] = a[j-1];
                a[j-1] = c_bub;
            }
        }
    }
    
    //Selec
    for(int i=0;i<N;i++){
        minj = i;
        for(int j=i;j<N;j++){
            bj = b[j][1] - '0';
            bminj = b[minj][1] - '0';
            if(bj < bminj){
                minj = j;
            }
        }
        c_sele = b[i];
        b[i] = b[minj];
        b[minj] = c_sele;
    }
    
    cout << a[0];
    for(int i=1;i<N;i++){
        cout << " " << a[i];
    }
    cout << endl;
    
    cout << "Stable" << endl;
    
    cout << b[0];
    for(int i=1;i<N;i++){
        cout << " " << b[i];
    }
    cout << endl;
    
    for(int i=0;i<N;i++){
        if(a[i] == b[i]){
            q = true;
        }
        else{
            q = false;
            break;
        }
    }
    if(q){
        cout << "Stable" <<endl;
    }
    else{
        cout << "Not stable" << endl;
    }
}



Measured memory_bytes: 3232
#include<stdio.h>
#include<algorithm>
#include<iostream>
#define dd double
using namespace std;
int main()
{
    dd a,b,t;
    while(cin>>a>>b>>t)
    {
        dd sum=0;
        dd p=a;
        while(a<=(t+0.5))
        {
            sum+=b;
            a+=p;
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/**
 * Author  : dhakad_123
 * Created : 07.08.2020
 **/

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

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

	int x;
	cin >> x;

	if(x >= 30){
		cout << "Yes" << endl;
	}

	else{
		cout << "No" << endl;

	}

	return 0;
}



Measured memory_bytes: 3604
#ABC045D
from collections import defaultdict
h,w,n=map(int,input().split())
ans=defaultdict(int)
for i in range(n):
    a,b=map(int,input().split())
    for j in range(0,-3,-1):
        for k in range(0,-3,-1):
            if a+j>0 and a+j<=h-2 and b+k>0 and b+k<=w-2:
                ans[(a+j,b+k)]+=1
res=[0 for i in range(10)]
for x in ans.values():
    res[x]+=1
res[0]=((h-2)*(w-2))-sum(res[1:])
for i in range(10):
    print(res[i])

Measured memory_bytes: 166920
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
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;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>

namespace n91 {

void solve(const usize n) {
  std::vector<std::string> a(n);
  for (auto &e : a) {
    std::cin >> e;
  }
  i32 lb = -1000000010, ub = 1000000010;
  for (usize i = 1; i < n; ++i) {
    const auto &l = a[i - i % 2];
    const auto &r = a[i - (i + 1) % 2];
    if (l == "x") {
      if (r == "x") {
        std::cout << "none" << std::endl;
        return;
      } else {
        chmin<i32>(ub, std::stoi(r) - 1);
      }
    } else {
      if (r == "x") {
        chmax<i32>(lb, std::stoi(l) + 1);
      } else {
        if (std::stoi(l) >= std::stoi(r)) {
          std::cout << "none" << std::endl;
          return;
        }
      }
    }
  }
  if (lb > ub) {
    std::cout << "none" << std::endl;
  } else if (lb == ub) {
    std::cout << lb << std::endl;
  } else {
    std::cout << "ambiguous" << std::endl;
  }
}

void main_() {
  while (true) {
    const usize n{scan<usize>()};
    if (n == 0) {
      return;
    }
    solve(n);
  }
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N; cin >> N;
    if (N%2==1){
        cout << 0 << endl;
        return 0;
    }
    ll cnt=10,ans=0;
    while(N>=cnt){
        ans+=N/cnt;
        cnt*=5;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, x, m = map(int, input().split())

f = [-1]*m
ans = x
n -= 1
while n > 0:
    if f[x] == -1:
        f[x] = pow(x, 2, m)
        ans += f[x]
        x = f[x]
        n -= 1
    else:
        break
loop = [x]
ans -= x
for i in range(n):
    tmp = pow(loop[-1], 2, m)
    if tmp == loop[0]:
        break
    loop.append(tmp)
loopsum = sum(loop)
ans += (n+1) // len(loop) * loopsum + sum(loop[0:((n+1) % len(loop))])
print(ans)


Measured memory_bytes: 13488
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int s[12]={1,2,1,3,1,3,1,1,3,1,3,1};
  if(s[a-1]==s[b-1]){
    cout << "Yes";
  }else{
    cout << "No";
  }
}


Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	int a = 0;

	roop(i, 0, 4) {
		char c;
		cin >> c;
		if (c == '+') {
			a++;
		}
		else {
			a--;
		}
	}

	cout << a << endl;

	return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

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

    int N, A;
    std::cin >> N >> A;

    const string YESNO[2] = {"No", "Yes"};
    std::cout << YESNO[N % 500 <= A] << std::endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

/*
 * ABC081A - Placing Marbles
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] in = sc.next().toCharArray();
        int count = 0;
        for(char c :in){
            if(c == '1'){
                count++;
            }
        }
        System.out.println(count);
        sc.close();

    }

}


Measured memory_bytes: 23892
const lines=readlines()
state=0
input()=lines[global state+=1]
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
floatSub(s::SubString{String})=parse(Float64,s)
intLine()=map(intSub,split(input()))
function main()
    n=int(input())
    w=input()
    s=Set{String}([w])
    for i=1:n-1
        v=input()
        if in(v,s)||w[end-1]!=v[1]
            println("No")
            exit()
        end
        push!(s,v)
        w=v
    end
    println("Yes")
end
main()

Measured memory_bytes: 121944
#include <bits/stdc++.h>
#define ll long long
#define pub push_back
#define mp make_pair
#define MAX 
#define ull unsigned ll 
using namespace std;

ifstream fin("input.txt");
string str;


int main()
{
  ios :: sync_with_stdio(false);
  ll d  , p , q ;
  int n , cnt = 0  ; 
  cin >> n >> d ;
  d *= d ;
  
  while (n--)
  {
    cin >> p >> q ;
    p *= p ;
    q *= q ;
    
    if (p + q <= d )
      cnt++;
  }
  cout<<cnt<<endl;
  
  
  
}

Measured memory_bytes: 3656
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

  int n,k;
  cin >> n >> k;
  int a[n+1]={0};
  for(int i=1;i<=n;i++){
    cin >> a[i];
  }
  sort(a+1,a+n+1);
  int ans = 0;
  for(int i=1;i<=k;i++)ans+=a[i];
  cout << ans << endl;
  


return 0;
}
///....


Measured memory_bytes: 3676
# coding: utf-8
# Your code here!

N,A,B = map(int,input().split())


if N == 1:
    if A==B:
        print(1)
    else:
        print(0)
else:
    if A>B:
        print(0)
    elif A==B:
        print(1)
    else :
        print(A+B*(N-1) - (B+A*(N-1)) + 1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
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; }

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

    int N, A, B; cin >> N >> A >> B;
    cout << min(N*A, B ) << '\n';
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};



int main(){
  string s;
  cin>>s;
  int a=s[0]-'0';
  int b=s[1]-'0';
  int c=s[2]-'0';

  if(a==b&&b==c){
    cout<<s<<"\n";
    return 0;
  }
  if(b*10+c<=a*10+a){
    cout<<a<<a<<a<<"\n";
    return 0;
  }else{
    cout<<a+1<<a+1<<a+1<<"\n";
  }

  return 0;
}


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

string is_seven(uint i, int sum, vector<int> nums, string formula) {
  if(i == nums.size()) {
    if(sum == 7) {
      return formula;
    }
    else {
      return "";
    }
  }
  string fm;
  if((fm = is_seven(i+1, sum + nums.at(i), nums, formula + "+" + to_string(nums.at(i)))).size() > 0) {
    return fm;
  }
  if((fm=is_seven(i+1, sum - nums.at(i), nums, formula + "-" + to_string(nums.at(i)))).size() > 0) {
    return fm;
  }
  return "";
}

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

  vector<int> nums(4);
  for(int i = 0; i < 4; i++) {
    nums.at(3-i) = n % 10;
    n /= 10;
  }
  cout << nums.at(0) << is_seven(1, nums.at(0), nums, "") << "=7" << endl;
}


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

using namespace std;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << (((abs(a - b) <=d && abs(b - c) <= d) || abs(a - c) <= d)? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
 
signed main(){
	int n,m,cnt[60] = {};
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		cnt[a]++;
		cnt[b]++;
	}
	for(int i = 0;i < n;i++) cout << cnt[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
    string S;
    cin >> S;
    int a = 0, b = 0;
    for (int i = 0; i < S.length(); i++) {
        if (i&1) { if (S[i] == '0') a++; }
        else { if (S[i] == '1') a++; }
    }
    for (int i = 0; i < S.length(); i++) {
        if (!(i&1)) { if (S[i] == '0') b++; }
        else { if (S[i] == '1') b++; }
    }
    
    cout << min(a, b) << endl;
    return 0;
}

Measured memory_bytes: 512
/*
* @Author: _dp95
* @Date:   2020-04-03 07:03:41
*/
#include "bits/stdc++.h"
using namespace std ;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

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

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

const int MAX = 2*1000 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

int n, x, y ;
int ans[MAX] ;
vector< int > v[MAX] ;

void bfs( int x ){
    queue<pair<int,int>>q;
    q.push({x,0});    
    vector< int > dis( n+1, -1 ) ;
    while(!q.empty()){
        auto j = q.front( ) ;
        q.pop( ) ;
        int x = j.F ;
        if(dis[x] != -1 )
            continue ;
        dis[x] = j.S ;
        for( int i : v[x] ){
            if(dis[i] == -1 )
                q.push({i,j.S+1});
        }
    }
    for( int i = 1 ; i <= n ; i++ ){
        ans[dis[i]]++ ;
    }
}

signed main( ){
  timesaver ;
  cin >> n >> x >> y; 
  if(x>y)
    swap(x, y);
  if(y-x>1){
    v[x].pb(y);
    v[y].pb(x);
  }
  for( int i = 2 ; i <= n ; i++ ){
    v[i].pb(i-1);
    v[i-1].pb(i);
  }
  for( int i = 1 ; i <= n ; i++ )
    sort(all(v[i]));
  for( int i = 1 ; i <= n ; i++ ){
    bfs( i ); 
  }
  for( int i = 1 ; i < n ; i++ ){
    cout << ans[i]/2 << nl ;
  }
  cout << nl ;
}

Measured memory_bytes: 384
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            getAns( n);
        }
    }
    static void getAns (int n)
    {
        var m0 = 0; var m1 = 0; var m2 = 0; var m3 = 0;
        var x = new int[n];
        var y = new int[n];
        for (int i = 1; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]);
            var d = int.Parse(line[1]);
            var nx = x[a];  var ny = y[a];
            if (d == 0) { ny--; m0 = Min(m0, ny); }
            else if (d == 1) { nx++; m1 = Max(m1, nx); }
            else if (d == 2) { ny++; m2 = Max(m2, ny); }
            else { nx--; m3 = Min(m3, nx); }
            x[i] = nx;
            y[i] = ny;
        }
        Console.WriteLine("{0} {1}", m2 - m0 + 1, m1 - m3 + 1);
    }
}



Measured memory_bytes: 15868
class Array
  alias_method :enqueue, :push
  alias_method :dequeue, :shift

  def exists?
    !self.empty?
  end
end

n, q = gets.chomp.split(" ").map(&:to_i)
queue = []

n.times {
  a, b = gets.chomp.split(" ")
  queue.enqueue([a, b.to_i])
}

elaps = 0

while queue.exists?
  key, value = queue.dequeue
  min = [value, q].min
  temp_time = value - min
  elaps += min
  if temp_time > 0
    queue.enqueue([key, temp_time])
  else
    puts "#{key} #{elaps}"
  end
end

Measured memory_bytes: 14756
#include <bits/stdc++.h>
using namespace std;
#define max_num_value 100

int selection_sort(vector<int> &value, int num_value){
	int i, j, j_min, num_switch=0;
	
	for(i=0;i<num_value;i++){
		// 未ソート部の位置を記録
		j_min = i;
		for(j=i+1; j<num_value; j++){
			if(value.at(j)<value.at(j_min)){
				j_min = j;
			}
		}
		
		// 未ソート部先頭要素と最小値をスワップ
		// 反転数を更新
		if(i!=j_min){
			swap(value.at(i), value.at(j_min));
			num_switch++;
		}
	}
	return num_switch;
}

int main(){
	int num_value, i, num_switch;
	vector <int> value(max_num_value);
	cin >> num_value;
	for(i=0;i<num_value;i++){
		cin >> value.at(i);
	}
	
	// 選択ソート
	num_switch = selection_sort(value, num_value);
	
	// 出力
	for(i=0;i<num_value-1;i++){
		cout << value.at(i) << " ";
	}
	cout << value.at(num_value-1) << endl << num_switch << endl;
		
	return 0;
}


Measured memory_bytes: 3116
#include <iostream>

using namespace std;

int a[101];
int l;

void printList()
{
  for(int i = 0; i < l-1; ++i) cout << a[i] << " ";
  cout << a[l-1] << endl;
}

void isort()
{
  printList();
  for(int j = 1; j < l; ++j){
    int key = a[j], i = j-1;
    while(i >= 0 && a[i] > key){
      a[i+1] = a[i];
      --i;
    }
    a[i+1] = key;
    printList();
  }
}

int main()
{
  while(cin>>l && l){
    for(int i  = 0; i < l; ++i) cin >> a[i];
    isort();
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  string str;
  cin >> str;
  int arr[26];
  memset(arr,0,sizeof(arr));
  for(int i=0;i<str.length();i++)
  {
    arr[str[i]-97]++;
  }
  int p=0;
  for(int i=0;i<26;i++)
  {
    if(arr[i]%2!=0)
    {
      p=1;
      break;
    }
  }
  if(p==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>

using namespace std;
#define SAY_YES cout<<"YES"<<endl;
#define SAY_Yes cout<<"Yes"<<endl;
#define SAY_NO cout<<"NO"<<endl;
#define SAY_No cout<<"No"<<endl;
#define IFYES(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} 
#define IFYes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} 
#define IFyes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} 
typedef pair<long long int,long long int> pll;


const long long int mod=1000000007;
const long long int INF=99999999999999999;



long long int N;
pll XL[100005],XL2[100005];
int main() {
	cout << fixed << setprecision(18);
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>XL[i].first>>XL[i].second;
        XL[i]={XL[i].second+XL[i].first,-XL[i].second+XL[i].first};
    }
    sort(XL,XL+N);
    long long int now=-INF,res=0;
    for(int i=0;i<N;i++){
        if(now<=XL[i].second){
            now=XL[i].first;
            res++;
        }
    }
    cout<<res<<endl;
} 


Measured memory_bytes: 1792
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
ll x,y;
int main(){
read(x),read(y);
puts(abs(x-y)<2?"Brown":"Alice");
}

Measured memory_bytes: 256
n = int(input())
arr = [int(input()) for _ in range(n)] 

def insertionSort(arr, n, g):
    cnt = 0
    for i in range(g, n):
        key = arr[i]
        j = i - g
        while j >= 0 and arr[j] > key:
            arr[j + g] = arr[j]
            j -= g
            cnt += 1
        arr[j + g] = key
    return cnt

def shellSort(arr, n):
    G = []
    g = 1
    cnt = 0
    while g < n or g == 1:
        G.append(g)
        g = 3*g + 1
    G = G[::-1]
    print(len(G))
    for i in range(len(G)):
        cnt += insertionSort(arr, n, G[i])
    print(*G)
    print(cnt)
    for a in arr:
        print(a)

shellSort(arr, n)


Measured memory_bytes: 45524
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())

    count = 0
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                count += 1
    if count == H+W-1:
        return "Possible"
    return "Impossible"

if __name__ == '__main__':
    print(main())

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

//long int
int min(int a, int b);

int main() {
	int h, w,counter;
	counter = 0;
	cin >> h;
	cin >> w;
	char str[100][100];
	int c[100][100];
	int i,j;
	for (i = 0; i < h; i++) {
		cin >> str[i];
	}
	
	int c1, c2;
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if ((i == 0) && (j == 0)) {
				if (str[0][0] == '#') {
					c[0][0] = 1;
				}
				else {
					c[0][0] = 0;
				}
			}
			else {

				c1 = 1000;
				c2 = 1000;
				if (i > 0) {
					if (str[i][j] == str[i - 1][j]) {
						c1 = c[i - 1][j];
					}
					else {
						c1 = c[i - 1][j] + 1;
					}
				}
				if (j > 0) {
					if (str[i][j] == str[i][j - 1]) {
						c2 = c[i][j - 1];
					}
					else {
						c2 = c[i][j - 1] + 1;
					}
					
				}
				c[i][j] = min(c1, c2);
			}
		}
	}
	cout << (int)((c[h - 1][w - 1] + 1) / 2);
	
}
int min(int a, int b) {
	if (a < b) {
		return a;
	}
	else {
		return b;

	}
}

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

ll dp[105][100005];

ll rec(vector<ll> &w,vector<ll> &v,ll low,ll high,ll weight)
{
    if(low==high)return 0;
    else if(dp[low][weight]!=-1)return dp[low][weight];
    else
    {
        if(w[low]<=weight)return dp[low][weight]=max(v[low]+rec(w,v,low+1,high,weight-w[low]),rec(w,v,low+1,high,weight));
        else return dp[low][weight]=rec(w,v,low+1,high,weight);
    }
}

int main()
{
    ll n,weight;cin>>n>>weight;
    vector<ll> w(n),v(n);
    for(ll i=0;i<n;i++){cin>>w[i]>>v[i];}
    memset(dp,-1,sizeof(dp));
    ll ans=rec(w,v,0,n,weight);
    cout<<ans<<"\n";
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  string s; cin >> s;

  int ans = 0;
  rep(i,n-2){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
  }

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


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

public class Main  {
	static FastReader in = new FastReader();

	public static void main(String[] args) {
		solve();
	}

	static void solve() {
		String s = in.nextLine();
		String t = in.nextLine();
		
		int count = 0;
		for(int i = 0; i < s.length(); i++)
		{
			if(s.charAt(i) != t.charAt(i)) count++;
		}
		System.out.println(count);
	}
	

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] readarr(int abc) {
			int[] a = new int[abc];
			for (int i = 0; i < abc; i++)
				a[i] = nextInt();
			return a;
		}
	}
}





Measured memory_bytes: 30772
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
void init(int a[100001]){
    for(int i = 0; i < 100001; i++){
        a[i] = MM;
    }
}
int main(){
    int cnt = 0;
    int r,g,b,n; cin >> r >> g >> b >> n;
    for(int i = 0; i*r <= 3000; i++){
        for(int j = 0; i*r + j*g <= 3000; j++){
            int tmp = n - i*r - j*g;
            if(tmp % b == 0 && tmp >= 0) cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
s=[x for x in input()]
t=[x for x in input()]
ans=[]
for i in range(len(s)):
  cnt=0
  nowi=i
  fi=i
  for j in range(len(t)):
    if s[nowi]==t[j] or s[nowi]=="?":
      cnt+=1
    else:
      break
    if cnt==len(t):
      ans.append((s[:fi]+t+s[nowi+1:]))
    if nowi+1<=len(s)-1:
      nowi+=1
    else:
      break

A=[]
if len(ans)==0:
  print("UNRESTORABLE")
else:   
  for i in ans:
    moji=""
    for m in i:
      if m=="?":
        moji+="a"
      else:
        moji+=m
    A.append(moji)
  A.sort()
  print(A[0])

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] a = new int[n+1];
		int[] b = new int[n];
		
		for(int i = 0; i < n+1; i++){
		    a[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++){
		    b[i] = sc.nextInt();
		}
		
		// 計算
		long result = 0;
		for(int i = 0; i < n; i++){
		    result = result + min(a[i], b[i]);
		    result = result + min(a[i+1], max(0, b[i] - a[i]));
		    a[i+1] = a[i+1] - min(a[i+1], max(0, b[i] - a[i]));
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 64192
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        while (a % 2 == 0) {
            ans++;
            a /= 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int a,b,c;
int main()
{
	scanf("%d%d",&a,&b);
	if(b<a)b^=a^=b^=a;
	for(;b!=0;a=b,b=c)c=a%b;
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <limits.h>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;

int n, q;
vector<ll> v;

ll query(int a, int b, int k, int l, int r) {
	if(r <= a || b <= l) return 0;
	if(a <= l && r <= b) return v[k];
	ll vl = query(a, b, k*2+1, l, (l+r)/2);
	ll vr = query(a, b, k*2+2, (l+r)/2, r);
	return vl + vr;
}

int main() {
	cin >> n >> q;
	int _n = n;
	n = 1;
	while(n < _n) n *= 2;
	v.resize(2*n-1, 0);
	rep(i, q) {
		int c, x, y;
		cin >> c >> x >> y;
		if(c == 0) {
			x += n-1 - 1;
			v[x] += y;
			while(x > 0) {
				x = (x-1) / 2;
				v[x] += y;
			}
		}
		else {
			cout << query(x-1, y+1-1, 0, 0, n) << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 4940
N = int(input())
S = list(map(int, input().split()))
cost_all = 1e10
for s_set in range(min(set(S)), max(set(S)) + 1):
	cost = 0
	for s in S:
		cost += (s_set - s)** 2
		#print(s, "->", s_set, ":", cost)
	cost_all = min(cost, cost_all)
print(cost_all)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&!(1<<i);}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mul(int a, int b) {return ((a%MOD)*(b%MOD))%MOD;}
int add(int a, int b) {return (a+b)%MOD;}
int sub(int a, int b) {return (((a-b)%MOD)+MOD)%MOD;}
int __div(int a, int b) {return mul(a, powmod(b, MOD-2, MOD));} //if MOD is prime;
const int inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

int32_t main(void)
{
	IOS;
	int n; cin>>n;
	vi a(n); vi b(n); vi c(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i]>>b[i]>>c[i];
	}
	int dp[n][3];
	dp[0][0]=a[0];dp[0][1]=b[0];dp[0][2]=c[0];
	for(int i = 1; i < n; i++) {
		dp[i][0] = max(dp[i-1][1], dp[i-1][2])+a[i];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2])+b[i];
		dp[i][2] = max(dp[i-1][0], dp[i-1][1])+c[i];
	}
	cout<<max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2])<<endl;
	time();	
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    repf(i,1,10) repf(j,1,10) {
        if (n == i*j) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans;

        if(N % 2 == 0){
            System.out.println(N);
        }else{
            System.out.println(2 * N);
        }
    }
}


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

int main() {
  int A;
  int B;
  int C;

  cin >> A >> B >> C;

  int ans = C - (A - B);

  if(ans < 0) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}



int main(){
  int n;
  cin >> n;
  int w[1000];
  FOR(i,n){
    cin >> w[i];
  }
  int cnt=0,cnt1=0,ans=1000000007;
  FOR(i,n){
    cnt=0;
    cnt1=0;
    FOR(j,n){
      
      
      if(j<=i){
        cnt+=w[j];
      }else{
        cnt1+=w[j];
      }
    }
    chmin(ans,abs(cnt-cnt1));
  }

  cout << ans << endl;
  
}

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'));
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	bool flag=true;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		if(a%2==0 && a%3!=0 && a%5!=0)flag=false;
	}
	if(flag)cout<<"APPROVED"<<endl;
	else cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
const LL MOD=1000000007;
typedef map<LL,LL>::iterator Itr;

int main()
{ 
    LL n;
    cin>>n;
    LL bi[n][40];
    for(int i=0;i<n;i++){
        LL x;
        cin>>x;
        for(int j=0;j<40;j++){
            bi[i][j]=x%2;
            x=x/2;
        }
    }
    LL xo[40];
    for(int i=0;i<40;i++){
        xo[i]=0;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<40;j++){
            xo[j]=(xo[j]+bi[i][j])%2;
        }
    }
    LL ans[n];
    for(int i=0;i<n;i++){
        for(int j=0;j<40;j++){
            bi[i][j]=(xo[j]+bi[i][j])%2;
        }
        LL x=bi[i][39];
        for(int j=0;j<39;j++){
            x=x*2+bi[i][38-j];
        }
        ans[i]=x;
    }
    for(int i=0;i<n-1;i++){
        cout<<ans[i]<<' ';
    }
    cout<<ans[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 67564
def main():
  n = int(input())
  a = [int(input()) for i in range(n)]

  s = 1
  for i in range(n):
    if a[s-1] == 2:
      print(i+1)
      exit()
    else:
      s = a[s-1]
  print(-1)
  
if __name__=='__main__':
  main()

Measured memory_bytes: 7192
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */
#include <vector>


int main(void){

    std::vector<int> list;
    for(int i = 0; i < 2; i++){
        int value;
        std::cin >> value;
        if (value <1 || value > pow(10,9)) {
            std::cout << "incorrect value:";
            return 0;
        } else list.push_back(value);
    }

    if (list[0]>list[1]) {
        int key = list[0];
        list[0] = list[1];
        list[1] = key;
    }
     
        while (list[1] > 0) {
            int r = list[0]%list[1];
            list[0] = list[1];
            list[1] = r;
        }

        std::cout << list[0] << std::endl;

        
    return 0;
}

Measured memory_bytes: 1212
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
typedef unsigned int uii;
const int maxn=3005;
int n,a[maxn],u,v,sg[maxn];
vector<int> vec[maxn];
void dfs(int u) {
    sg[u]=0;
    for (uii i=0;i<vec[u].size();++i) {
        int v=vec[u][i];
        if (sg[v]!=-1)
            continue;
        dfs(v);
        if (a[u]>a[v]&&sg[v]==0) {
            sg[u]=1;
            break;
        }
    }
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
        scanf("%d",&a[i]);
    for (int i=0;i<n-1;++i) {
        scanf("%d%d",&u,&v);
        vec[u].push_back(v);
        vec[v].push_back(u);
    }
    for (int i=1;i<=n;++i) {
        memset(sg,-1,sizeof sg);
        dfs(i);
        if (sg[i])
            printf("%d\n",i);
    }
    return 0;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

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

    bool flg = true;
    int  len = s.size();
    for (int i = 0; i < len; i++) {
        if (i % 2 == 0) {
            if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {
            } else {
                flg = false;
                break;
            }
        } else if (i % 2 != 0) {
            if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {
            } else {
                flg = false;
                break;
            }
        }
    }

    if (flg == true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

//  || s[i] == 'U' || s[i] == 'D')


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

class Dice {
	int num[6];
public:
	void set(int n, int s) {
		num[s] = n;
	}

	void move(char c) {
		if (c == 'E') {
			swap(num[0], num[3]);
			swap(num[3], num[5]);
			swap(num[5], num[2]);
		}
		else if (c == 'N') {
			swap(num[0], num[1]);
			swap(num[1], num[5]);
			swap(num[5], num[4]);
		}
		else if (c == 'S') {
			swap(num[0], num[4]);
			swap(num[4], num[5]);
			swap(num[5], num[1]);
		}
		else if (c == 'W') {
			swap(num[0], num[2]);
			swap(num[2], num[5]);
			swap(num[5], num[3]);
		}
	}

	int up() {
		return num[0];
	}

	void move_up(int n) {
		for (int i = 0; num[0] != n && i < 4; i++)
			move('E');
		for (int i = 0; num[0] != n && i < 4; i++)
			move('N');
	}

	void move_front(int n) {
		for (int i = 0; num[1] != n && i < 4; i++)
			move('E');
		for (int i = 0; num[1] != n && i < 4; i++)
			move('N');
	}

	int up_front_to_right(int n, int m) {
		move_up(n);
		if (num[1] == m) {
			return num[2];
		}
		else if (num[2] == m) {
			return num[4];
		}
		else if (num[3] == m) {
			return num[1];
		}
		else {
			return num[3];
		}
	}

	int get_num(int n) {
		return num[n];
	}
};

int main() {
	Dice d1, d2;
	int n;
	for (int i = 0; i < 6; i++) {
		scanf("%d", &n);
		d1.set(n, i);
	}
	for (int i = 0; i < 6; i++) {
		scanf("%d", &n);
		d2.set(n, i);
	}
	for (int l = 0; l < 2; l++) {
		d2.move('N');
		d2.move('E');
		d2.move('S');
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				for (int k = 0; k < 6; k++) {
					if (d1.get_num(k) != d2.get_num(k)) {
						break;
					}
					if (k == 5) {
						puts("Yes");
						exit(0);
					}
				}
				d2.move('E');
			}
			d2.move('N');
		}
	}
	puts("No");
}

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

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

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

#define INF INT_MAX/3

ll n;
string res;

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  ll sum=0;
  repl(i,1,n+1){
    ll nxt=i+1;
    if(nxt*(nxt+1)/2>n){
      n-=i*(i+1)/2;
      string tmp;
      rep(j,i)tmp='('+tmp;
      rep(j,i)tmp=')'+tmp;
      if(n>0){
        res=")"+tmp.substr(0,n-1)+"("+tmp.substr(n-1,tmp.size()-n+1);
      }else res=tmp;
      break;
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3372
N,k,*A = $<.read.split.map{ _1.to_i-1 }
B,C = [i=0],[c=0]
B << i and C[i] = c+=1  until o=C[i=A[i]]
B.shift k<c ? o=0 : o
p B[(k-o+1)%B.size] + 1

Measured memory_bytes: 32040
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>

using namespace std;

char c1,c2;

int main(){
	cin>>c1>>c2>>c2;
	if (c1==c2)puts("Yes");else puts("No");
	return 0;
}

Measured memory_bytes: 256
input = STDIN.readlines.map{|line|line.strip.split()}
line = input.shift
n = line[0].to_i
x = line[1].to_i

p_counts = [1]
whole_counts = [1]

n.times do |i|
    p_counts.push(2 * p_counts[i] + 1)
    whole_counts.push(2 * whole_counts[i] + 3)
end

l = 1
r = whole_counts[-1]
ans = p_counts.pop

while l <= r do
    center = (l + r) >> 1
    pc = p_counts.pop
    if pc.nil? then
        pc = 0
    end
    if x > center then
        r -= 1
        l = center + 1
    else
        l += 1
        r = center - 1
        ans -= pc
        if  x == center
            break
        end
        ans -= 1
    end
end
puts(ans)

Measured memory_bytes: 1788