akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<functional>
#include<iomanip>

using namespace std;
const int N = 16;
const double infty = 1e80;

struct state{
  int cur;
  int type;
  int vis;
  double cost;
  state(int cur, int type, int vis, double cost):cur(cur),type(type),vis(vis),cost(cost){}
  bool operator>(const state &t)const{
    return cost > t.cost;
  }
};

double calc_dist( double p[2], double q[2] ){
  return sqrt( pow(abs(p[0]-q[0]),2.) + pow(abs(p[1]-q[1]),2.) );
}

double solve(int n, double p[N][2][2])
{
  double ret = infty;
  priority_queue<state,vector<state>,greater<state> > q; 
  double A[n][2][(1<<n)];

  for(int i = 0; i < n; ++i){
    for(int j = 0; j < 2; ++j){
      for(int k = 0; k < (1<<n); ++k){
        A[i][j][k] = infty;
      }
    }
  }
  
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < 2; ++j){
      q.push(state(i,j,0,0));
      q.push(state(i,j,0,0));
    }
  }
  
  while(!q.empty()){
    state cst = q.top(); q.pop();
    vector<state> next;

    if( cst.vis == (1<<n)-1 ){
      ret = min( ret, cst.cost ); 
    }

    if( cst.vis & (1<<cst.cur) ){
      for(int i = 0; i < n; ++i){
        if( !(cst.vis & (1<<i)) ){
          for(int j = 0; j < 2; ++j){
            next.push_back( state(i,j,cst.vis,cst.cost+calc_dist(p[cst.cur][cst.type],p[i][j]) ) );
          }
        }
      }
    }else{
      next.push_back( state(cst.cur,cst.type^1,cst.vis|(1<<cst.cur),cst.cost+calc_dist(p[cst.cur][0],p[cst.cur][1])) );
    }
    
    for(int i = 0; i < (int)next.size(); ++i){
      if( next[i].cost < A[next[i].cur][next[i].type][next[i].vis] ){
        A[next[i].cur][next[i].type][next[i].vis] = next[i].cost;
        q.push( next[i] );
      }
    }
    
  }

  return ret;
}


int main()
{
  int tc=1;
  while(true){
    int n;
    double res;
    cin >> n;
    if( n == 0 ) break;
    
    double p[N][2][2];
    for(int i = 0; i < n; ++i){
      cin >> p[i][0][0] >> p[i][0][1] >> p[i][1][0] >> p[i][1][1];
    }

    res = solve(n,p);
    cout << "Case " << tc << ": " << fixed << setprecision(8) << res << endl;
    ++tc;
  }
  return 0;
}

Measured memory_bytes: 7516
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

int main(){
    ll n,m,d;
    string S;
    cin >> n >> m >> d;
    ld cnt = 0;
    if(d != 0){
        cnt = n-2*d+n;
    }else{
        cnt = n;
    }
    //cnt = cnt * (m-1);
    ld tmp = (cnt/(n*n));
    ld ans = 0;//tmp/n;//tmp/n;//cnt;
    //vector<ld> DP(m+1);
    //DP[0] = 0;
    rep(i,m-1){
        ans += tmp;
    }
    //cout << tmp << endl;
    cout << setprecision(10) << ans << endl; 
}


Measured memory_bytes: 256
def find_prime(x):
    while True:
        if x == 2:
            return x
        else:
            for i in range(2, x+1):
                if x % i == 0:
                    if i == x:
                        return x
                    else:
                        break
                else:
                    continue
            x += 1


def main():
    x = int(input())

    x = find_prime(x)

    print(x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62916
#!/usr/bin/env ruby

temp = gets.split.map(&:to_i)
vectorA = Array.new(temp[0]*temp[1],0)
vectorB = Array.new(temp[1],0)
sum = 0
temp[0].times do |i|
    foo = gets.split.map(&:to_i)
    temp[1].times do |index|
        vectorA[i*temp[1] + index] = foo[index]
    end
end

temp[1].times do |index|
    vectorB[index] = gets.split.map(&:to_i)[0]
end

temp[0].times do |i|
    temp[1].times do |index|
        sum += vectorA[i*temp[1] + index] * vectorB[index]
    end
    puts sum
    sum = 0
end


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    int D;
    cin >> D;
    vector<int> c(26);
    vector<vector<int>> s(D, vector<int>(26));
    vector<vector<pint>> ss(D, vector<pint>(26));
    REP(i, 26)
    cin >> c[i];
    REP(i, D)
    REP(j, 26){
        cin >> s[i][j];
        ss[i][j].first = s[i][j];
        ss[i][j].second = j;
    }
    REP(i,D)sort(ALL(ss[i]),greater<pint>());
    lint sat = 0;
    vector<int> las(26, -1), con(D);

    vector<int> t(D);
    REP(i,D){
        t[i] = ss[i][0].second + 1;
        cout << t[i] << "\n";
    }
    return 0;
}

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

string s;

int main()
{
        cin >> s;
        int A;
        for(int i=0;i<s.size();++i){
                if(s[i]=='A'){
                        A = i-1;
                        break;
                }
        }
        int Z;
        for(int i=0;i<s.size();++i){
                if(s[s.size()-1-i]=='Z'){
                        Z = s.size()-1-i;
                        break;
                }
        }
        cout << (Z-A) << endl;
}


Measured memory_bytes: 640
n,m = map(int,input().split())
if n==1 and m==1:
    print(1)
elif min(n,m)==1:
    print(max(n,m)-2)
elif min(n,m)==2:
    print(0)
else:
    print(n*m-4-(n-2)*2-(m-2)*2)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <typeinfo>
#include <list>
#include <queue>
#include <stack>
#include <limits.h>
#include <unordered_set>
#include <map>
#include <cstring>

using namespace std;

typedef long long ll;

int mod = 1e9 + 7;

bool Solve(string S, string T) {
    int n = S.size();
    vector<int> l(26, -1);
    vector<int> r(26, -1);
    for (int i = 0; i < n; i++) {
        if ((l[S[i] - 'a'] >= 0 && l[S[i] - 'a'] != T[i] - 'a') ||
            (r[T[i] - 'a'] >= 0 && r[T[i] - 'a'] != S[i] - 'a')) {
            return false;
        }
        if (l[S[i] - 'a'] == -1) {
            l[S[i] - 'a'] = T[i] - 'a';
        }
        if (r[T[i] - 'a'] == -1) {
            r[T[i] - 'a'] = S[i] - 'a';
        }
    }
    return true;
}


int main() {
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    if (Solve(S, T)) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 1112
#include <stdio.h>

int main(void)
{
	int n,i;
	int sum=0,a;
	
	while(scanf("%d",&n)&&n!=0){
		for(i=0;i<n/4;i++){
			scanf("%d",&a);
			sum+=a;
		}
		printf("%d\n",sum);
		sum=0;
	}
	return 0 ;
}

Measured memory_bytes: 600
a,b,n=map(int,input().split())
Alist = list(range(a,min(a+n,b+1),1))
Blist = list(range(max(a,b-n+1),b+1,1))
C = sorted(set(Alist)|set(Blist))
for i in list(C):
  print(i)

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

#define ll long long int

int main() {
string str;
cin>>str;
if(str.length()>=4)
 {
if(str[0]=='Y'&&str[1]=='A'&&str[2]=='K'&&str[3]=='I')
 {
   cout<<"Yes"; 
 }
 else
  {
     cout<<"No";
  }
 }
 else
  {
     cout<<"No";
  }
	return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int a, b;
    cin >> a >> b;
    cout << (a+b)%24<<endl;
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::Chars;

fn main() {
    input! {
        n: usize,
    }
    let mut ans = 0;
    for i in 1..=n {
        let t = f(i, n);

        ans += t
    }
    println!("{}", ans);
}

fn f(x: usize, n: usize) -> usize {
    let num = n / x;
    let ret = (x + x * num) * num / 2;
    return ret;
}


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

int main(){
  int c;
  c = 0;
  int N;
  cin >> N;
  vector<int>vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  while(true){
  int a = 0;
  for (int i=0; i<N; i++){
  	if(vec.at(i)%2 == 0){
  		vec.at(i)=vec.at(i)/2;
  		a++;
  	}
  }
    if(a == N){
      c++;
    }
  	else{
    	break;
  	}
  }
  cout << c <<endl;
}

Measured memory_bytes: 256
small  = [chr(i) for i in range(97,97+26)]
S = list(input())
n = len(S)
if S[0] != 'A' :
    print('WA')
else :
    cnt = 0
    for i in range(2,n-1) :
        if S[i] == 'C'  :
            cnt += 1

    if cnt != 1 :
        print('WA')
    else :
        c = 0
        for i in S :
            if i in small :
                c += 1
        
        if c != n-2 :
            print('WA')
        else :
            print('AC')

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

int main(){
    
    const int MOD = 1000000007;
    int n;
    cin >> n;
    vector<ll> numOfDivisor(n + 1,0);
    for(int i = 1;i <= n;i++){
        ll cur = (ll)i;
        for(int j=2;j <= i;j++){
            while(cur % j == 0){
                cur /= j;
                numOfDivisor[j]++;//i以下の約数を数える
            }

        }

    }

    ll ans =1;
    //剰余演算の合成
    for(int i=1;i <=n;i++){
        if(numOfDivisor[i] > 0LL)ans = (ans * (numOfDivisor[i] + 1LL)) % MOD;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0


int main(){
  int n,d;
  scanf("%d%d",&n,&d);
  d=2*d+1;

  printf("%d",(n-1)/d+1);
  return 0;
}


/// confirm df==0 ///


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll ans=0;
	if(a>=k) cout<<k<<endl;
	else{
		ans+=a;
		k-=a;
		if(b>=k) cout<<ans<<endl;
		else{
			k-=b;
			cout<<ans-k<<endl;
		}
	}
}

Measured memory_bytes: 3652
using System;

class Program{
  public static void Main(){
    var input = Console.ReadLine().Split();
    int n = int.Parse(input[0]);
    int m = int.Parse(input[1]);
    
    input = Console.ReadLine().Split();
    int[] a = new int[n];
    
    int sum_a = 0;
    for(int i=0; i<n; i++){
      a[i] = int.Parse(input[i]);
      sum_a += a[i];
    }
    
    int cnt = 0;
    for(int i=0; i<n; i++){
      if(a[i]　>　sum_a　/(4*m)) cnt++;
      else if(a[i]　==　sum_a　/(4*m)){
        if(sum_a　% (4*m) == 0) cnt++;
      }
    }
    
    if(cnt >= m) Console.WriteLine("Yes");
    else Console.WriteLine("No");
    
    
  }
}
  

Measured memory_bytes: 13140
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = (int)Math.round(a/0.08);
        int d = (int)Math.round(b/0.1);
        if((int)Math.floor(d*0.08) == a){
            System.out.println(d);
        }else if((int)Math.floor(c*0.1) == b){
            System.out.println(c);
        }else{
            System.out.println(-1);
        }
    }
}


Measured memory_bytes: 21972
import math
s = input().rstrip().split(' ')
a = float(s[0])
b = float(s[1])
c = float(s[2])
surface = a * b * math.sin(math.radians(c)) / 2
d = math.sqrt((a ** 2) + (b ** 2) - (2 * a * b * math.cos(math.radians(c))))
line = a + b + d
h = surface * 2 / a
print(surface)
print(line)
print(h)


Measured memory_bytes: 5692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fcout cout << fixed << setprecision(18)

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

  double N; cin >> N;
  double ax = 0.0, ay = 0.0;
  vector<double> x(N), y(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
    ax += x[i];
    ay += y[i];
  }

  ax /= N;
  ay /= N;

  double max;
  double m = 1.0;
  while (m > 1e-8) {
    int k;
    for (int t = 0; t < 100; t++) {
      max = 0.0;
      for (int i = 0; i < N; i++) {
        double temp = (ax - x[i]) * (ax - x[i]) + (ay - y[i]) * (ay - y[i]);
        if (max < temp) {
          k = i;
          max = temp;
        }
      }
      ax += (x[k] - ax) * m;
      ay += (y[k] - ay) * m;
    }
    m /= 1.5;
  }

  double ans = sqrt(max);
  fcout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>

struct Coordinate {
	int y, x;
};
int main() {
	int height, width; std::cin >> height >> width;
	int ch, cw, dh, dw; std::cin >> ch >> cw >> dh >> dw;
	std::vector<std::string> map(height);
	for (auto& row : map) std::cin >> row;
	std::deque<Coordinate> deque;
	deque.push_back(Coordinate{ ch - 1, cw - 1 });
	std::vector<std::vector<int>> min_step(height, std::vector<int>(width, -1));
	min_step[ch - 1][cw - 1] = 0;
	while (!deque.empty()) {
		const auto top = deque.front(); deque.pop_front();
		const auto step = min_step[top.y][top.x];
		for (auto dh = -1; dh <= 1; ++dh) {
			for (auto dw = -1; dw <= 1; ++dw) {
				if (std::abs(dh) + std::abs(dw) != 1) continue;
				const auto nh = top.y + dh;
				const auto nw = top.x + dw;
				if (nh < 0 || height <= nh || nw < 0 || width <= nw) continue;
				if (map[nh][nw] == '.' && (min_step[nh][nw] == -1 || min_step[nh][nw] > step)) {
					min_step[nh][nw] = step;
					deque.push_front(Coordinate{ nh, nw });
				}
			}
		}
		for (auto dh = -2; dh <= 2; ++dh) {
			for (auto dw = -2; dw <= 2; ++dw) {
				const auto nh = top.y + dh;
				const auto nw = top.x + dw;
				if (nh < 0 || height <= nh || nw < 0 || width <= nw) continue;
				if (map[nh][nw] == '.' && (min_step[nh][nw] == -1 || min_step[nh][nw] > step + 1)) {
					min_step[nh][nw] = step + 1;
					deque.push_back(Coordinate{ nh, nw });
				}
			}
		}
	}
	std::cout << min_step[dh - 1][dw - 1] << '\n';
}

Measured memory_bytes: 9600
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	void run(){

		boolean[] np = new boolean[500001];

		np[0] = np[1] = true;

		for(int i=0; i< 500001;i++){

			if(np[i]) continue;

			for(int j = i*2; j < 500001; j += i){

				np[j] = true;

			}

		}

		int[] ans = new int[10001];

		int sum=0;

		int j = 0;

		for(int i=0; j<10000;i++){

			if(!np[i]){

				sum+=i;

				j++;

				ans[j] = sum;

			}

		}

		for(;;){

			int n = sc.nextInt();

			if(n==0){

				break;

			}

			System.out.println(ans[n]);

		}

		

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

		

	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int a,b,c;cin >> a >> b >> c;
  cout << (a*b)/2 << endl;
  return 0;
}


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

int main(){
    int A, B, count = 0;
    cin >> A >> B;
    for(int i = A; i <= B; i++){
        string str = to_string(i);
        string former = str;
        reverse(str.begin(), str.end());
        if(former == str) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
x=[int(i)for i in input().split()]
y=[[int(0)for i in range(4)]for i in range(3)]
y[0][1]=x[0]
y[1][1]=x[1]
y[1][2]=x[2]
y[1][0]=x[3]
y[1][3]=x[4]
y[2][1]=x[5]
m=int(input())
for i in range(m):
    r,l= [int(i) for i in input().split()]
    for j in range(3):
        if y[0][1]==r:
            break
        y[0][1],y[1][1]=y[1][1],y[0][1]
        y[1][1],y[2][1]=y[2][1],y[1][1]
        y[2][1],y[1][3]=y[1][3],y[2][1]
        
    if y[0][1]==r:
        for j in range(4):
            if y[1][1]==l:
                break
            y[1][1],y[1][2]=y[1][2],y[1][1]
            y[1][2],y[1][3]=y[1][3],y[1][2]
            y[1][3],y[1][0]=y[1][0],y[1][3]
            if y[1][1]==l:
                break
    else:
        for j in range(4):
            if y[0][1]==r:
                break
            y[0][1],y[1][2]=y[1][2],y[0][1]
            y[1][2],y[2][1]=y[2][1],y[1][2]
            y[2][1],y[1][0]=y[1][0],y[2][1]
            if y[0][1]==r:
                break
        for j in range(4):
            if y[1][1]==l:
                break
            y[1][1],y[1][2]=y[1][2],y[1][1]
            y[1][2],y[1][3]=y[1][3],y[1][2]
            y[1][3],y[1][0]=y[1][0],y[1][3]
            if y[1][1]==l:
                break
    print(y[1][2])
    

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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int a, b, c; cin >> a >> b >> c;
	if(a == b && b == c) cout << "No" << endl;
	else if(a != b && b!= c && c != a) cout << "No" << endl;
	else cout << "Yes" << endl;   
} 

Measured memory_bytes: 256
n = gets.chomp.to_i
num = n.times.map{ gets.to_i }
max = num.max
semimax = 0
count = 0
n.times do |i|
  if num[i] == max
    if count == 0
      ox = num[i]
      num[i] = 0
      semimax = num.max
    end
    puts semimax
    if count == 0
      num[i] = ox
      count += 1
    end
  else
    puts max
  end
end

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    string t;
    vector<int64_t> nx;
    int64_t m = 0;
    for (auto c : s) {
        if (c == 'x') {
            ++m;
        } else {
            t.push_back(c);
            nx.push_back(m);
            m = 0;
        }
    }
    nx.push_back(m);

    auto tr = t;
    reverse(tr.begin(), tr.end());
    if (t != tr) {
        cout << -1 << endl;
        return 0;
    }

    int64_t ans = 0;
    for (auto i : irange(0uL, nx.size() / 2)) {
        ans += abs(nx[i] - nx[nx.size() - 1 - i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1656
S = list(input())
s = 0
f = 0
n = len(S)
for i in range(n):
    if S[i] == 'A':
        s = i
        break
for j in range(0, n)[::-1]:
    if S[j] == 'Z':
        f = j+1
        break

print(f-s)



Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector< lli > A(X);
  vector< lli > B(Y);
  vector< lli > C(Z);
  vector< lli > p;
  REP(i, X) {
    cin >> A.at(i);
    A.at(i) *= -1ll;
  }
  REP(i, Y) {
    cin >> B.at(i);
    B.at(i) *= -1ll;
  }
  REP(i, Z) {
    cin >> C.at(i);
    C.at(i) *= -1ll;
  }
  sort(ALL(A));
  sort(ALL(B));
  sort(ALL(C));

  // i,j,k => ijk+1位以下。
  REP(i, X) {
    REP(j, Y) {
      for (int k = 0; i * j * k < K && k < Z; k++) {
        p.push_back(A.at(i) + B.at(j) + C.at(k));
      }
    }
  }
  sort(ALL(p));
  REP(i, K) { cout << -1ll * p.at(i) << "\n"; }
}

Measured memory_bytes: 35176
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	hs := make([]int, n)
	for i := range hs {
		sc.Scan()
		hs[i], _ = strconv.Atoi(sc.Text())
	}

	to := make([][]int, n)
	for i := 0; i < m; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())
		a--
		b--
		to[a] = append(to[a], b)
		to[b] = append(to[b], a)
	}

	var ans int
	for i := 0; i < n; i++ {
		ok := true
		for _, j := range to[i] {
			if hs[i] <= hs[j] {
				ok = false
			}
		}
		if ok {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 12056
unittest
{
	assert( [ "3", "6 5 1", "1 10 1" ].parse.expand.solve == "12\n11\n0" );
	assert( [ "4", "12 24 6", "52 16 4", "99 2 2" ].parse.expand.solve == "187\n167\n101\n0" );
	assert( [ "4", "12 13 1", "44 17 17", "66 4096 64" ].parse.expand.solve == "4162\n4162\n4162\n0" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	auto csfs = new long[ 3 ][ n - 1 ];
	foreach( ref csf; csfs )
	{
		input.popFront;
		csf = input.front.split.to!( long[] );
	}
	return tuple( n, csfs );
}

auto solve( long n, long[ 3 ][] csfs )
{
	long[] r;
	foreach( i; 0 .. n - 1 )
	{
		auto t = 0L;
		foreach( csf; csfs[ i .. $ ] )
		{
			// 始発待ち時間
			if( t < csf[ 1 ] ) t = csf[ 1 ];
			
			// 次発待ち時間
			auto fr = t % csf[ 2 ];
			if( 0 < fr ) t += csf[ 2 ] - fr;
			
			// 次の駅までかかる時間
			t += csf[ 0 ];
		}
		r ~= t;
	}
	r ~= 0;
	
	return r.to!( string[] ).join( "\n" );
}


Measured memory_bytes: 380
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

long long N, M, K,a,b,c,d,e,g,mi;
long long ans[3];
long long A[200001];
long long total[200001];
bool f[601][601];
string S;
set <long long>sll;
vector <long long>vll;
typedef pair<long long, long long> pl;
pl buf;
vector <pl>vpl;

int main() {
	cin >> N>>M;
	ans[0] = 0;
	for (int i = 0; i < M; i++) {
		cin >> a>>b;
		buf.first = b;
		buf.second = a;
		vpl.push_back(buf);
	}

	sort(vpl.begin(), vpl.end());
	b = -1;
	for (int i = 0; i < M; i++) {
		if (b <= vpl[i].second) {
			ans[0]++;
			b = vpl[i].first;
		}
	}

	cout << ans[0] << endl;
	

	return 0;
}


Measured memory_bytes: 2420
#include<cstdio>
#include<string.h>
int a[30];
bool flag=true; 
int main(){
	char s[30];
	scanf("%s",s);
	int len=strlen(s);
	memset(a,0,sizeof(a));
	if(len>26) printf("no\n");
	else {
		for(int i=0;i<len;i++){
			if(a[s[i]-'a'+1]==0) a[s[i]-'a'+1]=1;
			else{
				flag=false;
				break;
			}
		}
		if(!flag) printf("no\n");
		else printf("yes\n"); 
	} 
	return 0;
}

Measured memory_bytes: 128
def main():
    target, N = map(int, input().split())
    p = list(map(int, input().split()))

    for i in range(101):
        if target - i not in p:
            print(abs(target - i))
            return
        if target + i not in p:
            print(abs(target + i))
            return


if __name__ == "__main__":
    main()


Measured memory_bytes: 8836
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define rep(i, x) for(int i = 0; i < (int)(x); i++)
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define debug(x)                 cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define debug2(x, y)             cerr << __LINE__ << #x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define debug3(x, y, z)          cerr << __LINE__ << #x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug4(a, b, c, d)       cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define debug5(a, b, c, d, e)    cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define debug6(a, b, c, d, e, f) cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define INF 999999999
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  string s;
  cin >> s;
  int d['z'-'a'+1]={};
  debug(int('a'));
  debug(int('A'));
  debug(char(92));

  rep(i, s.size()){
    d[s[i] - 'a'] = 1;
  }

  rep(i, 'z'-'a'+1){
    if (d[i]==0){
      cout << (char)('a'+i) << endl;
      return 0;
    }
  }

  cout << "None" << endl;

  return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        P p[]=new P[n];
        for (int i = 0; i < p.length; i++) {
			p[i] = new P(sc.nextInt(),sc.nextInt());
		}
        sort(p);
        
        double a=0;
        for (int i = 0; i < p.length; i++) {
        	double x=0,y=0;
			for (int j = i,t=0; t < p.length; t++,j++) {
				j%=n;
				x+=p[j].x;
				y+=p[j].y;
				a=max(a, sqrt(x*x+y*y));
			}
		}
        

        
        out.println(a);
     	out.flush();
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

class P implements Comparable<P>{
	int x,y;
	double rad;
	P(int y, int x) {
		this.x=x;
		this.y=y;
		this.rad=atan2(y,x);
		if(rad<0)
			this.rad+=2*PI;
	}
	
	public int compareTo(P p){
		return (int)signum(rad-p.rad);
	}
}

//class P {
//	int x, y;
//	P(int  x, int y) {
//	  this.x=x;
//	  this.y=y;
//	}
//}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//    	if(a==p.a) return b-p.b;
//        return -p.a+a;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 22868
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

bool func( string s) {
    
    bool flag = true;
    
    for ( int i = 0; i < s.length()-1; i++ ) {
        if ( s.substr( i,1 ) != s.substr( i+1, 1) ) {
            flag = false;
            break;
        }
    }
    
    return flag;
}

int main() {
    
    string S;
    cin >> S;
    
    int num[26] = {0};
    
    int n_max = 0;
    int ans = INT_MAX;
    char alphabet;
    int dist = INT_MAX;
    
    if ( func(S) ) {
        cout << 0 << endl;
        return 0;
    }
    
    
    for ( char c = 'a'; c <= 'z'; c++ ) {
        
        bool flg = false;
        
        for ( int i = 0; i < S.length(); i++ ) {
            if ( *(S.substr(i,1).c_str()) == c ) {
                flg = true;
                break;
            }
        }
        
        if ( !flg ) {
            continue;
        }
        
        int count = 0;
        
        string S_temp = S;  
    
        while ( !func(S_temp) ) {
            
            for ( int i = 0; i < S_temp.length()-1; i++ ) {
                if ( *(S_temp.substr(i,1).c_str()) != c && *(S_temp.substr(i+1,1).c_str()) == c ) {                
                    string temp{c};
                    S_temp.replace( i, 1, temp );
                }
            }
            
            S_temp.pop_back();
            
            count++;
        }
        
        ans = min( ans, count );
    }
    
    
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define pf push_front
#define ll long long
using namespace std;
void TxtRead(){
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
}
void TheTime(){
    ios_base::sync_with_stdio(false);
	cin.tie();
}
const int N = 1e3+5;
const ll INF = 1e9+5;
const ll MOD = 1e9+7;
const double PI = 3.141592653589793116;
const int dX[] = {1, 0};
const int dY[] = {0, 1};

int h, v;
char c[N][N];
bool used[N][N];
int dp[N][N];

void BFS()
{
	queue<pair<int, int> > q;
	q.push({1, 1});
	dp[1][1]=1;
	while(!q.empty()){
		int a=q.front().fr;
		int b=q.front().sc;
		q.pop();
		for(int i=0; i<2; i++)
		{
			int x=a+dX[i];
			int y=b+dY[i];
			if(x>h || y>v || c[x][y]=='#') continue;
			
			if(!used[x][y]){
				used[x][y]=true;
				q.push({x, y});
			}
			
            dp[x][y]+=dp[a][b];
			dp[x][y]%=MOD;
		}
	}
}

int main()
{
    //TxtRead();
    TheTime();
	
	cin>>h>>v;
	for(int i=1; i<=h; i++){
		for(int j=1; j<=v; j++){
			cin>>c[i][j];
		}
	}
	
	BFS();
	cout<<dp[h][v]; 
}


Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	string A, B;
	string ans = "EQUAL";
	cin >> A >> B;

	if (A.size() == B.size())
	{
		for (int i = 0;i < A.size();i++)
		{
			if (A[i] == B[i])
				continue;
			else if (A[i] > B[i])
			{
				ans = "GREATER";
				break;
			}
			else
			{
				ans = "LESS";
				break;
			}
		}
	}
	else
	{
		if (A.size() > B.size())
			ans = "GREATER";
		else
			ans = "LESS";
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    vector<long long> b;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
      long long cur = a[i];
      for (auto& x : b) {
        cur = min(cur, cur ^ x);
      }
      if (cur > 0) {
        if (s[i] == '1') {
          ans = 1;
          break;
        } else {
          b.push_back(cur);
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i<b; i++)
using namespace std;
typedef long long int ll;
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h,a,cnt=0;
    cin>>h>>a;
    while(h>0){
        h-=a;
        cnt++;
    }
    cout<<cnt<<endl;
return 0;
}

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

using namespace std;

int main() {

    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (u == s)
        a -= 1;
    else
        b -= 1;
    cout << a << " " << b;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 36
struct Card{
  char length;
  char value;
};

int main(){
  struct Card C1[N], C2[N],key;
  int i,j,y,f,l=0,mini;
  scanf("%d",&y);
  for(i=0;i<y;i++){
    scanf(" %c%c",&C1[i].length,&C1[i].value);
  }
  for(i=0;i<y;i++){
    C2[i]=C1[i];
  }

  /*BubbleSort*/
  for(i=0;i<y;i++){
    for(j=y-1;j>i;j--){
      if(C1[j].value<C1[j-1].value){
	key=C1[j];
	C1[j]=C1[j-1];  
	C1[j-1]=key;
      }
    }
  }
 for(i=0;i<y-1;i++){
   printf("%c%c ",C1[i].length,C1[i].value);
 }
 printf("%c%c\n",C1[i].length,C1[i].value);
 printf("Stable\n");

 /*SelectionSort*/ 
 for(i=0;i<y;i++){
    mini=i;
    f=0;
    for(j=i+1;j<y;j++){
      if(C2[j].value==C2[mini].value) f=1;
      if(C2[j].value<C2[mini].value){
	mini=j;
	if(f==1) l=1;
      }
    }
    if(mini!=i){
    key=C2[i];
    C2[i]=C2[mini];
    C2[mini]=key;
    }
  }
 for(i=0;i<y-1;i++){
   printf("%c%c ",C2[i].length,C2[i].value);
 }
 printf("%c%c\n",C2[i].length,C2[i].value);
 if(l==1) printf("Not stable\n"); 
 else
   printf("Stable\n");
  return 0;
}

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

public class Main {

    public static void main(String[] args) throws Exception {
        PrintWriter pw = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int n = sc.nextInt();
        int d = 0;
        for (int i = 0; i < n; i++) {
            d += sc.nextInt();
        }
        pw.println(d >= h? "Yes": "No");
        pw.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String file) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}




Measured memory_bytes: 31384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    string s,s1;
    cin>>n>>s;
    if(s.size()<=n)
        cout<<s<<endl;
    else
    {
        for(m=0;m<n+3;m++)
        {
            if(m+1>n)
                s1+='.';
            else
                s1+=s[m];
        }
        cout<<s1<<endl;
    }
    s1.clear();
    return 0;
}


Measured memory_bytes: 3600
class Dice
  #   1
  # 4 2 3 5
  #   6
  attr_reader :pips
  def initialize(*pips)
    @pips = pips
  end

  def rotate!(direction)
    pips = case direction
    when :n then [2, 6, 3, 4, 1, 5].map { |i| i - 1 }
    when :e then [4, 2, 1, 6, 5, 3].map { |i| i - 1 }
    when :w then [3, 2, 6, 1, 5, 4].map { |i| i - 1 }
    when :s then [5, 1, 3, 4, 6, 2].map { |i| i - 1 }
    when :z then [1, 3, 5, 2, 4, 6].map { |i| i - 1 }
    end
    @pips = @pips.values_at(*pips)
    self
  end

  def rotate_to_top!(index)
    case index
    when 1 then self
    when 2 then self.rotate!(:n)
    when 3 then self.rotate!(:w)
    when 4 then self.rotate!(:e)
    when 5 then self.rotate!(:s)
    when 6 then self.rotate!(:n).rotate!(:n)
    end
  end
end

dice1 = Dice.new(*gets.split.map(&:to_i))
dice2 = Dice.new(*gets.split.map(&:to_i))

dice2.pips.each.with_index(1) do |pip, idx|
  next unless pip == dice1.pips[0]
  dice2.rotate_to_top!(idx)
  3.times do
    break if dice2.pips == dice1.pips
    dice2.rotate!(:z)
  end
end

puts dice1.pips == dice2.pips ? 'Yes' : 'No'

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

int main(){
  int k,n,ans=0;cin>>k>>n;
  vector<int> x(n,0),d(n,0);
  REP(i,n) cin>>x.at(i);
  REP(i,n-1) d.at(i)=x.at(i+1)-x.at(i);
  d.at(n-1)=x.at(0)+k-x.at(n-1); 
  sort(d.begin(),d.end());

  cout<<k-d.at(n-1);
}

Measured memory_bytes: 1792
#include <iomanip>
#include <iostream>

using namespace std;


int main() {
  int N;
  cin >> N;
  double tot{};
  string cur;
  double x;
  for (int i = 0; i < N; i++) {
    cin >> x >> cur;
    if (cur == "JPY") {
      tot += x;
    } else {
      tot += x * 380000.;
    }
  }

  cout << fixed << setprecision(16)
       << tot << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
if N == 1:
  print(1)
  exit()
ans = 1
MAX = H[0]
for i in range(1,N):
  if H[i] >= MAX:
    ans += 1
  MAX = max(MAX,H[i])
print(ans)

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

int main()
{
  map<string, string> weather =
    {{"Sunny", "Cloudy"},
     {"Cloudy", "Rainy"},
     {"Rainy", "Sunny"}};
  string s;
  cin >> s;
  cout << weather[s] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  int ind = 1;
  REP(i,n){
    int a; cin >> a;
    if(a==ind) ind++;
  }
  cout << (ind!=1 ? n-ind+1 : -1) << endl;
  
}


Measured memory_bytes: 3548
N = int(input())
a = list(map(int, input().split()))
X = sum(a)
x = a[0]
ans = abs(X - 2*x)
for i in range(1, N-1):
    x += a[i]
    tmp = abs(X-2*x)
    if (ans > tmp):
        ans = tmp
print(ans)


Measured memory_bytes: 24936
N = int(input())
A = [int(input()) for _ in range(N)]
A_dic = {}
for ai in A:
    if ai not in A_dic:
        A_dic[ai] = 1
    else:
        A_dic[ai] += 1

A_sort = sorted(A, reverse=True)
max_1 = A_sort[0]
max_2 = A_sort[1]

for ai in A:
    if ai == max_1 and A_dic[ai] == 1:
        print(max_2)
    else:
        print(max_1)

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
#define fileio freopen("template.in", "r", stdin), freopen("template.out", "w", stdout);
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;

int main() {
    fastio;
    //fileio;
        
    ll n;
    cin >> n;
    ll A[n];
    FOR(i, 0, n) {cin >> A[i];}

    ll currentMax = A[0];
    ll height = 0;

    FOR(i, 0, n) {
        if (A[i] > currentMax) {
            currentMax = A[i];
        } else if (A[i] < currentMax) {
            height += currentMax - A[i];
        }
    }
    cout << height << "\n";
    return 0;
}


Measured memory_bytes: 5212
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
    return a / GCD(a, b) * b;
}

int main()
{ ll n,m;
    cin>>n>>m;
  vector<int>a(n);
  ll lcm=1;
    rep(i,n)
    {ll ai;
    cin>>ai;
    a.at(i)=ai;
    lcm=LCM(lcm,ai);
    //cout << i<<endl;
    }
    lcm/=2;
   // cout << lcm<<endl;
    ll count=0;
    for (ll i = 1; i*lcm <= m; i+=2)
    {
        count++;
      //  cout << i*lcm<<endl;
    }
    rep(i,n)
    {
      if(lcm*2/a[i]%2==0)
      {count=0;}
    }
    cout << count <<endl;
    return 0;
}

Measured memory_bytes: 640
lst = sorted(list(map(int, input().split())))

gap_1 = lst[2] - lst[1]
gap_2 = lst[2] - lst[0]

if (gap_1 - gap_2) % 2 == 0:
    print(gap_2 + (gap_1 - gap_2) // 2)
else:
    print(gap_2 + (gap_1 - gap_2) // 2 + 2)

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

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


int main() {
    int n; cin >> n;
    int ans = 0;
    vector<int> v(n), c(n);
    rep(i,n) cin >> v[i];
    rep(i,n) cin >> c[i];
    rep(i,n) ans += max(0, v[i]-c[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int sum = 0;
    int a[n];
    for (int i = 0; i < n; i++) {
        scanf("%d",&a[i]);
        sum += (a[i]&1);
    }
    printf("%s",(sum&1)?"NO":"YES");
}


Measured memory_bytes: 640
#include <stdio.h>

char s[200000];

int main(void) {

	int n;//食べた回数//
	int m;//食べた回数を15で割った商//
	int money;//今までに払った金額//

	scanf("%d", &n);

	m = n / 15;

	money = 800 * n - 200 * m;

	printf("%d", money);



	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

void visit(int);
int n,adj[101][101],d[101],f[101],time;
char color[101];
int main(){  
  int i,j,a,b;
  scanf("%d",&n);
 
  for(i=1;i<=n;i++) {
    scanf("%d%d",&a,&b);    
    for(j=1;j<=b;j++)
      scanf("%d",&adj[a][j]);
  }

  for(i=1;i<=n;i++) 
    color[i] = 'W';
  time = 0;
  for (i=1;i<=n;i++) 
    if (color[i] == 'W')
      visit(i);
  for(i=1;i<=n;i++)
    printf("%d %d %d\n",i,d[i],f[i]);

  return 0;
}


void visit(int u){

  int i,v;
  color[u] = 'G' ;
  d[u] = ++time;
  for(i=1;i<=n;i++){
    if(adj[u][i]!=0){
      v=adj[u][i];
      if (color[v] == 'W')
	visit(v);

    }
  }
  color[u] = 'B'; 
  f[u] = ++time;

}

Measured memory_bytes: 636
require 'set'

n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i).shuffle

def gcd(n1, n2)
  return n2 if n1 % n2 == 0
  gcd(n2, n1 % n2)
end

if a.inject { |acc, k| gcd(acc, k) } > 1
  puts 'not coprime'
else
  m = a.max
  d = (0..m).map { nil }
  (2..m).each { |k| k.step(m, k) { |i| d[i] ||= k } }

  setwise_coprime = false

  s = Set.new
  a.each do |k|
    primes = Set.new
    while k > 1
      primes.add(d[k])
      k /= d[k]
    end

    primes.each do |prime|
      if s.member?(prime)
        setwise_coprime = true
        break
      else
        s.add(prime)
      end
    end
    break if setwise_coprime
  end

  if setwise_coprime
    puts 'setwise coprime'
  else
    puts 'pairwise coprime'
  end
end


Measured memory_bytes: 126580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    
    int a, b; cin >> a >> b;
    cout << a*b << " " << 2*a+2*b << endl;
}


Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
#define f0(i, n) for (int i = 0; i < n; i++)
#define fs(i, s) for (int i = 0; i < s.size(); i++)
#define ll long long int
#define nl endl
int main()
{
	int n;
	cin>>n;
	if(n%1000!=0)cout<<1000-(n%1000);
	else cout<<0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
ll INF = 214748364700000000;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

bool F(string S){
    rep(i,26){
        if(count(ALL(S),'a'+i) >= 2) return true;
    }
    return false;
}

int main(){
   string S;
   cin >> S;
   rep(i,S.size()-1){
       if(S[i] == S[i+1]){
           cout << i+1 << ' ' << i+2 << endl;
           return 0;
       }
   }
   rep(i,S.size()-2){
       if(F(S.substr(i,3))){
           cout << i+1 << ' ' << i+3 << endl;
           return 0;
       }
   }
   cout << "-1 -1" << endl;
}


Measured memory_bytes: 512