akhauriyash/Code-Regression huggingface dataset:
import sys
from math import atan2, cos, pi

import numpy as np


def check(engines, theta):
    x, y = 0, 0
    cur = 0
    best = 0
    for dx, dy in engines:
        nx = x + dx
        ny = y + dy
        r = (nx ** 2 + ny ** 2) ** 0.5
        phi = atan2(ny, nx)
        new = r * cos(phi - theta)

        if cur < new:
            x, y = nx, ny
            cur = new
            best = r
    return best


n = int(input())
engines = []
for line in sys.stdin:
    x, y = map(int, line.split())
    engines.append((x, y))

ans = 0
for theta in np.linspace(0, 2 * pi, 10000, False):
    ans = max(ans, check(engines, theta))
print(ans)


Measured memory_bytes: 14648
//Problem *
#include<bits/stdc++.h>
using namespace std;
const int N=305;
int n,a,b,c;
double dp[N][N][N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int _;scanf("%d",&_);
		if(_==1)++a;if(_==2)++b;if(_==3)++c;
	}
	for(int k=0;k<=n;k++)for(int j=0;j<=n;j++)for(int i=0;i<=n;i++)if(0<i+j+k&&i+j+k<=n){
		if(i)dp[i][j][k]+=dp[i-1][j  ][k  ]*i;
		if(j)dp[i][j][k]+=dp[i+1][j-1][k  ]*j;
		if(k)dp[i][j][k]+=dp[i  ][j+1][k-1]*k;
		dp[i][j][k]=(n+dp[i][j][k])/(i+j+k);
	}
	printf("%.12lf",dp[a][b][c]);
	return 0;
}

Measured memory_bytes: 219392
from operator import itemgetter
from itertools import groupby
from heapq import heapify, heappop, heappush

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(reverse=True)
ABg = [(a, list(it))for a, it in groupby(AB, key=itemgetter(0))]
R = 0
H = []
for m in range(1, M+1):
    if ABg and ABg[-1][0] == m:
        for a, b in ABg.pop()[1]:
            heappush(H, -b)
    if H:
        R -= heappop(H)

print(R)

Measured memory_bytes: 40072
#include <stdio.h>
#include <algorithm>
int main( void )
{
	char S[100000+1] ;
	scanf("%s", S ) ;
	int n = 0, c = 0 ;
	char v;
	for( int i = 0 ; S[i] ; i++ ) {
		if( n == 0 ) {
			n++;
			v = S[i];
		} else
		if( v == S[i] ) n++ ;
		else {
			n-- ;
          	c++ ;
		}
	}
	printf("%d\n", c*2 ) ;
	return 0 ;
}



Measured memory_bytes: 256
// AtCoder Regular Contest 071
// C - 怪文書 / Dubious Document

#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX_N 50
#define ALPHABETS 26
using namespace std;
typedef long long int ll;


int N;
int cnt[ALPHABETS];

int main() {

  char s[MAX_N + 2];
  int tmp_count[ALPHABETS];

  scanf("%d", &N);
  fill(cnt, cnt + ALPHABETS, MAX_N);
  for (int i = 0; i < N; i++) {
    scanf("%*c%s", s);
    memset(tmp_count, 0, sizeof(tmp_count));
    for (int j = 0; j < strlen(s); j++) {
      tmp_count[s[j] - 'a']++;
    }
    for (int j = 0; j < ALPHABETS; j++) {
      cnt[j] = min(cnt[j], tmp_count[j]);
    }
  }

  for (int i = 0; i < ALPHABETS; i++) {
    for (int j = 0; j < cnt[i]; j++) {
      printf("%c", i + 'a');
    }
  }
  printf("\n");

  return 0;

}




Measured memory_bytes: 256
#include <cstdio>

int main(){
    int r = 0;
    int g = 0;
    int b = 0;
    scanf("%d %d %d", &r, &g, &b);
    int n = 100*r + 10*g + b;
    if(n % 4 == 0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
 
int main()
{
	long a[5] = {0,0,0,0,0};
	int N;
	scanf("%d",&N);
	int k;
	for(k = 0; k < N; k++)
	{
		char s[10];
		scanf("%s",s);
		if(s[0] == 'M')  a[0]++;
		if(s[0] == 'A')  a[1]++;
		if(s[0] == 'R')  a[2]++;
		if(s[0] == 'C')  a[3]++;
		if(s[0] == 'H')  a[4]++;
	}
	long O = 0;
	int u,n,ko;
	for(u=0; u<=2; u++)
	 {for(n=u+1; n<=3; n++)
	   {for(ko=n+1; ko<=4; ko++)
        {O+= a[u]*a[n]*a[ko];
	}}}
	printf("%ld", O);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); i++)

using namespace std;
using ll = int64_t;

ll gcd(ll x, ll y) {
  if (x == 0)
    return y;
  return gcd(y % x, x);
}

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

  ll a, b;
  cin >> a >> b;
  cout << a * b / gcd(a, b) << endl;
}


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

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e5 + 5;

/***************************************************************************/

int neplus = 0;

string C;
set<int> adj[N];
int deg[N];
int dep[N];

void dfs(int v, int p) {
	dep[v] += (((C[v] == 'W') + deg[v]) % 2) * 2;
	neplus += ((C[v] == 'W') + deg[v]) % 2;

	for(auto it : adj[v]) {
		if(it == p) continue;
		dep[it] = dep[v]; //+ 1;
		dfs(it, v);
	}
}

bool find_path(int v, int p, int t, vector<int> &path) {
	path.pb(v);
	if(v == t) return true;
	for(auto it : adj[v]) {
		if(it == p) continue;
		if(find_path(it, v, t, path)) return true;
	}
	path.pop_back();
	return false;
}

pii find_dia_point(int n) {
	int ans = -1, mx = -1;
	for(int i=1; i<=n; i++) {
		if(deg[i] != 1) continue;
		if(dep[i] > mx) {
			ans = i;
			mx = dep[i];
		}
	}
	assert(ans != -1);
	return mp(ans, mx);
}

inline void flip(char &c) {
	if(c == 'B') c = 'W';
	else c = 'B';
}

int ans = 0;

void dfs_order(int v, int p) {
	flip(C[v]);
	for(auto it : adj[v]) {
		if(it == p) continue;
		ans += 2;
		dfs_order(it, v);
		flip(C[v]);
	}
	if(C[v] == 'W') {
		flip(C[v]);
		ans++;
	}
}

set<pair<pii, int> > S;

int main() {

	boost;
	int n; cin>>n;
	for(int i=1; i<n; i++) {
		int a, b; cin>>a>>b;
		adj[a].insert(b);
		adj[b].insert(a);
		deg[a]++, deg[b]++;
	}
	cin>>C; C = '_' + C;
	
	for(int i=1; i<=n; i++) {
		S.insert(mp(mp(deg[i], (C[i]=='W')), i));
	}

	int ne = n-1;

	while(!S.empty()) {
		int d = S.begin()->fi.fi;
		int c = S.begin()->fi.se;
		int v = S.begin()->se;

		if(d > 1 or c != 0) break;

		S.erase(S.begin());
		ne--;

		for(auto it : adj[v]) {
			auto val = mp(mp(deg[it], (C[it]=='W')), it);
			deg[it]--;
			adj[it].erase(v);

			S.erase(val);
			val.fi.fi--;
			S.insert(val);
		}

		adj[v].clear();
		deg[v] = 0;
	}
	if(S.empty()) {
		cout<<"0\n";
		return 0;
	}
	if(S.size() == 1) {
		cout<<"1\n";
		return 0;
	}

	int root = S.begin()->se;
	dfs(root, 0);
	int a = find_dia_point(n).fi;
	memset(dep, 0, sizeof dep);
	dfs(a, 0);
	int b = find_dia_point(n).se;
	ne *= 2;
	ne -= b;
	ne += neplus / 2;
	cout<<ne<<"\n";


	// vector<int> path;
	// find_path(a, 0, b, path);

	// int last = -1;
	// for(auto it : path) {
	// 	if(last != -1) {
	// 		adj[last].erase(it);
	// 		adj[it].erase(last);
	// 	}
	// 	last = it;
	// }

	// for(auto it : path) {
	// 	ans++;
	// 	dfs_order(it, 0);
	// }
	// cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 26088
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <unordered_map>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main(){
    int n;
    cin >> n;
    int i, j;
    int sum = 0;
    int flag = 0;
    
    for(i = 0; i <= n/4; i++){
        for(j = 0; j <= n/7; j++){
            sum = 0;
            sum = 4 * i + 7 * j;
            if(sum == n){
                flag = 1;
            }
        }
    }
    
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int W,H,x,y,r;
        boolean result = true;//??????????????¨
        //?¨??????\??????????????????????????§????????????
    	Scanner scanner = new Scanner(System.in);
    	//??\????????????int??????????????????
    	W = scanner.nextInt();
    	H = scanner.nextInt();
    	x = scanner.nextInt();
    	y = scanner.nextInt();
    	r = scanner.nextInt();
    	//?¨??????????????????????
    	if((x+r) > W || (x-r) <0){
    		result = false;
    	}
    	//????????????????????????
    	if((y+r) > H || (y-r) <0){
    		result = false;
    	}
    	//????????????
    	if(result){
    		System.out.println("Yes");
    	}
    	else{
    		System.out.println("No");
    	}
    }
}

Measured memory_bytes: 25992
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>

using namespace std;

class Solver {
	
};

int get_value(string s) {
	int val = 0;
	int tmp = 1;
	for (int i = 0; i < s.size(); i++) {
		if ('2' <= s[i] && s[i] <= '9') {
			tmp = s[i] - '0';
			continue;
		}

		if (s[i] == 'm')val += tmp * 1000;
		if (s[i] == 'c')val += tmp * 100;
		if (s[i] == 'x')val += tmp * 10;
		if (s[i] == 'i')val += tmp * 1;
		tmp = 1;
	}
	return val;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s1, s2;
		cin >> s1 >> s2;
		int val = get_value(s1) + get_value(s2);
		vector<char> chars{ 'm','c','x','i' };
		for (int i = 0; i < 4; i++) {
			int digit = (val / 1000) % 10;
			if (digit == 1)cout << chars[i];
			if (digit > 1)cout << digit << chars[i];
			val *= 10;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3128
#include <stdio.h>
int main()
{
  int a,b,c,x,count=0;
  scanf("%d %d %d",&a,&b,&c);
  for(x=a;x<=b;x++)
  {
    if(c%x ==0 )count++;
    else continue;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 596
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    // Rust version 1.15.1, which is used by AtCoder,
    // does not support std::str::FromStr for char
    ($iter:expr, char) => {
        $iter.next().unwrap().chars().next().expect("Parse error")
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;
    use std::collections::HashMap;

    input!{
        n: i32,
        k: i32,
        X: [i32; n],
    }
    let mut ans = 0;
    for x in X {
        ans += min(x, (k-x).abs())*2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<bits/stdc++.h>
#include<climits>

#define forn(x,n,s) for(int i = x; i < n; i += s )
#define forr(x,n,s) for(int i = x; i>=n; i -= s)

using namespace std;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
}

int main(){
    go();

    // code here
    int n;cin>>n;
    long long arr[n];
    forn(0,n,1) cin>>arr[i];
    long long maxm = arr[0];
    long long sol = 0ll;
    forn(1,n,1){
        sol += max(0ll,maxm-arr[i]); 
        maxm = max(maxm,arr[i]);
    }
    cout<<sol;

}






Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
 
bool vector_finder(std::vector<ll> vec, ll number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) {
    return true;
  }
  else {
    return false;
  }
}

std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
 
 
int main() {
  string N;

  cin >> N;

  string ans = "No";
  ll tmp = 0;

  for (ll i = 0; i < N.size(); i++) {
    tmp += ctoi(N.at(i));
  }

  if(tmp%9 == 0) ans = "Yes";

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

Measured memory_bytes: 3724
require 'prime'

class Integer
  def my_divisor_list2
    return [1] if self == 1
    Prime.prime_division(self).map do |e|
      Array.new(e[1]+1).map.with_index do |element, i|
        e[0]**i
      end
    end.inject{|p,q| p.product(q)}.map do |a|
      [a].flatten.inject(&:*)
    end.sort
  end
end

inputs = gets
arr = inputs.split
num = arr[0].to_i
init_x = arr[1].to_i

citys = gets.split
citys.map!(&:to_i)

citys.map! {|a| (a - init_x).abs }

citys.sort!

arr = citys[0].my_divisor_list2.reverse!

arr.each do |a|
  flag = true
  citys.each do |x|
    if x % a != 0 then
      flag = false
      next
    end
  end
  if flag == true then
    p a
    break;
  end
end

Measured memory_bytes: 9240
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
using namespace std;


int main (int argc, char const *argv[])
{
    int a,b;
    cin>>a>>b;
    int c=a*b;

    
    if (c%2==0) {
        cout<<"Even"<<endl;
    }
    else
    {
        cout<<"Odd"<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  string x;
  cin >> x;
  if(x[0] != x[1] && x[1] != x[2] && x[2] != x[0]){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) (x.begin(), x.end())

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int a;
    cin >> a;
    cout << "Christmas ";
    rep(i, 25-a) {
        cout << "Eve ";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main()
{
	double r;
	cin >> r;
	printf("%.5f %.5f\n", r * r * M_PI, 2 * r * M_PI);
	return 0;
}


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

vector<string> divi = {"dream", "dreamer", "erase", "eraser"};
//string divi[4] = {"dream", "dreamer", "erase", "eraser"};

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

	reverse(s.begin(), s.end());
	rep(i, 4){
		reverse(divi.at(i).begin(), divi.at(i).end());
	}

	bool res = true;
	for(int i = 0; i < s.size();){
		bool res2 = false;
		for(int j = 0; j < 4; j++){
			string d = divi.at(j);
			if(d == s.substr(i, d.size())){
				res2 = true;
				i += d.size();
			}
		}

		if(!res2){
			res = false;
			break;
		}
	}

	if(res) cout << "YES" << endl;
	else cout << "NO" << endl;

}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
	int N, T;
	cin >> N >> T;
	int c[100 + 5];
	int t[100 + 5];
	for (int i = 0; i < N; i++)
	{
		cin >> c[i] >> t[i];
	}
	int min = 0;
	for (int i = 0; i < N; i++)
	{
		if (min == 0 && t[i] <= T)
			min = c[i];
		if (t[i] <= T && c[i] < min)
			min = c[i];
		
		
	}
	
	if (min == 0)
		cout << "TLE";
	else
		cout << min;
	

	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
using namespace std;
#define MAX 500000

//int *A = (int *)malloc(sizeof(int));
int A[MAX];

void maxHeapify(int i, int H){
  int l, r, largest, tmp;
  l = i * 2;
  r = i * 2 + 1;

  if(l <= H && A[i] < A[l]) largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i){
    tmp = A[largest]; A[largest] = A[i]; A[i] = tmp;
    maxHeapify(largest, H);
  }
}

void buildMaxHeap(int H){
  for(int i = H/2; i>0; i--) maxHeapify(i, H);
}

int main(void){
  int H;
  cin >> H;
  for(int i=1; i<=H; i++){
    cin >> A[i];
  }

  buildMaxHeap(H);
  for(int i=1; i<=H; i++) cout << " " << A[i];
  cout << endl;
  return 0;
}



Measured memory_bytes: 4928
while True:
	try:
		data = map(int, raw_input().split())
		if data[0] <= 1868 and data[1] <= 9 and data[2] < 8:
			gengo = 'pre-meiji'
		elif 1868 <= data[0] <= 1911:
			gengo = 'meiji' + ' ' + str(data[0]-1867)
		elif data[0] == 1912 and data[1] <= 7 and data[2] < 30:
			gengo = 'meiji 45'
		elif data[0] <= 1925:
			gengo = 'taisho' + ' ' + str(data[0]-1911)
		elif data[0] == 1926 and data[1] <= 12 and data[2] < 25:
			gengo = 'taisho 15'
		elif data[0] <= 1988:
			gengo = 'showa' + ' ' + str(data[0]-1925)
		elif data[0] == 1989 and data[1] == 1 and data[2] <8:
			gengo = 'showa 64'
		else:
			gengo = 'heisei' + ' ' + str(data[0]-1988)
			
		if gengo == 'pre-meiji':
			print gengo
		else:
			print gengo + ' ' +  str(data[1]) + ' ' + str(data[2])
	except EOFError:
		break


Measured memory_bytes: 4268
N=int(input())
data=[]
no10=[]
for i in range (N):
    a=int(input())
    data.append(a)
    if a%10!=0:
        no10.append(a)
        
ans=sum(data)
if ans%10!=0:
    print (ans)
elif len(no10)!=0:
    print(ans-min(no10))
else:
    print (0)

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  string s; cin >> s;
  int n; cin >> n;
  int c = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') c = i + 1;
    else break;
  }
  if (n <= c) cout << 1 << '\n';
  else cout << s[c] << '\n';
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

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

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

  if (n < 1000) cout << "ABC" << endl;
  else cout << "ABD" << endl;

  return 0;
}


Measured memory_bytes: 256
def judge(int):
    if int == 2:return 1
    elif int <= 1 :return 0
    i = 2
    while i*i <= int:
        if int % i == 0:return 0 
        i += 1
    return 1



n = input()
count = 0
for i in range(n):
    if judge(input()) == 1:
        count+=1
print count

Measured memory_bytes: 6608
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    s,w = wi()
    if s <= w:
        print('unsafe')
    else:
        print('safe')

if __name__ == '__main__':
    main()


Measured memory_bytes: 67196
#include <iostream>
using namespace std;
int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  bool ab,bc,ca,t;
  ab = abs(a-b)<=d;
  bc = abs(b-c)<=d;
  ca = abs(c-a)<=d;
  t = (ab&&bc) || ca;
  if(t) cout << "Yes"<<endl;
  else cout <<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  a--; b--;
  int ans = (b+a-1)/a;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
#define int ll
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
 
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
 
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
 
using pi=pair<int,int>;
using vi=vc<int>;
 
template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}
 
template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}
 
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	string s;cin>>s;
	int n=s.size()+1;
	vi a(n);
	rep(i,n-1)
		if(s[i]=='<')
			chmax(a[i+1],a[i]+1);
	per(i,n-1)
		if(s[i]=='>')
			chmax(a[i],a[i+1]+1);
	cout<<accumulate(all(a),int(0))<<endl;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int h, w, d;
map<int, pair<int, int> > rr;

int main(void) {
	//freopen("in.txt", "r", stdin);
	cin >> h >> w >> d;
    vector<vector<pair<int, int> > > r(d);
    rep(i,0,h) rep(j,0,w) {
        int a;
        cin >> a;
        rr[a] = mp(i,j);
    }
    rep(i,1,h*w+1) {
        r[(i%d)].pb(rr[i]);
    }
    vector<vector<ll> > psum(d);
    rep(i,0,d) {
        psum[i].pb(0);
        rep(j,0,sz(r[i])-1) {
            int x = r[i][j].F;
            int y = r[i][j].S;
            int nx = r[i][j+1].F;
            int ny = r[i][j+1].S;
            int cost = abs(x - nx) + abs(y - ny);
            psum[i].pb(cost);
        }
    }
    rep(i,0,d) {
        rep(j,1,sz(psum[i])) {
            psum[i][j] = psum[i][j-1] + psum[i][j];
        }
    }
    int q;
    cin >> q;
    rep(i,0,q) {
        int l, r;
        cin >> l >> r;
        int idx = l%d;
        l = l/d;
        r = r/d;
        if(idx == 0) {
            l--; r--;
        }
        cout << psum[idx][r] - psum[idx][l] << endl;
    }
	return 0;
}

Measured memory_bytes: 15872
program ABC054A
    implicit none
    integer(8)::A,B
    read(5,*)A,B

    if(A==B)then
        print'(A)',"Draw"
    else if(A==1)then
        print'(A)',"Alice"
    else if(B==1)then
        print'(A)',"Bob"
    else if(A>B)then
        print'(A)',"Alice"
    else if(B>A)then
        print'(A)',"Bob"
    end if
end program ABC054A

Measured memory_bytes: 384
N = int(input())
S = input()
ans = 0
d = {"RW": 0, "WR": 0}
for i in range(N):
    if S[i] == "R":
        d["RW"] += 1
ans = d["RW"]
for i in range(N):
    if S[i] == "R":
        d["RW"] -= 1
    else:
        d["WR"] += 1
    ans = min(ans, max(d["RW"], d["WR"]))
print(ans)

Measured memory_bytes: 67956
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int a,b,c; cin>>a>>b>>c;
  cout << (a+b>=c? "Yes" : "No") << '\n';
  return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

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

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);

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

    map<ll, ll> B;

    REP(i, N){
        if(B.count(A[i] + i+1)){
            B[A[i] + i+1]++;
        }
        else{
            B[A[i] + i+1] = 1;
        }
        
        // if(C.count(A[i] - (i+1))){
        //     C[A[i] - (i+1)]++;
        // }
        // else{
        //     C[A[i] - (i+1)] = 1;
        // }
    }
    ll ans = 0;
    REP(i, N){
        if(B.count((i+1) - A[i])){
            ans += B[(i+1) - A[i]];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17100
#include <bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef  unsigned long long ULL;
typedef  double db;
typedef  long double ld;
#pragma comment(linker, "/STACK:102400000,102400000")
#define fuck(x) cout<<x<<endl
#define fuck1(x,y) cout<<x<<" "<<y<<endl
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define MP(a,b) make_pair(a,b)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
const int INF = 0x3f3f3f3f3f,mod = 1e9+7;
const double eps  =1e-6,PI = acos(-1);
template<typename T> inline void read(T &x){
    x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
const int maxn =1e5+100;
int N;
priority_queue<double,vector<double>,greater<double> > ac;
int main(){
    read(N);
    double a;
    for(int i = 1;i<=N;i++)read(a),ac.push(a);
    while(ac.size()!=1){
        double k = ac.top();
        ac.pop();
        double k1 = ac.top();
        ac.pop();
        k = (k+k1)*1.0/2;
        ac.push(k);
    }
    cout<<ac.top()<<endl;

    return 0;
}
/*
abc
abc
*/


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

int main()
{
    int A , B;
    scanf("%d %d",&A,&B);
     int count = 1;
     int min = INT_MAX;
     int c = A;
     if (B==1){printf("0");return 0;}
    while (1)
    {
         if (A==B)
            break;
          else if (A>B)
              break;
     A+=c;
     A--;
     count++;

    }

    printf("%d",count);

    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <bitset>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
const long long N=(5050),M=(250025),LEN=(50);
const long long Mod=(323232323);
const long double EPS=(1e-7);
const long long MAX=(1e18);
///////////////////////////////////////////////
int n,a[N];
long long ans=MAX,A,B,f[N][N];
int main(){
	//freopen("problem.in","r",stdin);
	//freopen("problem.out","w",stdout);
	scanf("%d%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			f[i][j]=MAX;
		}
	}
	f[0][0]=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(a[i]>j){
				f[i][j]=min(f[i][j],f[i-1][j]+A);
				f[i][a[i]]=min(f[i][a[i]],f[i-1][j]);
			}
			if(a[i]<j) f[i][j]=min(f[i][j],f[i-1][j]+B);
		}
	}
	for(int i=1;i<=n;i++) ans=min(ans,f[n][i]);
	printf("%lld\n",ans);
	return 0;
}
/*
3 1 6 2
3 3 6 6
4 5
4 5
*/

Measured memory_bytes: 200540
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i, n) {
        cin >> b[i];
        b[i]--;
    }
    vector<int> ans;
    rep(i, n) {
        bool ok = 0;
        rrep(j, sz(b)) {
            if (b[j] == j) {
                ans.push_back(b[j]);
                b.erase(b.begin() + j);
                ok = 1;
                break;
            }
        }
        if (!ok) {
            cout << -1 << endl;
            return 0;
        }
    }
    rrep(i, n) cout << ans[i] + 1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((x+r<=W)&&(x-r>=0)&&(y+r<=H)&&(y-r>=0)){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

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

int main() {
	ll n,max=0;
	cin>>n;
	string s[n];
	map<string,ll> st;
	for(ll i=0;i<n;i++)
	{
		cin>>s[i];
		++st[s[i]];
	}
	for(auto itr=st.begin();itr!=st.end();itr++)
	{
		if(itr->second>max)
		max=itr->second;
	}
	for(auto itr=st.begin();itr!=st.end();itr++)
	{
		if(itr->second==max)
		cout<<itr->first<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 26752
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INF 1e9
#define PI (acos(-1))
int main() {
    int n;
    string s;
    bool f=true;
    cin>>n>>s;
    if(n%2==0){
        REP(i,n/2){
            if(s[i]!=s[i+n/2]){
                f=false;
            }
        }
        if(f){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n,ans=0;
  cin >> n;
  if(105<=n&&n<135)
    ans=1;
  else if(135<=n&&n<165)
    ans=2;
  else if(165<=n&&n<189)
    ans=3;
  else if(189<=n&&n<195)
    ans=4;
  else if(195<=n)
    ans=5;
  cout << ans << endl;
  return 0;
}

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

def binary_search(a,b):
  top = N
  bottom = b
  c = (top + bottom)//2
  while top - bottom > 1:
    #print(a,b,":",top,bottom,c)
    if L[c] < L[a] + L[b]:
      bottom = c
    else:
      top = c
    c = (top + bottom)//2
  return top - 1

cnt = 0
for a in range(N-2):
  for b in range(a+1,N-1):
    cnt += binary_search(a,b) - b

print(cnt)

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n,k; cin >> n >> k;
	if(n%k==0)cout << 0 << endl;
	else cout << 1;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <algorithm>
#include <limits>
#include <map>

using namespace std;
typedef long long ll;

const int MN = 65650;
int d[MN];
int main() {
    while(1) {
        int n;
        cin >> n;
        if (!n) break;
        ll r = 0;
        for (int i = 0; i < n; i++) {
            int u;
            scanf("%d", &u);
            r += u;
        }
        for (int i = 0; i < n-1; i++) {
            scanf("%d", d+i);
        }
        sort(d, d+n-1, greater<int>());
        ll res = r*n;
        for (int i = 0; i < n-1; i++) {
            r += d[i];
            res = max(res, r*(n-i-1));
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1504
n = int(input())
a = list(map(int, input().split()))
money = 1000
bnf = 0
for i in range(len(a)-1):
    if a[i] < a[i+1]:
        bnf = (money // a[i]) * (a[i+1]-a[i])
        money += bnf
print(money)

Measured memory_bytes: 61756
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	char a,b ;cin >> a >> b;
	if (a==b){
		print("=");
	}else if (a>b){
		print(">");
	}else{
		print("<");
	}
}

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

int main ()
{
 	int a,p,ans;
  cin>>a;
  if(a==1 && a==0)
    cout<<a<<endl;
  
  else if(a%2!=0)
  {
    p = a/2;
    ans = p+1;
    cout<<ans<<endl;
  }
  else
  {
    p = a/2;
    cout<<p<<endl;
  }
}

Measured memory_bytes: 256
a, b, c, d, e, f = map(int, input().split())
m_dens = e/(100+e)

water = 0
sugar = 0
density = 0

for i in range(31):
    for j in range(31):
        w = 100 * a * i + 100 * b * j
        for k in range(101):
            for l in range(101):
                s = c * k + d * l
                if w == 0:
                    break
                elif w + s > f:
                    break
                else:
                    if water == 0:
                        water = w + s
                        sugar = s
                        density = s/(w+s)
                    
                    if density < s/(w+s) <= m_dens:
                        water = w + s
                        sugar = s
                        density = s/(w+s)

print(water, sugar)
#print(density)
#print(m_dens)


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;


int main() {
    int n;
    cin >> n;
    vector<ll> call(n);
    rep(i, n) cin >> call[i];

    if (call.back() != 2) {
        cout << -1 << endl;
        ret();
    }

    vector<ll> cs = call;
    reverse(cs.begin(), cs.end());
    vector<ll> ds = cs;
    for (int i = 1; i < n; i++) {
        ll prev = ds[i - 1];
        ll next = cs[i];
        ll rate = (next + prev - 1) / next;
        ds[i] = next * rate;
    }

    vector<ll> es = cs;
    es[0] = 3;
    for (int i = 1; i < n; i++) {
        ll prev = es[i - 1];
        ll next = cs[i];
        prev++;
        ll rate = (next + prev - 1) / next;
        es[i] = next * rate - 1;
    }

    rep(i, n) {
        if (es[i] < ds[i]) {
            cout << -1 << endl;
            ret();
        }
    }

    cout << ds.back() << ' ' << es.back() << endl;

}



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

int main() {
  string s, t; cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t) cout << "Yes" << endl;
  else    cout << "No" << endl;
}

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


S = [0]*N
for i in range(N):
    S[i] = input()


d = {}
for i in range(N):
    if d.get(S[i]) is None:
        d[S[i]] = 1
    else:
        d[S[i]] += 1

max_val = max(d.values())
keys_of_max_val = [key for key in d if d[key] == max_val]

ans_lst = sorted(keys_of_max_val)
for v in ans_lst:
    print(v)

Measured memory_bytes: 35172
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){

    int n;
    cin >> n;
    ll l[n];
    inrep(n,l);

  
    sort(l,l+n);
    ll ans = 0;

    rep(i,0,n-2){
	rep(j,i+1,n-1){
	    ll w = l[i] + l[j];
	    //   PS(l[i]);PS(l[j]);
	    
	    int m = ub(l+j+1,n-j-1,w-1) ;
	    if(j+1+m < n && l[j+1+m] == w-1)m++;
	    //  P(m);
	    ans += m;
	}
    }
    P(ans);
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    if(s[0]==s[1]&&s[1]==s[2])cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cmath>

using namespace std;

int main()
{
	int A, B, K;
	cin >> A >> B >> K;

	for (int i = A; i < A + K && i <= B; i++)
	{
		cout << i << endl;
	}
	for (int i = max(B - K + 1, A + K); i <= B; i++)
	{
		cout << i << endl;
	}

	return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

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

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

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

	int n = l.size();

	vector<vector<ll>> dp(n+1,vector<ll>(2,0));

	// dp[0][0]=1;
	dp[0][1]=1;
	rep(i,n){
		if(l[i]=='0'){
			dp[i+1][0] += (3*dp[i][0])%mod;
			dp[i+1][0] %= mod;
			dp[i+1][1] += dp[i][1];
			dp[i+1][1] %= mod;
		}else{
			dp[i+1][0] += (3*dp[i][0] + dp[i][1])%mod;
			dp[i+1][0] %= mod;
			dp[i+1][1] += 2*dp[i][1];
			dp[i+1][1] %= mod;
		}
	}

	cout<<(dp[n][0] + dp[n][1])%mod<<endl;

	return 0;
}

Measured memory_bytes: 5760
# coding: utf-8
# Your code here!
kazu = input().split()
for i in range(len(kazu)):
    kazu[i] = int(kazu[i])
if kazu[0] < kazu[1]:
    if kazu[0] < kazu[2] and kazu[1] > kazu[2]:
        print("Yes")
    else:
        print("No")
elif kazu[0] > kazu[1]:
    if kazu[0] > kazu[2] and kazu[1] < kazu[2]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

class program
{
    static void Main()
    {
        var nk = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
        long n = nk[0], k = nk[1];
        var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var tel = new List<int>();
        var istel = new int[n];
        tel.Add(0);
        int rst = 0, pre = 0;
        for (int i = 1; i <= k; i++)
        {
            pre = a[pre] - 1;
            if (istel[pre] == 0)
            {
                tel.Add(pre);
                istel[pre] = i;
            }
            else
            {
                int roop = i - istel[pre];
                long ansid = ((k - istel[pre]) % roop);
                Console.WriteLine(tel[(int)ansid + istel[pre]] + 1);
                return;
            }
        }
        Console.WriteLine(tel.Last() + 1);
    }
}

Measured memory_bytes: 45540
#include <stdio.h>
int main(void){
    // Your code here!
    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+i)%2 == 1){
                        
                        printf(".");
                        
                     }else{
                         
                        printf("#");
                    }
                    
            }
            printf("\n");
            
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 1964