akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


ll x, ans=0;

void solve()
{
    cin >> x;
    ans += (x/500)*1000;
    x %= 500;
    ans += (x/5)*5;
    nout(ans);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import collections

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N = NI()
    xy = [NLI() for _ in range(N)]
    
    ls = [p for p in range(N)]
    p_list = list(itertools.permutations(ls))
    
    full_course = ["" for _ in range(len(p_list))]
    
    for k in range(len(p_list)):
        distance = 0
        for l in range(N-1):
            departure = p_list[k][l] 
            goal = p_list[k][l+1]
            Xd = xy[departure][0]
            Yd = xy[departure][1]
            Xg = xy[goal][0]
            Yg = xy[goal][1]
            distance += ((Xd-Xg)**2 + (Yd-Yg)**2)**(1/2)
        full_course[k] = distance

    print(sum(full_course)/len(p_list))


if __name__ == '__main__':
    main()

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

int LIS[100010];
int main() {
    int N; cin >> N;
    fill(LIS, LIS + N + 1, 1 << 30);
    for(int i=0; i<N; i++) {
        int val; cin >> val;
        LIS[ lower_bound(LIS, LIS + N, val) - LIS ] = val;
    }
    cout << lower_bound(LIS, LIS + N, 1 << 30) - LIS << endl;
    return 0;
}


Measured memory_bytes: 3476
import sys

input = lambda: sys.stdin.readline().rstrip()

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
F = sorted(list(map(int, input().split())))


def binary_search(min_n, max_n):

    while max_n - min_n != 1:
        tn = (min_n + max_n) // 2
        if judge(tn):
            max_n = tn
        else:
            min_n = tn

    return max_n


def judge(tn):

    k = 0
    for i in range(N):
        if A[i] * F[i] > tn:
            k += A[i] - (tn // F[i])
        if k > K:
            return False

    return True


def solve():

    ans = binary_search(-1, 10**12)
    print(ans)


if __name__ == '__main__':
    solve()


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

int ans, ans1, ans2;

int main() {
  string s;
  cin >> s;
  rep (i, s.length()) {
    if (s[i] == (i % 2 == 0 ? '0' : '1')) ans1++;
    if (s[i] == (i % 2 == 0 ? '1' : '0')) ans2++;
  }
  ans = min(ans1, ans2);
  cout << ans << endl;
  return 0;
}


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

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

    string s;
    cin >> s;

    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let s = scan.chars();
    let n = s.len();
    let mut is_ok = true;
    if s[0] != '1' || s[n-1] != '0' {
        is_ok = false;
    }
    for i in 0..n {
        if i >= n-2-i {break;}
        if s[i] != s[n-2-i] {
            is_ok = false;
        }
    }
    if !is_ok {
        println!("-1");
        return;
    }
    let mut leaf = vec![];
    let mut edge = vec![];
    for i in 0..n {
        let mut c = s[i];
        if i == n-1 {c = '1';}
        if c == '0' {
            leaf.push(i);
        } else {
            for &v in &leaf {
                edge.push((v, i));
            }
            leaf = vec![i];
        }
    }
    for &(p, q) in &edge {
        println!("{} {}", p+1, q+1);
    }
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

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

int solve_testcase() {
    int N; cin >> N;
    if(N == 0) return 1;

    vector< pair<int, int> > info;
    for(int i=0; i<N; i++) {
        int id; cin >> id;
        int sum = 0;
        for(int k=0; k<4; k++) {
            int m, s; cin >> m >> s;
            int total_time = m * 60 + s;
            sum += total_time;
        }
        info.emplace_back(sum, id);
    }

    sort(info.begin(), info.end());
    cout << info[0].second << endl;
    cout << info[1].second << endl;
    cout << info[N-2].second << endl;
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 3092
o = ord('a')
s = [ord(c) - o for c in raw_input().strip()]
k = int(raw_input())
for i, c in enumerate(s):
    if c and 26 - c <= k:
        k -= 26 - c
        s[i] = 0
k %= 26
s[-1] += k
if s[-1] >= 26:
    s[-1] -= 26
print ''.join(chr(o + c) for c in s)

Measured memory_bytes: 4360
n = int(input())
mod = 10**9+7
s = [0] * (n+1)

for i in range(2, n+1):
    p = 2
    while i>1:
        while i%p==0:
            i //= p
            s[p] += 1
        p += 1

ans = 1
for i in s:
    ans *= i+1
    ans %= mod

print(ans)

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

int main()
{
    int n, k, s, t, c;
    cin >> n >> k;
    set<int> st;
    for (int i = 0; i < k; i++)
    {
        cin >> t;
        st.insert(t);
    }
    s = n;
    c = 0;
    while (s != 0)
    {
        t = s % 10;
        s = s / 10;
        if (st.find(t) != st.end())
        {
            c++;
            s = n + c;
            continue;
        }
    }
    cout << n + c << endl;
}

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

int main()
{
    int W, a, b;
    cin >> W >> a >> b;

    if (a > b) swap(a, b);

    int ans = b - a - W;
    if (ans < 0)
        cout << 0 << endl;
    else
        cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String p = sc.next();
        boolean ans = false;
        
        s = s + s;
        
        if (s.indexOf(p) >= 0) {
            ans = true;
        }
            
        System.out.println(ans?"Yes":"No");
    }
}


Measured memory_bytes: 26236
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
template <typename T>
using V = std::vector<T>;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)
#define SORT(v) sort((v).begin(), (v).end())

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  V<int> a(N), sa(N);
  unordered_set<int> oddm;
  REP(i, N) {
    int x;
    cin >> x;
    a[i] = sa[i] = x;
  }
  SORT(sa);
  REP(i, N) {
    if (i % 2 == 1) oddm.insert(sa[i]);
  }
  int ans = 0;
  REP(i, N) {
    if (i % 2 == 0 && oddm.count(a[i])) ++ans;
  }
  cout << ans << endl;
}


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

int main() {
  
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  int x = 1,y = 1;
  
  while(true){
    c -= b;
    if( c <= 0 ){
      x = 0;
      break;
    }
    a -= d;
    if( a <= 0 ){
      y = 0;
      break;
    }
  }
  
  if ( x == 0 && y ==  1 ){
    cout << "Yes" << endl;
  }else if ( x == 1 && y == 0 ){
    cout << "No" << endl;
  }
    
      
  
  
}



Measured memory_bytes: 3636
using System;
using System.Linq;

class Test
{
    static void Main()
    {
        int d = int.Parse(Console.ReadLine());
        double[] e = Console.ReadLine().Split().Select(double.Parse).ToArray();

        Console.WriteLine("{0} {1} {2}", e.Min(), e.Max(), e.Sum());
    }
}


Measured memory_bytes: 20972
N = int(input())
A = sorted(list(map(int, input().split())))
# A = sorted(list(map(int, input().split())), reverse=True)


# print(A)

idx = []
for i in range(N + 1 // 2):
    idx.append(i)
    idx.append(i)

idx = idx[::-1]
idx = idx[1:N]
# print(idx)
ans = 0
for i in idx:
    ans += A[i]
print(ans)


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

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

using namespace std;

int n, a[200005];
map<int,int>m;
map<int,int>check;

int main () {

    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        int l = m[a[i]];
        if (!check[a[i]]) {
            ans += ((l * (l - 1ll)) / 2ll);
            check[a[i]] = 1;
        }
    }

    for (int i = 1; i <= n; i++) {
        int p = m[a[i]];
        ans -= (p - 1);
        cout << ans << '\n';
        ans += (p - 1);
    }



    return 0;
}


Measured memory_bytes: 14208
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a*c %mod;}a=a*a %mod;b>>=1;}return c;}
vi calc(ll x){vi res; while(x>0){res.eb(x%10);x/=10;}reverse(all(res)); return res;}

void solve() {
  ll n,a,b;
  cin>>n>>a>>b;
  ll p=n/(a+b),q=n%(a+b);
  if(q<=a) out(p*a+q);
  else out(p*a+a);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


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

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n,q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> sum(n+1,0); //[l,r]の和 = s[r+1]-s[l+1]
  for (int i = 1; i < n; ++i) {
    if (s[i-1] == 'A' && s[i] == 'C') sum[i+1]++;
    sum[i+1] += sum[i];
  }
  debug(sum[n]);
  rep(_,q) {
    int l, r;
    cin >> l >> r; // 1 <= l < r.
    int ans = sum[r] - sum[l];
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
	int n; scanf("%d", &n);
	multiset<int> ms;
	for (int i = 0; i < n; ++i) {
		int u; scanf("%d", &u);
		ms.insert(u);
	}
	int ans = 0;
	while (ms.size()) {
		int u = *ms.rbegin(); ms.erase(ms.find(u));
		int v = 1;
		while (v <= u) v <<= 1;
		if (ms.find(v - u) != ms.end()) {
			++ans; ms.erase(ms.find(v - u));
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _GLIBCXX_DEBUG
const int MOD = 1000000007;

int main() {
  int x;
  cin >> x;
  if (x<1200) cout << "ABC" << endl;
  else cout << "ARC" << endl;
}

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

using namespace std;

typedef long long ll;

#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()

ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll c(ll a,ll b)
{
  if(a==0)return b==0?1:0;

if(b>a)return 0;

  ll val=1;
ll fac=1;
for(int i=1;i<=b;i++)fac*=i;
for(int i=a;i>=a-b+1;i--)val*=i;

  return val/fac;

}

ll f(ll n)
{
  ll ans=1LL;
  while(ans<=n)ans<<=1;

return ans;
}

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

    ll n;cin>>n;

    map<ll,ll>m;

    vl a(n);

    for(int i=0;i<n;i++)
    {
      cin>>a[i];
      m[a[i]]++;
    }
ll ans=0;

    sort(all(a));

    for(int i=n-1;i>=0;i--)
    {
      //cout<<f(a[i])<<"\n";
     // cout<<m[2]<<"\n";
if(m[a[i]]==0)continue;
      ll temp=f(a[i])-a[i];
      m[a[i]]--;
      
       if(m[temp])
       {
      // cout<<a[i]<<" "<<m[temp]<<"\n";
          ans++;
          m[temp]--;
      }
    //  else continue;
  //     cout<<ans<<"\n";
    }

  //  cout<<f(1)<<"\n";

    cout<<ans<<"\n";



return 0;

}


Measured memory_bytes: 26880
a=int(input())
kami = int(a/100)
simo = a % 100
if kami >0 and kami <13:
    if simo >0 and simo <13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if simo >0 and simo <13:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 2940
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())

    ans = 0

    for n in range(a + 1):
        for m in range(b + 1):
            for l in range(c + 1):
                if (500 * n + 100 * m + 50 * l) == x:
                    ans = ans + 1

    print(ans)



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

int main()
{
    long long int n,flag=0,x;
    cin>>n;
    set<long long int>s;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(s.count(x))
        {
            flag=1;
            break;
        }
        s.insert(x);
    }
    if(flag==1)
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>

int f[44];

int fib(int n)
{
  if (n < 2) return 1;
  if (f[n] == 0) f[n] = fib(n - 1) + fib(n - 2);
  return f[n];
}

int main()
{
  int n;

  scanf("%d", &n);

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

  return (0);
}

Measured memory_bytes: 596
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int sum[100002] = {0};

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int2(n, k);
    if(!(n | k))break;
    rep(i, n + 2)sum[i] = 0;

    rep(i, k){
      int(x);
      sum[x] = 1;
    }

    for(i = 2;i <= n;++i)if(sum[i] > 0)sum[i] += sum[i - 1];

    int res = 0;
    if(sum[0] == 1){
      for(i = n;i >= 1;--i)if(i - sum[i] - 1 > 0)
      res = max(res, sum[i] + 1 + sum[i - sum[i] - 1]);
    }else{
      for(i = n;i >= 1;--i)res = max(res, sum[i]);
    }

    pri(res);

//*/

//*/ break;
  }
  return 0;
}

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

using namespace std;

int main(){
	int n,a,b;
	cin >> n >> a >> b;
	int diff = b - a;
	if(diff % 2){
		cout << "Borys" << endl;
	} else {
		cout << "Alice" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
let judge k ps =
    ps
    |> Array.sort
    |> fun x -> x.[..k - 1] |> Array.sum
//let input = [| 5, 3, [| 50; 100; 80; 120; 80|]; 1, 1, [|1000|] |]
//for (_,k,ps) in input do (judge k ps |> printfn "%d")
// expected 210; 1000
[<EntryPoint>]
let main argv =
    let _, k =
        stdin.ReadLine().Split()
        |> fun x -> x.[0], int x.[1]

    let ps =
        stdin.ReadLine().Split() |> Array.map int

    judge k ps |> printfn "%d"
    0


Measured memory_bytes: 30240
#include<bits/stdc++.h>
using namespace std;
bool check[2007][100005];
int a,n;
int main()
{
	cin>>n;
	int sum=0;
	check[0][0]=true;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		sum+=a;
		for(int j=0;j<=100000;j++)
		{
			if(j+a<=100000) check[i][j+a]|=check[i-1][j];
			check[i][abs(j-a)]|=check[i-1][j];
		}
	}
	for(int i=0;i<=100000;i++)
	{
		if(check[n][i])
		{
			cout<<((sum+i)>>1);
			break;
		}
	}
}

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

signed main(){
    int N; cin >> N;
    int c2 = 0, c4 = 0;
    for(int i = 0; i < N; i++){
        int a; cin >> a;
        if(a % 4 == 0) c4++;
        else if(a % 2 == 0) c2++;
    }
    int c1 = N - c2 - c4;
    if(c2 == 0){
      if(c1 <= c4 + 1) cout << "Yes" << endl;
      else cout << "No" << endl;
    }
  if(c2 != 0){
    if(c1 <= c4) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

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

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

    ll n, s;
    cin >> n >> s;
    if (s > n)
    {
        cout << -1 << endl;
        return 0;
    }
    if (s == n)
    {
        cout << n + 1 << endl;
        return 0;
    }

    for (ll b = 2; b <= (ll)floor(sqrtl(n)); b++)
    {
        ll sub = n, res = 0;
        while (sub > 0)
        {
            res += sub % b;
            sub /= b;
        }
        if (s == res)
        {
            cout << b << endl;
            return 0;
        }
    }
    vector<ll> a;
    a.push_back(1e12);

    for (ll p = 1; p <= (ll)floor(sqrtl(n)); p++)
    {
        ll b = (n - s) / p + 1;
        ll sub = n, res = 0;
        while (sub > 0)
        {
            if (b == 1)
                break;
            res += sub % b;
            sub /= b;
        }
        if (s == res)
        {
            a.push_back(b);
        }
    }
    sort(a.begin(), a.end());
    if (a[0] == 1e12)
        cout << -1 << endl;
    else
        cout << a[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int a[100][100],b[100];
	int n,m,i,j,s;
	scanf("%d %d\n",&n,&m);
	for(i=n;i;i--){
		for(j=m;j;j--){
		scanf("%d",&a[i-1][j-1]);
		}
	}
	for(j=m;j;j--){
		scanf("%d",&b[j-1]);
	}
	for(i=n;i;i--){
		for(j=m,s=0;j;j--){
			s+=a[i-1][j-1]*b[j-1];
		}
		printf("%d\n",s);
	}
	return 0;
}

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

int main(void){
    int n=0;
    int v[50]={0};
    int c[50]={0};
    int num=0;

    cin >> n;

    for(int i=0;i<n;i++){
        cin >> v[i];
    }

    for(int i=0;i<n;i++){
        cin >> c[i];
    }

    for(int i=0;i<n;i++){
        if(v[i]>=c[i])num+=v[i]-c[i];
    }

    cout << num << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = scan.nextInt();
		boolean reverseElement = true;
		int count = 0;
		while (reverseElement) {
			reverseElement = false;
			for (int j = n - 1; j >= 1; j--) {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			}
		}
		for (int i = 0; i < n; i++)
			System.out.print(a[i] + (i != n - 1 ? " ":"\n"));
		System.out.println(count);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 26280
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<long long> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	vector<long long> COUNT(N * 2, 0);
	long long ANS = 0;
	for (int i = 0; i < N; i++) {
		if (i - A[i] >= 0) ANS += COUNT[i - A[i]];
		if (i + A[i] < N * 2) COUNT[i + A[i]]++;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 8012
#include<stdio.h>
#include<string.h>
#include<stdbool.h>

int main(void){
	char str[100001];
  scanf("%s%*c",str);
  int i,l;
  l=strlen(str)-2;
  if(l==0){
    puts(str[0]==str[1] ? "1 2":"-1 -1");
    return 0;
  }
  for(i=0;i<l;i++){
    if(str[i]==str[i+1] || str[i+1]==str[i+2] || str[i+2]==str[i]){
      printf("%d %d\n",i+1,i+3);
      return 0;
    }
  }
  puts("-1 -1");
  return 0;
}

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

int ind[200001];

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> x, y;
    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        if(a == 1) ind[b]++;
        if(b == n) ind[a]++;
    }

    for(int i=1; i<=n; i++){
        if(ind[i] == 2){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(){
  int total=0;
  int N,M,P,i,k,h;
  int box[100];
  while(1){
    scanf("%d %d %d",&N,&M,&P);
    if(N==0&&M==0&&P==0) break;
    else{
      total=0;
    for(i=0;i<N;i++){
      scanf("%d",&box[i]);
      total+=box[i]*100;
    }
    k=total*(100-P)/100;
    if(box[M-1]!=0){
    h=k/box[M-1];
    printf("%d\n",h);
    }
    if(box[M-1]==0) 
    printf("0\n");
  }
  }
  return 0;
}

Measured memory_bytes: 1040
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<climits>
#include<cstring>

using namespace std;


int main(){

	int N;

	bool flag = false;

	cin >> N;

	set<int> ans;

	int cnt = 0;

	for(int i = 0;i < N;i++){
        int x;
        cin >> x;
        for(int i = 0;i < 8;i++){
		 if(400*i <= x && x < 400*(i+1)){
		     	ans.insert(i);
		 }
		}
        if(x >=3200){
        			 flag = true;
        			 cnt++;
        }
	}

	if(ans.size() == 0){
		cout << 1 << " " << cnt << endl;
		return 0;
	}

	if(flag){
		cout << ans.size() << " " << ans.size()  + cnt<< endl;
	}else{
		cout << ans.size() << " " << ans.size() << endl;
	}


	return 0;

}


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

int main() {
  int s;
  cin >> s;
  
  int a = s/100;
  int b = s%100;
  
  if(0<a&&a<=12) {
    if(0<b&&b<=12) cout <<"AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }
  else if(0<b&&b<=12) cout << "YYMM" << endl;
  else cout << "NA" << endl;
}

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    shops = []
    for _ in range(N):
        shops.append(tuple(map(int, input().split())))
    shops = sorted(shops, key=lambda x:x[0])

    cnt = 0
    ans = 0
    for s in shops:
        pay, lim = s
        if cnt+lim <= M:
            cnt += lim
            ans += lim*pay
        else:
            nokori = M-cnt
            ans += nokori*pay
            break
    print(ans)
main()

Measured memory_bytes: 18872
import math

A, B, H, M = map(int, input().split())
if M == 0:
  jishin = 360 / 12 * H
else:
  jishin = 360 / 12 * H + 360 / 12 / 60 * M
funshin = 360 / 60 * M
angle = abs(jishin - funshin)
if angle >= 180:
  angle = 360 - angle

length = math.sqrt(A**2 + B**2 - (2 * A * B * math.cos(math.radians(angle))))

print(length)

Measured memory_bytes: 9584
R,C,K=map(int,input().split())
f,g=range,max
G=[[0]*(C+1)for i in f(R+1)]
for i in'_'*K:r,c,v=map(int,input().split());G[r][c]=v
F=[[[0]*(C+1)for i in f(R+1)]for i in f(4)]
for r in f(1,R+1):
	for x in f(1,4):
		for c in f(1,C+1):F[x][r][c]=g(F[x-1][r][c-1]+G[r][c],F[x][r][c-1],(x<2)*(G[r][c]+g(F[1][r-1][c],F[2][r-1][c],F[3][r-1][c])))
print(g(F[1][R][C],F[2][R][C],F[3][R][C]))

Measured memory_bytes: 429200
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

    ll operator"" _64(unsigned long long x){ return ll(x); }

    ull operator"" _64u(unsigned long long x){ return ull(x); }

#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;


void sub_main(istream &is) {
    ll N;
    is >> N;
    string s;
    is >> s;
    if(!is) return;

    cout << (N < 3200 ? "red" : s) << endl;
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_A.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

int n,k,a[111111],b[111111];

int I_Love_Hashimoto_Kanna() {
	fastio;
	n=read();k=read();
	int A=111110,B=0;
	FOR(i,0,n){
		int x=read();
		if(x<0){
			a[A--]=-x;
		}
		else {
			b[++B]=x;
		}
	}
	int ans=inf;
	FOR(i,0,k+1){
		if(i<=B&&(k-i)<=(n-B)){
			Umin(ans,b[i]+a[A+(k-i)]*2);
			Umin(ans,b[i]*2+a[A+(k-i)]);	
		}
	}
	Tone(ans)
	
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;


#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

auto sumdig(ll num) {
	ll dig, sum;
	sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}

auto mdist(pair<int, int> a, pair<int, int> b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}

class four {
public:
	int a, b, c, d;
};


void dfs(vector<vector<int>> &ans,vector<int> a, int n, int nmax) {
	//n 今何番目の数列について考えているか
	//nmax n番目の数列に突っ込める最大の数
	//a 現状  (size Nのvector)
	//ans 全通り
	if (n == 0) {
		ans.push_back(a);
	}
	else {
		rep(i, 1, nmax + 1) {
			a[n - 1] = i;
			dfs(ans, a, n - 1, i);
		}
	}


}


int main() {

	int N, M, Q;
	cin >> N >> M >> Q;
	vector<int> A(N,-1);
	vector<four> tup(Q);
	vector<int> empty(N, 0);

	vector<vector<int>> pattern;

	vector<int> score;


	rep(i, 0, Q) {
		four temp;
		cin >> temp.a >> temp.b >> temp.c >> temp.d;
		tup[i] = temp;
	}

	dfs(pattern, empty, N, M);
	
	int ans = 0;

	rep(i, 0, pattern.size()) {
		int tmax = 0;
		rep(j, 0, Q) {
			int temp = pattern[i][tup[j].b-1] - pattern[i][tup[j].a-1];
			if ((pattern[i][tup[j].b-1] - pattern[i][tup[j].a-1]) == tup[j].c) {
				tmax += tup[j].d;
			}
		}
		ans = max(ans, tmax);
	}
	
	cout << ans << endl;

	return 0;
}



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

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

void solve();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main(void) {
    init();
    solve();
    return 0;
}

void solve() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    ll count = 0;
    for (int i = 0; i < 1000; i++) {
        string serchNum = to_string(i);
        if (serchNum.size() == 1) {
            serchNum = "00" + serchNum;
        }
        if (serchNum.size() == 2) {
            serchNum = "0" + serchNum;
        }
        ll pos = s.find(serchNum[0]);
        if (pos != string::npos) {
            string ss = s.substr(pos + 1);
            pos = ss.find(serchNum[1]);
            if (pos != string::npos) {
                string sss = ss.substr(pos + 1);
                pos = sss.find(serchNum[2]);
                if (pos != string::npos) {
                    count++;
                }
            }
        }
    }
    cout << count << "\n";
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int sum=a,count=1;
  while(sum<b){
    sum+=a-1;
    count++;
  }
  if(b==1){
    cout << 0;
  }else if(a>=b){
    cout << 1 <<endl;
  }else{
    cout << count << endl;
  }
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


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


def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2, 7, 61] if n < 1 << 32 else [2, 3, 5, 7, 11, 13,
                                        17] if n < 1 << 48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1:
            continue
        while y != n - 1:
            y = y * y % n
            if y == 1 or t == n - 1:
                return 0
            t <<= 1
    return 1


def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        def f(x): return (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g):
                return g
            elif isPrimeMR(n // g):
                return n // g
            return findFactorRho(g)


def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i * i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k:
            ret[i] = k
        i += i % 2 + (3 if i % 3 == 1 else 1)
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1:
        ret[n] = 1
    if rhoFlg:
        ret = {x: ret[x] for x in sorted(ret)}
    return ret


def divisors(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p] + 1):
            for r in ret_prev:
                ret.append(r * (p ** i))
    return sorted(ret)


N = ni()

fact_dic = primeFactor(N)

ans = 0
for k, v in fact_dic.items():
    i = 1
    while(v - i >= 0):
        ans += 1
        v -= i
        i += 1
print(ans)


Measured memory_bytes: 62328
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()

using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;

const D EPS = 1e-8;
const D PI = acos(-1);

inline pair<P,P> norm(const P &p){return make_pair(p*P(0,1),p*P(0,-1));}
inline D dot(const P &x, const P &y){return real(conj(x)*y);}
inline D cross(const P &x, const P &y){return imag(conj(x)*y);}

int ccw(const P &a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;
  if (cross(b,c)<-EPS) return -1;
  if (dot(b, c)<-EPS) return 2;
  if (abs(b)<abs(c)) return -2;
  return 0;
}

inline P line_cp(const L &a, const L &b){
  return a.fs+(a.sc-a.fs)*cross(b.sc-b.fs,b.fs-a.fs)/cross(b.sc-b.fs,a.sc-a.fs);
}

inline bool is_cp(const L &a, const L &b){
  return (ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0)
    && (ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0);
}

inline P symmetry_line(const L &l, const P &p){
  if(abs(ccw(l.fs,l.sc,p)) != 1)return p;
  return line_cp(l, L(p,p + norm(l.fs-l.sc).fs))*2.0 - p;
}

struct state{
  P goal;
  vector<L> mirrors;
  state(P p, vector<L> m):goal(p),mirrors(m){}

  inline state symmetry(int x){
    vector<L> sym(mirrors.sz);
    rep(i,mirrors.sz){
      if(i == x)sym[i] = mirrors[i];
      else sym[i] = L(symmetry_line(mirrors[x],mirrors[i].fs),
		      symmetry_line(mirrors[x],mirrors[i].sc));
    }
    return state(symmetry_line(mirrors[x],goal), sym);
  }
};

const int max_depth = 6;
int n;
int tx,ty,lx,ly;
D ans;

void rec(int depth, vector<int> &order, vector<state> &mir){
  if(depth == max_depth)return;
  D dis = abs(P(lx,ly) - mir.back().goal);
  if(dis + EPS < ans){ 
    bool f = true;
    P start = P(lx,ly);
    L route = L(start, mir.back().goal);
    rep(i,depth+1){
      state cur = mir[i];
      int axis = i==depth?-1:order[i], prev = !i?-1:order[i-1];
      if(axis>=0 && !is_cp(route, cur.mirrors[axis])){ f = false; break; }
      
      P cp = axis>=0?line_cp(route, cur.mirrors[axis]):mir.back().goal;
      L seg = L(start, cp);
      rep(j,n){
	if(axis!=j && prev!=j && is_cp(seg, cur.mirrors[j])){ f = false; break; }
      }
      if(!f)break;
      start = cp; route.fs = start;
    }
    if(f)ans = dis;
  }

  rep(i,n){
    if(depth && order[depth-1] == i)continue;
    order.pb(i);
    mir.pb(mir.back().symmetry(i));
    rec(depth+1, order, mir);
    mir.pop_back();
    order.pop_back();
  }
}

int main(){
  while(scanf("%d",&n), n){
    vector<L> vl(n);
    rep(i,n){
      int px, py, qx, qy;
      scanf("%d%d%d%d",&px,&py,&qx,&qy);
      vl[i] = L(P(px,py), P(qx,qy));
    }
    scanf("%d%d%d%d",&tx,&ty,&lx,&ly);
    
    vector<state> vs;
    vs.push_back( state(P(tx,ty), vl) );
    vector<int> vi;
    ans = 1e7;
    rec(0,vi,vs);
    printf("%.4lf\n",ans);
  }
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


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

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

int n,k,x[110000], left[110000], right[110000];
signed main(){
  cin>>n>>k;
  int cnt = 0;
  rep(i,n){
    cin>>x[i];
    if(x[i] < 0)cnt++;
  }
  int ans = INF;
  repd(i,1,k){
    if(cnt+i-1 >= n || cnt-(k-i) < 0)continue;
    int l = x[cnt+i-1], r = x[cnt-(k-i)];
    int s = min(l*2-r, l-r*2);
    chmin(ans, s);
  }
  if(cnt+k-1 < n)chmin(ans, x[cnt+k-1]);
  if(cnt - k >= 0)chmin(ans, -x[cnt-k]);
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <stack>
#include <math.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int, int> pii;
int main(){
int n,i,count=1;
cin>>n;
char arr[n];
for(i=0;i<n;i++){
  cin>>arr[i];
}
for(i=0;i<n;i++){
  while(arr[i+1]==arr[i]&&i<n){
    i++;
  }
  if(i!=n-1)  count++;
}
cout<<count<<endl;







}


Measured memory_bytes: 384
#include <stdio.h>

int main(void){
		int a[30]={0};
		int n,i,p,b,c,o,t,first=0,second=0,temp=0;
		scanf("%d",&n);
		for(i=0;i<n;i++)
				a[i]=i+1;

		scanf("%d",&p);
		for(i=0;i<p;i++){
				scanf("%d,%d",&b,&c);
				for(o=0;o<n;o++){
						if(o+1 == b)
								first=o;
						if(o+1 == c)
								second=o;
				}temp=a[first];
				a[first]=a[second];
				a[second]=temp;
		}
		for(i=0;i<n;i++)
				printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 596
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 998244353;

int64 power_mod(int64 a, int n) {
  int64 ret = 1;
  for (; n; n >>= 1) {
    if (n & 1) ret = ret * a % MOD;
    a = a * a % MOD;
  }
  return ret;
}

const int N = 300 + 10;
int a[N][N];
int gauss(int a[N][N], int n, int m) {
  int i;
  for (i = 0; i < n && i < m; ++i) {
    int p, q;
    for (p = i; p < n; ++p) {
      for (q = i; q < m; ++q) {
        if (a[p][q]) break;
      }
      if (q < m) break;
    }
    if (p == n) break;
    if (p != i) {
      for (int j = i; j < m; ++j) {
        swap(a[i][j], a[p][j]);
      }
    }
    if (q != i) {
      for (int j = i; j < n; ++j) {
        swap(a[j][i], a[j][q]);
      }
    }
    for (int j = i + 1; j < n; ++j) {
      if (a[j][i]) {
        for (int k = i; k < m; ++k) {
          a[j][k] ^= a[i][k];
        }
      }
    }
  }
  return i;
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
    }
  }
  int rk = gauss(a, n, m);
  int ret = (power_mod(2, n) + MOD - power_mod(2, n - rk)) *
    power_mod(2, m - 1) % MOD;
  printf("%d\n", ret);
  return 0;
}


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

bool is_integer(double k)
{
  return floor(k) == k;
}

int main()
{
  double N;
  cin >> N;
  int answer = 0;
  for(int i = N; i > 0; --i)
  {
    double rt = sqrt(i);
    if (is_integer(rt))
    {
      answer = i;
      break;
    }
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main(N,Y):
    if 10000*N < Y:
        return -1, -1, -1
    else:
        for a in range(N+1):
            for b in range(N+1-a):
                c = N-a-b
                if 10000*a+5000*b+1000*c == Y:
                    return a,b,c
        return -1, -1, -1

if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, Y = list(map(int,_in[0].split(' ')))
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    a,b,c = main(N,Y)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(a,b,c)


Measured memory_bytes: 38768
import java.util.Scanner;
 public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
      int A = scanner.nextInt();
      int B = scanner.nextInt();
      int C = scanner.nextInt();
      int D = scanner.nextInt();
      
      while(true){
        C-=B;
       
      if(C<=0){
     System.out.println("Yes");
        break;
      }
         A-=D;
      if(A<=0){
      System.out.println("No");
        break;
      }
      }
    }
 }

Measured memory_bytes: 35772
#include<stdio.h>

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

	scanf("%d%d",&a,&b);

	/* 偶数と奇数を判定 */
	if(((a*b)%2) == 0)
	{
		printf("Even");
	}
	else
	{
		printf("Odd");
	}

	return(0);
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null) {

			Scanner sc;
			int[] a = new int[4];
			int[] b = new int[4];
			int hit = 0;
			int blow = 0;

			sc = new Scanner(line);
			for (int i = 0; i < a.length; i++) {
				a[i] = sc.nextInt();
			}
			sc = new Scanner(br.readLine());
			for (int i = 0; i < b.length; i++) {
				b[i] = sc.nextInt();
			}

			// hit
			for (int i = 0; i < a.length; i++) {
				if (a[i] == b[i]) {
					hit++;
					a[i] = -1;// 例外値
				}
			}

			// blow
			for (int i = 0; i < a.length; i++) {
				if (a[i] == -1)
					continue;
				for (int j = 0; j < b.length; j++) {
					if (a[i] == b[j])
						blow++;
				}
			}

			//
			System.out.println(hit + " " + blow);
		}
	}
}

Measured memory_bytes: 24580