akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define input_from_file  freopen("input.txt", "r", stdin);
using namespace std;

int main()
{
FASTIO
//input_from_file

string s, t;
cin >> s >> t;
int ss = s.size(), ts = t.size();

int dp[ss+1][ts+1];
for(int i = 0; i < ts+1; i++){
  dp[0][i] = 0;
}
for(int i = 0; i < ss+1; i++){
  dp[i][0] = 0;
}

string ans = "";

for(int i = 1; i < ss+1; i++){
  for(int j = 1; j < ts+1; j++){
    if(s[i-1] == t[j-1]){
      dp[i][j] = dp[i-1][j-1] + 1;
    }
    else{
      dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    }
  }
}

int i = ss, j = ts;

while(i > 0 && j > 0){
  if(s[i-1] == t[j-1]){
    ans += s[i-1];
    i--; j--;
    continue;
  }
  if(dp[i][j] == dp[i-1][j]){
    i--;
    continue;
  }
  if(dp[i][j] == dp[i][j-1]){
    j--;
    continue;
  }
}

int a = ans.size();
string sol = "";

for(int i = a-1; i >= 0; --i){
  sol += ans[i];
}

cout << sol;
}


Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
typedef pair<double, string> pds;

int N, P, A, B, C, D, E, F, S, M;
string L;

int main(void) {
  while(cin >> N, N) {
    vector<pds> v;
    REP(i, 0, N) {
      cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
      int R = S * F * M - P;
      int T = A + B + C + (D + E) * M;
      double Q = - (double) R / T;
      v.push_back(pds(Q, L));
    }
    sort(v.begin(), v.end());
    REP(i, 0, N) cout << v[i].second << endl;
    cout << "#" << endl;
  }

  return 0;
}

Measured memory_bytes: 3016
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);
 
#define f first
#define s second
 
#define inf (int)1e9 + 7
 
#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
 
#define mp(x,y) make_pair(x,y)
 
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)
 
#define pb push_back
#define ppb pop_back
 
#define bitcoin __builtin_popcount
 
#define endl "\n"
 
#define in(x) insert(x)
 
#define sz(x) (int)x.size()
 
#define all(x) x.begin(),x.end()
 
#define pw2(x) (1ll<<x) //2^x
 
#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
 
#define sqr(x) ((x) * 1ll * (x))
 
#define UpdateRandom srand (time(NULL));
 
using namespace std;
 
const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;

int n,k,ans;
int a[N];
int dp[N][4];
bool was[N][4];

int calc(int x,int cur){
	if(was[x][cur])return dp[x][cur];
	was[x][cur]=1;
	bool found=0;
	for(int i=1;i<=n;i++){
		if(x+a[i]<=k){
			if(calc(x+a[i],(cur^1))==cur)found=1;	
		}
	}
	if(found)return dp[x][cur]=cur;
	else return dp[x][cur]=(cur^1);
}

int main(){
		
	NFS

	cin >> n >> k;
	
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	
	if(calc(0,0)==0){
		cout << "First" << endl;
	}
	else cout << "Second" << endl;
	
	ioi
}

Measured memory_bytes: 12672
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using plpii = std::pair<long long, std::pair<int, int>>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

struct book {
	int c;
	int a[12];
};

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

	int n, m, x;
	cin >> n >> m >> x;
	book* books = new book[n];
	rep(i, n) {
		cin >> books[i].c;
		rep(j, m) {
			cin >> books[i].a[j];
		}
	}

	int ans = _MOD;
	int* score = new int[m];
	rep(bit, 1 << n) {
		memset(score, 0, sizeof(int)*m);
		bool flag = false;

		int sum = 0;
		rep(i, n) {
			if (bit & (1 << i)) {
				sum += books[i].c;
				
				if (!flag) {
					bool ok = true;
					rep(j, m) {
						score[j] += books[i].a[j];
						if (score[j] < x) ok = false;
					}

					if (ok) flag = true;
				}
			}
		}

		if(flag) ans = min(ans, sum);
	}

	if (ans == _MOD) {
		cout << "-1" << "\n";
	}
	else {
		cout << ans << "\n";
	}

	return 0;
}



Measured memory_bytes: 3556
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;
  for(int i=0;i<4;i++) cout << s[i];
  cout << " ";
  for(int i=4;i<12;i++) cout << s[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

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

int myabs(int x){
    return x > 0 ? x : -x;
}


int main(){
    int x, n;   cin >> x >> n;
    set<int> a;
    for(int i = 0; i < n; i++){
        int y;
        cin >> y;
        a.insert(y);
    }

    int res = INT32_MAX, ret = -1;
    for(int i = -20; i <= 120; i++){
        if(a.find(i) != a.end())   continue;
        if(res > myabs(i - x)){
            res = myabs(i-x);
            ret = i;
        }
    }
    cout << ret << endl;

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	cin>>n;
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		if(i%3 != 0 && i%5 != 0)ans += i;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
 
void solve(){
    int n;
    cin >> n;
    cout << (n + 1) / 2;
}

 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]

d = {}
#key設定
for i in A:
    d[i]=0
#数字keyが偶数回出たら0,奇数回出たら1になるようにvalueを設定
for i in A:
    if d[i]==1:
        d[i]=0
    else:
        d[i]=1
    
print(sum(d.values()))

Measured memory_bytes: 20444
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int a[200000+10];
int S[200000+10];

signed main(void) {
    int N; cin>>N;
    rep(i, N) {
        cin>>a[i];
        if (i==0) S[i]=a[i];
        else S[i]=S[i-1]+a[i];
    }
    int ans=INF;
    REP(i, 1, N-1) { //i:上から撮る枚数
        int sunuke=S[i-1];
        int kuma=S[N-1]-S[i-1];
        ans=min(ans, abs(sunuke-kuma));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
a = []

for i in range(5):
    a.append(int(input()))


def ceil10(n):
    return ((n + 9) // 10) * 10


ans = 999

for i in range(5):
    t = 0

    for j in range(5):
        if j == i:
            t += a[j]
        else:
            t += ceil10(a[j])
    ans = min(ans, t)

print(ans)


Measured memory_bytes: 3060
from collections import defaultdict
n = int(input())
x = [0] * n
y = [0] * n
dir = [0] * n
INF = 10**8


def g(v):
    v.sort(key=lambda x: x[0])
    ret = INF
    for i in range(1, len(v)):
        if v[i - 1][1] == 0 and v[i][1] != 0:
            ret = min(ret, v[i][0] - v[i - 1][0])
    return ret


def f(d):
    ret = INF
    for k, v in d.items():
        ret = min(ret, g(v))
    return ret


for i in range(n):
    # x[i], y[i], c = map(int, input().split())
    sx, sy, c = input().split()
    x[i] = int(sx)
    y[i] = int(sy)
    if c == 'U':
        dir[i] = 0
    if c == 'R':
        dir[i] = 1
    if c == 'D':
        dir[i] = 2
    if c == 'L':
        dir[i] = 3

ans = INF
for ri in range(4):
    # UD
    d = defaultdict(list)
    for i in range(n):
        if dir[i] != 0 and dir[i] != 2:
            continue
        d[x[i]].append((y[i], dir[i]))
    ans = min(ans, f(d) * 5)
    # UR
    d2 = defaultdict(list)
    for i in range(n):
        if dir[i] != 0 and dir[i] != 1:
            continue
        d2[x[i] + y[i]].append((y[i], dir[i]))
    ans = min(ans, f(d2) * 10)

    # rotate
    for i in range(n):
        px = x[i]
        py = y[i]
        x[i] = py
        y[i] = -px
        dir[i] = (dir[i] + 1) % 4
if ans >= INF:
    print('SAFE')
else:
    print(ans)


Measured memory_bytes: 132220
#define _CRT_SECURE_NO_WARNINGS
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(void) {
#ifdef DEBUG
	printf("");
#endif
	int N;
	int i;
	int l, r;
	int ans = 0;

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d %d", &l, &r);
		ans += r - l + 1;
	}
		printf("%d\n", ans);
}

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

int main(){
    long long int n;

    cin>>n;

    long long int a[n],b[n],c[n];


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

        if(i>=1){
            a[i]=max(a[i]+b[i-1],a[i]+c[i-1]);
            b[i]=max(a[i-1]+b[i],b[i]+c[i-1]);
            c[i]=max(a[i-1]+c[i],b[i-1]+c[i]);
        }


    }

    cout<<max(a[n-1],max(b[n-1],c[n-1]))<<endl;

}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-10;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int a[n];
    int cnt[n+1];
    fill(cnt,cnt+n+1,0);
    rep(i,0,n){
        cin>>a[i];
        cnt[a[i]]++;
    }
    vector<int> v;
    rep(i,1,n+1){
        if(cnt[i]>0)v.push_back(cnt[i]);
    }
    sort(v.begin(),v.end());
    int ans[n+1];
    fill(ans,ans+n+1,-1);
    int sum=0;
    int num=0;
    int sa[n+1];
    sa[0]=n;
    rep(i,1,n+1){
        while(num<v.size()&&v[num]==i){
            sum+=i;
            num++;
        }
        int ss=sum+(v.size()-num)*i;
        sa[i]=ss/i;
        rrep(j,sa[i-1],sa[i]+1)ans[j]=i-1;
    }
    ans[1]=n;
    rep(i,1,n+1)cout<<ans[i]<<endl;
}





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

#define int     long long int
#define pii     pair<int, int>
#define vi      vector<int>
#define vii     vector<pair<int, int>>
#define pb      push_back
#define all(a)  (a).begin(),(a).end()
#define f       first
#define s       second
#define endl    '\n'
#define mod     1000000007    		

void solve()
{
	int n ;
	cin >> n ;
	int a[n] ;
	int cmp = 1E18, ans = 1 ;
	for(int i =  0 ; i < n ; i++)
	{
		cin >> a[i] ;
	}
	sort(a, a + n) ;
	if(a[0] == 0)
	{
		cout << 0 << endl ;
		return ;
	}
	for(int i =  0 ; i < n ; i++)
	{	
		int x = (cmp / ans) ;
		if(x < a[i])
		{
			cout << -1 << endl ;
			return ;
		}
		ans = ans * a[i] ;
	}
	cout << (int)ans << endl ;
}

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

    int t = 1 ;
    //cin >> t ;
    while(t--)
    {
        solve() ;
    }
    return 0 ;
}

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

int main() {

  while( true ) {

    long long int n, m, a;
    cin >> n >> m >> a;
    if ( n == 0 ) break;

    vector< pair< long long int, pair< long long int, long long int > > > v;

    for ( long long int i = 0; i < m; i++ ) {

      long long int h, p, q;
      cin >> h >> p >> q;

      v.push_back( make_pair( h, make_pair( p, q ) ) );

    }

    sort( v.begin(), v.end() );

    long long int c[101];
    for ( long long int i = 1; i <= n; i++ ) {
      c[i] = i;
    }

    for ( long long int i = 0; i < m; i++ ) {

      long long int k = c[ v[i].second.second ];
      c[ v[i].second.second ] = c[ v[i].second.first ];
      c[ v[i].second.first ] = k;

    }

    cout << c[a] << endl;

  }

  return 0;

}

Measured memory_bytes: 1244
#include <stdio.h>
int n, m, a, g;
char x[200];
char s[50][200];
int t[50];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf(" %s", s[i]);
		scanf("%d", t + i);
	}
	scanf(" %s", x);
	for (int i = 0; i < n; i++) {
		if (m)a += t[i];
		g = 0;
		for (int j = 0; j < 200; j++) {
			if (s[i][j] == x[j])g++;
		}
		if (g == 200)m = 1;
	}
	printf("%d\n", a);
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
    int hairetu[3];
    int temp;
    int i,j;
    for(i=0;i<3;i++)scanf("%d",&hairetu[i]);
    for(i=2;i>=0;i--) {
        for(j=0;j<i;j++) {
            if(hairetu[j]>hairetu[j+1]) {
                temp=hairetu[j];
                hairetu[j]=hairetu[j+1];
                hairetu[j+1]=temp;
            }
        }
    }
    printf("%d %d %d\n",hairetu[0],hairetu[1],hairetu[2]);
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

#define N 100000
#define Q 50000

int left, right, mid, n;
int s[N], t[Q];

int binarySearch(int);

int main()
{

  int i, j, q, c = 0;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%d", &s[i]);
  }

  scanf("%d", &q);

  for(j=0; j<q; j++){
    scanf("%d", &t[j]);
  }

  for(j=0; j<q; j++){
    if(binarySearch(t[j]) == 1){
      c++;
    }
  }

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

  return 0;

}

int binarySearch(int key)
{

  left = 0;
  right = n;

  while(left < right){
    mid = (left + right) / 2;

    if(s[mid] == key){
      return 1;
    }

    else if(key < s[mid]){
      right = mid;
    }

    else{
      left = mid + 1;
    }
  }

  return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<unordered_map>
#include<string>

int main(){
  std::string nday;
  
  std::unordered_map<std::string, int>
    wd{
       {"SUN",7},{"MON",6},{"TUE",5},{"WED",4},{"THU",3},{"FRI",2},{"SAT",1} };


  std::cin >> nday;
  std::cout  << wd.at(nday) << std::endl;
}


Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=100111;
const int mod=998244353;

int n,a[maxn];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	sort(a+1,a+n+1);
	
	int ans=1;
	
	for(int i=1;i<=n;i++)ans=(LL)ans*__gcd(a[i],i-1)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int intA = sc.nextInt();
		int intB = sc.nextInt();
		int intC = sc.nextInt();
		int intKosuu = 0;

		for(int i = intA; i <= intB; i++){

			if(intC % i == 0){
				intKosuu++;
			}
		}

		System.out.println(intKosuu);
	}
}

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

using namespace std;

#define int long long

#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)

typedef vector<int> VI;
typedef pair<int, int> PII;

//--------

int N;

signed main(){
    cin >> N;
    string s;
    cin >> s;

    int r= 0, b= 0;
    REP(i, N){
        if(s[i] == 'R'){
            r++;
        }
        else{
            b++;
        }
    }

    if(r > b){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>

#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(void)
{
	long n, m;
	while(cin >> n >> m, n > 0){
		map<long, long> pd;
		long ans=0;
		//map pdを構成
		rep(i, n){
			int d, p;
			cin >> d >> p;
			if (pd.count(p) == 0){
				pd.insert(make_pair(p, d));
			}else{
				pd[p] += d;
			}
		}
		for(auto itr = pd.rbegin(); itr != pd.rend(); itr++){
			if (m > itr->second){
				m -= itr->second;
			}else{
				ans += itr->first * (itr->second - m);
				m = 0;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            var C = int.Parse(Console.ReadLine());
            var D = int.Parse(Console.ReadLine());

            Console.WriteLine((A < B ? A : B) + (C < D ? C : D));
        }
    }
}

Measured memory_bytes: 11092
#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define is insert
#define es erase
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
int n,ans;
ll tp,D,x,y;
int main(){
	gi(n);gi(D);
	D=1ll*D*D;
	rep(i,1,n){
		gi(x);gi(y);
		tp=x*x+y*y;
		//printf("now%lld %lld\n",tp,D);
		if(tp<=D)++ans;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define M 100010
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
int a[M];
int main() {
	int n,L;
	scanf("%d%d",&n,&L);
	rep(i,1,n)scanf("%d",&a[i]);
	rep(i,1,n-1){
		if(a[i]+a[i+1]>=L){
			puts("Possible");
			rep(j,1,i-1)printf("%d\n",j);
			for(int j=n-1;j>=i;--j)printf("%d\n",j);
			return 0;
		}
	}
	puts("Impossible");
}

Measured memory_bytes: 1152
import java.util.Scanner;

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 count = 0;
		for(int x = 1; x <= c; x++)
		{
			if(c % x == 0)
			{
				if(a <= x && x <= b)
				{ 
					count++;
				}
				else
				{
				}
			}
			else
			{
			}
		}
		System.out.println(count);
	}
}
		


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

int main(){
  int n,a;
  cin>>n;
  int count0=0,count1=0,count2=0;
  lp(i,n){
    cin>>a;
    a%=3;
    if(a==0) count0++;
    if(a==1) count1++;
    if(a==2) count2++;
  }
  int ccount00=count0;
  int ccount11=count1;
  int ccount22=count2;
  int ans=0,ans2=0;
  if(count1!=0||count2!=0) {
    ans+=count0;
    ans2+=count0;
  }
  if(count1!=0){
    count1--;ans++;
    while(1){
      if(count1!=0&&count2!=0) {
	ans+=2;
      count1--;count2--;
      }
      else break;
    }
    if(count1>0) ans++;
    if(count1>1) ans++;
    if(count2>0) ans++;
  }
  count0=ccount00;
  count1=ccount11;
  count2=ccount22;
  if(count2!=0){
    count2--;ans2++;
    while(1){
      if(count1!=0&&count2!=0) {
	ans2+=2;
	count1--;count2--;
      }
      else break;
    }
    if(count2>0) ans2++;
    if(count2>1) ans2++;
    if(count1>0) ans2++;
  }
  if(ans==0) ans=1;
  if(ans2==0) ans2=1;
  cout<<max(ans,ans2)<<endl;
  return 0;
}



Measured memory_bytes: 3092
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,k = LI()
    print(n%k)
    return

#B
def B():
    n = I()
    po = LIR(n)
    if n == 1:
        print(1)
        quit()
    ans = float("inf")
    for i in range(n):
        for j in range(n):
            if i == j:continue
            x,y = po[i]
            s,t = po[j]
            p,q = s-x,t-y
            m = n
            for k in range(n):
                for l in range(n):
                    if (po[k][0]-po[l][0],po[k][1]-po[l][1]) == (p,q):m -= 1
            if m < ans:
                ans = m
    print(ans)
    return

#C
def C():
    n = I()
    a = LI()
    a.sort()
    if a[0] >= 0:
        print(sum(a)-2*a[0])
        for i in range(1,n-1):
            print(a[0],a[i])
            a[0] -= a[i]
        print(a[n-1],a[0])
    else:
        if a[-1] < 0:
            print(2*a[-1]-sum(a))
            for i in range(n-1):
                print(a[-1],a[i])
                a[-1] -= a[i]
        else:
            m = bisect.bisect_left(a,0)
            p = n-m
            ans = -sum(a[:m])+sum(a[m:])
            print(ans)
            if p > m:
                l = a[-1]
                a = a[:-1]
                a = a[::-1]
                p -= 1
                p,m = m,p
                k = a[m]-a[m-1]
                print(a[m],a[m-1])
                for i in range(p-1):
                    print(a[m-i-2],k)
                    k = a[m-i-2]-k
                    print(a[m+i+1],k)
                    k = a[m+i+1]-k
                for i in range(m-p):
                    print(k,a[i])
                    k -= a[i]
                print(l,k)
            else:
                k = a[m]-a[m-1]
                print(a[m],a[m-1])
                for i in range(p-1):
                    print(a[m-i-2],k)
                    k = a[m-i-2]-k
                    print(a[m+i+1],k)
                    k = a[m+i+1]-k
                for i in range(m-p):
                    print(k,a[i])
                    k -= a[i]
    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#G
def G():
    n = I()

    return

#H
def H():
    n = I()

    return

#I
def I_():
    n = I()

    return

#J
def J():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()


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

using namespace std;

struct Vector {
  double x, y;
  Vector() {}
  Vector(double x, double y): x(x), y(y) {}
  Vector operator+(Vector v) { return Vector(x + v.x, y + v.y); }
  Vector operator-(Vector v) { return Vector(x - v.x, y - v.y); }
  Vector operator*(double k) { return Vector(x * k, y * k); }
  Vector operator/(double k) { return Vector(x / k, y / k); }
  bool operator==(Vector v)  { return abs(x - v.x) < 1e-10 && abs(y - v.y) < 1e-10; }
  friend void input(Vector &v) { cin >> v.x >> v.y; }
  friend double norm(Vector v) { return dot(v, v); }
  friend double  abs(Vector v) { return sqrt(norm(v)); }
  friend double   dot(Vector v1, Vector v2) { return v1.x * v2.x + v1.y * v2.y; }
  friend double cross(Vector v1, Vector v2) { return v1.x * v2.y - v1.y * v2.x; }
  friend void show(Vector v) { if (abs(v.x) < 1e-10) v.x = 0.0; if (abs(v.y) < 1e-10) v.y = 0.0; printf("%.10f %.10f\n", v.x, v.y); }
  friend bool ccw(Vector v, Vector v1, Vector v2) { return cross(v1 - v, v2 - v) > 1e-10; }
  friend bool  cw(Vector v, Vector v1, Vector v2) { return cross(v1 - v, v2 - v) < -1e-10; }
  friend bool parallel(Vector v1, Vector v2) { return abs(cross(v1, v2)) < 1e-10; }
  friend bool onLine(Vector v, Vector v1, Vector v2) { return v == v1 || v == v2 || (parallel(v1 - v, v2 - v) && dot(v1 - v, v2 - v) < -1e-10); }
  friend int direct(Vector v1, Vector v2, Vector v) { if (ccw(v1, v2, v)) return  1; if ( cw(v1, v2, v)) return -1; if (dot(v2 - v1, v - v1) < -1e-10) return  2; if (dot(v1 - v2, v - v2) < -1e-10) return -2; return 0; }
};
typedef Vector Point;

int main(void) {
  Point p[4];
  while (cin >> p[0].x >> p[0].y) {
    for (int i = 1; i < 4; i++) {
      input(p[i]);
    }

    cout << ((ccw(p[3], p[0], p[1]) && ccw(p[3], p[1], p[2]) && ccw(p[3], p[2], p[0])) || (cw(p[3], p[0], p[1]) && cw(p[3], p[1], p[2]) && cw(p[3], p[2], p[0])) ? "YES" : "NO") << endl;
  }

  return 0;
}


Measured memory_bytes: 3056
#include<stdio.h>
#include<string.h>
int main(){
	int N,R;
	scanf("%d %d", &N , &R );
	int rating;
	if (N<10){
		rating = R + 100 * (10-N);
	} else if (10<=N<=100 ){
		rating = R;
	}
	printf("%d",rating);
}

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

int main(){
  string a[110];
  int c;
  cin >> c;
  for(int i = 0; i < c; i++){
    cin >> a[i];
    if(a[i] == "Y"){
      cout << "Four" << endl;
      break;
    }else if(i == (c-1)){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
min_value = sum(abs(i) for i in a)
total = 0
for i in range(n-1):
    total += a[i]
    if abs((2 * total) - sum_a) < min_value:
        min_value = abs((2 * total) - sum_a)
print(min_value)

Measured memory_bytes: 24812
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll n;cin >> n;
    if(n==1)cout << 1 << endl,exit(0);
    vpl p(n);rep(i,n){
        cin >> p[i].fi >> p[i].se;
    }
    sort(all(p));
    ll ans=inf;
    rep(i,n){
        rep(j,n){
            if(i==j)continue;
            ll res=0;
            ll a=p[i].fi-p[j].fi,b=p[i].se-p[j].se;
            rep(k,n){
                if(!binary_search(all(p),make_pair(p[k].fi-a,p[k].se-b)))res++;
            }
            chmin(ans,res);
        }
    }
    cout << ans <<endl;
}

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

using namespace std;

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

		int l[N+M];
		int index = 0;
		for (int i = 1; i <= N; i++) {
			l[index] = 2 * i;
			index++;
		}
		for (int i = 1; i <= M; i++) {
			l[index] = 2 * i - 1;
			index++;
		}

		int res = 0;
		for(int i = 0; i < N+M; i++) {
			for (int j = i+1; j < N+M; j++) {
				if ((l[i] + l[j]) % 2 == 0) {
					res += 1;
				}
			}
		}

		cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int a[3],n;
 cin>>a[0]>>a[1]>>a[2]>>n;
 ll dp[4][n+1];
 for(ll i=0;i<=n;i++) dp[3][i]=0;
 dp[3][0]=1;
 for(int i=2;i>=0;i--){
  for(int j=0;j<=n;j++){
   dp[i][j]=0;
   for(int k=0;k*a[i]<=j;k++){
     dp[i][j]+=dp[i+1][j-k*a[i]];
   }
  }
 }
 cout<<dp[0][n]<<endl;
 return 0;
}

Measured memory_bytes: 384
n = int(input())
l=[]
for i in range(n):
        tmp = list(map(int,input().split()))
        l.append(tmp)
lis = range(n)
import itertools
import math
cities = list(itertools.permutations(lis))
ans=0
for j in range(len(cities)):
        vils = cities[j]
        for i in range(1,n):
                last= l[vils[i-1]]
                now = l[vils[i]]
                dist = (last[0] - now[0])**2 + (last[1] - now[1])**2
                dist = math.sqrt(dist)
                ans+=dist
print(ans/len(cities))

Measured memory_bytes: 7992
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

const double EPS = 1e-10;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : VP{
    L(const P& a, const P& b){ resize(2); at(0)=a; at(1)=b; }
    L(){ resize(2); }
};
double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}

int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //counter clockwise
    if(cross(b,c) <-EPS) return -1; //clockwise
    if(dot(b,c) < EPS) return +2; //c-a-b
    if(norm(b) < norm(c)) return -2; //a-b-c
    return 0; //a-c-b
}

bool intersectSS(const L& s, const L& t){
    return ( ccw(s[0],s[1],t[0]) *ccw(s[0],s[1],t[1]) <= 0 ) &&
        ( ccw(t[0],t[1],s[0]) *ccw(t[0],t[1],s[1]) <= 0 );
}
bool intersectSP(const L& s, const P& p){
    return abs(s[0]-p) +abs(s[1]-p) -abs(s[1]-s[0]) < EPS;
}
P projection(const L& l, const P& p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}
double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0]-p), abs(s[1]-p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        int sx,sy,ex,ey;
        cin >> sx >> sy >> ex >> ey;
        L stoe(P(sx, sy), P(ex, ey));
        double ans = INF;
        for(int i=0; i<n; i++){
            vector<P> p(4);
            int x1,y1,x2,y2,h;
            cin >> x1 >> y1 >> x2 >> y2 >> h;
            p[0] = P(x1, y1);
            p[1] = P(x1, y2);
            p[2] = P(x2, y2);
            p[3] = P(x2, y1);
            double dist = INF;
            if(x1<sx && sx<x2 && y1<sy && sy<y2) dist=0;
            if(x1<ex && ex<x2 && y1<ey && ey<y2) dist=0;
            for(int i=0; i<4; i++){
                dist = min(dist, distanceSS(stoe, L(p[i], p[(i+1)%4])));
            }
            if(dist > h){
                ans = min(ans, (dist*dist+h*h)/(2*h));
            }else{
                ans = min(ans, dist);
            }
        }
        cout << fixed;
        cout << setprecision(5);
        cout << ans << endl;
    }    
    return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)       sort((a).begin(), a.end()), (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;

LL gcd(LL a, LL b)
{
	if (!a)return b; return gcd(b%a, a);
}
double intlog(double base, double x) {
	return (double)((double)log(x) / (double)log(base));
}

int main()
{
	int n;
	cin >> n;
	int count = 0;
	for (int i = 1; i <= n; i++)
	{
		string s = to_string(i);
		if (s.length() & 1)
			count++;

}
	cout << count << endl;
}













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

using namespace std;
#define ll long long
ll dp[3002];
int S;
int N;
int A[3002];
const ll mod = 998244353;

ll qpow(ll x, int k)
{
	ll ans = 1;
	while(k)
	{
		if(k & 1)
		{
			ans *= x;
			ans %= mod;
		}
		k >>= 1;
		x = x * x % mod;
	}
	return ans;
}

ll inv(ll x)
{
	return qpow(x, mod - 2);
}

int main()
{
	memset(dp, 0, sizeof(dp));
	cin>>N>>S;
	for(int i = 1; i <= N; ++i)
		cin>>A[i];
	dp[0] = qpow(2, N);
	ll inv2 = inv(2);
	for(int i = 1; i <= N; ++i)
	{
		for(int j = S; j >= A[i]; --j)
		{
			dp[j] += dp[j-A[i]] * inv2 % mod;
			dp[j] %= mod;
		}
	}
	cout<<dp[S]<<endl;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define MOD ((long long)(1e9 + 7))

int main(void) {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<long long> sum(N + 1, 0);
    for (int i = 0; i < N; i++) {
        sum[i + 1] = sum[i] + A[i];
    }

    long long ans = 0;
    for (int i = 0; i < N; i++) {
        ans += (A[i] * ((sum[N] - sum[i + 1]) % MOD)) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6424
// C.

#include <iostream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	int left = 0, right = (int)s.length() - 1, ans = 0;
	while (left < right) {
		while (left < right && s[left] == 'x') {
			++left;
			if (s[right] == 'x') {
				--right;
			} else {
				++ans;
			}
		}
		while (left < right && s[right] == 'x') {
			--right;
			++ans;
		}
		if (left < right && s[left] != s[right]) {
			ans = -1;
			break;
		}
		++left;
		--right;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, elaps;

void enqueue(P x){
  Q[tail] = x;
  if(tail + 1 == LEN)
    tail = 0;
  else
    tail++;
}

P dequeue(){
  P x;
  x = Q[head];
  if(head + 1 == LEN)
    head = 0;
  else
    head++;
  return x;
}


int main(){
  int i, q, n;
  P u;
  scanf("%d %d", &n, &q);
  head = 1;
  tail = n + 1;

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  while(head != tail){
    u = dequeue();
    if(u.t > q){
      u.t -= q;
      elaps += q;
      enqueue(u);
    }
    else{
      elaps += u.t;
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}



Measured memory_bytes: 11856
from collections import deque
n,m =  map(int,input().split())
l = [list() for _ in range(n+1)]
for _ in range(m):
    a,b = map(int,input().split())
    l[a].append(b)
s,t = map(int,input().split())

reach = [[-1,-1,-1] for _ in range(n+1)]
reach[s][0] = 0
bfs = deque()
bfs.append((s,0))
while bfs:
    cur,dis = bfs.popleft()
    for x in l[cur]:
        if reach[x][(dis+1)%3] < 0:
            bfs.append((x,dis+1))
            reach[x][(dis+1)%3] = dis+1
ans = reach[t][0]
if ans > 2:
  ans //= 3
print(ans)

Measured memory_bytes: 38100
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);

  for(int i=0;i<n;i++){
    double x1, y1, x2, y2, x3, y3, x4, y4;
    scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1,&y1,&x2,&y2,&x3, &y3,&x4, &y4);

    double ab = (y1-y2)/(x1-x2);
    double cd = (y3-y4)/(x3-x4);

    printf("%s\n", (ab==cd)? "YES":"NO");
  }
  return 0;
}

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

int main(void){

  int n,m;
  int sumT,sumH;
  int bt,bh;
  int flag;

  while(1){

    sumT=0;
    sumH=0;
    bt=0;
    bh=0;
    flag=0;
  int t[150],h[150];

    cin >> n >> m;

    if( n == 0 && m == 0 ) break;

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

      cin >> t[i];

      sumT += t[i];

    }

    sort( t , t+n ); 

    for( int j = 0 ; j < m ; j++ ){

      cin >> h[j];

      sumH += h[j];

    }

    sort( h , h+m );

    for( int i = 0 ; i < n ; i++ ){
      for( int j = 0 ; j < m ; j++ ){
	
	if( flag == 0){
	    
	    bt = t[i];
	    bh = h[j];
	    sumT = sumT + bh - bt;
	    sumH = sumH + bt - bh;

	    if( sumT == sumH ) flag = 1;
	    else{
	      sumT = sumT - bh + bt;
	      sumH = sumH - bt + bh;

	    }
	    
	}
	
      }
    }
    

	if( flag == 1 ) cout << bt <<" "<< bh << endl;
	else cout << "-1" << endl;
	
  }

  return 0;
  
}

Measured memory_bytes: 1184
n = int(input())
A = sorted(list(map(int, input().split())))
from collections import Counter
c = Counter(A)

dp = [1]*(max(A)+1)
#print(dp)
for i in c.keys():
    j = i*2
    while j<len(dp):
        dp[j] = 0
        j += i
        #print(j, end=',')
ans = 0
for i in c.keys():
    if c[i] == 1:
        if dp[i] == 1:
            ans += 1
print(ans)


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

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

    sort(h.begin(), h.end());

    for(int i = 0; i <= n-k; i++){
        ans.push_back(h.at(k-1+i) - h.at(i));
    }

    cout << *min_element(ans.begin(),ans.end())  << endl;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    vector<int> v(3);
    for (int i = 0; i < 3; i++) cin >> v[i];

    sort(v.begin(), v.end());
    cout << (v[0] + v[1] == v[2] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int n, r;
  while (cin >> n >> r && n + r) {
    auto deck = vector<int>(n);
    for (int i = 0; i < n; i++) deck[i] = n-i;
    for (int i = 0; i < r; i++) {
      int p, c; //3 1
      cin >> p >> c;
      auto temp = vector<int>(c);
      for (int j = 0; j < c; j++) temp[j] = deck[p-1+j];
      for (int j = c+p-2; j >= c; j--) deck[j] = deck[j-c];
      for (int j = 0; j < c; j++) deck[j] = temp[j];
    }
    cout << deck[0] << endl;
  }
}



Measured memory_bytes: 3072
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;

int W[100001];
int n,k;

int rec(int p){
    int maxw = 0;
    int numtr = 1;
    int tr = p;
    int i;
    for (i = 0; i < n; i++) {
        if (tr - W[i] >= 0) {
            tr -= W[i];
        }else if(numtr < k){
            tr = p;
            i--;
            numtr++;
        }else{
            break;
        }
    }
    return i;
}

int binary(int left, int right){
    //cout << left << "???" << right << endl;
    
    if (right - left == 1) return right;
    int mid = (right + left)/2;
    int nn = rec(mid);
    if (nn >= n) {
        return binary(left,mid);
    }else{
        return binary(mid,right);
    }
}

int main(){
    int sum=0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        scanf("%d",&W[i]);
        sum += W[i];
    }
    int min_p = sum/k;
    if (sum%k != 0) {
        min_p++;
    }
    cout << binary(min_p-1,sum) << endl;
    
    
    return 0;
}

Measured memory_bytes: 1632
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int x;
  cin>>x;
  if(x==7 || x==5 || x==3) cout<<"YES"<<'\n';
  else cout<<"NO"<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define for1(i,n) for(int i=1;i<=(int)(n);i++)
#define debug(x) cout << '>' << #x << ':' << x << endl;
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){  a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// https://www.geeksforgeeks.org/minimum-number-of-increasing-subsequences/
int MinimumNumIncreasingSubsequences(int arr[], int n) 
{ 
    multiset<int> last; 
  
    // last element in each  increasing subsequence  
    // found so far 
    for (int i = 0; i < n; i++) { 
  
        // here our current element is arr[i] 
        multiset<int>::iterator it = last.lower_bound(arr[i]); 
  
        // iterator to the first element larger  
        // than or equal to arr[i] 
        if (it == last.begin()) 
  
            // if all the elements in last larger 
            // than or to arr[i] then insert it into last 
            last.insert(arr[i]); 
  
        else { 
            it--; 
  
            // the largest element smaller than arr[i] is the number 
            // before *it which is it-- 
            last.erase(it); // erase the largest element smaller than arr[i] 
            last.insert(arr[i]); // and replace it with arr[i] 
        } 
    } 
    return last.size(); // our answer is the size of last 
} 
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      int n;
      cin>>n;
      int a[n];
      for(int i=0;i<n;i++) cin>>a[i];
      cout<<MinimumNumIncreasingSubsequences(a,n);
}
/*
4
0 1 0 1
1 0 0 1
*/
// I never lose. I either win or I learn

Measured memory_bytes: 5760
#include<iostream>
using namespace std;
int main() {
	int d, n;
	cin >> d >> n;
	int ans = 1;
	for (int i = 0; i < d; i++) {
		ans *= 100;
	}
	if (n == 100) {
		cout << (n + 1) * ans << endl;
	}
	else {
		cout << n * ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	double a, b, c, d, e, f,y,x;
	while (cin >> a >> b >> c >> d >> e >> f){
		x = ((e*c - b*f) / (a*e - b*d));
		y = ((-(d*c) + a*f) / (a*e - b*d));
		if (x == 0){ x = 0.0; }
		if (y == 0){ y = 0.0; }
		printf("%.3lf %.3lf\n", x, y);
	}
}

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

signed main(){
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  int ans=0;
  if(A>=K)ans=K;
  if(A<K&&A+B>=K)ans=A;
  if(A<K&&A+B<K)ans=A-(K-(A+B));
  cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    ll n, m;
    cin >> n >> m;

    vector<vector<ll>> G(n);
    for(ll i=0; i<m; i++) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    ll r = 0;

    bool eo = false;
    ll e = 0, o = 0;

    vector<ll> t(n);
    auto dfs = [&](auto dfs, ll cur, ll pre, ll d) -> ll {
        if(t[cur]) return t[cur];
        t[cur] = d;
        (d&1 ? o : e)++;

        for(auto &v: G[cur]) {
            if(v == pre) continue;

            ll dd = dfs(dfs, v, cur, d+1);
            if(~(d+dd)&1) eo = true;
        }
        return t[cur];
    };

    dfs(dfs, 0, -1, 1);

    cout << (eo ? n*(n-1)/2 - m : e*o - m) << endl;
}


Measured memory_bytes: 8192
n = int(input())

ans = [0 for _ in range(n+1)]

for x in range(1, int(n ** 0.5) + 1):
    for y in range(1, int(n ** 0.5) + 1):
        for z in range(1, int(n ** 0.5) + 1):
            a = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if a <= n:
                ans[a] += 1

for i in range(1,n+1):
    print(ans[i])



Measured memory_bytes: 9488
a, b, c = map(int, input().split())
x = max(a+b+c, 3*max(a, b, c))
y = (x//3 + (x%3>0))*3 
if (a+b+c)%2 != y%2:
  y += 3
print((y-(a+b+c))//2)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<iomanip>
#include<bits/stdc++.h>
using namespace std;

int main(void) {
	int a, b, h, m;
	cin >> a >> b >> h >> m;

	long double rad, rad_a, rad_b;
	rad_a = h * 30 + m * 0.5;
	rad_b = m * 6;
	rad = abs(rad_a - rad_b);
	if (rad > 180) rad = 360 - rad;
	rad = M_PI * rad / 180;

	long double ans;
	ans = pow(a, 2.0) + pow(b, 2.0) - 2 * a * b * cos(rad);
	ans = sqrt(ans);

	cout << fixed << setprecision(20) << ans;
	return 0;
}

Measured memory_bytes: 4092
n, m = map(int, input().split())
l = []
for i in range(n):
    l.append(list(map(int, input().split())))
l.sort(key = lambda x: x[0])
cost, rest = 0, m
for i in range(n):
    cost += min(rest, l[i][1]) * l[i][0]
    rest -= l[i][1]
    if rest <= 0:
        break
print(cost)

Measured memory_bytes: 29024
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0;

int main (){
    ll x;   cin >> x;
    ll all=0;
    all += (x/500)*1000;
    all += ((x%500)/5)*5;
    cout << all << endl;
}

Measured memory_bytes: 256