akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
string s;
int main() {
  cin >> s;
  n = s.size() + 1;
  vector<i64> a(n);
  for (int i = 1; i < n; ++i) {
    if (s[i - 1] == '<') a[i] = a[i - 1] + 1;
  }
  for (int i = n - 2; i >= 0; --i) {
    if (s[i] == '>') a[i] = a[i + 1] + 1;
  }
  for (int i = 1; i < n - 1; ++i) {
    if (s[i - 1] == '<' && s[i] == '>') {
      a[i] = max(a[i - 1], a[i + 1]) + 1;
    }
  }

  // for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
  // cerr << endl;

  i64 ans = 0;
  for (int i = 0; i < n; ++i) ans += a[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4740
N, M = map(int, input().split())
A = list(map(int, input().split()))
D = {}
for a in A:
    if a in D:
        D[a] += 1
    else:
        D[a] = 1

for i in range(M):
    B, C = map(int, input().split())
    if C in D:
        D[C] += B
    else:
        D[C] = B

K = sorted(D.keys(), reverse=True)
ans = 0
cnt = N
for k in K:
   a = min(D[k], cnt)
   ans += k * a
   cnt -= a
   if cnt == 0: break
print(ans)

Measured memory_bytes: 34236
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define el '\n'
#define MOD 1000000007

int n,m, vis[100005];
vector<int> adjList[100005];
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m;
    while(m--){
        int a,b,c;
        cin >> a >> b >> c;
        adjList[a].push_back(b);
        adjList[b].push_back(a);
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            vis[i]=1;
            queue<int> q;
            q.push(i);
            while(!q.empty()){
                int fr = q.front();
                q.pop();
                for(auto x:adjList[fr]){
                    if(!vis[x]){
                        vis[x]=1;
                        q.push(x);
                    }
                }
            }
            cnt++;
        }
    }
    cout << cnt << el;
    return 0;
}

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

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

Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
ll GCD(ll a,ll b){
  ll r = a % b;
  if(r==0){
    return b;
  }
  else{
    return GCD(b,r);
  }

}

int main() {

int A,B,C,g;
cin>>A>>B>>C;
g=GCD(A,B);
if(C%g==0){
  cout<<"YES"<<endl;
}
else{
  cout<<"NO"<<endl;
}





return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,n; cin>>n>>k;
    vi l(n);
    rep(i,n) cin>>l[i];
    sort(rall(l));
    int sum=0;
    rep(i,k){
        sum+=l[i];
    }
    cout<<sum<<endl;
    return 0;
}


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

int main(){
int i,j;
string a;
cin>>a;int ans=0;
for (char c:a) c=='-'?ans--:ans++;
cout<<ans;
}

Measured memory_bytes: 256
import collections

n = int(input())
a = [0]*n
count = 0
for i in range(n):
  a[i] = list(input())
  a[i].sort()
  d = ""
  for j in a[i]:
    d += j
  a[i] = d
c = collections.Counter(a)
for i in c.values():
  count += (i-1) * i // 2
print(count)


Measured memory_bytes: 19720
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, M = map(int, readline().split())
    A = list(map(int, readline().split()))
    ans = max(N-sum(A), -1)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9844
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import Counter 
def main():
    n = int(readline())
    a = [int(i) for i in readline().split()]
    odd = Counter(a[::2]).most_common(2)
    even = Counter(a[1::2]).most_common(2)
    odd.append((0, 0))
    even.append((0, 0))
    if odd[0][0] == even[0][0]:
        print(min(n-odd[1][1]-even[0][1], n-odd[0][1]-even[1][1]))
        return
    print(n-odd[0][1]-even[0][1])
if __name__ == '__main__':
    main()


Measured memory_bytes: 16204
x,y,a,b,c = map(int, input().split())
p1 = list(map(int, input().split()))
p2 = list(map(int, input().split()))
p3 = list(map(int, input().split()))
p1.sort(reverse= True)
p2.sort(reverse= True)
ans =p1[:x]+p2[:y]+p3
ans.sort(reverse= True)
print(sum(ans[:x+y]))

Measured memory_bytes: 23328
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int A, B;
bool ans;

int main()
{
	in >> A >> B;
	out << ((A <= B + (16 - A - B)) && (B <= A + (16 - A - B)) ? "Yay!" : ":(") << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<float.h>
#include<cfloat>
#include<string>
#include<ctype.h>
#include<algorithm>
#include<errno.h>
#include<cerrno>
#include<assert.h>
#include<cassert> 
#include<map>
#include<memory.h>
#include<cctype>
#include<ctype.h>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<new>
#include<memory>
#include<cmath>
#include<queue>
#include<cstring>
#define ll long long
#define fo(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define br break
#define ct continue
#define pb push_back
#define pi 3.141592653589793238462643383279502884197169
#define F first
#define S second
#define em empty()
#define vei vector<int>
#define ves vector<string>
#define qui queue<int> 
#define qu queue
using namespace std;
int main()
{int x,a,b;
 cin>>x>>a>>b;
 int ans=b-a;
 if(ans<=x&&ans>0){
 cout<<"safe"<<endl;
 }
 else if(ans<=0){
 cout<<"delicious"<<endl;
 }
 else if(ans>x){
 cout<<"dangerous"<<endl;
 }
 system("pause");
 return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
*/

char a,b[2000];

int main(void){
	cin>>a;
	b['A']='T';
	b['T']='A';
	b['G']='C';
	b['C']='G';
	cout<<b[a]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	uint64_t N;
	scanf("%ld", &N);
	uint64_t A, B;
	scanf("%ld %ld", &A, &B);

	uint64_t d = B - A;

	if (d & 1) {
		// goto 1 or N
		uint64_t dis_A = A - 1, dis_B = N - B;
		if (dis_A < dis_B) {
			printf("%ld\n", dis_A + 1 + d / 2);
		} else {
			printf("%ld\n", dis_B + 1 + d / 2);
		}
		return 0;
	}

	printf("%ld\n", d / 2);

	return 0;
}


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

int main() {
  int a,b,c,d;
  cin >> a >> b;
  vector<int> ans(a,0);
  int sum;
  for(int i= 0;i<b;i++){
    cin >> c;
    for(int j = 0;j<c;j++){
      cin >> d;
      ans.at(d-1)++;
    }
  }
  for(int i = 0;i<a;i++){
    if(ans.at(i)==0)sum++;
  }
  cout << sum;
}


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

#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)

using ll = long long;
#define INF 1e9


int main(){
  int N, ans=1, ansc = 0;
  cin >> N;

  FOR(i, 1, N+1){
    int box = i, cnt= 0;
    while(box % 2 == 0 && box > 0){
      cnt++;
      box /= 2;
    }
    if(cnt > ansc){
      ansc = cnt;
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int sib(int n){
    return (n & 1) ? (n - 1):(n + 1);
}

int update_gcd(int i, const vector<int> & gcds){
    int g = gcds[sib(i)];
    i = i / 2;
    while (i > 1){
        g = __gcd(g, gcds[sib(i)]);
        i = i / 2;
    }
    return g;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> gcds(2 * N, 0LL);
    for (int i = 0; i < N; ++i) cin >> gcds[N + i];
    for (int i = N - 1; i >= 1; --i) gcds[i] = __gcd(gcds[2 * i], gcds[2 * i + 1]);
    int ans = 1;
    for (int i = N; i < 2 * N; ++i) ans = max(ans, update_gcd(i, gcds));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


a, b, c = list(map(int, sys.stdin.readline().split()))
if a==b==c:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 21284
#include<iostream>
#include<algorithm>

using namespace std;


int main() {
    string s;

    cin >> s;

    s.erase(--s.end());

    if(s.length() % 2 != 0) {
        s.erase(--s.end());
    }

    while(1) {
        int flag = 0;
        int ans = 0;
        
        if(s.length() % 2 == 0) {
            for(int i = 0; i < s.length() / 2; i++) {
                if(s[i] != s[s.length() / 2 + i]) {
                    flag = 1;
                }
            }

            if(flag == 0) {
                cout << s.length() << endl;
                return 0;
            }

        }
        
        s.erase(--s.end());
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    string s;
    cin >> s;
    for(auto &c: s)if(c == '?') c = 'D';
    cout << s << endl;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	V a(n);
	cin >> a;
	sort(all(a));
	ll sum = 0LL;
	int cnt = 0;
	rep(i,n){
		if(sum*2 >= a[i]){
			sum += a[i];
			cnt++;
		}else{
			cnt = 1;
			sum += a[i];
		}
	}
	ans = cnt;
	cout<<ans<<endl;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1e9 + 7

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

    int a,b,c,d;

    cin >> a >> b >> c >> d;

    cout << max(min(b,d)-max(a,c),0);
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int a,b;
  scanf("%d %d",&a,&b);
  if(a==1){
    if(b==2)puts("3");
    if(b==3)puts("2");
  }
  if(a==2){
    if(b==1)puts("3");
    if(b==3)puts("1");
  }
  if(a==3){
    if(b==1)puts("2");
    if(b==2)puts("1");
  }
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
int main(){
  int count[123]={};
  char c;
  while(scanf("%c",&c)!=EOF){
    if(c>96)count[c]++;
    else count[c+32]++;
  }
  for(int i=97;i<123;i++)printf("%c : %d\n",i,count[i]);
  return 0;
}

Measured memory_bytes: 968
sx,sy,tx,ty = map(int,input().split())
dx = tx-sx
dy = ty-sy

print("R"*dx+"U"*dy+"R"+"D"*(dy+1)+"L"*(dx+1) +"U"\
    +"U"*dy+"R"*dx+"U"+"L"*(dx+1)+"D"*(dy+1) +"R" )


Measured memory_bytes: 9124
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
int a[maxn];
int main()
{
	int n,k;cin>>n>>k;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	int cur = 0;
	for(int i=1;i<=k;i++)cur += a[i];
	int maxi = cur;
	for(int i=k+1;i<=n;i++){
		cur += a[i];
//		cout<<"!"<<cur<<endl;
		cur -= a[i-k];
		if(cur>maxi)maxi = cur;
//		cout<<"!"<<i<<" "<<cur<<endl;
	}
	double ans = maxi+k;
	ans /= 2;
	printf("%.7f\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll inf=1e18;
const int N=2e5+10;
ll factorial(ll x){
    if(x==0||x==1) return 1;
    return x*factorial(x-1);
}

#define MX 1e9

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);

    sort(a.begin(),a.end());
    cout<<abs(a[n-1]-a[0])<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,j,k) for(ll i=j;i<k;i++)
int main(){
  ll N,K,Q,buf;
  cin >> N >> K >> Q;
  ll point[N]={};
  rep(i,0,Q){
    cin >> buf;
    point[buf-1]++;
  }
  rep(i,0,N){
    if(Q-point[i]>=K) cout << "No\n";
    else cout << "Yes\n";
  }
}

Measured memory_bytes: 1408
def cmb(n,r,mod):
  if r<0 or r>n:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod
 
n=int(input())
mod=998244353

g1=[1,1]
g2=[1,1]
inverse=[0,1]
 
for i in range(2,n+1):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)

a=0
b=1
for i in range(n,n//2,-1):
  a+=cmb(n,i,mod)*b
  a%=mod
  b*=2
  b%=mod
ans=(pow(3,n,mod)-2*a)%mod
print((ans+mod)%mod)

Measured memory_bytes: 481456
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max();

int main() {
	int a;
	string s;
	cin >> a >> s;
	if (a < 3200) cout << "red" << endl;
	else cout << s << endl;
}


Measured memory_bytes: 888
N = int(input())
a = str(input()).split(" ")
a_list = list(map(int,a))

a_list_sort = a_list.sort(reverse=True)

Alice = a_list[1::2]
Bob = a_list[0::2]

Alice_score = sum(Alice)
Bob_score = sum(Bob)

dif = abs(Alice_score - Bob_score)
print(dif)

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

int main(){
    int a,b;
    double a_d, b_d;
    scanf("%d %d", &a, &b);
    a_d = static_cast<double>(a);
    b_d = static_cast<double>(b);
    printf("%d %d %.5f\n", a / b, a % b, a_d / b_d);
    return 0;
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   long f(long b, long n) {
      long res = 0;
      while( n != 0 ) {
         res += n % b;
         n /= b;
      }
      return res;
   }
   void solve() {
      long n, s; scan(n, s);
      long inf = (1LL << 53);
      long res = inf;
      if( n == s ) {
         res = std::min(res, n + 1);
      }
      for(long b = 2; b <= 1000000; ++b) {
         if( f(b, n) == s ) {
            res = std::min(res, b);
            break;
         }
      }
      // x * b + y = n
      // x + y = s
      for(long x = 1000000; x >= 1; --x) {
         long y = s - x;
         if( (n - y) % x != 0 ) continue;
         long b = (n - y) / x;
         if( b >= 2 and 0 <= x and x < b and 0 <= y and y < b and x + y == s ) {
            res = std::min(res, b);
         }
      }
      if( res == inf ) res = -1;
      printf("%ld\n", res);
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> height(n);
  vector<bool> tembo(n, true);
  
  rep(i, n) {
    int h;
    cin >> h;
    height[i] = h;
  }
  
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    if(height[a] == height[b]) {
      tembo[a] = false;
      tembo[b] = false;
    } else if(height[a] > height[b]) tembo[b] = false;
    else tembo[a] = false;
  }
  
  int answer = 0;
  rep(i, n) if(tembo[i]) ++answer;
  
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3788
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <utility>
#include <vector>
#define sqr(x) ((x)*(x))
#define X first
#define Y second
const double eps=1e-8;
const double PI=acos(-1.);
struct v2d
{
	double x,y;int p;
	double l(){return sqrt(sqr(x)+sqr(y));}
	friend v2d operator +(const v2d&a,const v2d&b){return v2d{a.x+b.x,a.y+b.y,0};}
	friend v2d operator -(const v2d&a,const v2d&b){return v2d{a.x-b.x,a.y-b.y,0};}
	friend double operator |(const v2d&a,const v2d&b){return a.x*b.x+a.y*b.y;}
	friend double operator ^(const v2d&a,const v2d&b){return a.x*b.y-a.y*b.x;}
	friend bool operator <(const v2d&a,const v2d&b){return fabs(a.y-b.y)<eps?a.x<b.x:a.y<b.y;}
};
int sgn(double x){return x<-eps?-1:x>eps;}
std::vector<v2d> p,l;
double ans[101];
int n;
void graham(std::vector<v2d> p,std::vector<v2d>&a)
{
	std::stack<v2d> s1,s2;
	s1.push(p[0]);s2.push(p[0]);s2.push(p[1]);
	for(size_t i=2;i<p.size();++i)
	{
		while(!s1.empty()&&sgn((p[i]-s1.top())^(s2.top()-s1.top()))==-1)
		s1.pop(),s2.pop();
		s1.push(s2.top());s2.push(p[i]);
	}
	for(;!s2.empty();s2.pop())
	a.push_back(s2.top());
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	{
		double x,y;scanf("%lf%lf",&x,&y);
		p.push_back(v2d{x,y,i});
	}
	if(n==2)return puts("0.5\n0.5"),0;
	std::sort(p.begin(),p.end());
	graham(p,l);l.pop_back();
	std::reverse(p.begin(),p.end());
	graham(p,l);l.pop_back();
	for(size_t i=0;i<l.size();++i)
	{
		int p=(i+l.size()-1)%l.size(),s=(i+1)%l.size();
		double d=((l[s]-l[i])|(l[p]-l[i]))/((l[s]-l[i]).l()*(l[p]-l[i]).l());
		ans[l[i].p]=acos(-d)/(2.*PI);
	}
	for(int i=0;i<n;++i)printf("%.10f\n",ans[i]);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
string s,t;
  cin>>s>>t;
  int l=s.size();
  int L=t.size();
  bool ans=true;
  
    for(int i=0;i<l;i++){
      if(s[i]!=t[i]){
        cout<<"No"<<endl;
        ans=false;
        break;
      }
      
    }
  
  if(ans==true)cout<<"Yes"<<endl;
}

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


int main()
{
	char ch;
	
	while (1) {
		scanf("%c",&ch);
		if (isalpha(ch)) {
			if (islower(ch))printf("%c", toupper(ch));
			if (isupper(ch))printf("%c", tolower(ch));
		}
		else if (ch != '\n') {
			printf("%c",ch);
		}
		else {
			cout << endl;
			break;
		}

	}

	return 0;
}



Measured memory_bytes: 3156
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

int main(){
	int n,m;
	while(cin>>n>>m,n|m){
		vi h(n);
		REP(i,n){
			cin>>h[i];
		}
		vi w(m);
		REP(i,m){
			cin>>w[i];
		}

		vi all_width;
		REP(i,m){
			int sum=0;
			FOR(j,i,m){
				sum+=w[j];
				all_width.push_back(sum);
			}
		}
		sort(ALL(all_width));

		int ans=0;
		REP(i,n){
			int total_height=0;
			FOR(j,i,n){
				total_height+=h[j];
				vi::iterator lb=lower_bound(ALL(all_width),total_height);
				if(*lb==total_height){
					ans+=upper_bound(ALL(all_width),total_height)-lb;
				}
			}
		}

		cout<<ans<<endl;
	}
}

Measured memory_bytes: 15396
import sys
input = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations
from itertools import accumulate
from math import ceil, sqrt, pi

def LLL(a, ls):
    INF = 10 ** 15
    
    flag = 0
    prev = 0
    indx = 0
    ls_i = bisect_left(ls, a)
    if a < ls[ls_i]:
        flag = 1
        prev = ls[ls_i]
        indx = ls_i
    ls[ls_i] = min(ls[ls_i], a)

    ls_ii = bisect_left(ls, INF)
    return ls_ii, ls, flag, prev, indx

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
A = [0] + list(map(int, input().split()))
UV = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N + 1)]
for uv in UV:
    u, v = uv
    graph[u].append(v)
    graph[v].append(u)
#print(graph)

INF = 10 ** 15

LIS = [INF for i in range(N + 2)]

answer = [0] * (N + 1)
def dfs(prev, n, LIS):
    answer[n], LIS, flag, prv, indx = LLL(A[n], LIS)
    #print(n, LIS, flag, prv, indx)
    for g in graph[n]:
        if g != prev:
            dfs(n, g, LIS)
    if flag:
        LIS[indx] = prv

dfs(-1, 1, LIS)

for a in answer[1:]:
    print(a)

Measured memory_bytes: 392272
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,cnt;
	cnt=0;
	cin >> a >> b >> c;
	for(int i=101;i>0;i--){
      if(a%i==0 && b%i==0){
        cnt++; 
	  }
if(cnt==c){
	cout << i << endl;
	return 0;
}	
     
    }
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1000000000;

vector<int> a;
int memo[100001][2];
int N;

int dfs(int k,int c){
    if(~memo[k][c]) return memo[k][c];
    for (int i = 0; i < N; i++) {
        if(k-a[i]<0) break;
        if(c){
            if(dfs(k-a[i],c^1)) return memo[k][c]=c;
        }
        else{
            if(!dfs(k-a[i],c^1)) return memo[k][c]=c;
        }
    }
    return memo[k][c]=c^1;
}



int main(){
    int K;cin >> N >> K;
    for (int i = 0; i < N; i++) {
        int x;cin >> x;
        a.pb(x);
    }
    memset(memo,-1,sizeof(memo));
    if(dfs(K,1)) puts("First");
    else puts("Second");
    return 0;
}



Measured memory_bytes: 5760
#include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

    int n=5;
    int w=4;
    int t=1;
    int tmp;

int go_r()
{ 
    tmp = n;
    n = w;
    w = 7-tmp;
    return t;
}
int go_l()
{
    tmp = w;
    w = n;
    n = 7-tmp;
    return t;
}
int go_n()
{
    tmp = n;
    n = t;
    t = 7-tmp;
    return t;
}
int go_e()
{
    tmp = t;
    t = w;
    w = 7-tmp;
    return t;
}
int go_w()
{
    tmp = w;
    w = t;
    t = 7-tmp;
    return t;
}
int go_s()
{
    tmp = t;
    t = n;
    n = 7-tmp;
    return t;
}

int main(int argc, char const* argv[])
{
    int row;
    while (cin >> row) 
    {
        int sum=1;
        n=5;
        w=4;
        t=1;
        //テァツオツづァツォツッテ・ツ按、テヲツ鳴ュ
        if (row==0){break;}
        string s;
        for (int i = 0; i < row; i++) 
        {
            cin >> s;
            if(s == "North"){ sum += go_n();}
            if(s == "South"){ sum += go_s();}
            if(s == "West") { sum += go_w();}
            if(s == "East") { sum += go_e();}
            if(s == "Right"){ sum += go_r();}
            if(s == "Left") { sum += go_l();}
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int a,b,n;

int main()
{
  scanf("%d %d %d",&n,&a,&b);
  printf("%d\n",min(n*a,b));
  return 0;
}










Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    while(1){
        cin >> n;
        if(n == 0){
            return 0;
        }
        int s_max = 0;
        int s_min = 1000;
        int sum = 0;
        int s;
        for( int i = 0; i < n ; ++i) {
            cin >> s;
            sum += s;
            s_max = max(s, s_max);
            s_min = min(s, s_min);
        }
        int ave = (sum-s_max-s_min)/(n-2);
        cout << ave << endl;
    }
}



Measured memory_bytes: 3080
/*
求 i*f(i) 
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define maxn 10000007

ll sum[maxn],ans,n;

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j+=i){
			sum[j]++;
		}
	for(int i=1;i<=n;i++)
		ans+=i*sum[i];
	cout<<ans<<'\n';
} 


Measured memory_bytes: 81792
w, h, n = map(int,input().split())
x1 = []
x2 = []
y3 = []
y4 = []
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        x1.append(x)
    elif a == 2:
        x2.append(x)
    elif a == 3:
        y3.append(y)
    else:
        y4.append(y)

for t in [x1,y3]:
    if not t:
        t.append(0)
if not x2:
    x2.append(w)
if not y4:
    y4.append(h)

if max(x1) >= min(x2) or max(y3) >= min(y4):
    print(0)
    exit()
print((min(x2) - max(x1)) * (min(y4) - max(y3)))

Measured memory_bytes: 3064
import sys
   
a = []
for line in sys.stdin:
    x,y = map(int,line.split(" "))
    if x == 0 and y == 0:
      break
    item = [x,y]
    item.sort()
    a.append(item)
   
for x,y in a:
  print "%s %s" %(x,y)

Measured memory_bytes: 6452
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 


using namespace std;

int main(){

    int h,w;
    cin >> h >> w;

    vector<vector<int>> grid;

    rep(i,h){
        vector<int> tmpv;
        rep(j,w){
            int tmp;
            cin >> tmp;
            tmpv.pback(tmp);
        }
        grid.pback(tmpv);
    }

    vector<tuple<int,int,int,int>> ans;

    rep(i,h - 1){
        rep(j,w){
            if(grid[i][j] % 2 == 1){
                grid[i][j]--;
                grid[i + 1][j]++;

                ans.pback(make_tuple(i + 1, j + 1 ,i + 2 , j + 1 ));
            }
        }
    }

    rep(i,w - 1){
        if(grid[h - 1][i] % 2 == 1){
            grid[h - 1][i]--;
            grid[h - 1][i + 1]++;

            ans.pback(make_tuple(h, i + 1, h,  i + 2));
        }
    }

    cout << ans.size() << endl;

    rep(i,ans.size()){

        cout << get<0>(ans[i]) << " " << get<1>(ans[i]) << " " << get<2>(ans[i]) << " " << get<3>(ans[i]) << endl;
    }

    return 0;
}

Measured memory_bytes: 5232
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int dp[100010];
vector<vector<int>> graph(100010, vector<int>());

int dfs(int n) {
	if (dp[n]) {
		return dp[n];
	}
	int res = 0;
	for (int i : graph[n]) {
		chmax(res, dfs(i) + 1);
	}
	return dp[n] = res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n, m;
	cin >> n >> m;
	vector<int> x(m), y(m);
	rep(i, m) {
		cin >> x[i] >> y[i];
		x[i]--; y[i]--;
		graph[x[i]].pb(y[i]);
	}
	int ans = 0;
	rep(i, n) chmax(ans, dfs(i));
	cout << ans << endl;
}

Measured memory_bytes: 10112
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back 
#define N 110
using namespace std;
int dp[N][100010], pref[100010], A[N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> A[i];
	dp[n][0] = 1;
	for(int i = 0; i <= k; i++)
		pref[i] = 1;
	for(int i = n - 1; i >= 0; i--){
		for(int j = 0; j <= k; j++){
			int low = j - min(j, A[i]);
			if(low == 0)
				dp[i][j] = pref[j];
			else 
				dp[i][j] = (pref[j] - pref[low - 1]  + MOD) % MOD;
		}
		for(int j = 0; j <= k; j++)
			pref[j] = dp[i][j];
		for(int j = 1; j <= k; j++)
			pref[j] = (pref[j] + pref[j - 1]) % MOD;
	}
	cout << dp[0][k] << '\n';

}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

#define EPS (1e-10)
#define eq(a, b) (fabs((a)-(b)) < EPS)
#define lt(a, b) ((a)-(b) < -EPS)
#define le(a, b) (eq(a, b) || lt(a, b))


struct Point {
  int x, y;
  Point(){}
  Point(int x, int y):x(x), y(y){}
  Point operator - (Point p) {
    return Point(x-p.x, y-p.y);
  }
};

struct Circle {
  Point p;
  int r;
  Circle(){}
  Circle(Point p, int r):p(p), r(r){}
  bool operator < (const Circle& c) const {
    return r < c.r;
  }
};

int n;
Point s, t;
vector<Circle> cs;

int dot(Point a, Point b) {
  return a.x*b.x+a.y*b.y;
}
int norm(Point a) {
  return dot(a, a);
}

int sq(int a) {
  return a*a;
}

bool contain(Circle c, Point p) {
  if(norm(c.p-p) <= c.r*c.r) return true;
  return false;
}

vector<Circle> encircle(Point p, Point q) {
  vector<Circle> res;
  rep(i, n) {
    if(contain(cs[i], p) && !contain(cs[i], q)) res.push_back(cs[i]);
  }
  sort(all(res));
  reverse(all(res));
  return res;
}

bool intersect(Circle c1, Circle c2) {
  int d = norm(c1.p-c2.p);
  return d <= sq(c1.r+c2.r) && d >= sq(c1.r-c2.r);
}

vector<Circle> css, cst;
int dps[1024], dpt[1024];

int solve(vector<Circle>& cs1, int idx, int dp[]) {
  int& res = dp[idx];
  if(~res) return res;
  res = 1;
  reps(i, idx+1, cs1.size()) {
    if(!intersect(cs1[idx], cs1[i])) {
      chmax(res, solve(cs1, i, dp)+1);
    }
  }
  return res;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> n, n) {
    cin >> s.x >> s.y >> t.x >> t.y;
    resz(cs, n);
    rep(i, n) {
      cin >> cs[i].p.x >> cs[i].p.y >> cs[i].r;
    }

    css = encircle(s, t);
    cst = encircle(t, s);

    memset(dps, -1, sizeof(dps));
    memset(dpt, -1, sizeof(dpt));
    rep(i, css.size()) solve(css, i, dps);
    rep(i, cst.size()) solve(cst, i, dpt);

    int ans = 0;
    rep(i, cst.size()) chmax(ans, dpt[i]);
    rep(i, css.size()) chmax(ans, dps[i]);
    rep(i, css.size()) rep(j, cst.size()) {
      if(!intersect(css[i], cst[j])) chmax(ans, dps[i]+dpt[j]);
    }

    cout << ans << endl;
  }

  return 0;
}

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

#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> mat;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void solve() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int ret;
  if (a >= k) {
    ret = k;
  } else if (a + b >= k) {
    ret = a;
  } else {
    ret = a - (k - a - b);
  }

  cout << ret << endl;
}

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

  // cout << fixed << setprecision(10);

  solve();

  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};

int main() {
	ll N;
	cin >> N;
	map<ll, ll>m;
	vector<int>a(N);
	rep(i, N){
		cin >> a[i];
		m[a[i]-1] = i+1;
	}
	rep(i, N) {
		cout << m[i]<<" ";
	}
}
	

Measured memory_bytes: 9212
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

class UnionFindTree:
    def __init__(self, n):
        self.nodes = list(range(n+1))
    def find(self, x):
        if self.nodes[x] == x:
            return x
        parent = self.find(self.nodes[x])
        self.nodes[x] = parent
        return parent
    def unite(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b:
            return
        self.nodes[a] = self.nodes[b]
    def is_same(self, a, b):
        return self.find(a) == self.find(b)

UFL=UnionFindTree(100010)
UFR=UnionFindTree(100010)

N=II()
rmap = {}
lmap = {}
for i in range(N):
    l,r=LI()
    if not r in rmap:
        rmap[r] = []
    if not l in lmap:
        lmap[l] = []
    rmap[r].append(l)
    lmap[l].append(r)

for l, lis in lmap.items():
    for r in lmap[l]:
        for l2 in rmap[r]:
            UFL.unite(l,l2)
for r, lis in rmap.items():
    for l in rmap[r]:
        for r2 in lmap[l]:
            UFR.unite(r,r2)

varl = {}
varr = {}

for l in lmap.keys():
    gr = UFL.find(l)
    if gr in varl:
        varl[gr] += 1
    else:
        varl[gr] = 1

for r in rmap.keys():
    gr = UFR.find(r)
    if gr in varr:
        varr[gr] += 1
    else:
        varr[gr] = 1

res = {}
for l, lis in lmap.items():
    gl = UFL.find(l)
    gr = UFR.find(lis[0])
    res[(gl,gr)] = varl[gl] * varr[gr]

# print(varl)
# print(varr)
# print(res)
ressum = 0
for i in res.values():
    ressum += i
print(ressum - N)

Measured memory_bytes: 155992
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cnt=0
a=0
b=0

while a<n and cnt<k:
    if cnt+A[a]<=k:
        cnt+=A[a]
        a+=1
    else:
        break
ans=a      
        
while b<m:
    if cnt+B[b]<=k:
        cnt+=B[b]
        b+=1
        ans=max(a+b,ans)
    elif a>0:
        a-=1
        cnt-=A[a]
    else:
        break
        
print(ans)

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

#define reint register int
#define coint const int

using namespace std;

const double EPS = 1e-8;

struct Vector {
    double x, y;

    inline Vector operator+(const Vector &v) const {
        return (Vector){ x + v.x, y + v.y };
    }

    inline double dot(const Vector &v) const { return x * v.x + y * v.y; }
    inline double cross(const Vector &v) const { return x * v.y - y * v.x; }
    inline double length(void) const { return sqrt(x * x + y * y); }
    inline double square(void) const { return x * x + y * y; }
    inline double getAngle(void) const { return atan2(y, x); }

    inline Vector operator*(const double a) const {
        return (Vector){ x * a, y * a };
    }
};

struct Point {
    double x, y;

    inline Vector operator-(const Point &p) const {
        return (Vector){ x - p.x, y - p.y };
    }

    inline Point operator+(const Vector &v) const {
        return (Point){ x + v.x, y + v.y };
    }
};

inline int isEq(const double a, const double b) {
    return abs(a - b) < EPS;
}

int main(void) {
    int q;
    scanf("%d", &q);
    for (reint i = 1; i <= q; ++i) {
        Point p0, p1, p2, p3;
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",
              &p0.x, &p0.y, &p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y);
        const Vector vec01 = p1 - p0;
        const Vector vec23 = p3 - p2;
        if (!isEq(vec01.cross(vec23), 0)) {
            if (isEq(vec01.dot(vec23), 0))
                puts("1");
            else puts("0");
            continue;
        }
        //const Point p = p0 + vec01 * ((p3.x - p0.x) / (p1.x - p0.x));
        //if (isEq(p3.y - p.y, 0))
            //puts("0");
        //else puts("2");
        puts("2");
    }

    return 0;
}



Measured memory_bytes: 3232