akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) throws Exception {
	    String[] inputs = Io.read();

        int[] metas = parse(inputs[0]);
        int[] nums = parse(inputs[1]);

        Dp dp = new Dp(nums, metas[1]);
        Io.write(dp.calc(metas[1]));
    }

    private static int[] parse(String str) {
        String[] split = str.split(" ");
        int[] result = new int[split.length];

        for (int i = 0; i < split.length; i++) {
            result[i] = Integer.parseInt(split[i]);
        }

        return result;
    }
}

class Dp {
    private long[][][] dp;
    private int[] nums;
    private int numMaxLim;

    public Dp(int[] nums, int target) {
        this.nums = nums;
        int maxNum = Math.max(IntStream.of(nums).max().getAsInt(), target);
        numMaxLim = nums.length * maxNum;

        dp = new long[nums.length + 1][nums.length + 1][numMaxLim + 1];

        for (int i = 0; i <= nums.length; i++) {
            dp[i][0][0] = 1;
        }
    }

    public long calc(int target) {
        long result = 0;
        setupDp();

        for (int j = 1; j <= nums.length; j++) {
            result += dp[nums.length][j][j * target];
        }

        return result;
    }

    private void setupDp() {
        for(int i = 1; i <= nums.length; i++) {
            for (int j = 1; j <= nums.length; j++) {
                if (j > i) break;

                for (int k = 1; k <= numMaxLim; k++) {
                    if (nums[i - 1] > k) {
                        dp[i][j][k] = dp[i - 1][j][k];
                    } else {
                        dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - nums[i - 1]];
                    }
                }
            }
        }
    }
}

class Io {

    /**
     * 標準入力から1行ずつ受け取る
     * @return
     * @throws IOException
     */
    public static String[] read() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null) {
            if (line.equals(""))
                break;

            inputs.add(line);
        }
        br.close();
        return inputs.toArray(new String[0]);
    }

    /**
     * 標準出力
     * @param answer
     */
    public static void write(long answer)
    {
        System.out.println(answer);
    }
}

Measured memory_bytes: 89340
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class ACatsAndDogs {
public:
	void solve(std::istream& in, std::ostream& out)
	{
        int a, b, x;
        in >> a >> b >> x;
        if(a > x) ans2(false, out);
        else if(x > a+b) ans2(false, out);
        else ans2(true, out);
	}
};


int main() {
	ACatsAndDogs solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import fractions

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)



a,b,c,d = map(int,input().split())

lcm_cd = lcm_base(c, d)

print((b-a+1)-(b//c + b//d - b//lcm_cd) + ((a-1)//c + (a-1)//d - (a-1)//lcm_cd))

Measured memory_bytes: 5048
from operator import itemgetter
import sys
input = sys.stdin.readline

MOD = int(1e9+7)


def main():
    N = int(input())
    P = [None] * N * 2
    for i in range(N):
        a = int(input())
        P[i] = (a, 0)
    for i in range(N):
        b = int(input())
        P[i+N] = (b, 1)
    P.sort(itemgetter(0))
    cand = [0] * 2
    ans = 1
    for p in P:
        cur = p[1]
        peer = cur ^ 1
        if cand[peer]:
            ans = (ans * cand[peer]) % MOD
            cand[peer] -= 1
        else:
            cand[cur] += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 56780
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,(n)-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
lng N;
vector<int> a;
/**********************************/


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    lng n = N;
    while(n > 0) {
        a.push_back(n%10);
        n /= 10;
    }
    reverse(ALL(a));
    int len = (int)a.size();

    lng ans = 0;
    REP(b, 1<<(len-1)) {
        int s = 0;
        REP(i, len-1) {
            if(b&(1<<i)) {
                lng d = 1;
                DOWN(k, i, s) {
                    ans += d*a[k];
                    d *= 10;
                }
                s = i+1;
            }
        }
        lng d = 1;
        DOWN(k, len-1, s) {
            ans += d*a[k];
            d *= 10;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
(r, c) = [int(i) for i in input().split()]
src = []
for _ in range(r):
    row = [int(i) for i in input().split()]
    row.append(sum(row))
    src.append(row)

last_row = [0 for _ in range(c+1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]
src.append(last_row)


for rc in range(r+1):
    print(' '.join([str(a) for a in src[rc]]))

Measured memory_bytes: 7724
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
    while(1){
	int n;
	cin>>n;
	if(n==0)break;
	ll sum =0;
	for(int i=0;i<n;i++){
		ll p;
		cin>>p;
		sum+= p;

	}
	priority_queue<ll,vector<ll> , greater<ll> > q;
	ll bit = 1;
	for(int i=0;i<n-1;i++){
		ll j = 0;
		cin>>j;
		sum+=j;
		q.push(j);
	}
	ll res = 0;
	res = max(res,sum*bit);
	for(int i=0;i<n-1;i++){
	    ll dis = q.top();
	    sum-=dis;
	    q.pop();
	    bit++;
	    res = max(res,sum*bit);
	}
	cout<<res<<endl;
    }
	return 0;
}



Measured memory_bytes: 3800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    vector<int> x(5);
    for(int i = 0; i < 5; i++){
        cin >> x[i];
    }
    int count = 0;
    for(int i = 0; i < 5; i++){
        count++;
        if(x[i] == 0){
            break;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3624
import sys, math
from collections import deque

readline = sys.stdin.readline

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

P = 10**9 + 7

aL = [0] * N
aR = [0] * N

for i in range(N):
    for j in range(i):
        if A[j] < A[i]:
            aL[i] += 1

for i in range(N):
    for j in range(i + 1, N):
        if A[j] < A[i]:
            aR[i] += 1

ans = 0
for n in range(N):
    x = K * (K - 1) // 2 % P
    ans += x * (aL[n] + aR[n]) + K * aR[n]
    ans %= P

print(ans)



Measured memory_bytes: 41692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    int a,b,c;
    cin >> a>> b>> c;
    if(a==5&&b==7&&c==5||b==5&&c==7&&a==5||c==5&&a==7&&b==5) {
        cout << "YES"<<'\n';
    }else {
        cout << "NO" <<'\n';
    }
    return 0;
}

Measured memory_bytes: 256
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	string s;
	cin>>s;
	
	int best=0;
	int curr=0;
	
	for (auto &it:s){
		if (it=='R') curr++;
		else curr=0;
		
		best=max(best,curr);
	}
	
	cout<<best<<endl;
	
}


Measured memory_bytes: 3656
#include <stdio.h>

int main(void)
{
    int a,b,x,y,z,count = 0;
    scanf("%d%d",&a,&b);
    for (x = 0; x <= a; x++) {
        for (y = 0; y <= a; y++) {
            z = b - x - y;
            if (z <= a && z >= 0) {
                count++;
            }
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<string.h>
int main() {
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	int x,y;
	x=a*b;
	y=c*d;
	if(x>y){
		printf("%d",x);
	}else{
		printf("%d",y);
	}
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>

#define SERO 1
#define GARO 0
#define MOD 1000000007

int main()
{
	int N, i = 0;
	int before;
	char s[53], t[53];
	scanf("%d", &N);
	scanf("%s", s);
	scanf("%s", t);
	long long int ans = 1;
	while (i < N) {
		if (i + 1 < N && s[i] == s[i + 1]) {
			if (i == 0)
				ans = 6;
			else if (before == SERO)
				ans *= 2;
			else
				ans *= 3;
			i += 2;
			before = GARO;
			ans %= MOD;
		}
		else {
			if (i == 0)
				ans = 3;
			else if (before == SERO)
				ans *= 2;
			else
				ans *= 1;
			i++;
			before = SERO;
			ans %= MOD;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 128
#include<algorithm>
#include<cstdio>
#include<functional>
#include<iostream>
#include<cfloat>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<time.h>
#include<vector>
using namespace std;
int main()
{
	string x;
	cin >> x;
	x[3]='8';
	cout << x << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
from collections import deque
def bfs(maze, sy, sx, gy, gx):
    d = [[-1] * w for _ in range(h)]
    que = deque([[sy, sx]])
    #print(que)
    d[sy][sx] = 0
    while que:
        y, x = que.popleft()
        if y == gy and x == gx:
            break
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            ny, nx = y + j, x + k
            if 0 <= nx < w  and 0 <= ny < h  and d[ny][nx] == -1 and maze[ny][nx] != "#":
                d[ny][nx] = d[y][x] + 1
                que.append([ny, nx])
                
    return d
gx, gy = w - 1, h - 1
def counting(maze, h, w, aim):
    cnt = 0
    for i in range(h):
        for j in range(w):
            if maze[i][j] == aim:
                cnt += 1
    return cnt
a = bfs(maze, 0, 0, gy, gx)
if a[gy][gx] == -1:
    print(-1)
else:
    print(h * w - (counting(maze, h, w, '#') + (a[gy][gx] + 1)))


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

double dp[305][305][305];

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

    int N;
    cin >> N;

    int x = 0, y = 0, z = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (a == 1) x++;
        if (a == 2) y++;
        if (a == 3) z++;
    }

    int MX = x + y + z + 2;
        
    dp[0][0][0] = 0.0;
    for (int k = 0; k <= MX; k++) {
        for (int j = 0; j <= MX; j++) {
            for (int i = 0; i <= MX; i++) {
                int T = i + j + k;
                if (T == 0) continue;
                dp[i][j][k] = (1.0*N / T);
                
                double r1 = 0.0;
                if (i > 0) r1 = (1.0*i / T) * dp[i-1][j][k];

                double r2 = 0.0;
                if (j > 0) r2 = (1.0*j / T) * dp[i+1][j-1][k];

                double r3 = 0.0;
                if (k > 0) r3 = (1.0*k / T) * dp[i][j+1][k-1];

                dp[i][j][k] += (r1 + r2 + r3);
            }
        }
    }

    cout << setprecision(9) << fixed << dp[x][y][z] << "\n";
}



Measured memory_bytes: 221568
X,N = list(map(int, input().split()))
try:
  n = list(map(int, input().split()))
except:
  n = []

c = 0
while(1):
  if X-c not in n:
    print(X-c)
    break
  if X+c not in n:
    print(X+c)
    break
  c+=1

Measured memory_bytes: 9176
N, X=map(int, input().split())
x=[abs(int(i)-X) for i in input().split()]

def gcd(x, y):
    x, y=max(x,y), min(x,y)
    if y==0:
        return x
    else:
        return gcd(y, x%y)

ans=1
for i in range(N):
    if i==0:
        ans=x[i]
    else:
        ans=gcd(ans, x[i])
print(ans)

Measured memory_bytes: 14252
#include <iostream>
using namespace std;
int main(){
  long n,k;
  cin >> n >> k;
  long ans = 0;
  if(k==0){
    cout << n*n << endl;
    return 0;
  }
  for(int i = k+1;i<=n;i++){
    ans+=((n/i)*(i-k));
    ans+=max(0L,n%i-k+1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
def m(L,R):
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):
 l=len(A);global c;c+=l
 s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A
c=0
n=int(input())
print(*d(list(map(int,input().split()))))
print(c-n)


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

struct Point {
  double x;
  double y;
};

void print(Point pt) {
  printf("%.8f %.8f\n", pt.x, pt.y);
}


void koch(int n, Point p1, Point p2) {
  if ( n == 0 ) return;

  Point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
  s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
  t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
  t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n - 1, p1, s);
  print(s);
  koch(n - 1, s, u);
  print(u);
  koch(n - 1, u, t);
  print(t);
  koch(n - 1, t, p2);
}

int main() {
  int n;
  cin >> n;

  Point p1;
  Point p2;
  p1.x = 0.0, p1.y = 0.0;
  p2.x = 100.0, p2.y = 0.0;

 print(p1);
  koch(n, p1, p2);
  print(p2);

  return 0;
}

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

int main() {
    string s;
    cin >> s;
    int count=0;
    if(s[0]== '1'){count++;}
    if(s[1]== '1'){count++;}
    if(s[2]== '1'){count++;}
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;cin >> a >> b;
	cout << a + b / 2 << endl;
}


Measured memory_bytes: 256
S = input().strip()

if S == "SUN":
    print(7)
elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
elif S == "SAT":
    print(1)

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

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

#define REPISE (s,e) for(int i=s,i<e;i++)
#define REPJSE (s,e) for(int j=s,j<e;j++)

typedef long long ll;

using namespace std;

int main ()
{
  int a,b;
  cin >> a >> b;
  string numstr = to_string (a) + to_string (b);

  int num = atoi(numstr.c_str ());
  
  if ((int)sqrt(num)*(int)sqrt(num) == num)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3756
// Problem : C - Welcome to AtCoder
// Contest : AtCoder - AtCoder Beginner Contest 151
// URL : https://atcoder.jp/contests/abc151/tasks/abc151_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*

WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF LLONG_MAX/2

int main()
{
    io;
    ll n,m,ac=0,pen=0;
    cin>>n>>m;
    vb check(n+5);
    vll wa(n+5);
    
    FOR(i,0,m)
    {
    	ll p;
    	string s;
    	cin>>p>>s;
    	if(check[p]==true)//already accepted
    	{
    		continue;
    	}
    	else
    	{
    		if(s=="AC")
    		{
    			check[p]=true;
    			ac++;
    			pen+=wa[p];
    		}
    		else if(s=="WA")
    		{
    			wa[p]++;
    		}
    	}
    }
    
    cout<<ac<<" "<<pen;
    
    return 0;
}



Measured memory_bytes: 3964
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N = int(input())
    if N == 0:
        exit()
    L = list(map(int, input().split()))
    L = sorted(L)
    min_diff = float('inf')
    for l1, l2 in zip(L, L[1:]):
        min_diff = min(min_diff, abs(l1-l2))
    print(min_diff)


while True:
    solve()



Measured memory_bytes: 5664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif
struct segtree{
	using D = long long;
	D inf = 1e18;

	int N;
	vector<D> val;

	segtree(){}
	segtree(int n){
		N=1;
		while(N<n) N*=2;
		val.assign(N*2,0);
	}
	segtree(const vector<D>& ds){
		int n = ds.size();
		N=1;
		while(N<n) N*=2;
		val.assign(N*2,-inf);
		rep(i,n) val[i+N] = ds[i];
		for(int i=N-1;i>0;i--) val[i] = max(val[i*2],val[i*2+1]);
	}
	void assign(int k,D d){
		k+=N;
		val[k]=d;
		k/=2;
		while(k){
			val[k] = max(val[k*2],val[k*2+1]);
			k/=2;
		}
	}
	D getmax(int a,int b){
		D res = -inf;
		a+=N,b+=N;
		while(a<b){
			if(a&1) chmax(res,val[a++]);
			if(b&1) chmax(res,val[--b]);
			a/=2,b/=2;
		}
		return res;
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	const int X = 300010;
	segtree seg(X+1);
	int N,K; cin >> N >> K;
	rep(i,N){
		int a; cin >> a;
		int v = seg.getmax(max(a-K,0),min(a+K,X)+1) + 1;
		seg.assign(a,v);
	}
	cout << seg.getmax(0,X+1) << endl;
}


Measured memory_bytes: 11324
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int h,w;
      cin >> h >> w;
      vector<string> ans(h+2);
      ans.at(0)="#";
      ans.at(h+1)="#";
      for (int j=0; j<w+1; j++){
        ans.at(0).insert(0,"#");
        ans.at(h+1).insert(0,"#");
      }
      for (int i=0; i<h; i++){
        cin >> ans.at(i+1);
        ans.at(i+1).insert(0,"#");
        ans.at(i+1).insert(w+1,"#");
      }
      for(int i=0; i<h+2; i++)
        cout << ans.at(i) <<endl;
    }

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

int main(){
  int x, y, temp;
  int n=0;

  while(1){
    cin>>x>>y;
    if(x==0&&y==0){
      break;
    }
    if(x>y){
      cout<<y<<" "<<x<<endl;
    }else{
      cout<<x<<" "<<y<<endl;
    }
  }
  return 0;
};

Measured memory_bytes: 3044
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long M, long[] A) {
    string[long] nums;
    if (A.canFind(1)) nums[2] = "1";
    if (A.canFind(2)) nums[5] = "2";
    if (A.canFind(3)) nums[5] = "3";
    if (A.canFind(4)) nums[4] = "4";
    if (A.canFind(5)) nums[5] = "5";
    if (A.canFind(6)) nums[6] = "6";
    if (A.canFind(7)) nums[3] = "7";
    if (A.canFind(8)) nums[7] = "8";
    if (A.canFind(9)) nums[6] = "9";
    
    const NONE = "0";
    string[long] memo;
    string maxNumMadeOf(long matches) {
        if (matches in memo)
            return memo[matches];
        if (matches == 0)
            return "";
        if (matches < 0)
            return NONE;

        return memo[matches] = nums.byKeyValue
            .map!(t => t.value ~ maxNumMadeOf(matches - t.key))
            .filter!(s => !s.canFind(NONE))
            .chain([NONE])
            .reduce!((a, b) => lt(a, b) ? b : a);
    }

    return maxNumMadeOf(N);
}


bool lt(string a, string b) {
    if (a.length != b.length)
        return a.length < b.length;
    return a < b;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long M;
    M = input.front.to!long;
    input.popFront;

    long[] A = new long[](cast(size_t) (M));
    foreach (i; 0 .. cast(size_t) (M)) {
        A[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, M, A);
    else
        solve(N, M, A).writeln;
}


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

int main()
{
    long long val,te,cou=0,A[30],B[30],C[30],i,j,n;
    cin>>n;
    int co[30]={0};
    cin>>A[0];

    for(i=1;i<n;i++)
        {
            cin>>A[i];
            if(A[i-1]+1==A[i])
                    co[A[i-1]-1]++;
//                    cout<<i-1<<" SEE "<<A[i-1]<<" "<<A[i]<<endl;}

        }
    for(i=0;i<n;i++)
    {
        cin>>te;
        cou+=te;
    }
    for(i=0;i<n-1;i++)
    {
        cin>>val;
        if(co[i]>0) cou+=val;
    }
    cout<<cou<<endl;
    return 0;
}



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

template<typename T>
struct Segtree {
    int n;
    T e;
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input){
        initialize(n_input, f_input, e_input);
    }
    void initialize(int n_input, Func f_input, T e_input){
        f = f_input;
        e = e_input;
        n = 1;
        while(n < n_input) n <<= 1;
        dat.resize(2*n-1, e);
    }

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

    T get(int k){
        return dat[k+n-1];
    }

    T between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

void fail(){
    cout << -1 << endl;
    exit(0);
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> B[i];
    for(int i=0; i<N; i++) if(A[i] > B[i]) fail();
    typedef pair<int, int> P;
    P MIN = {-1e9, -1};
    Segtree<P> st(N, [](P a, P b){ return max(a, b); }, MIN);
    for(int i=0; i<N; i++) st.update(i, {B[i], i});

    int64_t ans = 0;
    while(true){
        int i = st.between(0, N-1).second;
        if(i == -1) break;
        int n1 = B[(i+1)%N], n2 = B[(i+N-1)%N];
        int d = n1 + n2;
        int num = (B[i]-A[i])/d;
        ans += num;
        B[i] -= num*d;
        if(B[i] == A[i]){
            st.update(i, MIN);
        }else{
            if(B[i] >= max(n1, n2)) fail();
            st.update(i, {B[i], i});
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6016
program Iron_Bar_Cutting
  implicit none
  integer :: n, i
  integer(8) :: a(200000) = 0_8, l = 0_8, r, m
  read(*,*) n
  read(*,*) a(1:n)
  r = sum(a(1:n))
  m = r
  do i = 1, n
    l = l+a(i)
    r = r-a(i)
    m = min(m,abs(r-l))
  end do
  write(*,'(i0)') m
end program Iron_Bar_Cutting

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a<=c&&c<=b)||(b<=c&&c<=a))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<string>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<string>
#define UP(i,l,h) for(int i=l;i<h;i++)
#define DOWN(i,h,l) for(int i=h-1;i>=l;i--)
#define W(a) while(a)
#define MEM(a,b) memset(a,b,sizeof(a))
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f
#define MAXN 20050
#define MOD 1000000007
#define EPS 1e-3
using namespace std;
int a[100010];
bool vis[100010];

int main() {
    MEM(vis,false);
    int n;
    scanf("%d",&n);
    int ans=0;
    UP(i,0,n) {
        scanf("%d",&a[i]);
    }
    UP(i,0,n) {
        if(a[i]==i+1) {
            if(a[i+1]==i+2) swap(a[i],a[i+1]);
            ans++;
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
	fast;
	ll x,y,z,k,flag=0;
	cin>>x>>y>>z>>k;
	vector<ll> a(x);
	vector<ll> b(y);
	vector<ll> c(z);
	for(int i=0;i<x;i++)
		cin>>a[i];
	for(int i=0;i<y;i++)
		cin>>b[i];
	for(int i=0;i<z;i++)
		cin>>c[i];
	sort(a.begin(),a.end(),greater<ll>());
	sort(b.begin(),b.end(),greater<ll>());
	sort(c.begin(),c.end(),greater<ll>());
	vector <ll> ans;
	for(int i=0;i<x;i++)
	{
		for(int j=0;j<y;j++)
		{
			for(int m=0;m<z;m++)
			{
				if((i+1)*(j+1)*(m+1)<=k)
					ans.push_back(a[i]+b[j]+c[m]);
				else
					break;
			}
		}
	}
	sort(ans.begin(),ans.end(),greater<ll>());	
	for(int i=0;i<k;i++)
		cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 4316
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

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

int main() {

	int n, a, b;
	cin >> n >> a >> b;

	cout << min(a, b) << " ";

	a + b - n < 0 ? cout << 0 : cout << a + b - n;
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s,a;
	int i, j;
	int n=0;
	int t = 0;
	cin >> s;
	for (i = 0; i < s.length(); ++i) {
		for (j = s.length() - i; j > 0; --j) {
			n = 0;
			a = s.substr(i, j);
			for (int k = 0; k < j; ++k) {
				if (a.substr(k, 1) != "A"&&a.substr(k, 1) != "T"&&a.substr(k, 1) != "G"&&a.substr(k, 1) != "C"){
					n = 1;
					break;
			}
			}
			if (n==1)continue;
		    if (a.length() > t)t = a.length();
		}
	}
	cout << t << "\n";
	return 0;
}

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

using namespace std;

#define i64 int64_t
#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define fore(i,a) for (auto &i : a)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1;} return 0;}

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    char b;
    cin >> b;
    if (b == 'A') cout << 'T' << endl;
    if (b == 'T') cout << 'A' << endl;
    if (b == 'C') cout << 'G' << endl;
    if (b ==  'G') cout << 'C' << endl;
    
    return 0;
}

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

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
    #include "lib/dump.hpp"
#else
    #define dump(...) 42
    #define dump_1d(...) 42
    #define dump_2d(...) 42
    #define cerrendl 42
#endif
//}}}

signed main() {
    int h,n;cin>>h>>n;
    vi a(n), b(n);
    rep(i, n){
        cin>>a[i]>>b[i];
    }

    vector<int> dp(h+1, INF);
    dp[0] = 0;
    rep(i, n){
        rep(j, h) chmin(dp[min(j+a[i], h)], dp[j] + b[i]);
    }
    cout << dp[h] << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>

int main()
{
    std::vector<int> v(1001,0);
    std::bitset<1001> b(0);
    for(int i = 1; i <= 1000; ++i)
    {
        for(int j = 2; j <= 1000 && std::pow(i, j) <= 1000; ++j)
        {
            b.set(std::pow(i, j));
        }
    }
    
    int x;
    std::cin >> x;
    for(int i = x; x > 0; --i)
    {
        if(b[i] != 0)
        {
            std::cout << i << std::endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <functional>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <algorithm>
#define ll long long
#define PI acos(-1)
#define mes(x,y) memset(x,y,sizeof(x))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll GCD(ll a, ll b) {//最大公约数
	return b == 0 ? a : GCD(b, a % b);
}
ll Power(ll a, ll b, ll p) { //计算(a^b)%p;
	ll ans = 1;
	while (b) {
		if (b & 1) //等价于b%2，判断b的奇偶性
			ans = ans * a % p; //如果为奇数，证明该位为1，需要乘上a
		a = a * a % p; //计算a^(2^i)
		b >>= 1; //等价于b/=2;
	}
	return ans;
}
bool isprime(ll num)
{
	if (num == 2 || num == 3)
		return true;
	if (num % 6 != 1 && num % 6 != 5)
		return false;
	ll t = sqrt((double)num);
	for (ll i = 5; i <= t; i += 6)
		if (num % i == 0 || num % (i + 2) == 0)
			return false;
	return true;
}
string sum(string s1, string s2)
{
	if (s1.length() < s2.length())
	{
		string temp = s1;
		s1 = s2;
		s2 = temp;
	}
	int i, j;
	for (i = s1.length() - 1, j = s2.length() - 1; i >= 0; i--, j--)
	{
		s1[i] = char(s1[i] + (j >= 0 ? s2[j] - '0' : 0));   //注意细节
		if (s1[i] - '0' >= 10)
		{
			s1[i] = char((s1[i] - '0') % 10 + '0');
			if (i) s1[i - 1]++;
			else s1 = '1' + s1;
		}
	}
	return s1;
}
bool isRunyear(int year)
{
	if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
	{
		return true;
	}
	else {
		return false;
	}
}
ll n, m, i, j, k, t;
const ll INF = 1e9 + 10;

int main() {
	FAST_IO;
	double r;
	while (cin >> r) {
		r = 2 * r * PI;
		printf("%.22lf\n", r);
	}
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

char s[100005];int n,m;
int w[100005];
vector<int> g[100005];
bool vis[100005];

int dfs(int x){
	if(vis[x])return 0;
	vis[x]=true;
	int r=w[x];
	for(int y:g[x])r+=dfs(y);
	return r;
}

int main(){
	scanf("%s%d",s,&m);n=strlen(s);
	while(m--){
		int a,b;
		scanf("%d%d",&a,&b);a--;
		g[a].pb(b);g[b].pb(a);
	}
	fore(i,0,n)s[i]-='a';
	w[0]=s[0];
	fore(i,1,n)w[i]=s[i]-s[i-1];
	w[n]=-s[n-1];
	fore(i,0,n+1)g[i].pb(n-i);
	fore(i,0,n+1)if(!vis[i]&&dfs(i)%26){puts("NO");return 0;}
	puts("YES");
	return 0;
}

Measured memory_bytes: 8064
n = int(input())
lst = []
dic = {}
for _ in range(n) :
    s = input()
    lst += [s]

for i in lst :
    if i in dic.keys() :
        dic[i] += 1
    else :
        dic[i] = 1

dic = sorted(dic.items(), key=lambda x:x[1], reverse=True)
result = [dic[0][0]]
if len(dic) > 1 :
    for j in range(n-1) :
        if dic[j][1] == dic[j+1][1] :
            result += [dic[j+1][0]]
        else :
            break

result = sorted(result)
for k in result :
    print(k)


Measured memory_bytes: 44688
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var sr = new InputReader(Console.In);
            //var sr = new InputReader(new StreamReader("input.txt"));
            var task = new Task();
            using (var sw = Console.Out)
            //using (var sw = new StreamWriter("output.txt"))
            {
                task.Solve(sr, sw);
                //Console.ReadKey();
            }
        }
    }

    internal class Task
    {
        const long mod = 1000000007L;
        public void Solve(InputReader sr, TextWriter sw)
        {
            var n = sr.NextInt32();
            var p = 1L;
            for (var i = 1; i <= n; i++) {
                p = ((p % mod) * (i % mod)) % mod;
            }

            sw.WriteLine(p);
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(NextString());
    }

    public long NextInt64()
    {
        return Int64.Parse(NextString());
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();
            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}

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

int main() {
  int i,j,n,k;
  read(n),read(k);
  for (i=1;i<=n;++i) p[i]=read();
  for (j=1;j<=n;++j) c[j]=read();
  ll ans=-2e9;
  for (i=1;i<=n;++i) {
    vector<ll> v;
    ll tmp=c[i];
    v.push_back(c[i]);
    for (j=p[i];j^i;j=p[j]) v.push_back(tmp+=c[j]);
    for (j=0;j<v.size();++j) {
      ll res=k-j-1;
      if (res<0) break;
      ans=max(ans,v[j]+res/(ll)v.size()*max(tmp,0ll));
    }
  }
  cout<<ans<<'\n';
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int n;
  cin>>n;
  int x,y;
  pair<int,int> a[100],b[100];
  rep(i,n){
    cin>>x>>y;
    a[i]=make_pair(y,x);
  }
  rep(i,n){
    cin>>x>>y;
    b[i]=make_pair(x,y);
  }
  sort(a,a+n);
 
  sort(b,b+n);
  
  int flagb[100]={0};
  int ans=0;
 
  rep(i,n){
    repn(j,n-1){
      if(a[j].fst<b[i].scd && a[j].scd<b[i].fst && flagb[j]==0){
	//	cout<<i<<" "<<j<<endl;
	flagb[j]=1;
	ans++;
	break;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}










Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(input())
count=0
for i in range(n):
    if a[i]=="L" and i-1>=0 and a[i-1]=="L":
        count+=1
    elif a[i]=="R" and i+1<=n-1 and a[i+1]=="R":
        count+=1
print(min(n-1,count+k*2))

Measured memory_bytes: 71612
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  if(a == 22)
    cout << "Christmas Eve Eve Eve "<<endl;
  if(a == 23)
    cout << "Christmas Eve Eve "<<endl;
  if(a == 24)
    cout << "Christmas Eve "<<endl;
  if(a == 25)
    cout << "Christmas "<<endl;
  
    
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin>>n;
  int d[n];
  for(int i=0;i<n;i++)
    cin>>d[i];
  int sum=0;
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++){
      sum+=d[i]*d[j];
    }}
  cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a[31] = {0},i,no;
	for (i = 0;i <= 28;i++){
		scanf("%d",&no);
		a[no] = 1;
	}
	for (i = 1;i <= 30;i++){
		if (a[i] == 0){
			printf("%d\n",i);
		}
	}
	return 0;
}

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    vector<pair<int,int>> students;
    for (int i = 0; i < n; ++i) {
    	int x; cin >> x;
    	students.push_back({x, i});
    }
    sort(students.begin(), students.end());
    for(auto p : students) cout << p.second + 1 << ' ';
	cout << '\n';
}


Measured memory_bytes: 1780
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/20.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main(){
    
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i=0;i<N;i++) cin >> d[i];
    
    sort(d.begin(), d.end());
    
    int Ks;
    Ks = d[N/2] - d[N/2-1];
    cout << Ks << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl
 
#define ld double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
 
#define INF 1000000000000000000

ll n,k;
ll a[101];
ll dp[100001];

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

    cin >> n;
    cin >> k;

    rep(i,n)
    {
        cin >> a[i];
    }

    dp[0] = 0;

    sort(a, a+n);

    fr(i,1,k)
    {
        rep(j,n)
        {
            if(i>=a[j])
            {
                dp[i] = dp[i]|(1-dp[i-a[j]]);
            } 
        }
    }

    if(dp[k])
        cout << "First" << endl;
    else
        cout << "Second" << endl;
}

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

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

  int a,b,c;
  cin >> a >> b >> c;
  
  if(a == 1 && b == 1 && c == 0 || a == 0 && b == 0 && c == 1){
    cout << "Open" << endl;
  } else {
    cout << "Close" << endl;
  }

  return 0;
}



Measured memory_bytes: 3184
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nc = readln.split.to!(int[]);
    auto N = nc[0];
    auto C = nc[1];

    long[][] DS;
    DS.length = C;
    foreach (i; 0..C) DS[i] = readln.split.to!(long[]);

    auto CS = new long[][](3, C);
    foreach (i; 0..N) foreach (j, c; readln.split.to!(int[])) ++CS[(i+j)%3][c-1];

    auto r = long.max;
    foreach (i; 0..C) {
        foreach (j; 0..C) {
            foreach (k; 0..C) {
                if (i == j || j == k || k == i) continue;
                long rr;
                foreach (c; 0..C)
                    rr +=
                        DS[c][i] * CS[0][c] +
                        DS[c][j] * CS[1][c] +
                        DS[c][k] * CS[2][c];
                r = min(r, rr);
            }
        }
    }
    writeln(r);
}

Measured memory_bytes: 4348
"""

https://atcoder.jp/contests/cf17-final/tasks/cf17_final_g

1回の操作で捨てられる石は1個
いくつ捨てられるかを考えた方がいいだろう

大きい方から?→そんなことはない
小さいほうから?→そんなことはない
今i=aiを満たしている中で最小のものからやるべき？→これはそう

数え上げなので…？ → X回とれる盤面は何通りあるか(1)
または、あるindexより右をX回選択できるindexより右側の数列は何通りか(2) → 左は自由

(2)の方がやりやすそう(Nはでかいとする)
→ 右端は1通り (Nのみ)
→ 右から2番目は 1回選択が N-1,A / 2回選択が N-2,N
→ 右から3番目は 1回選択が N-2,(0回選択)

右から順番に見てく？
100*100→10000個しか取れない
毎回何の数字か全探索したとしても 100^3で間に合う
取れる個数は100log100

3300 * 100 * 100 = 3.3*10^7
間に合いそう
"""

N,K = map(int,input().split())
mod = 10**9+7
lis = [0] * 3300
lis[0] = 1

for i in range(N,0,-1):

    nlis = [0] * 3300
    
    for j in range(K+1):

        for last in range(3300):

            if i < j:
                nlis[last] += lis[last]
                nlis[last] %= mod
            elif (last+j)//i + last < 3300:
                nlis[last+(last+j)//i] += lis[last]
                nlis[last+(last+j)//i] %= mod
                

    lis = nlis
    #print (lis[:20])

ans = K * (K+1) // 2 * pow(K+1,N-1,mod) * N
#print (ans)

for i in range(3300):
    ans -= lis[i] * i
    ans %= mod
print (ans)

"""
#test

ans = 0
for i in range(100,0,-1):
    ans += (ans//i) + 1
print (ans)
"""

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

int main(){
  int N; cin >> N;
  vector<pair<pair<string,int>,int>> p(N);
  for(int i = 0; i < N; i++){
      string s; cin >> s;
      int P; cin >> P;
      p[i] = make_pair(make_pair(s,-P),i);
  }
  sort(p.begin(),p.end());
  for(int i = 0; i < N; i++){
      cout << p[i].second + 1 << endl;
  }
}



Measured memory_bytes: 256