akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n,ans;
  ans = 0;
  cin >> n;
  vector<char> vec1(n);
  for(int i=0;i<n;i++){
    cin >> vec1.at(i);
  }
  for(int i=0;i<n;i++){
    if (vec1.at(i) == 'Y'){
        ans += 1;
    }
  }
  if (ans == 0){
    cout << "Three" << endl;
  }
  else{
  	cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
/**
 * Only By Abhi_Valani
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Unstoppable solver = new Unstoppable();
	//	int t=in.nextInt();
	//	while(t-->0)
        solver.solve(in, out);
        out.close();
    }
 
    static class Unstoppable {
        public void solve(InputReader in, PrintWriter out) {
          //from here...
		  //int[] a = readArray(in, n);
		  int n=in.nextInt();
		  String s=in.next();
		  char[] c=s.toCharArray();
		  int sum=n;
		  char prev=' ';
		  for(int i=0;i<n;i++)
		       {
		           if(c[i]==prev) sum--;
		           prev=c[i];
		       }
		 
		 out.println(sum);
        }
 
    }
 
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
 
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
 
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
 
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
    }
}
 

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

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

    int n; cin >> n;
    vector<double> a(n);
    ll sum = 0;
    for(int i=0; i<n; ++i) cin >> a[i];

    double pro = 1;
    for(int i=0; i<n; ++i) pro *= a[i];
    double X = 0;
    for(int i=0; i<n; ++i) X += pro/a[i];

    double ans = pro/X;

    printf("%.10lf\n", ans);

    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int N;
long double dp[301][301][301];
long double calc(int i, int j, int k) {
	if (dp[i][j][k] != -1) return dp[i][j][k];
	if (i == 0 and j == 0 and k == 0) return dp[i][j][k] = 0;
	dp[i][j][k] = (long double)N / (long double)(i + j + k);
	if (i > 0) dp[i][j][k] += (long double)i / (long double)(i + j + k) * calc(i - 1, j, k);
	if (j > 0) dp[i][j][k] += (long double)j / (long double)(i + j + k) * calc(i + 1, j - 1, k);
	if (k > 0) dp[i][j][k] += (long double)k / (long double)(i + j + k) * calc(i, j + 1, k - 1);
	return dp[i][j][k];
}
int a[301];
int main() {
	cin >> N;
	cout.precision(15);
	for (int i = 1; i <= N; i++) cin >> a[i];
	int i = 0, j = 0, k = 0;
	for (int l = 1; l <= N; l++) i += a[l] == 1, j += a[l] == 2, k += a[l] == 3;
	for (int l = 0; l <= N; l++) {
		for (int m = 0; m <= N; m++) {
			for (int n = 0; n <= N; n++) {
				dp[l][m][n] = -1;
			}
		}
	}
	cout << fixed << calc(i, j, k) << endl;
}


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

int main() {
    int n;
    cin >> n;
    
    vector<long long> A(n);
    for (int i = 0; i < n; i++){
        cin >> A.at(i);
    }
    
    int mode=0;;
    int ans=0;
    for (int i = 0; i < n-1; i++){
        if(A[i]<A[i+1]){
            if(mode==2){
                ans++;
                mode=0;
            }
            else{
            mode=1;
            }
        }
        if(A[i]>A[i+1]){
            if(mode==1){
                ans++;
                mode=0;
            }
            else{
            mode=2;
            }
        }
    }
    cout << ans+1 << endl;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	long long A[100] = {}; 
	for(int i = 0; i < N; i++) cin >> A[i]; 
	bool buy[100] = {}; bool sell[100] = {}; 
	fill(buy, buy + N, true);
	fill(sell, sell + N, true);
	for(int i = 0; i < N-1; i++){
		if(A[i] >= A[i+1]){
			buy[i] = false; sell[i+1] = false; 
		}else{
			buy[i+1] = false; sell[i] = false; 
		}
	}
	long long money = 1000;
	long long kabu = 0; 
	long long ans = 1000; 
	for(int i = 0; i <= N-1; i++){
		if(buy[i]){
			kabu = money / A[i]; 
			money %= A[i]; 
		}else if(sell[i]){
			money += kabu * A[i]; 
			kabu = 0; 
			ans = max(ans, money); 
		}
	}
	cout << ans << "\n"; 
}

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

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

  int ans4 = 100 * r + 10 * g + b;

  if(ans4 % 4 ==0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3612
#include<stdio.h>


void selectionSort(int A[], int N){

  int i, j, k, min, count = 0;

  for( i = 0; i < N ; i++ ){

    min = i;

    for(j = i ; j < N; j++ ){

      if(A[j] < A[min]){
        min = j;
      }
    }
     k = A[i];
     A[i] = A[min];
     A[min] = k;
     if(i != min)count += 1;


  }

  space(A, N);

  printf("%d\n",count);

}


void space(int A[], int N){

  int i;

  for( i = 0; i < N; i++){

    if( i > 0 ){

      printf(" ");

    }

    printf("%d", A[i]);

  }

  printf("\n");

}


int main(void){

  int N, i, j;

  int A[100];

  

  scanf("%d", &N);

  for(i = 0; i < N; i++){

    scanf("%d", &A[i]);

  }

  selectionSort(A, N);

}

Measured memory_bytes: 1852
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int h,w,n; cin >> h >> w >> n;
	h=max(h,w);
	cout << (n+h-1)/h << endl;
}

Measured memory_bytes: 892
// Greedy
#include <bits/stdc++.h>
using namespace std;
int n, k, R, S, P;
string T;
string v;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> k;
    cin >> R >> S >> P;
    cin >> T;
    
    int ans = 0;
    for (int i = 0; i < k; i++){
        if (T[i] == 'r'){
            ans += P;
            v.push_back('p');
        }
        if (T[i] == 'p'){
            ans += S;
            v.push_back('s');
        }
        if (T[i] == 's'){
            ans += R;
            v.push_back('r');
        }
    }

    for (int i = k; i < n; i++){
        if (T[i] == 'r'){
            if (v[i - k] != 'p'){
                ans += P;
                v.push_back('p');
            }
            else v.push_back('?');    
        }
        if (T[i] == 'p'){
            if (v[i - k] != 's'){
                ans += S;
                v.push_back('s');
            }
            else v.push_back('?');    
        }
        if (T[i] == 's'){
            if (v[i - k] != 'r'){
                ans += R;
                v.push_back('r');
            }
            else v.push_back('?');    
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            //string s = Console.ReadLine();

            // 整数の入力
            long a = long.Parse(Console.ReadLine());

            // 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            //var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long result = a + a * a + a * a * a;

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27504
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;

typedef long long ll;
#define RPT(n) for (int i = 0; i < n; i++)

// ABC102-C - Linear Approximation
int main()
{
    int N;
    cin >> N;

    vector<int> A;
    RPT(N)
    {
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }

    vector<int> B;
    RPT(N) B.push_back(A[i] - (i + 1));

    std::sort(B.begin(), B.end());
    int b =
        (B.size() % 2 == 1) ?
            B[B.size()/2] :
            (B[B.size()/2-1] + B[B.size()/2]) / 2;

    ll sadness = 0;
    RPT(N) sadness += abs(A[i] - (b + i + 1));

    cout << sadness << endl;

    return 0;
}


Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

int main(){
    LL N;
    cin >> N;
    LL A,B;
    cin >> A >> B;
    LL T=B-A;
    LL C,D;
    cin >> C >> D;
    LL S=D-C;
    for(int i=0;i<N;i++){
        if(D*i-C*(N-1-i)-S*(N-1)<=T&&T<=D*i-C*(N-1-i)){
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt(),a=scan.nextInt(),b=scan.nextInt(),t1,t2,s=0,i;
		scan.close();
		for(i=1;i<=n;i++) {
			t1=i;
			t2=0;
			do {
				t2+=t1%10;
				t1/=10;
			}while(t1>0) ;
			if(t2>=a&&b>=t2) s+=i;
		}
		System.out.print(s);
	}
}

Measured memory_bytes: 23764
#include<iostream>
using namespace std;
typedef long long ll;
#define inf 1e8
int main() {
    int a, b, c; cin >> a >> b >> c;
    if (a % 2 == 0 && b % 2 == 0 && c % 2 != 0) {
        cout << "NO" << endl;
        return 0;
    }
    for (int i = 1; i < inf; ++i) {
        if ((long long)(a * i) % b == c) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main(void){
    double x1,x2,y1,y2,x,y;
     
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    x = x2 - x1;
    y = y2 - y1;
     
    printf("%lf\n" , sqrt(x*x+y*y));
     
    return 0;
}


Measured memory_bytes: 2044
(defun split (x str)
  (let ((size (length x))
	(retval nil))
    (loop
       :with pos = (search x str)
       :if pos
       :do
	 (push (subseq str 0 pos) retval)
	 (setq str (subseq str (+ size pos)))
	 (setq pos (search x str))
       :else
       :do (return (reverse (push str retval))))))

(defun numbers-by-readline ()
  (mapcar #'parse-integer (split " " (read-line))))

(defconstant blank 0)
(defconstant mine 1)

(defun neighbors (pos w)
  (remove-if #'null
	     (list (if (= (mod pos w) 0) nil (- pos w 1))
		   (- pos w)
		   (if (= (mod pos w) (1- w)) nil (- pos w -1))
		   (if (= (mod pos w) 0) nil (- pos 1))
		   (if (= (mod pos w) (1- w)) nil (+ pos 1))
		   (if (= (mod pos w) 0) nil (+ pos w -1))
		   (+ pos w)
		   (if (= (mod pos w) (1- w)) nil (+ pos w 1)))))

(defun full-inputs ()
  (let ((size (numbers-by-readline)))
    (values
     size
     (format nil "~{~A~}" (loop :repeat (car size) :collect (read-line))))))

(defun find-mine (board w)
  (loop
     :for i :below (length board)
     :collect
       (if (equal (aref board i) #\#)
	   #\#
	   (mapcar #'(lambda (x)
		       (if (equal (aref board x) #\#)
			   mine
			   blank))
		   (remove-if #'(lambda (x)
				  (or (< x 0) (>= x (length board))))
			      (neighbors i w))))))

(defun reshape (l)
  (mapcar #'(lambda (x)
	      (if (listp x)
		  (reduce #'+ x)
		  x))
	  l))

(defun show-result (s w)
  (labels ((f (w)
	     (concatenate 'string "~{~<~%~," (princ-to-string w) ":;~A~>~}")))
    (format t (f w) s)))

(defun mine-sweeper ()
  (multiple-value-bind (s b) (full-inputs)
    (show-result (reshape (find-mine b (cadr s))) (cadr s))))

(mine-sweeper)

Measured memory_bytes: 28920
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a > b)
    for(int i = 0; i < a; i++){
        cout << b;
    }
    else if(a < b){
        for(int i = 0; i < b; i++){
            cout << a;
        }
    }
    else
    {
        for(int i = 0; i < a; i++){
            cout << a;
        }
    }
cout << endl;
}

Measured memory_bytes: 256
import math
a,b,rad_c = map(int,input().split())
S = b * a * math.sin(math.pi / 180 * rad_c) / 2
c = math.sqrt(a**2 + b**2 -2 * a * b * math.cos(math.pi / 180 * rad_c))
L = a + b + c
h = b * math.sin(math.pi / 180 * rad_c)
print(S,L,h)

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

int main() {
  long long int n;
  cin>>n;
  int L=0;
  long long int ans=0;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){  
    L=max(L,a[i]);
      if(a[i]<=L){
        ans+=L-a[i];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3988
import java.util.Scanner;
import java.util.TreeSet;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			char[] c = scanner.next().toCharArray();
			TreeSet<Integer> redSet = new TreeSet<>(), whiteSet = new TreeSet<>();
			IntStream.range(0, n).forEach(i -> {
				if ('R' == c[i]) {
					redSet.add(i);
				} else {
					whiteSet.add(i);
				}
			});
			if ((0 == redSet.size()) || (0 == whiteSet.size())) {
				System.out.println(0);
				return;
			}
			int count = 0;
			while (redSet.last() > whiteSet.first()) {
				int red = redSet.last(), white = whiteSet.first();
				redSet.remove(red);
				redSet.add(white);
				whiteSet.remove(white);
				whiteSet.add(red);
				count++;
			}
			System.out.println(count);
		}
	}
}


Measured memory_bytes: 67068
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;
typedef pair<int,int> pi;
typedef long long ll;

const int N=4e5+5;

int n,m,vi[N],cnt,mx,mn;
pi b[N];
ll ans=1e18;

int main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<=n;i++)scanf("%d%d",&u,&v),b[++m]={u,i},b[++m]={v,i};
	sort(b+1,b+m+1);
	mn=b[1].fi,mx=b[m].fi;
	int l,r;
	for(l=r=1;l<=m;cnt-=--vi[b[l++].se]==0){
		while(r<=m&&cnt<n)cnt+=vi[b[r++].se]++==0;
		if(cnt!=n)break;
		if(l!=1&&r!=m+1)ans=min(ans,(ll)(b[r-1].fi-b[l].fi)*(mx-mn));
	}
	for(int i=1;i<=n;i++)vi[i]=0;cnt=0;
	for(l=1;cnt<n;cnt+=vi[b[l++].se]++==0);l--;
	for(int i=1;i<=n;i++)vi[i]=0;cnt=0;
	for(r=m;cnt<n;cnt+=vi[b[r--].se]++==0);r++;
	ans=min(ans,(ll)(b[l].fi-mn)*(mx-b[r].fi));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(void){
  int H,W,i,j;
  while(1){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0){
        break;
    }
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	    if(j%2==1){
	      if(i%2==1){
	          printf("#");
	      }else{
	          printf(".");
	      }
	    }else{
            if(i%2==1){
                printf(".");
            }else{
                printf("#");
            }
	        }
	    }
        printf("\n");
        }
    printf("\n");
	}
  return 0;
}


Measured memory_bytes: 2056
#include <stdio.h>
#include <stdlib.h>

int euclidian(int a, int b)
{
	int tmp = -1;
	int i = 0;

	while (tmp != 0)
	{
		if ((i % 2) == 0)
		{
			tmp = a % b;
			a = tmp;
		}
		else
		{
			tmp = b % a;
			b = tmp;
		}

		i++;
	}

	if ((i % 2) == 0)
		return a;
	else
		return b;
}

int main()
{
	int a = 0, b = 0;

	scanf("%d %d", &a, &b);
	printf("%d\n", euclidian(a, b));

	return 0;
}


Measured memory_bytes: 2132
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int prime(int n)
{
  for(int i=2;i<=sqrt(n);i++)
  {
    if(n%i==0)
      return 0;
  }
  return 1;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin>>n;
  while(1)
  {
    
    if(prime(n))
    {
      cout<<n;
      break;
    }
    else
      n++;
  }
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn main() {
  input! {
    a: f64, b: f64, h: f64, m: f64
  };

  let r1 = 0.5 * ((h * 60.0 + m) % (12.0 * 60.0));
  let r2 = 6.0 * m;
  let r = if (r1 - r2).abs() > 180.0 {
    180.0 - ((r1 - r2).abs() - 180.0)
  } else {
    (r1 - r2).abs()
  }
  .to_radians();
  let cos = r.cos();
  let res = ((a * a) + (b * b) - (2.0 * a * b * cos)).sqrt();
  println!("{}", res);
}


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

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

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    int current = 1;
    int m = 0;
    rep(i, n)
    {
        if (a.at(i) == current)
        {
            current++;
        }
        else
        {
            m++;
        }
        if (m == n)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 1024
#![allow(dead_code)]
use crate::scanner::Scanner;
fn main() {
    let mut scan = Scanner::new();
    let mut a = scan.read::<i64>();
    let b = scan.read::<i64>();
    let mut c = scan.read::<i64>();
    let d = scan.read::<i64>();
    loop {
        c -= b;
        if c <= 0 {
            println!("Yes");
            return;
        }
        a -= d;
        if a <= 0 {
            println!("No");
            return;
        }
    }
}
mod scanner {
    use std::io::{stdin, BufReader, Bytes, Read, Stdin};
    use std::str::FromStr;
    pub struct Scanner {
        buf: Bytes<BufReader<Stdin>>,
    }
    impl Scanner {
        pub fn new() -> Scanner {
            Scanner {
                buf: BufReader::new(stdin()).bytes(),
            }
        }
        pub fn read_next<T: FromStr>(&mut self) -> Option<T> {
            let token = self
                .buf
                .by_ref()
                .map(|c| c.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect::<String>();
            token.parse::<T>().ok()
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_next().unwrap()
        }
        pub fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read::<T>()).collect()
        }
        pub fn chars(&mut self) -> Vec<char> {
            self.read::<String>().chars().collect()
        }
        pub fn char(&mut self) -> char {
            self.read::<String>().chars().next().unwrap()
        }
    }
}



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

int A, B;

int main () {
    cin >> A >> B;
    if (A == B) {
        cout << "Draw" << endl;
    } else if (A == 1) {
        cout << "Alice" << endl;
    } else if (B == 1) {
        cout << "Bob" << endl;
    } else if (A > B) {
        cout << "Alice" << endl;
    } else {
        cout << "Bob" << endl;
    }
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

int n, i, x;
int cnt, ans;

int main()
{
  //  freopen("test.in","r",stdin);

    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> x;
        if (x == i) {
            cnt++;
        } else {
            ans += (cnt + 1) / 2;
            cnt = 0;
        }
    }

    ans += (cnt + 1) / 2;
    cout << ans;


    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    bool vis[n+1]={false};

    int  x=arr[1];
    int ans=1;
    vis[1]=true;
    if(x==2){
        cout<<ans;
        return 0;
    }
    while(true){

        vis[x]=true;
        ans++;
        x=arr[x];
        if(x==2){
            vis[x]=true;
            break;
        }
        if(vis[x])break;
        }
        if(vis[2])cout<<ans;
        else cout<<-1;
}




Measured memory_bytes: 768
n = int(input())
data = [list(map(int, input().split())) for _ in range(n)]

def to_getH(cx,cy):
    for x, y, h in data:
        if h > 0: #h=0だと式が立てられない
            return abs(x - cx) + abs(y - cy) + h
def to_checkH(cx,cy,H):
    for x, y, h in data:
        if h != max(H - abs(x - cx) - abs(y - cy), 0):
            return False
    return True

for cx in range(101):
    for cy in range(101):
        H = to_getH(cx, cy)
        if to_checkH(cx, cy, H):
            print(cx, cy, H)
            exit()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

ll gcd(ll x, ll y) {
  if(x > y)
    return gcd(y, x);
  else if(x == 0)
    return y;
  else
    return gcd(y % x, x);
}
ll lcm(ll x, ll y) {
  ll g = gcd(x, y);
  return g * (x / g) * (y / g);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int X;
  cin >> X;
  cout << lcm(X, 360) / X << "\n";
  return 0;
}


Measured memory_bytes: 3616
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define clr(x, y) memset(x,y,sizeof(x));
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i, m, n) for(int i=m ; i<n ; i++)
#define forr(i, m, n) for(int i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const double eps = 1e-9;
using namespace std;
int n, k;
ll a[N],fact[N], inv[N];

ll fp(ll base, ll exp) {
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n) {
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r) {
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

int main() {
    IO;
    cin >> n >> k;
    calcFacAndInv(n);
    rep(i, 0, n) cin >> a[i];
    ll mxX = 0,mnX=0;
    sort(a, a + n);
    rep(i, 0, n) {
        mxX += ((a[i] + mod) * ncr(i, k - 1)) % mod;
        mxX %= mod;
    }
    reverse(a, a + n);
    rep(i, 0, n) {
        mnX += ((a[i] + mod) * ncr(i, k - 1)) % mod;
        mnX %= mod;
    }
    ll res = mxX - mnX;
    if (res < 0) res += mod;
    cout << res;

}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int q = sc.nextInt();
		int[][] train = new int[n + 1][n + 1];
		for(int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			train[l][r]++;
		}
		int[][] sum = new int[n + 1][n + 1];
		for(int i = 1; i < n + 1; i++) {
			for(int j = 1; j < n + 1; j++) {
				sum[i][j] = train[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
			}
		}
		for(int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = sum[r][r] - sum[l - 1][r] - sum[r][l - 1] + sum[l - 1][l - 1];
			System.out.println(ans);
		}

	}

}

Measured memory_bytes: 164752
#include <bits/stdc++.h>
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
typedef long long ll;
using namespace std;
const ll INF = 1<<30;
 
string n;
 
int main(){
    cin >> n;
    int sum = 0;
    rep(i, n.size()){
        sum += n[i] - '0';
        sum %= 9;
    }
    
    if(sum==0){
        cout << "Yes" << endl;
        
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3740
#include<iostream>

using namespace std;
 
int main() {
 int n, m;
  int a[30] = {0};
  cin >> n >> m;
  for(int i = 0; i < n; i++) {
  	int k;
    cin >> k;
    for(int j = 0; j < k; j++) {
      int v;
      cin >> v;
      a[v - 1]++;
    }
  }
  int ans = 0;
  for(int i = 0; i < m; i++) {
  	if(n == a[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
let _ =
  let k, s = Scanf.scanf "%d %d\n" (fun k s -> k, s) in
  let res = ref 0 in
  for x=0 to k do
    for y=0 to k do
      if (s - x - y) >= 0 && k >= (s - x - y) then res := !res + 1;
    done
  done;
  !res |> print_int


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int cnt;

void insertionSort(vector<int> &A, int N, int g){
    for(int i=g; i<N; i++){
        int v = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > v){
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void ShellSort(vector<int> &A, int N){
    int m = 0;
    vector<int> G;
    int As = A.size();
    if(As == 1){
        G.push_back(1);
        m += 1;
    }
    while(As != 1){
        if((As % 2 == 1) && As == A.size()) As -= 1;
        else As /= 2;
        G.push_back(As);
        m += 1;
    }
    for(int i=0; i<m; i++){
        // cout << "g" << i << ": " << G[i] << endl;
        insertionSort(A, N, G[i]);
    }
    cout << m << endl;
    for(int j=0; j<m; j++){
        cout << G[j];
        if(j != m-1) cout << " ";
    }
    cout << endl;
    cout << cnt << endl;
}

int main()
{
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        int Ai; cin >> Ai;
        A[i] = Ai;
    }
    ShellSort(A, N);
    for(int i=0; i<N; i++){
        cout << A[i] << endl;
    }
}


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

int main() 
{
    int N,D;
    cin >> N >> D;

    if(N%(D*2+1)==0) {
        cout << N/(D*2+1) << endl;
    }
    else {
        cout << (N/(D*2+1))+1 << endl;
    }
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M[3];
vector<int> E[3][101010];
const ll mo=998244353;
ll p10[20];
ll pv[303030];

int ok[3][303030];

ll from[1010];
ll dp[1010];
ll to[1010];



void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	ll sum=0;

	p10[0]=1;
	FOR(i,19) p10[i+1]=p10[i]*10%mo;
	pv[0]=1;
	FOR(i,302020) pv[i+1]=pv[i]*p10[18]%mo;
	
	from[0]=1;
	FOR(i,3) {
		cin>>M[i];
		FOR(j,M[i]) {
			cin>>x>>y;
			E[i][x-1].push_back(y-1);
			E[i][y-1].push_back(x-1);
		}
		ZERO(dp);
		for(j=N-1;j>=0;j--) {
			set<int> S;
			FORR(e,E[i][j]) if(e>j) S.insert(ok[i][e]);
			while(S.count(ok[i][j])) ok[i][j]++;
			(dp[ok[i][j]]+=pv[j+1])%=mo;
		}
		ZERO(to);
		FOR(x,1000) FOR(y,1000) {
			(to[x^y]+=from[x]*dp[y])%=mo;
		}
		swap(from,to);
	}
	
	cout<<from[0]<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

#define         ull             unsigned long long
#define         ll              long long
#define         inf             INT_MAX
#define         pi              acos(-1.0)
#define         vi              vector<int>
#define         vl              vector<long long>
#define         pii             pair<int,int>
#define         pll             pair<long long,long long>
#define         mp              make_pair
#define         mii             map<int,int>
#define         mll             map<int,int>
#define         mli             multimap<int,int>
#define         mlll            multimap<long long,long long>
#define         msi             multiset<int>
#define         msl             multiset<long long>
#define         si              set<int>
#define         sl              set<long long>
#define         FOR(I,A,B)      for(int I = (A); I < (B); I++)
#define         rev(I,A,B)      for(int I = A ; I >= B ; I--)
#define         mem(a, v)       memset(a, v, sizeof (a))
#define         mod             1000000007
#define         all(a)          a.begin(),a.end()
#define         rall(a)         a.rbegin(),a.rend()
#define         ff              first
#define         ss              second
#define         arsort(ar,n)    sort(ar,ar+n);
#define         vsort(v)        sort(v.begin(),v.end())
#define         vrev(v)         reverse(v.begin(),v.end())
#define         arrev(ar,n)     reverse(ar,ar+n)
#define         pb              push_back
#define         popb            pop_back
#define         booster()       ios_base::sync_with_stdio(0); cin.tie(0);
#define         read(f)         freopen(f, "r", stdin)


#define         min3(a,b,c)     min(a,min(b,c))
#define         max3(a,b,c)     max(a,max(b,c))
#define         min4(a,b,c,d)   min(min(a,b),min(c,d))
#define         max4(a,b,c,d)   max(max(a,b),max(c,d))
#define         max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define         min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))


#define         bitCheck(a,k)     ((bool)(a&(1<<(k))))
#define         bitOff(a,k)       (a&(~(1<<(k))))
#define         bitOn(a,k)        (a|(1<<(k)))
#define         bitFlip(a,k)      (a^(1<<(k)))


int fx[] = {-1,+0,+1,+0,+1,+1,-1,-1,+0};
int fy[] = {+0,-1,+0,+1,+1,-1,+1,-1,+0};
int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

using namespace std;

bool comp(int x, int y) { return x > y; }

int arr[1000000],arr1[1000000];

/*********************** let the play begin() ***********************************/

int main()
{
    booster()
    int a,b,c,d,cnt=0;
    cin>>a>>b>>c>>d;
    FOR(i,a,b+1)
    {
        arr[i]=1;
    }
    FOR(i,c,d+1)
    {
        arr1[i]=1;
    }
    FOR(i,0,500)
    {
        if(arr[i]==1&&arr1[i]==1)
            cnt++;
    }
    if(cnt==0)
        cout<<cnt;
    else
        cout<<cnt-1;
    return 0;
}


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

using namespace std; 

vector<long long> findDivisors(long long n) {
	vector<long long> res;
	for(long long p = 1; p * p <= n; p++) {
		if(n % p == 0) {
			if(p * p == n) {
				res.push_back(p);
			}
			else {
				res.push_back(p);
				res.push_back(n/p);
			}
		}	
	}
	return res;
}

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

	long long n;
	cin >> n;

	vector<long long> divisors = findDivisors(n);

	long long ans = 1e18;

	for(auto i : divisors) {
		ans = min(ans, i + n/i - 2);
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 384
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

global current_time
global visited,go_time,back_time
global G


def dfs(node_id):
    global current_time #書かないとローカル変数扱いされる
    go_time[node_id] = current_time
    current_time += 1

    for next_node in G[node_id]:

        if visited[next_node] == True:
            continue
        visited[next_node] = True
        dfs(next_node)

    back_time[node_id] = current_time
    current_time += 1


V = int(input())

G = [[] for i in range(V)]

visited = [False]*V

go_time = [0]*V
back_time = [0]*V

for loop in range(V):
    node_id,num,*tmp_adj = list(map(int,input().split()))
    node_id -= 1
    for i in range(num):
        G[node_id].append(tmp_adj[i]-1)

current_time = 1;

for i in range(V):
    if visited[i] == True:
        continue
    visited[i] = True
    dfs(i)

for i in range(V):
    print("%d %d %d"%(i+1,go_time[i],back_time[i]))







Measured memory_bytes: 6412
#include <iostream>
#define int long long
using namespace std;

const int N = 3e3;

bool b[N][N];
int n, a[N], val[N][N];

int DFS(int i, int j, int k) {
  if(b[i][j])
    return val[i][j];
  b[i][j] = true;
  if(k < 0)
    val[i][j] = min(DFS(i+1, j, 1) - a[i], DFS(i, j-1, 1) - a[j]);
  else
    val[i][j] = max(DFS(i+1, j, -1) + a[i], DFS(i, j-1, -1) + a[j]);
  return val[i][j];
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  cin >> n;
  int k = ((n % 2) * 2) - 1;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    b[i][i] = true;
    val[i][i] = a[i] * k;
  }
  cout << DFS(0, n-1, 1);
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;


int main() {

	int x;
	cin >> x;
	if (x)cout << 0 << endl;
	if (!x)cout << 1 << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;  
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool bad=false;
    for(int i=0;i<3;++i){
        if(s[i]==s[i+1])bad=true;
    }
    if(!bad){
        cout << "Good" <<endl;
    }else{
        cout << "Bad" <<endl;
    }
    return 0;
}


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

const int N = 1e5 + 10;
const int inf = 1e9 + 7;

struct Node {
    int val;
    int res;
    int l, r;
    Node () {}
    Node (int val, int res, int l, int r) : val(val), res(res), l(l), r(r) {}
};

Node nodes[N * 20];

void build_tree(int l, int r, int id) {
    if (l == r) {
        nodes[id] = Node(l, 0, l, r);
    }
    else {
        nodes[id] = Node(-1, 0, l, r);
        int m = (l + r) >> 1;
        build_tree(l, m, id * 2);
        build_tree(m + 1, r, id * 2 + 1);
    }
}

int get_value(int id, int x) {
    if (nodes[id].val != -1) {
        return nodes[id].val;
    }
    int m = (nodes[id].l + nodes[id].r) >> 1;
    if (x <= m)
        return get_value(id * 2, x);
    else
        return get_value(id * 2 + 1, x);
}

void push_down(int id) {
    if (nodes[id].val != -1 && nodes[id].l != nodes[id].r) {
        nodes[id * 2].val = nodes[id].val;
        nodes[id * 2].res = nodes[id].res;
        nodes[id * 2 + 1].val = nodes[id].val;
        nodes[id * 2 + 1].res = nodes[id].res + nodes[id * 2 + 1].l - nodes[id].l;
        nodes[id].val = -1;
    }
}


void push_up(int id) {
    nodes[id].res = min(nodes[id * 2].res, nodes[id * 2 + 1].res);
}


void update(int id, int l, int r, int val) {
    if (nodes[id].l == l && nodes[id].r == r) {
        nodes[id].val = val;
        nodes[id].res = (val == 0 ? inf : l - val);
        return;
    }
    push_down(id);
    int m = (nodes[id].l + nodes[id].r) >> 1;
    if (r <= m)
        update(id * 2, l, r, val);
    else if (m < l)
        update(id * 2 + 1, l, r, val);
    else {
        update(id * 2, l, m, val);
        update(id * 2 + 1, m + 1, r, val);
    }
    push_up(id);
}

int main() {
//    freopen("in.txt", "r", stdin);
    int h, w, a, b;
    cin >> h >> w;
    build_tree(1, w, 1);
    for (int i = 0; i < h; i++) {
        cin >> a >> b;
        int left_val = (a == 1 ? 0 : get_value(1, a - 1));
        update(1, a, b, left_val);
        if (nodes[1].res == inf) cout << "-1" << '\n';
        else cout << nodes[1].res + i + 1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 11756
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pii pair<ll,ll>
#define forn(i,n) for(int i=0;i<n;i++)
int main()
{
    boost;
    ll n,ans=0,x;
    cin>>n;
    vector<ll> vec;
    map<ll,ll> m1;
    forn(i,n)
    {
        cin>>x;
        m1[x]++;
        if(m1[x]==2 || m1[x]==4)
        {
            vec.pb(x);
        }
    }
    for(int i=0;i<vec.size();i++)
    {
        if(m1[vec[i]]==4)
        ans=(long long int)max(ans,vec[i]*vec[i]);
        
        for(int j=i+1;j<vec.size();j++)
        {
            ans=(long long int)max(ans,vec[i]*vec[j]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6528
def f(start, goal, steps):
  res = set([start])
  for s in steps:
    next_res = set()
    for r in res:
      next_res.add(r + s)
      next_res.add(r - s)
    res = next_res
  return goal in res

s = input()
x, y = map(int, input().split())

ss = s.split("T")
xmove = [i.count("F") for i in ss[::2]]
xfirst = xmove[0] # xの１回目はプラス方向固定のため切り出す
xmove = xmove[1:] # ２回目以降でリスト再作成
ymove = [i.count("F") for i in ss[1::2]]

if f(xfirst, x, xmove) and f(0, y, ymove):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 46044
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
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 FOR(i,m,n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    int n,x[3],dig;
    cin >> n;
    rep(i,3){
        dig = n%10;
        n /= 10;
        if(dig == 9) x[i] = 1;
        else if(dig == 1) x[i] = 9;
        else x[i] = dig;
    }
    repR(i,2) cout << x[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

int main()
{
	ll X;
	cin >> X;
	
	for(ll A = 0; A < 200; A++){
		for(ll B = 0; B < 200; B++){
			if(A*A*A*A*A - B*B*B*B*B == X){
				cout << A << " " << B << endl;
				return 0;
			}
			else if(A*A*A*A*A + B*B*B*B*B == X){
				cout << A << " " << -B << endl;
				return 0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>

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

int main(){

    string s,t;
    int a,b;
    string u;
    cin >>s>>t>>a>>b>>u;

    if(s==u) a-=1;
    if(t==u) b-=1;

    cout << a << " " << b << endl;

     return 0;
}

Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    ans = 0
    for i in range(1, N+1):
        if i&1:
            cnt = 0
            for d in range(1, i+1):
                if i%d==0:
                    cnt += 1
            if cnt == 8:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62560
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

n = ni()
a = na()

flag = True

for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 != 0 and a[i] % 5 != 0:
            flag = False

if flag:
    print("APPROVED")
else:
    print("DENIED")

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


signed main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> A(H, vector<char>(W));
  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W; j++ ){
      cin >> A.at(i).at(j);
    }
  }
  
  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W; j++ ){
      cout << A.at(i).at(j);
    }
    cout << endl;
    for( int j = 0; j < W; j++ ){
      cout << A.at(i).at(j);
    }
    cout << endl;
  }
}



Measured memory_bytes: 256
#include <cstdio>
typedef long long ll;
using namespace std;

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

ll lcm(ll a,ll b){
		return (a*b)/gcd(a,b);
	}	

int main(){
	ll a,b;scanf("%lld %lld",&a,&b);
	ll num = lcm(a,b);
	printf("%lld",num);
	return 0;
	}


Measured memory_bytes: 1732
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>
inline void read(T &x) {
	Finish_read=0;x=0;int f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x*=f;Finish_read=1;
}
template<class T>
inline void print(T x) {
	if(x/10!=0)
		print(x/10);
	putchar(x%10+'0');
}
template<class T>
inline void writeln(T x) {
	if(x<0)
		putchar('-');
	x=abs(x);
	print(x);
	putchar('\n');
}
template<class T>
inline void write(T x) {
	if(x<0)
		putchar('-');
	x=abs(x);
	print(x);
}
/*================Header Template==============*/
const int mx=(1<<26);
int pos[mx],f[200010];
char s[200010];
bitset<26> x[200010];
//vector<int>oddpos;
int main() {
	scanf("%s",s+1);
	int n=strlen(s+1);
	f[0]=0;
	memset(pos,-1,sizeof pos);
	pos[0]=0;
	for(int i=1;i<=n;i++) {
		x[i]^=x[i-1];
		x[i][s[i]-'a']=1-x[i][s[i]-'a'];
		f[i]=2e9;
		int t=x[i].to_ulong(),ind=i;
		for(int j=0;j<26;j++) {
			int tmp=(1<<j)^t;
			if(pos[tmp]!=-1&&f[ind]>f[pos[tmp]])
				ind=pos[tmp];
		}
		if(pos[t]!=-1&&f[ind]>f[pos[t]])
			ind=pos[t];
		f[i]=f[ind]+1;
		if(pos[t]==-1||f[i]<f[pos[t]])
			pos[t]=i;
	}
	printf("%d\n",f[n]);
	return 0;
}

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

typedef long long int ll;

typedef complex<ll> point;

ll cross(point a, point b) { return imag(conj(a) * b); }

ll dot(point a, point b) { return real(conj(a) * b); }

ll area2(point a, point b, point c) { return cross(b - a, c - a); }

namespace std
{
	bool operator<(const point &a, const point &b)
	{
		return real(a) < real(b) || (real(a) == real(b) && imag(a) < imag(b));
	}
}

const ll oo = 0x3f3f3f3f3f3f3f3f;

struct dynamic_hull
{
	dynamic_hull() : hulls() {}

	void add_point(point p)
	{
		hull h;
		h.add_point(p);

		for (hull &_h : hulls)
			if (_h.empty())
			{
				h.swap(_h);
				break;
			}
			else h = merge(h, _h), _h.clear();

		if (!h.empty()) hulls.emplace_back(h);
	}

	ll max_dot(point p)
	{
		ll best = -oo;

		for (hull &h : hulls)
			if (!h.empty()) best = max(best, h.max_dot(p));

		return best;
	}

private:
	struct hull : vector<point>
	{
		void add_point(point p)
		{
			for (int s = size(); s > 1; --s)
				if (area2(at(s - 2), at(s - 1), p) < 0) break;
				else pop_back();
			push_back(p);
		}

		ll max_dot(point p)
		{
			int lo = 0, hi = (int) size() - 1, mid;

			while (lo < hi)
			{
				mid = (lo + hi) / 2;

				if (dot(at(mid), p) <= dot(at(mid + 1), p))
					lo = mid + 1;
				else hi = mid;
			}

			return dot(at(lo), p);
		}
	};

	static hull merge(const hull &a, const hull &b)
	{
		hull h;
		size_t i = 0, j = 0;

		while (i < a.size() && j < b.size())
			if (a[i] < b[j]) h.add_point(a[i++]);
			else h.add_point(b[j++]);

		while (i < a.size()) h.add_point(a[i++]);

		while (j < b.size()) h.add_point(b[j++]);

		return h;
	}

	vector<hull> hulls;
};

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int n;ll c;
  cin >> n >> c;
  vector<ll> h(n);
  for(ll& i: h) cin >> i;
  
  dynamic_hull dh;
  
  dh.add_point(point(h[0] * h[0], h[0]));
  
  ll ans = 0;
  for(int i=1;i<n;++i)
  {
    ll cte = h[i] * h[i] + c;
    
    ll q = -dh.max_dot(point(-1ll, 2ll * h[i])) + cte;
    
    dh.add_point(point(h[i] * h[i] + q, h[i]));
    
    ans = q;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 9960
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    long long int n, a, b;
    while (scanf("%lld %lld %lld",&n,&a,&b)!=EOF) {
        printf("%lld\n", n/(a+b)*a + (((n%(a+b))>a)?a:(n%(a+b))));
    }
    return 0;
}


Measured memory_bytes: 256
#
# abc079 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1222"""
        output = """1+2+2+2=7"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """0290"""
        output = """0-2+9+0=7"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3242"""
        output = """3+2+4-2=7"""
        self.assertIO(input, output)


def resolve():
    N = input()

    for bit in range(1 << 3):
        S = ""
        for j in range(3):
            S += N[j]
            if bit & (1 << j) == 0:
                op = "+"
            else:
                op = "-"
            S += op
        S += N[3]
        if eval(S) == 7:
            print(S+"=7")
            break


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16228