akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define isEven(t) t % 2 == 0

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

	string a, b;
	cin>>a>>b;
	int num = stoi(a + b);

	bool flg = false;

	for (int i = 0; i <= num; i++) {
		if(i*i==num){
			flg = true;
		}
	}

	yn(flg);

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#ifdef _MSC_VER
#include <conio.h>
#else
#define getch()
#include <climits>
#define _CRT_INT_MAX INT_MAX
#endif

int mysqrt(long long int x){
	int a=0,c=0,y=0,i=0,t=x;
	while(t>>=1){
		++i;
	}
	for(i+=i&1; i>=0; i-=2){
		c=(y<<1|1)<=x>>i;
		a=a<<1|c;
		y=y<<1|c;
		x-=c * y<<i;
		/* if(c){
		x -= y << i;
		} */
		y+=c;
	}
	return a;
}

int Digits(long long int A){
	return log10(A)+1;
}

inline int Min(int A,int B){
	return A<=B?A:B;
}

inline long long int Max(int A,int B){
	return A>=B?A:B;
}

int main(){
	long long int N=0;
	int Ans=0;
	scanf(" %lld",&N);
	long long int Sqrt=sqrt(N);
	bool TickFlag=false;
	int Tick=1;
	if(N%2!=0)TickFlag=true;
	for(long long int i=Sqrt;;i-=Tick){
		if(TickFlag==true&&Tick==1&&i%2!=0){
			Tick=2;
		}
		if(N%i==0){
			Ans=Max(Digits(i),Digits(N/i));
			break;
		}
	}
	printf("%d\n",Ans);
	getch();
}

Measured memory_bytes: 128
#include <cmath>
#include <iostream>
#include <string>

#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)

// five-five-everywhere.cpp ---
// author: Seong Yong-ju <sei40kr@gmail.com>

using namespace std;

int n;
bool isprime[55556] = {false, false};

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

  fill(&isprime[2], isprime + 55556, true);

  cin >> n;

  FOR(i, 2, floor(sqrt(55556) + 1)) {
    if (!isprime[i]) {
      continue;
    }
    for (int j = i * 2; j < 55556; j += i) {
      isprime[j] = false;
    }
  }

  int cnt = 0;
  FOR(i, 2, 55556) {
    if (isprime[i] && i % 5 == 1) {
      cout << i;

      if (n <= ++cnt) {
        cout << endl;
        break;
      } else {
        cout << ' ';
      }
    }
  }
}


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

// range MAXIMUM query
class RMQ {
  private:
    static const int MAX_N = 100000*2;
    int n;
    // score, -team_id
    pii dat[2 * MAX_N - 1];
    pii rec(int a, int b, int k, int l, int r) {
        if (b <= l || r <= a) {
            return {0, 0};
        }

        if (a <= l && r <= b) {
            return dat[k];
        } else {
            pii rl = rec(a, b, 2 * k + 1, l, (l + r) / 2);
            pii rr = rec(a, b, 2 * k + 2, (l + r) / 2, r);
            return max(rl, rr);
        }
    }

  public:
    void init(int n_) {
        n = 1;
        while (n < n_) n *= 2;

        for (int i = 0; i < 2 * n - 1; i++) {
            dat[i] = {0, 0};
        }
    }

    void update(int k, int a) {
        int reaf = k + n - 1;
        dat[reaf] = {dat[reaf].first + a, -k};
        while (reaf > 0) {
            reaf = (reaf - 1) / 2;
            dat[reaf] = max(dat[reaf * 2 + 1], dat[2 * reaf + 2]);
        }
    }

    pii query(int a,int b){
      return rec(a,b+1,0,0,n);
    }
};

int main() {
    int team_n, record_n, end_time;
    cin >> team_n >> record_n >> end_time;

    RMQ r;
    r.init(team_n);
    REP(i, team_n) {
        r.update(i, 0);
    }

    vi top(team_n);
    int btime = 0;
    REP(i, record_n) {
        int team_id, time, point;
        cin >> team_id >> time >> point;
        team_id--;

        pii t = r.query(0, team_n-1);
        top[-t.second] += time - btime;
        btime = time;
//        LOG("--> %d [%d] (%d)\n", t.first, -t.second, time - btime);

        r.update(team_id, point);
    }
    pii t = r.query(0, team_n-1);
    top[-t.second] += end_time - btime;
    cout << (max_element(ALL(top)) - top.begin() + 1) << endl;
}

Measured memory_bytes: 6244
s=input()
t=input()

ans1=0
ans2=0

ss=s*2

for i in range(len(t)):
    a=ss.find(t[i],ans2)
    if a==-1:
        ans=-1
        break
    if a>=len(s):
        ans1+=1
    ans2=a%(len(s))+1
    ans=ans1*len(s)+ans2
print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
    lld n;
    vector<lld> c,s,f;

    cin >> n;
    for(int i = 0; i < n-1; i++)
    {
        lld x,y,z;
        cin >> x >> y >> z;
        c.push_back(x);
        s.push_back(y);
        f.push_back(z);
    }

    vector<lld> time(n);

    for(int i = 0; i < n; i++)
    {
        time[i] = 0;
    }

    for(int i = 0; i < n-1; i++)
    {
        time[i] = c[i] + s[i];
        for(int j = i+1; j < n-1; j++)
        {
            if (time[i] >= s[j])
            {
                lld a = time[i] - s[j];
                time[i] += ceil((double)a / f[j]) * f[j] - a + c[j];
            }else
            {
                time[i] = c[j] + s[j];
            }
        }
    }

    for(int i = 0; i < n; i++)
    {
        cout << time[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())

len_n = len(str(N)) # N <= 10 ^ 5 より len(N) <= 6

count = 0 

if len_n == 1:
  count += N
elif len_n == 2:
  count += 9
elif len_n == 3:
  count += 9
  count += (N - 99)
elif len_n == 4:
  count += 909
elif len_n == 5:
  count += 909
  count += (N - 9999)
elif len_n == 6:
  count += 90909
  
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = 1e12;

LL f(LL b, LL n){
    if(b == 1) return -1;
    LL ret = 0;
    while(n){
        ret += n % b;
        n /= b;
    }
    return ret;
}

int main(){
    LL n, s;
    scanf("%lld%lld", &n, &s);
    LL ans = INF;
    for(LL b = 2; b * b <= n; b++){
        if(f(b, n) == s){
            printf("%lld\n", b);
            return 0;
        }
    }
    if(s > n){
        puts("-1");
        return 0;
    }
    if(n == s){
        printf("%lld\n", n + 1);
        return 0;
    }
    LL d = n - s;
    for(LL i = 1; i * i <= d; i++){
        if(d % i == 0){
            LL b = i + 1;
            if(f(b, n) == s)
                ans = min(ans, b);
            b = d / i + 1;
            if(f(b, n) == s)
                ans = min(ans, b);
        }
    }
    if(ans == INF) ans = -1;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
m = 2019
L, R = list(map(int, input().split()))
if R-L>=m-1:
    result=0
else:
    result = m-1
    for i in range(L%m, R%2019+1):
        for j in range(i+1, R%2019+1):
            if (i*j)%m < result:
                result = (i*j)%m
print(result)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001;
const int NMAX=8;
const int mod = 1000000007;

int main()
{
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  deque<int>d;
  rep(i,n){
    int idx=lower_bound(d.begin(),d.end(),a[i])-d.begin();
    if (idx==0) d.push_front(a[i]);
    else{
      d[idx-1]=a[i];
    }
  }
  cout<<d.size();



}


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

int main(){
	int n;
	int id;
	double height, weight;
	double defferencial;
	double bestBody;
	int ans;
	while(cin >> n, n){
		bestBody = 1000;
		for(int i=0; i< n; i++){
			cin >> id >> height >> weight;
			defferencial = abs(22 - weight / pow(height/100, 2));

			if(defferencial < bestBody){
				bestBody = defferencial;
				ans = id;
			}
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 1228
import math
A,B,H,M = map(int,input().split())
a = H*30 + M*0.5
b = M*6
r = abs(a-b)
if r > 180:
    r = 360-r
if r == 180:
    print(A+B)
    exit()

ans = A**2 + B**2 -2*A*B*math.cos(math.radians(r))
print(math.sqrt(ans))

Measured memory_bytes: 9548
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    L, R, d = map(int, readline().split())

    ans = 0
    for n in range(L, R + 1):
        if n % d == 0:
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61808
//
//  main.cpp
//  Pana2020A
//
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, const char * argv[]) {
    int K;
    cin >> K;
    vector<int>S={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout<<S.at(K-1)<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long y = 100;
    int n = 0;
    while(x>y) {
    	y *=1.01;
    	n++;
    }
    System.out.println(n);
  }
}

Measured memory_bytes: 35712
#include<stdio.h>

int max(int A[],int N)
{
  int max=0;
  for(int i=0;i<N;i++){
    if(max<A[i]){max = A[i];}
  }
  return max;
}
int min(int A[],int N)
{
  int min=999999;
  for(int i=0;i<N;i++){
    if(min>A[i]){min = A[i];}
  }
  return min;
}

int main()
{
  int N,M;
  scanf("%d %d",&N,&M);
  int L[100001],R[100001];
  for(int i=0;i<M;i++){scanf("%d %d",&L[i],&R[i]);}
  
  int ans = min(R,M)-max(L,M)+1;
  if(ans<0){ans = 0;}
  printf("%d",ans);
}

Measured memory_bytes: 2504
N,M,x = [int(x) for x in input().split()]
l = []
und = [0]*M
ans = 10**7
for i in range(N):
    uke = [int(x) for x in input().split()]
    l.append(uke)
#bit全探索
for i in range(2**N):
    und = [0]*(M)
    money = 0
    for j in range(N):
        if ((i >> j)&1):
            money += l[j][0]
            for k in range(M):
                und[k] += l[j][k+1]
    if min(und) >= x:
        ans = min(ans,money)
if ans == 10**7:
    ans = -1
print(ans)

Measured memory_bytes: 9224
#include <iostream>
using namespace std;
int main(){
    int h, n, a;
    cin >> h >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        h -= a;
    }
    if(h <= 0) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a,b,temp;
    while(scanf("%d%d",&a,&b)){
            if(a==0 && b==0)
            break;
            else if(a>b){
        temp=a;
        a=b;
        b=temp;
         printf("%d %d\n",a,b);
            }
         else
        printf("%d %d\n",a,b);
        }

    return 0;
}




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



int main() {
 

  int n;
  cin>>n;

  int cnt4=0,cnt2=0;
  //4の倍数
  //4の倍数出ないが、2の倍数/2
  //の合計がn/2より大きい
  for(int i=0;i<n;i++){
    int wk;
    cin>>wk;
    if(wk%4==0)
      cnt4++;
    else if(wk%2==0)
      cnt2++;
  }

  if(cnt4+cnt2/2>=n/2)
    cout<<"Yes"<<endl;
  else 
    cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{	
	int n,ans=1;
	cin>>n;
	for(int i=2;i*i<=n;i++)
	{
		int k=i*i,t=1;
		while(k<=n)
		{
			t=k;
			k*=i;
		}
		ans=max(ans,t);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
while True:
    five_num = 0
    expo = 1
    x = int(input())
    if x == 0:
        break
    elif x < 10:
        print(0)
    else:
        while x >= 5 ** expo:
            five_num += int((x/(5 ** expo)))
            expo += 1
        print(five_num)


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

int main(){
	ll n;
	cin >> n;
	vector<ll> ans(n);
	rep(i,n){
		ans[i] = i+1;
	}
	rep(i,n){
		if(ans[i]%3 == 0) ans[i] = 0;
		if(ans[i]%5 == 0) ans[i] = 0;
	}
	ll sum = 0;
	rep(i,n) sum += ans[i];
	cout << sum << endl;
}

Measured memory_bytes: 11024
#include<bits/stdc++.h>
#define maxn 100100
using namespace std;
int num=0,n,seg[maxn];
int main(){
	cin >> n;
	for ( int i = 1 ; i <= n ; i++) cin >> seg[i];
	for ( int i = 1 ; i <= n ; i++) {
		if ( seg[i] == i ){
			num ++;
			if( seg[ i+1] ==i +1 ) i++;
		}
	}
	cout << num ;
	return 0;
}

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

int main() {
    int ans=0;
    string s;
    cin>>s;
    for(int i=0; i<4; i++) {
        if(s[i]=='+') ans++;
        if(s[i]=='-') ans--;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long LL;
int Q;
LL a,b;
LL LLsqrt(LL x){
	LL L=0,R=1e9,mid,ans=-1;
	while (L<=R){
		mid=(L+R)>>1;
		if (mid*mid<=x)
			L=mid+1,ans=mid;
		else
			R=mid-1;
	}
	return ans;
}
int main(){
	scanf("%d",&Q);
	while (Q--){
		scanf("%lld%lld",&a,&b);
		if (a>b)
			swap(a,b);
		LL c=a*b-1;
		LL d=LLsqrt(c);
		LL ans=d+d;
		if (a!=b)
			ans--;
		if (d!=0)
			if (d==c/d)
				ans--;
		printf("%lld\n",max(ans,0LL));
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void) {
  int n;
  string s;
  cin >> n;
  while(getline(cin, s)) {
    //cout << o << endl;
    for (int i = 1; i < 26; i += 2) {
      if (i == 13)
        continue;
      REP(j, 26) {
        string t = s;
        REP(k, t.size()) {
          if (t[k] == ' ')
            continue;
          t[k] = (char)('a' + (i * (t[k] - 'a') + j) % 26);
        }
        if (t.find("this") != string::npos || t.find("that") != string::npos) {
          cout << t << endl;
          break;
        }
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3032
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
int n,a,b;
signed main(){
    cin>>n>>a>>b;
    int dis=b-a;
    if(dis%2)puts("Borys");
    else puts("Alice");
    return 0;
}

Measured memory_bytes: 256
from collections import deque

header = input().split(" ")
N = int(header[0])
q = int(header[1])

queue = deque([])

for i in range(N):
    row = input().split(" ")
    queue.append((row[0], int(row[1])))

totalTime = 0

while queue:
    task = queue.popleft()
    name = task[0]
    time = task[1]
    leftTime = time - q
    if leftTime > 0:
        totalTime += q
        queue.append((name, leftTime))
    else:
        totalTime += time
        print(name + " " + str(totalTime))


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

int main(){
    int a, b;
    char op;
    
    while(true){
        cin >> a >> op >> b;
        if (op == '?'){
            break;
        } else if (op == '+'){
            cout << a + b << endl;
        } else if (op == '-'){
            cout << a - b << endl;
        } else if (op == '*'){
            cout << a * b << endl;
        } else if (op == '/'){
            cout << a / b << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a, b, M;
  cin >> a >> b >> M;
  vector<int> as(a);
  vector<int> bs(b);

  vector<int> wa(M);
  vector<int> wb(M);
  vector<int> wc(M);
  int amin = 999999999;
  int bmin = 999999999;
  int xmin = 999999999;
  int tmp;
  for (int i = 0; i < a; i++) {
    cin >> as[i];
    if (amin > as[i]) {
      amin = as[i];
    }
  }
  for (int i = 0; i < b; i++) {
    cin >> bs[i];
    if (bmin > bs[i]) {
      bmin = bs[i];
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> wa[i] >> wb[i] >> wc[i];
    tmp = as[wa[i]-1] + bs[wb[i]-1] - wc[i];
    if (xmin > tmp) {
      xmin = tmp;
    }
  }
  if (xmin < amin +bmin){
    cout<< xmin;
  } else {
    amin += bmin;
    cout << amin;
  }
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)

typedef long long ll;
typedef long long int lli;

int main() {
    int N;
    ll mid, res;
    cin >> N;
    vector<ll> Ai; 
    res = 0;
    for (int i = 0; i < N; i++) {
        ll num;
        cin >> num;
        Ai.push_back(num - i + 1);
        //Ai[i] = Ai[i] - (i + 1);
        //cout << Ai[i] << endl;
    }
    sort(Ai.begin(), Ai.end());
    mid = Ai[N / 2];
    
    for (int i = 0; i < N; i++) {
        res = res + abs(Ai[i] - mid);
    }
    
    //cout << mid << endl;
    cout << res << endl;
	return 0;
}

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

int main(){
    string s1, s2;
    cin >> s1;
    cin >> s2;
    int s1_len, s2_len;
    s1_len = s1.length();
    s2_len = s2.length();

    if(s2_len <= s1_len){
        for(int i = 0; i < s1_len; i++){
            if(s1.substr(i, s2_len) == s2){
                cout << i << "\n";
            }
    }

    }
}



Measured memory_bytes: 3984
//package reedeka;
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int d, n;
		d = sc.nextInt();
		n = sc.nextInt();
		int i;
		int s = 1;
		for(i=0; i<d; i++) s *= 100;
		if(n<=99) {
			System.out.println(s*n);
		}
		else {
			System.out.println(s*101);
		}
	}
}


Measured memory_bytes: 35568
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = myconv(next(),1);
    myout(Math.ceil(N / 2));
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n,k;
	cin>>n>>k;

	vector<pair<lli,lli>> v;
	//各種別で最大のものを探す
	REP(i,0,n){
		lli t,d;
		cin>>t>>d;
		t--;
		v.push_back(make_pair(d,t));
	}
	sort(v.begin(),v.end(),greater<pair<lli,lli>>());

	priority_queue<pair<lli,lli>,vector<pair<lli,lli>>,greater<pair<lli,lli>>> q;
	set<lli> kind;
	vector<lli> kindCnt(n,0);
	lli sum = 0;
	REP(i,0,k){
		q.push(v[i]);
		sum += v[i].first;
		kind.insert(v[i].second);
		kindCnt[v[i].second]++;
	}
	lli ans = sum+(kind.size())*(kind.size());
	lli now = k;
	while(q.size() && now<n){
		lli topKind = q.top().second;
		lli topValue = q.top().first;
		if(DEBUG)cout<<"topKind="<<topKind<<" topValue="<<topValue<<endl;
		q.pop();
		if(kindCnt[topKind]==1)continue;

		sum -= topValue;
		sum += v[now].first;
		kind.insert(v[now].second);
		q.push(v[now]);
		kindCnt[v[now].second]++;
		ans = max((unsigned lli)ans,sum+(lli)(kind.size())*(kind.size()));
		now++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define inf 100000000000000001
#define PI 3.14159265
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

// string to integer stoi() Remember: it takes string not character
// string to long long stol()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
ll n;
ll a[200001];
vector<ll> adj[200001];
bool vis[200001];
ll dp[200001];

void dfs(ll u, vector <ll> &v1){
    for (auto i = adj[u].begin(); i != adj[u].end(); ++i)
    {
        if(!vis[*i]){
            // cout<<*i<<" :: "<<endl;
            ll fg=0;
            ll ori=0;
            ll po=0;
            auto it = lower_bound(v1.begin(), v1.end(), a[*i]);
            if(it==v1.end()){
                fg=1;
                v1.push_back(a[*i]);
            }
            else{
                ll pos = it-v1.begin();
                po=pos;
                ori=v1[pos];
                v1[pos]=a[*i];
            }
            dp[*i]=v1.size();
            vis[*i]=true;
            dfs(*i, v1);
            if(fg==1){
                v1.pop_back();
            }
            else{
                v1[po]=ori;  
            }
        }   
    }
}

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    cin>>n;
    for (int i = 1; i<=n; ++i)
    {
        cin>>a[i];
        vis[i]=false;
        dp[i]=0;
    }
    for (int i = 0; i < n-1; ++i)
    {
        ll a1, b1;
        cin>>a1>>b1;
        adj[a1].push_back(b1);
        adj[b1].push_back(a1);
    }

    vector<ll> v1;
    v1.push_back(a[1]);
    dp[1]=1;
    vis[1]=true;
    dfs(1, v1);

    for (int i = 1; i<=n; ++i)
    {
        cout<<dp[i]<<endl;
    }

    return 0;
} 


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

vector<pair<int, int>> v;
long long cache[105][100005];

long long take(int w, int i, int cw) {
    if (cw > w) {
        return -1e18;
    }
    if (i >= v.size()) {
        return 0;
    }

    if (cache[i][cw] != -1) {
        return cache[i][cw];
    }

    long long value = max(v[i].second + take(w, i+1, cw + v[i].first), take(w, i+1, cw));
    cache[i][cw] = value;
    return value;
}

int main() {
    int n, w;
    cin>>n>>w;
    v.resize(n);

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


    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= w; j++) {
            cache[i][j] = -1;
        }
    }

    long long ans = take(w, 0, 0);
    cout<<ans<<endl;
}



Measured memory_bytes: 80128
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [[0] * 2] * m

for i in range(m):
    bc[i] = list(map(int, input().split()))

a.sort()
bc = sorted(bc, key=lambda x: -x[1])
new = []

cnt = 0

for e in bc:
    new += [e[1]] * e[0]
    cnt += e[0]

    if (n <= cnt):
        break

for i in range(min(n, cnt)):
    a[i] = max(a[i], new[i])

print(sum(a))


Measured memory_bytes: 36928
#include <bits/stdc++.h>
using namespace std;
// Macros for easier access
#define ll long long
#define endl '\n'
#define F first
#define S second
#define umap unordered_map
#define uset unordered_set
#define test ll cases; cin>>cases; for(ll testCase = 1; testCase <= cases; testCase++)   //test cases
#define fill(name, val) memset(name, val, sizeof(name));
#define mop(a, op, b)    (a%mod op b%mod)%mod
#define error(x) fixed<<setprecision(x) //cout<<error(5)<<someDouble    -> example - 3.14159
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define get(a, n)    for(ll i = 0; i < n; i++)    cin>>a[i];
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cerr << #x << " : " << (x) << endl
// Constants
#define MX 100001
#define mod 1000000007LL
#define inf 1000000000000000000LL
void init(){
	boost;
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

/*	Author: 🆉🅴🅽🅾🅻🆄🆂	*/

int main(){
	init();
	ll k, a, b;	cin>>k>>a>>b;	bool p = 0;
	for(ll i = a; i <= b; i++){
		if(i%k)	continue;
		p = 1;	break;
	}
	cout<<(p?"OK":"NG")<<endl;
}

Measured memory_bytes: 3624
n, m = tuple(map(int, input().split(" ")))
matrixA = [list(map(int, input().split(" "))) for i in range(n)]

temp_row = []
for i in range(m+1):
    temp_row.append(0)
matrixA.append(temp_row)

temp_col = []
cnt = 0
for i, row in enumerate(matrixA):
    if i == n:
        break
    row.append(sum(row))
    cnt += 1
    for j, column in enumerate(row):
        matrixA[n][j] += column
        
for row in matrixA:
    print(" ".join(map(str, row)))



Measured memory_bytes: 5704
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, H = map(int, read().split())
print(max(N - H,0))


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<list>
using namespace std;

int main() {
    int n, key;
    char op[20];
    list<int> List;
    scanf("%d", &n);
    getchar();

    for (int i = 0; i < n; i++) {
        scanf("%s %d", op, &key);
        if (op[0] == 'i') {
            List.push_front(key);
        }
        else {
            if (strlen(op) > 6) {
                if (op[6] == 'F') {
                    List.pop_front();
                }
                else {
                    List.pop_back();
                }
            }
            else { 
                for (list<int>::iterator it = List.begin(); it != List.end(); it++) {
                    if (*it == key) {
                        List.erase(it);
                        break;
                    }
                }
            }
        }
    }
    int flag = 0;
    for (list<int>::iterator it = List.begin(); it != List.end(); it++) {
        if (flag != 0)
            printf(" ");
        flag++;
        printf("%d", (*it));
    }
    printf("\n");
    return 0;
}


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

int main(){
    int a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    if((a1+a2+a3) >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 3616
/*input
5 8
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main(){
	IOS;
	int n,k;
	cin>>n>>k;
	if(k>(n-1)*(n-2)/2){
		cout<<"-1\n";
		return 0;
	}
	cout<<(n-1)*n/2-k<<'\n';
	for(int i=1;i<n;i++){
		cout<<i<<' '<<n<<'\n';
	}
	int tmp=(n-1)*(n-2)/2-k;
	for(int i=1;i<n;i++) for(int j=i+1;j<n;j++){
		if(tmp){
			cout<<i<<' '<<j<<'\n';
			tmp--;
		}
		else break;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
const int N=100010,mod=(int)1e9+7;
int s[26];
char a[N];
int main(){
	int n,i,sum=1;
	scanf("%d",&n);
	scanf("%s",a+1);
	for(i=1;i<=n;i++) s[a[i]-'a']++;
	for(i=0;i<26;i++) sum=(long long)sum*(s[i]+1)%mod;
	printf("%d\n",sum-1);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);


signed main(){
    int n,bunbo;cin>>n;
    double ans;
    bunbo=(n+1)/2;
    cout<<fixed<<setprecision(20)<<(db)bunbo/n<<endl;

}


Measured memory_bytes: 256
def gcd(a,b):
	if b==0:
		return a
	else:
		return gcd(b,a%b)

N=int(input())
array=sorted([int(x) for x in input().split()])
prefix_GCD=[0]*(N)
suffix_GCD=[0]*(N)
currentGCD=array[0]

for i in range(N):
	prefix_GCD[i]=gcd(currentGCD,array[i])
	currentGCD=gcd(currentGCD,(array[i]))
currentGCD=array[N-1]

for i in range(N-1,-1,-1):
	suffix_GCD[i]=gcd(currentGCD,(array[i]))
	currentGCD=gcd(currentGCD,(array[i]))
	
highest=0
for i in range(N):
	if i==0:
		gcdwithout=suffix_GCD[1]
	elif i==N-1:
		gcdwithout=prefix_GCD[-2]
	else:
		gcdwithout=gcd(prefix_GCD[i-1],suffix_GCD[i+1])
	highest=max(highest,gcdwithout)
print(highest)

Measured memory_bytes: 87456
r, c = map(int, input().split())
array = [list(map(int, input().split())) for _ in range(r)]
add = [0] * (c+1)

for i in range(r+1):
    if i == r:
        array.append(add)
        break
    for j in range(c+1):
        if j == c:
            array[i].append(sum(array[i]))
            add[j] += array[i][j]
        else:
            add[j] += array[i][j]

for i in range(r+1):
    print(*array[i], sep=' ')


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N;
    cin >> N;
    vector<lint> A(N, 0);
    rep(i, N) cin >> A[i];
    vector<lint> B(N);
    for (int i = 0; i < N; i++) {
        B[i] = A[i] - i + 1;
    }
    sort(all(B));
    int b    = B[B.size() / 2];
    lint ans = 0;
    for (int i = 0; i < N; i++) {
        ans += abs(B[i] - b);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6400
import sys
readline = sys.stdin.readline
import math

def main():
    X = int(readline())
    ans = 1
    for b in range(1, math.floor(X**(1/2))+1):
        for p in range(2, math.floor(math.log2(X))+1):
            if b ** p <= X:
                ans = max(ans, b ** p)
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn dfs(l: usize, r: usize, ans: &mut [Vec<usize>], lv: usize) {
    if r - l <= 1 {
        return;
    }
    let mid = (r + l) / 2;
    for i in l..mid {
        for j in mid..r {
            ans[i][j] = lv;
        }
    }
    dfs(l, mid, ans, lv + 1);
    dfs(mid, r, ans, lv + 1);
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
    }
    let mut ans = vec![vec![0; n]; n];
    dfs(0, n, &mut ans, 1);
    for i in 0..n {
        for j in i + 1..n {
            puts!("{} ", ans[i][j]);
        }
        puts!("\n");
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 10748
#include "bits/stdc++.h"
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define gcd(a,b) __gcd(a,b)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define pb(n) push_back(n)
#define pp pop_back()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define type(a) typeid(a).name();
#define print(arr) cout << "[" ;for(unsigned int i=0;i<(unsigned int) arr.size();i++){ (i==arr.size()-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define Arr(arr,l) cout << "[" ;for(unsigned int i=0;i<(unsigned int) l;i++){ (i==l-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define console(arr) cout << "["<<endl; for(ll i=0;i<(ll)arr.size();++i){cout << " [";for(ll j=0;j<(ll)arr[i].size();++j){(j==(int)arr[i].size()-1)?cout << arr[i][j]:cout << arr[i][j] << ",";}cout << "]"<<endl;} cout << "]"<<endl
#define starting() auto start = high_resolution_clock::now()
#define ending() auto stop = high_resolution_clock::now();auto duration = duration_cast<microseconds>(stop - start);cout << endl << endl << "Execution Time : "<<duration.count()/1000 << " ms" << endl
 
template <typename T1,typename T2>
void mapped(map<T1,T2>m){for(auto ite=m.begin();ite!=m.end();++ite){cout << "'" << ite->first << "'"<<" : "<<ite->second <<endl;}}
 
template <typename T1 , typename T2>
void mappedArr(map<T1,vector<T2>>m){for(auto ity=m.begin();ity!=m.end();++ity){cout << "'"<< ity->first <<"'"<<" : "<<"[";
for(int i=0;i<(int)ity->second.size();++i){(i==(int)ity->second.size()-1)?cout << ity->second[i]:cout << ity->second[i] << ",";}cout << "]"<<endl;}}
 
string int_to_string(int x){ stringstream ss; ss << x; string ni = ss.str(); return ni;}
int char_to_int(char c){ int n = (int)c - 48; return n; }
int string_to_int(string x){ int n; stringstream s(x); s >> n; return n; }
char upperCase(char a){int d = (int)a - 97 + 65;char c = (char)d;return c;} 
char lowerCase(char a){int d = (int)a - 65 + 97;char c = (char)d;return c;}  
bool isInt(char a){int d = (int)a - 48;if(d>=0 && d<=9){return true;}return false;}
//string char_to_string(char a){string d = (1,a);return d;}
 
template <typename T1,typename T2>
void ArrPair(vector<pair<T1,T2>>vp){for(int i=0;i<(int)vp.size();++i){
cout << "(" << vp[i].first << "," << vp[i].second << ")"<<endl ;}}
 
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;
 
//unordered_map<int,int> um;
//unordered_set<int> us;
//set<int> s;
// v.front() gives the first element of vector 
// v.back()  gives the last element of vector
// insert erase substr

//bool bySecond(pair<int,int> a,pair<int,int> b){
//  return a.second < b.second;
//} 

//bool f(vector<ll> a,vector<ll> b){
//	return a[1] > b[1];
//}

//swap(a,b);
 
int main(){
 string s;
 cin >> s;
 string d = s;
 reverse(d.begin(),d.end());
 int cnt = 0;
 for(int i=0;i<(int)d.size()/2;++i){
	 if(d[i]!=s[i]){
		 cnt++;
	 }
 }
 cout << cnt;
 return 0;
}







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

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll res = 1;
  rep(i, n) {
    res *= i+1;
    res %= mod;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
d[5000],c;main(w,n,i,C,W,b){for(;scanf("%d%d",&w,&n),w;printf("Case %d:\n%d\n%d\n",++c,d[w],b))for(bzero(d,w*5);n--;)for(i=w+scanf("%d,%d",&C,&W);i-->W;)d[i]=fmax(d[i],d[i-W]+C),b=d[i]-d[w]?b:i;}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
int main(){
  int n,i,j,r[100],d[100],t;
  char s[100][100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",s[i],&d[i]);
    for(j=i;j;j--){
      t=strcmp(s[i],s[r[j-1]]);
      if(t<0||(t==0&&d[i]>d[r[j-1]]))r[j]=r[j-1];
      else break;
    }//printf("j:%d\n",j);
    r[j]=i;
  }
  for(i=0;i<n;i++)printf("%d\n",r[i]+1);
  return 0;
}


Measured memory_bytes: 128
#include "iostream"
#include "vector"
#include "algorithm"
#include "numeric"

int main() {
	int n, m, num = 0;
	std::cin >> n;
	std::cin >> m;

	std::vector<int>v(n);
	std::iota(v.begin(), v.end(), 1);

	std::vector<std::pair<int, int>>x(m);

	for (int i = 0; i < m; ++i) {
		std::cin >> x[i].first;
		std::cin >> x[i].second;
	}

	bool ex;
	do {
		if (v[0] == 1) {
			for (int i = 0; i < n - 1; ++i) {
				ex = false;
				for (int j = 0; j < m; ++j) {
					if ((x[j].first == v[i] && x[j].second == v[i + 1]) || (x[j].first == v[i + 1] && x[j].second == v[i])) {
						ex = true;
						break;
					}
				}
				if (!ex) break;
			}
			if (ex)num++;
		}

	} while (std::next_permutation(v.begin(), v.end()));

	std::cout << num << std::endl;
}

Measured memory_bytes: 256
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const X = parseInt(input[0].split(" ")[0]);
    const Y = parseInt(input[0].split(" ")[1]);
    // i = tsuru
    for(let i = 0; i<=X; i++){
        for(let j = 0; j<=X; j++){
            if(i+j == X && 2*i + 4*j === Y){
                console.log("Yes")
                return
            } 
        }
    }
    console.log("No")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 29624
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define REP0(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REP1(i,n) for((i)=1;(i)<=(long long)(n);(i)++)
#define ll long long
using namespace std;

ll i,j,k;
const ll MOD = 1000000000 + 7;

int main(){
    ll n;
    string ans="hon";
    cin>>n;
    if(n%10==0||n%10==1||n%10==6||n%10==8){
        ans="pon";
    }
    else if(n%10==3){
        ans="bon";
    }
    

    cout<<ans<<'\n';
    
    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(){
  int x[3000], y[3000];
  int i, count, temp=0;

  while (i<=3000) {
    scanf("%d %d", &x[i], &y[i]);

    if(x[i]==0&&y[i]==0)break;

    if(x[i]>y[i]){
      temp = y[i];
      y[i] = x[i];
      x[i] = temp;
    }

    count++;
    i++;
  }
  for(i = 0;i<count;i++){
    printf("%d %d\n", x[i], y[i]);
  }

  return 0;
}

Measured memory_bytes: 1052
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const int mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int dp[105][4][4][4]; //dp[X][a][b][c] := 長さがXで最後の3文字がabcとなる場合の数
// AGCT を0123とすると012を部分文字列として含まない

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	rep(a,4)rep(b,4)rep(c,4)dp[3][a][b][c] = 1;
	dp[3][0][1][2] = 0;
	dp[3][0][2][1] = 0;
	dp[3][1][0][2] = 0;
	for(int i=3;i<=N;i++){
		rep(a,4)rep(b,4)rep(c,4)rep(k,4){
			//kは新たに追加する文字
			//現在の最後の3文字はabcとなっている
			if(b==0&&c==1&&k==2)continue;
			if(b==0&&c==2&&k==1)continue;
			if(b==1&&c==0&&k==2)continue;
			if(a==0&&c==1&&k==2)continue;
			if(a==0&&b==1&&k==2)continue;
			dp[i+1][b][c][k] += dp[i][a][b][c];
			dp[i+1][b][c][k] %= mod;
		}
	}
	int ans = 0;
	rep(a,4)rep(b,4)rep(c,4){
		ans += dp[N][a][b][c];
		ans %= mod;
	}
	cout << ans%mod << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
void main()
{
  long int a,b,k;
  scanf("%ld %ld %ld",&a,&b,&k);
  if(a<=k&&k<a+b)
  {
  
    printf("%d %ld",0,b+a-k);
  }
  if(a>k)
  { 
    printf("%ld %ld",a-k,b);
  }
  if(k>=a+b)
  {
    printf("%d %d",0,0);
  }
}
  
  


Measured memory_bytes: 1736
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B, K = LI()

    for i in range(K):
        if i % 2 == 0:
            if A % 2 == 1:
                A -= 1
            A //= 2
            B += A
        else:
            if B % 2 == 1:
                B -= 1
            B //= 2
            A += B

    print(A, B)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10084
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
bool rev(long long int a,long long int b)
{
    if(a>b)return true;
    else return false;
}
bool compa(pair<string,pair<int,int>>a,pair<string,pair<int,int>>b)
{
    if(a.first==b.first)
    {
        if(a.second.first>b.second.first)
        return true;
        else
        return false;
    }
    if(a.first<b.first)
    return true;
    else 
    return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int a,b,c,d;
    string s;
    cin>>s;
    a=s[0]-'0';b=s[1]-'0';c=s[2]-'0';d=s[3]-'0';
    long long int v=0;
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
            for(int k=0;k<2;k++)
            {
                if(i==0)
                v=a+b;
                if(i==1)
                v=a-b;
                if(j==0)
                v=v+c;
                if(j==1)
                v=v-c;
                if(k==0)
                v=v+d;
                if(k==1)
                v=v-d;
                if(v==7)
                {
                    char o1,o2,o3;
                    if(i==0)
                    o1='+';
                    if(i==1)
                    o1='-';
                    if(j==0)
                    o2='+';
                    if(j==1)
                    o2='-';
                    if(k==0)
                    o3='+';
                    if(k==1)
                    o3='-';
                    cout<<a<<o1<<b<<o2<<c<<o3<<d<<"=7";return;
                }
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

int main(void){
    int n, l, r;
    
    while( 1 ){
        cin >> n >> l >> r;
        if( n == 0 && l == 0 && r == 0 ) break;
        vector<int> a(n);
        REP( i, n ) cin >> a[i];
        
        int cnt = 0;
        FOR( i, l, r + 1 ){
            REP( j, n ){
                if( i % a[j] == 0 && ( ( j + 1 ) % 2 ) == 1 ){
                    cnt++;
                    break;
                }
                if( i % a[j] == 0 && ( ( j + 1 ) % 2 ) == 0 ){
                    break;
                }
                
                if( ( j == n - 1 ) && n % 2 == 0 ){
                    cnt++;
                } 
            }
        }
        
        cout << cnt << endl;
        
    }
    


}


Measured memory_bytes: 3056