akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

#define x(p) real(p)
#define y(p) imag(p)

const double eps=1e-10;
const double inf=1e12;
const double PI=acos(-1);
typedef complex<double> P;

namespace std{
  bool operator<(const P& a,const P& b){
    return x(a)==x(b)?y(a)<y(b):x(a)<x(b);
  }
}
double cross(const P& a,const P& b){
  return y(conj(a)*b);
}
double dot(const P& a,const P& b){
  return x(conj(a)*b);
}
struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};

struct C{
  P p;
  double r;
  C(const P& p,double r):p(p),r(r){}
};
int ccw(P a,P b,P c) {
  b=b-a;c=c-a;
  if(cross(b,c)>0) return +1;       // counter clockwise
  if(cross(b,c)<0) return -1;       // clockwise
  if(dot(b,c)<0)   return +2;       // c--a--b on line
  if(norm(b)<norm(c)) return -2;       // a--b--c on line
  return 0;
}
P projection(const L& l,const P& p){
  P b=l[1]-l[0],c=p-l[0];
  return l[0]+b*x(c/b);
}
bool intersectSP(const L& s,const P& p){
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0])<eps;
}
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;
}
double distanceSP(const L& s,const P& p) {
  const P r=projection(s,p);
  return intersectSP(s,r)?abs(r-p):min(abs(s[0]-p),abs(s[1]-p));
}
void crosspointCC(const C& c1,const C& c2,P& p1,P& p2){
  double x1=x(c2.p)-x(c1.p),y1=y(c2.p)-y(c1.p);
  double r1=c1.r,r2=c2.r;
  double a=(x1*x1+y1*y1+r1*r1-r2*r2)/2.0;
  p1=P(((a*x1+y1*sqrt((x1*x1+y1*y1)*r1*r1-a*a))/(x1*x1+y1*y1))+x(c1.p),((a*y1-x1*sqrt((x1*x1+y1*y1)*r1*r1-a*a))/(x1*x1+y1*y1))+y(c1.p));
  p2=P(((a*x1-y1*sqrt((x1*x1+y1*y1)*r1*r1-a*a))/(x1*x1+y1*y1))+x(c1.p),((a*y1+x1*sqrt((x1*x1+y1*y1)*r1*r1-a*a))/(x1*x1+y1*y1))+y(c1.p));
}

double d[333];

int main(){
	cin.sync_with_stdio(false);
  while(1){
    int n;
    vector<C> cs;
    vector<P> ps;
    cin>>n;
    if(n==0)break;
    rep(i,n){
      double x,y,r;
      cin>>x>>y>>r;
      cs.pb(C(P(x,y),r));
    }
    ps.push_back(cs[0].p);
    rep(i,n-1){
      P p1,p2;
      crosspointCC(cs[i],cs[i+1],p1,p2);
      ps.push_back(p1);ps.push_back(p2);
    }
    ps.push_back(cs[n-1].p);
    rep(i,333)d[i]=inf;
    d[0]=0;
    int m=ps.size();
    rep(i,m)repl(j,i+i%2+1,m){
      // i->j
      bool ok=true;
      repl(k,(i%2==0?i-1:i),(j%2==0?j:j+1)){
        if(!intersectSS(L(ps[k],ps[k+1]),L(ps[i],ps[j])))ok=false;
        k++;
      }
      if(ok){
        minch(d[j],d[i]+abs(ps[i]-ps[j]));
      }
    }
    printf("%.10f\n", d[m-1]);
  }
	return 0;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int S,W; cin >> S >> W;
    debug(S,W);
    cout << (W>=S?"unsafe":"safe") << '\n';
}

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

string S;
vector<int> C(3,0);

int main(){
	cin >> S;
	int N = S.size();
	if(N==1) cout << "YES" << endl;
	else{
		for(int i=0;i<N;i++){
			C[S[i]-'a']++;
		}
		sort(C.begin(),C.end());
		reverse(C.begin(),C.end());
		if(N==2){
			if(C[1]==0) cout << "NO" << endl;
			else cout << "YES" << endl;
		}else{
			if(C[2]==0) cout << "NO" << endl;
			else{
				if(C[0]==C[1] && C[1]==C[2]) cout << "YES" << endl;
				else if(C[0]==C[1]){
					if(C[1]==C[2]+1) cout << "YES" << endl;
					else cout << "NO" << endl;
				}else if(C[1]==C[2] && C[0] == C[1]+1) cout << "YES" << endl;
				else cout << "NO" << endl;
			}
		}
	}
}

Measured memory_bytes: 512
import sys
import math
from collections import defaultdict
n,x,y=map(int,sys.stdin.readline().split())
dis=defaultdict(lambda:10000)
dis=[[0 for _ in range(n)] for a in range(n)]
dis[x-1][y-1]=1
x-=1
y-=1
#print(x,'x',y,'y')
k=[0 for _ in range(n-1)]
for i in range(n):
    for j in range(i+1,n):
        dis[i][j]=j-i
        if i<=x:
            dis_x=x-i
        else:
            dis_x=i-x
        if j<=y:
            dis_y=y-j
        else:
            dis_y=j-y
        dis[i][j]=min(dis[i][j],dis_x+dis_y+1)
        k[dis[i][j]-1]+=1
#print(dis,'dsi')
for i in range(n-1):
    print(k[i])
'''dis[(x-1,y-1)]=1
for i in range(n):
    dis[(i,i)]=0
d=defaultdict(int)
for i in range(n-1,-1,-1):
    for j in range(i+1,n):
        dis[(i,j)]=min(dis[(i,j)],dis[(i+1,j)]+1,dis[(i,j-1)]+1,dis[(i-1,j)]+1,dis[(i,j+1)]+1)
        d[dis[(i,j)]]+=1
#print(dis,'dis')
for i in range(1,n):
    print(d[i])'''



Measured memory_bytes: 81372
using System;
using System.Linq;
class P{
  static int Euc(int a,int b){
    if(a<b)return Euc(b,a);
    else if(a%b==0)return b;
    else return Euc(b,a%b);
  }
  static void Main(){
    int N=int.Parse(Console.ReadLine());
    var s=Console.ReadLine().Split().Select(int.Parse).ToArray();
    int ans=s[0];
    foreach(int x in s)ans=Euc(ans,x);
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 17632
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	int a, b;

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

	if (a < b) {
		printf("a < b\n");
	}
	else if (a > b) {
		printf("a > b\n");
	}
	else {
		printf("a == b\n");
	}

	return 0;
}


Measured memory_bytes: 2116
#include<stdio.h>
int main() {
  int i, a, b, n, k, s, l;
  scanf("%d", &k);
  for (s = 0; s < k; s ++) {
    scanf("%d", &a); b = 0; l = 1;
    for(i = 1;i < 10; i ++) {
      scanf(" %d", &n);
      if (a < n) {
	a = n;
      } else if (a > n && b < n) {
	b = n;
      } else {
	l = 0;
      }
    }
    if (l) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long mypow(long long px, long long py){
	if(py == 0) return 1;
	if(py % 2 == 0) return mypow((px * px), py / 2);
	else return (px * mypow(px, py - 1));
}
int main() {
    // your code goes here
    ll i,j,l,n,k,kt,ans=0,mt,m,mb;
    ll co[10][10]={0};
    cin >> n;
    if(n<10) k=1;
    else if(n<100) k=2;
    else if(n<1000) k=3;
    else if(n<10000) k=4;
    else if(n<100000) k=5;
    else k=6;
    kt=mypow(10,k-1);
    m=n; mt=(m-m%kt)/kt;
  if(k==1){
    cout << n*n << endl;
    return 0;
  }
    for(i=1;i<=min(9ll,n);i++) co[i][i]=1;
    for(i=2;i<k;i++){
        for(j=1;j<=9;j++){
            for(l=1;l<=9;l++){
                co[j][l]+=mypow(10,i-2);
            }
        }
    }
    for(i=1;i<mt;i++){
        for(j=1;j<=9;j++){
            co[i][j]+=mypow(10,k-2);
        }
    }
    mb=n%10; m=(m-mt*kt-mb)/10;
    for(i=1;i<=mb;i++) co[mt][i]+=(m+1);
    for(i=mb+1;i<=9;i++) co[mt][i]+=m; 
    for(i=1;i<=9;i++){
        for(j=1;j<=9;j++){
            ans+=co[i][j]*co[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 51
using namespace std;
typedef long long ll;
int n,m;
int x[N],y[N],z[N];
int X[N],Y[N],Z[N];
int s[N],t[N],u[N];
int S[N],T[N],U[N];
int xd[201],yd[201],zd[201];


void compress(int a[51],int A[51],int b[51],int B[51],int c[201]){
  vector <int> v;
  for(int i=0;i<n;i++)v.push_back(a[i]),v.push_back(A[i]);
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  for(int i=0;i<v.size();i++) c[i]=v[i];
  for(int i=0;i<n;i++){
    b[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
    B[i]=lower_bound(v.begin(),v.end(),A[i])-v.begin();
  }
}

ll calc(){
  ll res=0;
  for(int i=0;i<101;i++) //x
    for(int j=0;j<101;j++)//y
      for(int k=0;k<101;k++){//z
	int cnt=0;
	for(int l=0;l<n;l++)cnt+=((s[l]<=i&&i<S[l])&&(t[l]<=j&&j<T[l])&&(u[l]<=k&&k<U[l]));
	if(cnt<m)continue;
	ll a=xd[i+1]-xd[i],b=yd[j+1]-yd[j],c=zd[k+1]-zd[k];
	res+=a*b*c;
      }
  return res;
}

int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>z[i]>>X[i]>>Y[i]>>Z[i];
  compress(x,X,s,S,xd),compress(y,Y,t,T,yd),compress(z,Z,u,U,zd);
  cout << calc()<<endl;  
  return 0;
}

Measured memory_bytes: 1220
n = int(input())
nstr = str(n)
score = 0
ln = len(nstr)
lnfor = ln // 2

for i in range(lnfor):
  score += 9 * 100 ** i
if ln % 2 == 1:
  score += n - 10 ** (ln - 1) + 1
print(score)

Measured memory_bytes: 3064
#include<stdio.h>
#define MOD 1000000007

int n,a[100001],i,j,k,count[100000];

long long ans, fac[300002];

long long inv(long long a){
	long long E = MOD - 2;
	long long P = 1, S = a;
	while(E>0){
		if(E%2==1){P = (P*S) % MOD;}
		S = (S*S) % MOD;
		E = E / 2;
	}
	return P;
}

long long sub(long long a1, long long a2 ){
	return (MOD + a1-a2) % MOD;
}
long long mult(long long a1, long long a2 ){
	return (a1 * a2) % MOD;
}

long long comb(int a1, int a2){
	if(a1<a2){
		return 0;
	}else{
		return mult(fac[a1] ,inv(mult(fac[a2] , fac[a1-a2])));
	}
}

int main(void){

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

	for(i=0;i<n;i++){
		count[i] = -1;
	}

	for(i=0;i<n+1;i++){
		if(count[a[i]-1]==-1){
				count[a[i]-1] = i;
		}else{
			j = count[a[i]-1];
			k = i;
		}
	}

	fac[0] = 1;
	for(i=1;i<300001;i++){
		fac[i] = mult(i,fac[i-1]);
	}

	for(i=1;i<n+2;i++){
		printf("%lld\n", sub(comb(n+1,i), comb(n+j-k,i-1)));
	}

}

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

int main(void){
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> hint(n,vector<pair<int,int>>());
    for(int i=0;i<n;i++){
        int hintnum;
        cin >> hintnum;
        for(int j=0;j<hintnum;j++){
            int x,y;
            cin >> x >> y;
            hint[i].push_back(make_pair(x-1,y));
        }
    }

    int maxperson = 0;
    for(int i=0;i<(1<<n);i++){
        bitset<15> bit(i);
        vector<int> charactor(n,-1);
        int bitnum=0;

        bool good = true;
        for(int j=0;j<n;j++){
            if(bit.test(j) && good){
                bitnum++;
                for(int k=0;k<hint[j].size();k++){
                    if(bit.test(hint[j][k].first)==0 && hint[j][k].second==1) good = false;
                    if(bit.test(hint[j][k].first)==1 && hint[j][k].second==0) good = false;
                }
            }
        }


        if(good){
            maxperson = max(maxperson,bitnum);
            //cout << bit << endl;
        }

    }
    cout << maxperson << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>

int main(){
  int H, W;
  scanf("%d", &H);
  scanf("%d", &W);
  std::vector<std::vector<int > > a(H+4, std::vector<int > (W+4, 0));
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      scanf("%d", &a[i][j]);
    }
  }
  //printf("=======\n");
  std::queue<int > queue;
  for (int i=0; i<H; i++){
    if (i%2==0){
      for (int j=0; j<W; j++){
        //printf("i=%d, j=%d\n", i,j);
        if (a[i][j]%2==0 || (i==H-1&&j==W-1)){
          continue;
        } else {
          if (j!=W-1){
            //            queue.push("%d, %d, %d, %d\n",i,j,i,j+1);
            queue.push(i);
            queue.push(j);
            queue.push(i);
            queue.push(j+1);
            a[i][j+1]++;
          } else {
            //            queue.push("%d, %d, %d, %d\n",i,j,i+1,j);
            queue.push(i);
            queue.push(j);
            queue.push(i+1);
            queue.push(j);
            a[i+1][j]++;
          }
        }
      }
    } else {
      for (int j=W-1; j>=0; j--){
        if (a[i][j]%2==0 || (i==H-1&&j==0)){
          continue;
        } else {
          if (j!=0){
            //            queue.push("%d, %d, %d, %d\n",i,j,i,j-1);
            queue.push(i);
            queue.push(j);
            queue.push(i);
            queue.push(j-1);
            a[i][j-1]++;
          } else {
            //queue.push("%d, %d, %d, %d\n",i,j,i+1,j);
            queue.push(i);
            queue.push(j);
            queue.push(i+1);
            queue.push(j);
            a[i+1][j]++;
          }
        }
      }
    }
  }
  printf("%lu\n", queue.size()/4);
  while(queue.size()){
    int a1 = queue.front();
    queue.pop();
    int a2 = queue.front();
    queue.pop();
    int a3 = queue.front();
    queue.pop();
    int a4 = queue.front();
    queue.pop();
    printf("%d %d %d %d\n", a1+1, a2+1, a3+1, a4+1);
  }
  return 0;
}


Measured memory_bytes: 5120
import math

n=int(input())

n_lst=[]
x_lst=[]
for i in range(1,50000):
    n_lst.append(i)
    x_lst.append(math.floor(i*1.08))

if n in x_lst:
    print(n_lst[x_lst.index(n)])
else:
    print(':(')


Measured memory_bytes: 7100
N, K, Q = map(int, input().split())

lose_point = Q - K

ls = [0 for i in range(N)]

for i in range(Q):
    A = int(input())
    ls[A - 1] += 1

for i in range(N):
    if ls[i] <= lose_point:
        print("No")
    else:
        print("Yes")

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

using namespace std;

char s2[100000+1], s3[100000+1];
int main(){
	string s;
	cin >> s;
	
	for(int i=0;i<s.size();++i){
		if(i % 2){
			s2[i] = 0 + '0';
			s3[i] = 1 + '0';
		}else{
			s2[i] = 1 + '0';
			s3[i] = 0 + '0';
		}
	}
	s2[s.size()+1] = '\0';
	s3[s.size()+1] = '\0';

	int s2_diff = 0, s3_diff = 0;
	for(int i=0;i<s.size();++i){
		if( s[i] != s2[i] ){
			s2_diff++;
		}
		if( s[i] != s3[i] ){
			s3_diff++;
		}
	}

	if ( s2_diff < s3_diff ){
		cout << s2_diff << endl;
	}else{
		cout << s3_diff << endl;
	}
	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 N = sc.nextInt();

    int[] kitayo = new int[N];
    
    for (int i=0;i<N;i++){
    	int number = sc.nextInt();
        kitayo[number-1] = i+1;
    }
    
    for (int j=0; j<N; j++){
     	System.out.println(kitayo[j]);
 	}
  }
}

Measured memory_bytes: 55532
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 200100
 
using namespace std;
long long mod=1000000000;
struct point
{
	long long x,y;
}a[2*maxn];
long long xmu(point p1,point p2,point p0)
{
	return abs((p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y));
}
int main()
{
	long long T,O=0,I=1;
	scanf("%lld",&T);
	if(T%mod==0)
	{
		printf("0 0 %lld %lld %lld %lld\n",mod,O,O,T/mod);
	}
	else
	{
		long long o=(T/mod+1)*mod-T;
		printf("0 0 %lld %lld %lld %lld\n",mod,I,o,T/mod+1);
	}
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner src = new Scanner(System.in);
		
		int n=Integer.parseInt(src.next());

		List<Contents> list = new ArrayList<>();

		for (int i=0; i<n; i++) {
			int value = Integer.parseInt(src.next());
			int weight = Integer.parseInt(src.next());
			char type = src.next().charAt(0);
			long time = Long.parseLong(src.next());
			String name = src.next();
			
			list.add(new Contents(value, weight, type, time, name));
		}

		list.sort(Comparator.comparingInt(Contents :: getX)
				.thenComparingInt(Contents :: getY)
				.thenComparing(Contents :: getX2)
				.thenComparingLong(Contents :: getZ)
				.thenComparing(Contents :: getY2));

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

			System.out.println(list.get(i).x + " " + list.get(i).y + " " + list.get(i).x2 + " " + list.get(i).z + " " + list.get(i).y2);

		}

	}
}

//各情報を返す
class Contents{

	int x, y;
	long z;
	char x2;
	String y2;

	Contents(int a, int b, char c, long d, String e){

		x = a;
		y = b;
		z = d;
		x2 = c;
		y2 = e;

	}

	int getX() {
		return x;
	}

	int getY() {
		return y;
	}
	
	long getZ() {
		return z;
	}
	
	char getX2() {
		return x2;
	}
	
	String getY2() {
		return y2;
	}
}



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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

bool prime[1000000];
vector<int> v;

void is_prime() {
    memset(prime, 0, sizeof(prime));
    repl(i, 2, 1000000) {
        if (!prime[i]) {
            v.pb(i);
            for(int j = i; j < 1000000; j += i) prime[j] = true;
        }
    }
}

int main(){
    cin.sync_with_stdio(false);
    int n, p;
    is_prime();
    while(cin >> n >> p, n > -1) {
        int id = lower_bound(all(v), n) - v.begin();
        if (v[id] == n) id++;
        vector<int> wa;
        rep(i, p)repl(j, i, p) {
            wa.pb(v[id + i] + v[id + j]);
        }
        sort(all(wa));
        cout << wa[p - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 4324
public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		int n = s.nextInt();
		int a[] = new int[n];
		int max[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
			max[i]=a[i];
		}
		java.util.Arrays.sort(max);
		int top = max[max.length-1];
		int second = max[max.length-2];
		for(int i=0;i<a.length;i++) {
			System.out.println((a[i]!=top)?top:second);
		}
	}
}


Measured memory_bytes: 93956
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] set1 = line2.split(" ");
		int[] set = new int[n];
		long sum = 0;

		for (int i = 0; i < n; i++) {
			set[i] = Integer.parseInt(set1[i]);
			sum += set[i];
		}

		Arrays.sort(set);

		System.out.print(set[0]);
		System.out.print(" ");
		System.out.print(set[n-1]);
		System.out.print(" ");
		System.out.println(sum);
		
	}

}

Measured memory_bytes: 31488
// https://atcoder.jp/contests/abc042/tasks/arc058_b
#include <bits/stdc++.h>
const int MOD = 1e9 + 7;

template <int N, typename T, T M> struct factorial_mod {
    T mod[N + 1];
    T inv_mod[N + 1];

    constexpr factorial_mod() : mod(), inv_mod() {
        mod[0] = 1;
        for (int i = 0; i < N; ++i) {
            mod[i + 1] = (mod[i] * (i + 1)) % M;
        }
        inv_mod[N] = power(mod[N], M - 2);
        for (int i = N - 1; i >= 0; --i) {
            inv_mod[i] = (inv_mod[i + 1] * (i + 1)) % M;
        }
    }

    constexpr T power(T a, T b) {
        T r = 1;
        while (b > 0) {
            if ((b & 1) != 0)
                r = (r * a) % M;
            a = (a * a) % M;
            b >>= 1;
        }
        return r;
    }

    constexpr T comb(T n, T r) {
        return (((mod[n] * inv_mod[r]) % M) * inv_mod[n - r]) % M;
    }
};
factorial_mod<2000000, long long, MOD> facmod;

int main() {
    using namespace std;
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long H, W, A, B, ans = 0;
    cin >> H >> W >> A >> B;
    for (int i = 0; i < H - A; i++) {
        ans += facmod.comb(B - 1 + i, B - 1) *
               facmod.comb(H - i - 1 + W - B - 1, W - B - 1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

H,W,K=mint()
s=[input() for _ in range(H)]
res=[[0]*W for _ in range(H)]
ans=1
index=[]
for k in range(H):
    index.append(k)
    if s[k].count('#')==0:
        continue
    tmp=True
    for j in range(W):
        if s[k][j]=='#':
            K-=1
            if tmp:
                tmp=False
            else:
                ans+=1
        for i in index:
            res[i][j]=ans
    ans+=1
    index=[]
    if K==0:
        for i in range(k+1,H):
            for j in range(W):
                res[i][j]=res[k][j]
        break
for r in res:
    lprint(r,' ')
    print('')

Measured memory_bytes: 77244
import java.util.*;

class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

       if((a == b && a != c) || (a == c && a != b) || (b == c && b != a)){
           System.out.println("Yes");
       } else {
           System.out.println("No");
       }
    }
}

Measured memory_bytes: 23508
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    vector<int>v(101, 0);
    int mx = 0;
    for(int i;cin>>i;){
        v[i]++;
        mx = max(mx, v[i]);
    }
    for(int i = 1; i <= 100; i++){
        if(v[i] == mx)cout << i << endl;
    }

    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

ll dp[1010][1010];
void solve(long long H, long long W, std::vector<std::vector<char>> a)
{
}

int main()
{
    long long H;
    scanf("%lld", &H);
    long long W;
    scanf("%lld", &W);
    char a[1010][1010];
    for (int i = 0; i < H; i++)
    {
        string str;
        cin >> str;

        for (int j = 0; j < W; j++)
        {
            a[i][j] = str[j];
        }
    }
    dp[0][0] = 1;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (i != 0)
            {
                if (a[i][j] != '#')
                {
                    dp[i][j] += dp[i - 1][j];
                    dp[i][j] %= MOD;
                }
            }
            if (j != 0)
            {
                if (a[i][j] != '#')
                {
                    dp[i][j] += dp[i][j - 1];
                    dp[i][j] %= MOD;
                }
            }
        }
    }

    cout << dp[H - 1][W - 1] << endl;
    return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a,b,c[200000],ans;
int main(void){
    cin>>n>>m;
    vector<vector<ll>>v(n);
    for(int i=0;i<m;i++){
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    c[0]=1;
    stack<ll> sta;
    sta.push(0);
    while(!sta.empty()){
        ll p=sta.top();
        sta.pop();
        for(auto x:v[p]){
            if(c[x]==0){
                if(c[p]==1)c[x]=-1;
                else c[x]=1;
                sta.push(x);
            }
            else{
                if(c[x]*c[p]!=-1){cout<<n*(n-1)/2-m<<endl;return 0;}
            }
        }
    }
    for(int i=0;i<n;i++){
        if(c[i]==1)ans++;
    }
    cout<<ans*(n-ans)-m<<endl;
}


Measured memory_bytes: 7168
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>

using namespace std;

template<typename T, typename S>
istream& operator >> (istream& is, pair<T, S>& p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

int dfs(int v, int k, vector<vector<int>>& e, int& ans) {
    int max_d = 0;
    for (auto u : e[v]) {
        int d = dfs(u, k, e, ans);
        // cout << v << " " << u << " " << d << " " << k << endl;
        if (v != 0 && d >= k) ++ans;
        else max_d = max(max_d, d);
    }
    return max_d + 1;
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    cin >> a;
    for (auto& x : a) x--;

    int ans = 0;
    if (a[0] != 0) {
        a[0] = 0;
        ++ans;
    }

    vector<vector<int>> e(n);
    for (int i = 1; i < n; ++i) {
        e[a[i]].push_back(i);
    }
    dfs(0, k, e, ans);
    cout << ans << endl;
}


Measured memory_bytes: 16916
#include <stdio.h>
#include <string.h>


int main()
{
	int i, j, len1 = 0, len2 = 0, ans = 0;
	char s[200], p[100];

	
	scanf("%s", s);
	scanf("%s", p);
	len1 = strlen(s);
	for (i = 0; i < len1; i++) {
		s[len1 + i] = s[i];
	}
	len2 = strlen(p);

	for (i = 0; i < len1; i++) {
		if (s[i] == p[0]) {
			for (j = 0; j < len2; j++) {
				if (s[i + j] != p[j]) {
					ans = 0;
					break;
				}
				ans = 1;
			}
		}
		if (ans == 1) {
			break;
		}
	}

	if (ans == 0) {
		printf("No\n");
	}
	else printf("Yes\n");

    return 0;
}

Measured memory_bytes: 524
#include <numeric>
#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <queue>


using namespace std;

#define ll long long int
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repp(i, n) for(ll i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const ll MOD = 1e9 + 7;
vi alphabet = { 'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z' };


ll func(ll m){
    ll s = m / 10;
    ll count5 = s;
    while (s > 1) {
        count5 += s / 5;
        s = s / 5;
    }
    return count5;
}

int main() {
    ll n;
    cin >> n;
    ll m = n;
    ll count2 = 0;
    ll count5 = 0;
    ll count10 = 0;
    if (n % 2 == 0 && n > 0) {
        while (n % 2 == 0) {
            count2 += n / 2;
            n = n / 2;
        }
    }
    if (m % 10 == 0 || m % 10 == 2 || m % 10 == 4 || m % 10 == 6 || m % 10 == 8) {
        count5 += func(m);
    }
    else if (m == 1 || m == 3) {
        count5 = 0;
    }
    else {
        while (m % 5 != 0) m -= 2;
        ll k = m;
        ll l = (m - 5) / 10;
        count5 += l + 1;
        m = m / 5;
        while (m > 1) {
            count5 += m / 5;
            m = m / 5;
        }
        count5 -= func(k);
    }
    cout << min(count2, count5) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MAX 10000

int n;
vector<pair<int,int>> adj[MAX];
int d[MAX],p[MAX];

void dijkstra(int start){
  priority_queue<pair<int,int>> pq;
  for(int i=0;i<n;i++){
    d[i]=INF;;
    p[i]=0;
  }
  d[start]=0;
  pq.push(make_pair(0,0));
  while(!pq.empty()){
    pair<int,int> f=pq.top();pq.pop();
    int u=f.second;
    p[u]=1;
    if(d[u]<f.first*(-1)) continue;

    for(int i=0;i<adj[u].size();i++){
      int v=adj[u][i].first;
      if(p[v]) continue;
      if(d[v]>d[u]+adj[u][i].second){
	d[v]=d[u]+adj[u][i].second;
	pq.push(make_pair(d[v]*(-1),v));
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<d[i]<<endl;
  }
}


  

    
int main(){
  int u,k,v,c;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      adj[u].push_back(make_pair(v,c));
    }
  }
  dijkstra(0);
  return 0;
}
  



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

int main() {
  int N, M, L, R, LM=0, RM=100000;
  cin >> N >> M;
  vector<int> V(N);
  rep(i, M){
    cin >> L >> R;
    LM=max(L, LM);
    RM=min(R, RM);
  }
  cout << max(0, RM-LM+1) << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> vec(3);
  for(int i=0;i<vec.size();i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  if(vec.at(0)==vec.at(1)){
    cout<<vec.at(2)<<endl;
  }
  else{
    cout<<vec.at(0)<<endl;
  }
  
}

Measured memory_bytes: 256
s = input()
k = int(input())

subs = []
# sからi文字取り出す時の、文字列の組み合わせを全列挙
for i in range(1, 6):
	for j in range(len(s)-i+1):
		subs.append(s[j:j+i])

subs = list(set(subs))
subs.sort()
print(subs[k-1])

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

int main() {
	int n,k;
	cin>>n>>k;
	vector<bool> dp(k+1,false);
	vector<int> moves(n);
	for(int i=0;i<n;i++) {
	    cin>>moves[i];
	}
	for(int i=1;i<=k;i++) {
	    for(auto m : moves) {
	        if(i-m>=0 && !dp[i-m]) {
	            dp[i] = true;
	            break;
	        }
	    }
	}
	if(dp[k]) {
	    cout<<"First";
	}
	else {
	    cout<<"Second";
	}
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define maxn 100001
#define maxa 1000005
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second
#define rep(i, a, n) for(ll i = a; i < n; i++)
#define repr(i, a, n) for(ll i = n-1; i >= a; i--)
#define meme(a, b) memset(a, b, sizeof(a))

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}
ll ceil(ll a, ll b){if((a%b) != 0) return a/b+1; return a/b;}
void flaged(bool flag){
    if(flag) cout << "YES\n";
    else cout << "NO\n";
}
ll power(ll a, ll b = MOD-2){
    if(b == 0) return 1;
    ll r = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2 == 1) r = (r*a)%MOD;
    return r;
}

void solve(){
    ll x, y; cin >> x;
    ll f = 0;
    map<ll, ll> mp;
    for(ll i = 0; i < x; i++){
        cin >> y;
        if(mp[y]) f = 1;
        else mp[y] = 1;
    }
    flaged(1-f);
 }

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


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, a, b) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << '\n';

struct Hash2 {
  int n, p1, p2, m1, m2;
  vector<int> H[4];
  int mul(int x, int y, int m) { return 1LL * x * y % m; }
  int add(int x, int y, int m) {
    int t = x + y;
    return t < 0 ? t + m : t < m ? t : t - m;
  }
  template <typename T> Hash2(const T& S, int p1 = 131, int p2 = 1313, int m1 = 1e9 + 7, int m2 = 1e9 + 9)
      : n(S.size()), p1(p1), p2(p2), m1(m1), m2(m2) {
    for (int i = 0; i < 4; i++) H[i].assign(n + 1, 0ULL);
    H[2][0] = H[3][0] = 1;
    for (int i = 1; i <= n; i++)
      H[2][i] = mul(H[2][i - 1], p1, m1), H[3][i] = mul(H[3][i - 1], p2, m2);
    for (int i = n - 1; i >= 0; i--) {
      H[0][i] = add(mul(H[0][i + 1], p1, m1), S[i], m1);
      H[1][i] = add(mul(H[1][i + 1], p2, m2), S[i], m2);
    }
  }
  pair<int, int> get(int l, int r) {
    return {add(H[0][l], -mul(H[0][r], H[2][r - l], m1), m1),
            add(H[1][l], -mul(H[1][r], H[3][r - l], m2), m2)};
  }
};

int n;
string s;
Hash2 hs(string(""));

bool check(int len) {
  set<pair<int, int>> se;
  for (int i = len; i + len <= n; ++i) {
    se.insert(hs.get(i - len, i));
    if (se.count(hs.get(i, i + len))) return true;
  }
  return false;
}

int main() {
  cin >> n >> s;
  hs = Hash2(s); 
  int l = 0, r = n + 1;
  while (l + 1 < r) {
    int m = (l + r) >> 1;
    if (check(m)) l = m;
    else r = m;
  }
  cout << l << endl;
}


Measured memory_bytes: 640
/*
*/
import java.io.*;

class Main {
	static int map[];
	static int mapb[];
	
	public static void main(String[] args) {
		try {
			run();
		} catch(IOException e) {
			System.out.println(e);
		}
	}
	private static void run() throws IOException{
		final int MAX = 1000000;
		int n;
		int instant;
		map = new int[MAX+1];
		mapb = new int[MAX+1];
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		for(int i=1;i<=MAX;i++) {
			//if(i%100000==0)System.out.print(".");
			map[i] = f(i);
			mapb[i] = fb(i);
		}
		//System.out.println("");
		
		while(true) {
			n = Integer.parseInt(in.readLine());
			if(n==0) break;
			
			System.out.println(map[n] + " " + mapb[n]);
		}
		System.exit(0);
	}
	
	private static int f(int n) {
		int instant;
		int min=1000000;
		int tk;
		
		if(n<=0) return 0;
		
		for(int i=n;i>0;i--) {
			if(i>1000) {
				i = 1000;
				continue;
			}
			
			tk = i*(i+1)*(i+2)/6;
			
			if(n-tk < 0) continue;
			
			if(map[n-tk] > 0) {
				if(min > map[n-tk]) {
					min = map[n-tk];
				}
			}
			else if(min > (instant=f(n-tk))) {
				min = instant;
			}
		}
		
		return 1+min;
	}
	
	private static int fb(int n) {
		int instant;
		int min=1000000;
		int tk;
		
		if(n<=0) return 0;
		
		for(int i=n;i>0;i--) {
			if(i>1000) {
				i = 1000;
				continue;
			}
			
			tk = i*(i+1)*(i+2)/6;
			
			if(n-tk < 0 || tk%2==0) continue;
			
			if(map[n-tk] > 0) {
				if(min > mapb[n-tk]) {
					min = mapb[n-tk];
				}
			}
			else if(min > (instant=f(n-tk))) {
				min = instant;
			}
		}
			
			return 1+min;
	}
}

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

using namespace std;

struct expand_type {
    template <typename... T>
    expand_type (T&&...) {}
};
template <typename... ArgTypes>
void print (ArgTypes... args) {
    expand_type {0, (cerr << args << ", ", 0)...};
    cerr << "\b\b \n";
}
#define printv(x) cerr << "["; for(auto i : (x)) cerr << i << ", "; cerr << "\b\b]\n";
#define PI 3.14159265358979323846

typedef unsigned long long ull;
typedef long double ld;


void solve () {
    ld a, b, h, m;
    cin >> a >> b >> h >> m;
    ld th = 2 * PI * (h / 12.0 + m / 60.0 / 12.0 - m / 60.0);
    ld res = (a*a + b*b) - 2*a*b*cos(th);
    cout << setprecision (20) << sqrt(res) << endl;
}

int main () {
    std::ios::sync_with_stdio (false);
    cin.tie (nullptr);
    cout.tie (nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 4120
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class A
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ABC = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var dict = new Dictionary<int, int>();
            var is5 = 0;
            var is7 = 0;
            foreach (var x in ABC)
            {
                if (x == 5) is5++;
                if (x == 7) is7++;
            }
            Console.WriteLine(is5 == 2 && is7 == 1 ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 27944
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n],ans=0;
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }
    ll num,index;
    bool maki=1;
    while(maki){
    	maki=0;
    	for(int i=0;i<n;i++){
    	    if(a[i]>=n){
    	    	num=a[i]/n;
    	    	index=i;
    	    	a[i]%=n;
    	    	for(int i=0;i<n;i++){
        	        if(i==index)continue;
        	        a[i]+=num;
                }
                ans+=num;
    	    }
        }
        for(int i=0;i<n;i++)if(a[i]>=n)maki=true;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
	string A, B;
	cin >> A >> B;
	if(A.length() > B.length()) cout << "GREATER" << endl;
	else if(A.length() < B.length()) cout << "LESS" << endl;
	else{
		for(int i = 0; i < A.length(); i++){
			if(A[i] > B[i]){
				cout << "GREATER" << endl;
				break;
			}else if(A[i] < B[i]){
				cout << "LESS" << endl;
				break;
			}
			if(i == A.length() - 1){
				cout << "EQUAL" << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
int N, K;
const ll P = 1e9+7;
ll fact[100000];

// Extended Euclid's greatest common divisor algorithm
// Find (x, y, g)
// where $a*x + b*y = g$ and g is the greatest common divisor of (a, b)
ll ext_gcd(ll a, ll b, ll &x, ll &y){
	if(b == 0){
		x = 1;
		y = 0;
		return a;
	}
	ll nx, ny;
	ll g = ext_gcd(b, a%b, nx, ny);
	x = ny;
	y = nx - a/b *ny;
	return g;
}

// Modular inverse of x given modulo p, y
// x*y = 1 mod p
// <=> x*y + z*p = 1
ll inv_mod(ll x, ll p){
	ll y,z;
	ext_gcd(x, p, y, z);
	return y>=0 ? y : p+(y%p);
}


// Modular factorial of n, also counting p's appearance e
// n! = a * p^e
// return: a % p
// n! = n * (n-1) * ... * (k*p+1) *
//      (k*p) * (k*p-1) * ... ((k-1)*p+1) *
//      ...
//      p * (p-1) * ... * 2 * 1   (k = floor(n/p))
//    = (n%p) * ... * 1 *
//      (k*p) * (p-1) * ... * 1 *
//      p * (p-1) * ... * 1       (mod p, preserving p's multiples)
//    = (n%p)! * p^k * k! * (p-1)^k
//    = (n%p)! * p^k * k! * (p-1)^(k%2)
//
// From the facts:
//   (p-1)! = p-1 (mod p) (c.f. Willson's theorem)
//   (p-2)**2 = 1 (mod p)
ll fact_mod(ll n, ll p, ll &e){
	if(n == 0){
		e = 0;
		return 1;
	}

	ll na = fact_mod(n/p, p, e);

	e += n/p;
	ll a = na * fact[n%p] % p;

	if((n/p)%2) a = a * (p-1)%p;
	return a;
}


// Modular combination (n, m) given module p
// (n, m) = n!/(n-m)!m!
//        = (a_n * p^(e_n)) / ((a_{n-m} * p^(e_{n-m}) * (a_m * p^e_m))
//        = a_n / (a_{n-m} * a_m) * p^(e_n - e_{n-m} - e_m)
ll comb_mod(ll n, ll m, ll p){
	ll e1,e2,e3;
	ll a1 = fact_mod(n, p, e1);
	ll a2 = fact_mod(m, p, e2);
	ll a3 = fact_mod(n-m, p, e3);

	if(e1 > e2+e3) return 0;
	else return a1*inv_mod(a2*a3%p, p)%p;
}

int main(){
	cin >> N >> K;
	fact[0] = fact[1] = 1;
	for(int i=2; i<100000; i++) fact[i] = fact[i-1]*i%P;

	for(int i=1; i<=K; i++){
	//int i=1060; {
		if(N-K+1 < i) {
			cout << 0 << endl;
		} else {
		//cout << comb_mod(K-1, i-1, P) << endl;
		//cout << comb_mod(N-K+1, i, P) << endl;
			cout << comb_mod(K-1, i-1, P) * comb_mod(N-K+1, i, P) % P << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 1024
/**
*   @Author : MeGA
*   @InitTime :02/08/20 17:52:27
*   @Idea : 
*
*
*
*
*
*
*
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
  // freopen("out","w",stdout);
#endif

     ios::sync_with_stdio(false);
     cin.tie(0);
     int r;
     cin>>r;
     cout<<(r*r)*3<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int main()
{
//	c_p_c();
	int a, b;
	cin >> a >> b;
	int p = a * b;
	if (p & 1)
		cout << "Odd";
	else
		cout << "Even";
	//cout << ((a * b) & 1) ? "Odd" : "Even";
}

Measured memory_bytes: 256
XY = input()
xy = list(map(int, XY.split()))

x = xy[0]
y = xy[1]

exist = False
for i in range(x + 1):
  if 2 * i + 4 * (x - i) == y:
    exist = True
    break
    
if exist:
  print("Yes")
else:
  print("No")

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

#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

//プロトタイプ宣言
void faster(void);
ll gcd(auto , auto);
ll get_digent(auto);
ll POW(auto , auto);



int main(){
  faster();
  ll n,ans=0;
  cin >> n;
  vl v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(),v.end());
  for(ll fir=n-1;fir>=0;fir--){
    for(ll sec=fir-1;sec>=0;sec--){
      auto itr = lower_bound(v.begin(),v.end(),v[fir]+v[sec]);
      ll dis = distance(itr,v.end());
      ans += n - fir - 1 - dis;
    }
  }
  cout << ans << endl;
}





























//以下、ライブラリ

//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
ll gcd(auto a, auto b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
ll get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
ll POW(auto x,auto y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using ll = long long int;
using namespace std;

#define FOR(i,N) for(int i=0;i<N;i++)
#define pb(x) push_back(x)

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

    if (N % 2 == 1){
        cout << "No";
        return 0;
    }
    FOR(i, N / 2) {
        if (s[i] != s[i + N / 2]) { cout << "No"; return 0; }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    int ans = (n / 500) * 1000;
    n %= 500;
    cout << ans + n / 5 * 5 << endl;
}


Measured memory_bytes: 256