akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())

if n % 2 == 1:
    for i in range(m):
        print(i + 1, n - i)
        
else:
    max_num = n // 2
    loop_num = max_num // 2
    if loop_num >= m:
        for i in range(m):
            print(i + 1, max_num - i)
    else:
        for i in range(loop_num):
            print(i + 1, max_num - i)
        loop_num = m - loop_num
        for i in range(loop_num):
            print (i + 1 + max_num, n - i - 1)

Measured memory_bytes: 9280
#include<cstdio>
#include<vector>
#include<queue>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string>
#define MAXN 10000
#define INF 1000000005

using namespace std;
int a[105][105]={0};
bool vis[105][105]={0};
int sum=0;
int step[4][2]={-1,0,1,0,0,-1,0,1};
int fl;
void dfs(int x,int y)
{
    vis[x][y]=1;
    for(int i=0;i<4;i++)
    {
        int xx=x+step[i][0],yy=y+step[i][1];
        if(a[xx][yy]==fl&&!vis[xx][yy]){
            dfs(xx,yy);
        }
    }
}
int main()
{
    int m,n;
    while(1)
    {
        scanf("%d%d",&n,&m);
        if(m==0&&n==0)break;
        memset(a,0,sizeof(a));
        memset(vis,0,sizeof(vis));
        sum=0;
        for(int i=1;i<=n;i++)
        {
            string x;cin>>x;
            for(int j=1;j<=m;j++)
            {
                if(x[j-1]=='#')a[i][j]=1;
                if(x[j-1]=='@')a[i][j]=2;
                if(x[j-1]=='*')a[i][j]=3;
            }
        }
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
        {
            if(!vis[i][j]){fl=a[i][j];dfs(i,j);sum++;}
        }
        printf("%d\n",sum);
    }

}



Measured memory_bytes: 3652
n=int(input())
for i in range(n):
    board=[]
    check=[[0 for a in range(9)] for b in range(9)]
    for j in range(9):
        board.append(list(map(int,input().split())))
    board_r = [list(x) for x in zip(*board)]
    for j in range(9):
        for k in range(9):
            if board[j].count(board[j][k])>1:check[j][k]=1
    for j in range(9):
        for k in range(9):
            if board_r[j].count(board_r[j][k])>1:check[k][j]=1
    for j in range(3):
        for k in range(3):
            ch_list=[]
            for l in range(9):
                ch_list.append(board[j*3+l%3][k*3+l//3])
            for l in range(9):
                if ch_list.count(ch_list[l])>1:check[j*3+l%3][k*3+l//3]=1
    for j in range(9):
        for k in range(9):    
            if check[j][k]==1:print("*",end="")
            else:print(" ",end="")
            print(board[j][k],end="")
        print()
    if i<n-1:print()


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define vl vector<ll>
#define pll pair<ll,ll>
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i= 0;i < a;i++)
#define rep1(i,a) for(ll i= 1;i < a;i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define pb push_back
#define sz(v) v.size()
#define all(a) a.begin(), a.end()
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000005
#define MOD 1000000007
#define el "\n"
const ll INF = 2e9+5;

using namespace std;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll isPrime(ll n){if(n<=3) return 1;if(n%2==0||n%3==0) return 0;
for(ll j=5;j*j<=n;j+=6){if(n%j == 0||n%(j+2) == 0) return 0;}return 1;}

vector<ll>adj[100001];
ll dp[100001],vis[100001];
void dfs(ll node){
   vis[node] = 1;
   dp[node] = 0;
   for(auto i:adj[node]){
      if(vis[i] == 0) dfs(i);
      dp[node] = max(dp[node],1+dp[i]);
   }
}

void solve(){
   ll n,m;
   cin>>n>>m;
   rep(i,m){
      ll x,y;
      cin>>x>>y;
      adj[x].pb(y);
   }
   // vl vis(n,0);
   rep1(i,n+1){
      if(vis[i] == 0) dfs(i);
   }
   ll mx=-1;
   rep1(i,n+1){mx=max(mx,dp[i]);}
   cout<<mx;
}
 
int main() {
   #ifndef ONLINE_JUDGE
      freopen("input.txt", "r" , stdin);
      freopen("output.txt", "w" , stdout);
   #endif
   ios::sync_with_stdio(0); 
   cin.tie(0); cout.tie(0);   
   ll t;
   // cin>>t;
   t = 1;
   ll tc=0;
   while(tc++<t){
      // cout<<"Case #"<<tc<<": ";
      solve();
   }
   cerr<<"Time taken : "<<(double)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
   return 0;
}

Measured memory_bytes: 13552
import pdb

N = int(input())
i = 0
list = [0] * N

while i < N:
  list[i] = input()
  i += 1

list.sort()
k = 1
count_list = [0]*N
count_list[0] = 1
ans_list = [0] * N
ans_list[0] = list[0]
l = 0



while k < N:
  if list[k] != list[k-1]:
    l +=1
    ans_list[l] = list[k]

  count_list[l] += 1
  k += 1

s = max(count_list)

for i in range(N):
  if count_list[i] == s:
    print(ans_list[i])

Measured memory_bytes: 23920
#i+1の倍数の和
def sum_remainder_before_i(i, a):
    ans = 0
    j = 1
    while True:
        if (j+1)*(i+1)-1 > len(a)-1:
            return ans
        else:
            ans = ans + a[(j+1)*(i+1)-1]
            j = j + 1

N = int(input())
a = tuple(map(int, input().split()))

i = N - 1
ans = [-1]*N
result = False

while True:
    sum = sum_remainder_before_i(i, ans)
    if sum % 2 == a[i]:
        ans[i] = 0
    else:
        ans[i] = 1
    if i == 0:
        break
    i = i - 1

m = 0
answers = []
for i, a in enumerate(ans):
    if a == 1:
        answers.append(i+1)
        m = m + 1

print(m)
if m > 0:
    print(" ".join(map(str,answers)))


Measured memory_bytes: 19116
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int main() {

    string S;
    cin >> S;
    if(S.length() == 2){
        cout << S << endl;
    }else{
        string R = "";
        for (int i = S.length() - 1; i >= 0; --i) {
            R.push_back(S[i]);
        }
        cout << R << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline void write_bool(bool b, const string &tval, const string &fval) {
  cout << (b ? tval : fval) << endl;
} 
inline void YESNO(bool b) { return write_bool(b, "YES", "NO"); }
inline void YesNo(bool b) { return write_bool(b, "Yes", "No"); }
inline void yesno(bool b) { return write_bool(b, "yes", "no"); }

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } 

int main() {
  int n;
  while (cin >> n) {
    ll result = 1;
    REP(i,n) {
      ll t; cin >> t;
      result = lcm(result, t);
    }
    cout << result << endl;
  }
}


Measured memory_bytes: 256
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

#import math
INF = 10 ** 12 # math.inf
V = 10 ** 5 + 10

dp = [[INF] * V for _ in range(N + 1)]
dp[0][0] = 0

for i, (w, v) in enumerate(WV):
	for n in range(V):
		if v <= n:
			dp[i + 1][n] = min(dp[i + 1][n], dp[i][n - v] + w)
		dp[i + 1][n] = min(dp[i + 1][n], dp[i][n])
"""
for line in dp:
	for cell in line:
		if cell == INF:
			print("  INF", end="")
		else:
			print("{:5d}".format(cell), end="")
	print()
"""
r = 0
for i in range(V):
	if dp[-1][i] <= W:
		r = i
print(r)

Measured memory_bytes: 121324
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x;
		int i=1;
		while(true){
			x = sc.nextInt();
			if(x == 0) break;
			System.out.println("Case "+(i++)+": "+x);
		}
	}
}

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

int main()
{
	int n, m, s[400], l[400], p[400], w[400], dp[400];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i] >> l[i] >> p[i];
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> w[i];
	}
	fill(dp, dp + 400, -1);
	dp[0] = 0;
	for (int i = 1; i < 400; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = s[j]; k <= l[j]; k++) {
				if (i - k >= 0) dp[i] = max(dp[i], dp[i - k] + p[j]);
			}
		}
	}
	for (int i = 0; i < m; i++) {
		if (dp[w[i]] < 0) {
			cout << -1 << endl;
			return 0;
		}
	}
	for (int i = 0; i < m; i++) {
		cout << dp[w[i]] << endl;
	}
	return 0;
}


Measured memory_bytes: 3104
n=int(input())
l=[]
for i in range(n):
  s,p=[x for x in input().rstrip().split()]
  l.append([s,int(p),i+1])
l.sort(key=lambda x:x[1],reverse=True)
l.sort(key=lambda x:x[0])

for s,p,i in l:
  print(i) 

Measured memory_bytes: 3060
#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(){
   int n,m; cin>>n>>m;
   vector<int> l(m);
   vector<int> r(m);
   rep(i,m) cin>>l[i]>>r[i];
   int maxl=l[0];
   int minr=r[0];
   rep(i,m){
      if(l[i]>maxl) maxl=l[i];
      if(r[i]<minr) minr=r[i];
   }
   if(maxl<=minr) cout<<minr-maxl+1<<endl;
   else cout<<0<<endl;
   return 0;
}

   


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> a(n+1);
  vector<int> b(n);
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];

  ll total = 0;
  rep(i, n) {
    if(b[i]>=a[i]) total += a[i];
    else total += b[i];
    int temp = b[i];
    b[i] = max(b[i]-a[i], 0);
    a[i] = max(a[i]-temp, 0);

    if(b[i]>=a[i+1]) {
      total += a[i+1];
    } else {
      total += b[i];
    }
    temp = b[i];
    b[i] = max(b[i]-a[i+1], 0);
    a[i+1] = max(a[i+1]-temp, 0);
  }
  cout << total << endl;
  return 0;
}

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

int main() {
	// your code goes here
	long long int v[4];
	int N;
	long long int ans;
	
	//input
	cin >> v[0] >> v[1] >> v[2] >> v[3];
	cin >> N;
	
	//cost = cost / 1L
	long double cost[4] = {0.25, 0.50, 1.00, 2.00};
	long double mini = 400000000;
	int minS = 0;
	for(int i = 0; i < 4; i++){
		cost[i] = v[i] / cost[i];
		//cout << cost[i] << endl;
		if(mini > cost[i]){
			minS = i;
			mini = cost[i];
		}
	}
	
	
	if(minS == 3){
		if(N%2==0){
			ans = N * mini;
		}else{
			long double miniSec = cost[2];
			if(miniSec >= cost[1]){ miniSec = cost[1]; }
			if(miniSec >= cost[0]){ miniSec = cost[0]; }
			ans = (2*(int)(N / 2)) * cost[3] + miniSec;
		}
		
	}else{
		ans = N * mini;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Data.List

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine :: IO [Integer]
  as <- map read . words <$> getLine :: IO [Integer]
  let
    ss = map (`mod` m) $ scanl1 (+) as
    cs = map (\i -> (head i,genericLength i)) $ group $ sort ss

  print $ sum $ map (\(i,c) -> c*(c-1)`div`2 + (if i == 0 then c else 0)) cs

Measured memory_bytes: 39932
#include <iostream>
#include <stdio.h>

using namespace std;

int n, a=0, b=0;

int main()
{
    int i, k;
    scanf("%d", &n);
    for(i=0;i<n;++i)
    {
        scanf("%d", &k);
        if(k%2==1) a++;
        else b++;
    }
    if(a%2==1)
    {
        printf("NO");
        return 0;
    }
    else{
        printf("YES");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
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;}

const ll INF = 1000000000;

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

    vector<ll> a(n, 0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

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

    for(int i = 1; i < n; i++){
        if(a[i-1] == a[i]){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=1e9+7;
const int N=2e5+5;


int main(){
    string S, T; cin >> S >> T;
    T=T+S;
    cout << T << endl;
    return 0;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 100 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    int a,b;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) cin >> p.at(i);
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    if (i != N-1 && p.at(i) == i+1) {
      swap(p.at(i),p.at(i+1));
      count++;
    } else if (p.at(i) == i+1) count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
main(){
    int W,H,N,x,y,n;
    cin >> W >> H >> N;
    int mx = W,my = H,sx = 0,sy = 0;
    for(int i = 0;i < N;i++){
        cin >> x >> y >> n;
        if(n==1){
            sx = max(sx,x);
        }if(n==2){
            mx = min(mx,x);
        }if(n==3){
            sy = max(sy,y); 
        }if(n==4){
            my = min(my,y);
        }
    }
    if(mx < sx || my < sy)cout << 0 << endl;
    else cout << (mx-sx)*(my-sy) << endl;

}

Measured memory_bytes: 256
from collections import Counter
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))

s = [0] + list(accumulate(A))

c = list(Counter(s).values())

ans = 0
for i in c:
    if i >= 2:
        ans +=  (i * (i - 1)) // 2

print(ans)

Measured memory_bytes: 41976
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long

LL n,dp[105][105]={},r[105],c[105];

LL solve(int L, int R){
	if(dp[L][R]!=0)return dp[L][R];
	if(L==R)return 0ll;
	if(R-L==1)return dp[L][R]=r[L]*c[L]*c[R];
	LL tmp=(1ll<<40);
	for(int i=L;i<R;i++)
		tmp=min(tmp,solve(L,i)+r[L]*r[i+1]*c[R]+solve(i+1,R));	
	return dp[L][R]=tmp;
	
}

int main() {
	cin>>n;
	for(int i=0;i<n;i++)cin>>r[i]>>c[i];
	cout<<solve(0,n-1)<<endl;
	return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

ll x[55];
ll y[55];

ll cx[55];
ll cy[55];

ll dist(int i, int j) {
	return llabs(x[i]-cx[j])+llabs(y[i]-cy[j]);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m;
	
	cin >> n >> m;
	FOR(i,0,n) {
		cin >> x[i] >> y[i];
	}
	FOR(i,0,m) {
		cin >> cx[i] >> cy[i];
	}
	
	FOR(i,0,n) {
		int ans = 0;
		FOR(j,1,m) {
			if (dist(i,ans) > dist(i,j)) {
				ans = j;
			}
		}
		cout << ans+1 << "\n";
	}

}


Measured memory_bytes: 3580
///In the name of GOD
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 4e5 + 10;
ll n, a, b, c, d;
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    char ch;
    cin >> ch;
    cout << (ch <= 'Z' ? 'A' : 'a');
    return 0;
}
/*!
    I CHOOSE TO HAVE FAITH,
    BECAUSE WITHOUT THAT,
    I HAVE NOTHING....
    ITS THE ONLY THING THAT'S KEEPING ME GOING.
*/
//! N.N


Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A[3]; cin >> A[0] >> A[1] >> A[2];
    sort(A, A+3);
    cout << A[0]+A[1];
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
import sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')

INF = 10**12


def main():

    A, B, Q = in_nn()
    tmp = list(map(int, read().split()))
    s = [-INF] + tmp[:A] + [INF]
    t = [-INF] + tmp[A:A + B] + [INF]
    x = tmp[A + B:]

    a = [0] * Q
    d = lambda a, b: abs(a - b)

    for i in range(Q):

        n = x[i]

        si = bisect.bisect_right(s, n)
        a1 = s[si - 1]
        a2 = s[si]

        ti = bisect.bisect_right(t, n)
        b1 = t[ti - 1]
        b2 = t[ti]

        ans = d(n, a1) + min(d(a1, b1), d(a1, b2))
        ans = min(ans, d(n, a2) + min(d(a2, b1), d(a2, b2)))
        ans = min(ans, d(n, b1) + min(d(b1, a1), d(b1, a2)))
        ans = min(ans, d(n, b2) + min(d(b2, a1), d(b2, a2)))
        a[i] = ans

    print('\n'.join(map(str, a)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 37540
#include <stdio.h>

int main(void) {
	int a, b;
	for (a = 1; a < 10; a++)
	{
		for (b =1; b < 10; b++)
		{
			printf("%dx%d=%d\n", a, b, a * b);
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include "bits/stdc++.h"
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)
typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> cnt(N + 1);
    Rep(i, N) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    int kind = 0;
    Rep(i, N + 1) {
        if (cnt[i]) kind++;
        else cnt[i] = 10000000;
    }
    Sort(cnt);
    int ans = 0;
    Rep(i, kind - K) {
        ans += cnt[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3988
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] arg) {
		int N = sc.nextInt();
		int K = sc.nextInt();
		int T = sc.nextInt();
		int U = sc.nextInt();
		int V = sc.nextInt();
		int L = sc.nextInt();
		int[] D = new int[N];
		for (int i = 0; i < N; ++i) {
			D[i] = sc.nextInt();
		}
		int pos = 0;
		double time = 0;
		double dist = 0;
		double bootEnd = -1;
		int carrot = 0;
		while (true) {
			if (bootEnd < 0) {
				if (carrot > 0) {
					--carrot;
					bootEnd = dist + T * V;
				} else {
					if (pos < N) {
						time += (D[pos] - dist) / U;
						dist = D[pos];
						++pos;
						++carrot;
					} else {
						time += (L - dist) / U;
						break;
					}
				}
			} else {
				if (pos < N) {
					if (bootEnd < D[pos]) {
						time += (bootEnd - dist) / V;
						dist = bootEnd;
						bootEnd = -1;
					} else {
						time += (D[pos] - dist) / V;
						dist = D[pos];
						if (carrot == K) {
							bootEnd = D[pos] + T * V;
						} else {
							++carrot;
						}
						++pos;
					}
				} else {
					if (bootEnd < L) {
						time += (bootEnd - dist) / V;
						dist = bootEnd;
						bootEnd = -1;
					} else {
						time += (L - dist) / V;
						break;
					}
				}
			}
		}
		System.out.println(time);
	}

}

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

int main(){
	int n;
	cin >> n;
	if(n == 1)cout << "Hello World" << endl;
	else{
		int a,b;
		cin >> a >> b;
		cout << a + b << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

ll inf=(ll)2e18;
const int mod=1000000007;
//const int mod=998244353;

int n,m;
const int N=2e5+10;

ll ho[1<<16][16],ver[1<<16][16];
ll dp[1<<16];

struct node{
    ll x, y;
    ll p;
};
int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int q,t,k,u,v;
    ll x,a,b,c,d,y,p,z;
    cin >> n;
    vector<node> vv(16);
    for(int i=0; i<n; i++){
        cin >> vv[i].x >> vv[i].y >> vv[i].p;
    }
    for(int i=0; i<1<<n; i++){
        for(int j=0; j<n; j++){
            ho[i][j]=abs(vv[j].y);
            ver[i][j]=abs(vv[j].x);
        }
        for(int j=0; j<n; j++){
            if(i>>j&1){
                for(int k=0; k<n; k++){
                    ho[i][k]=min(ho[i][k],abs(vv[k].y-vv[j].y));
                    ver[i][k]=min(ver[i][k],abs(vv[k].x-vv[j].x));
                }
            }
        }
    }
    vll ans(16,inf);
    for(int i=0; i<1<<n; i++){
        for(int j=i; j>=0; j=(j-1)&i){
            int p=j;
            vll mn(15,inf);
            for(int k=0; k<n; k++){
                mn[k]=min({mn[k],ho[p][k],ver[i^p][k]});
            }
            a=0;
            for(int k=0; k<n; k++){
                a+=vv[k].p*mn[k];
            }
            ans[__builtin_popcount(i)]=min(ans[__builtin_popcount(i)],a);
            if(!j){
                break;
            }
        }
    }
    for(int i=0; i<n; i++){
        cout << ans[i] << ' ';
    }
    cout << 0 << el;
    return 0;
}






Measured memory_bytes: 11816
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	string s;
	while(cin>>s){
		int J=0,I=0;
		rep(i,0,s.size()-2){
			if(s[i]=='J'&&s[i+1]=='O'&&s[i+2]=='I') J++;
			if(s[i]=='I'&&s[i+1]=='O'&&s[i+2]=='I') I++;
		}
		o(J); o(I);
	}
}

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

int main() {
    ll N,M;
    cin >> N >>M;
    vector<pair<ll,ll>> X;
    for(int i=0;i<N;i++){
        ll a,b;
        cin >> a >>b;
        --a;
        X.emplace_back(a,b);
    }
    sort(X.begin(),X.end());
    priority_queue<ll> pq;
    ll t=0;
    ll ans =0;
    for(int i=0;i<M;i++){
        while(t<N &&X[t].first == i){
            pq.push(X[t].second);
            t++;
        }
        if(!pq.empty()){
            int a = pq.top();pq.pop();
            ans +=a;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3568
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main(void){
    map<int, int> exist;
    int X, N; cin >> X >> N;
    while (N--){
        int p; cin >> p;
        exist[p] = 1;
    }
    for (int i = 0; ; ++i){
        if (!exist[X - i]){
            cout << (X - i) << endl;
            return 0;
        }
        if (!exist[X + i]){
            cout << (X + i) << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;

string deduplicate(string a) {
    sort(a.begin(),a.end());
    auto itr=unique(a.begin(),a.end());
    a.resize(itr-a.begin());
    return a;
}

vector<string> sdeduplicate(vector<string> a) {
    sort(a.begin(),a.end());
    auto itr=unique(a.begin(),a.end());
    a.resize(itr-a.begin());
    return a;
}

int main() {
    string s;
    int k;
    cin >> s;
    cin >> k;
    string t=s;
    int n=s.size();
    sort(t.begin(),t.end());
    string b=deduplicate(t);
    int cnt=k;
    rep(i,b.size()){
        vector<string> ans;
        rep(j,n) {
            if (s[j]==b[i]) {
                string tans;
                int u=min(n-j,k);
                rep(l,u) {
                    tans.push_back(s[j+l]);
                    ans.push_back(tans);
                }
            }
        }
        vector<string> aans=sdeduplicate(ans);
        if (aans.size()<cnt) cnt-=aans.size();
        else {
            cout << aans[cnt-1] << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1788
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, M, A[123];

int main() {

	cin >> N >> M;
	rep(i, N) cin >> A[i];

	int cnt = 0;
	double sum = 0;
	rep(i, N) sum += A[i];

	rep(i, N) if (A[i] >= sum / 4 / M) cnt++;

	if (cnt >= M)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main(){
  string t;
  cin>>t;
  for(int i=0;i<t.size();i++){
    if(t[i]=='?'){
      t[i]='D';
    }
  }
  for(int i=0;i<t.size();i++){
    cout<<t[i];
  }
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define esort(s) sort((s).begin(),(s).end())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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

    int N;cin>>N;
    vector<ll> A(N,0);
    rep(i,N){
        cin>>A[i];
    }

    ll zero,one,digit;
    ll sum=0;
    digit=1;
    // bool flag=true;
    // while(flag){
    rep(j,65){
        // flag=false;
        zero=one=0;
        rep(i,N){
            // if(A[i]!=0) flag=true;
            // cout<<A[i]<<"("<<(A[i]&1)<<") ";
            if(A[i]&1) ++one; 
            else ++zero;
            A[i]=(A[i]>>1);
        }
        sum+=(((one*zero)%1000000007)*digit)%1000000007;
        sum%=1000000007;
        // cout <<"one:"<<one<<" zero:"<<zero<<" digit:"<<digit<< "\n";
        digit*=2;
        digit%=1000000007;
    }
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 2560
a,b=[str(i) for i in input().split()]
list1=["1","3","5","7","8","10","12"]
list2=["4","6","9","11"]
if a in list1 and b in list1:
  print('Yes')
elif a in list2 and b in list2:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

using Weight = int;

// 重み付きの辺
struct Edge {
    int from, to;
    Weight weight;

    Edge() {}
    Edge(int to) : from(-1), to(to), weight(-1) {}
    Edge(int from, int to) : from(from), to(to), weight(-1) {}
    Edge(int from, int to, Weight weight) : from(from), to(to), weight(weight) {}

    bool operator<(const Edge& e) const {
        return (weight != e.weight) ? (weight < e.weight) : (from < e.from);
    }
    bool operator>(const Edge& e) const {
        return (weight != e.weight) ? (weight > e.weight) : (from > e.from);
    }
};

using Arc = Edge;
using Graph = vector<vector<Edge>>;
using DGraph = vector<vector<Arc>>;

using Tree = Graph;

// 最初に初期化することを忘れないように!
using GArray = vector<Weight>;
using GMatrix = vector<GArray>;

// この4つの関数は頂点数を固定したバージョンでも動く
void add_edge(Graph& g, int u, int v, Weight w = -1) {
    g[u].push_back(Edge(u, v, w));
    g[v].push_back(Edge(v, u, w));
}

void add_arc(DGraph& dg, int u, int v, Weight w = -1) {
    dg[u].push_back(Arc(u, v, w));
}

const int GM_INF = (1LL << 25);

void init_gmatrix(GMatrix& gm) {
    for (int u = 0; u < gm.size(); u++) {
        for (int v = 0; v < gm[u].size(); v++) {
            gm[u][v] = GM_INF;
        }
    }
}

void add_edge(GMatrix& gm, int u, int v, Weight w = -1) {
    gm[u][v] = w;
    gm[v][u] = w;
}

void add_arc(GMatrix& gm, int u, int v, Weight w = -1) {
    gm[u][v] = w;
}

Graph graph;

bool from[300000], to[300000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    graph = Graph(N);

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        add_edge(graph, a, b);
    }

    for (Edge& e : graph[0]) {
        from[e.to] = true;
    }

    for (Edge& e : graph[N - 1]) {
        to[e.to] = true;
    }

    for (int v = 1; v < N - 1; v++) {
        if (from[v] && to[v]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 13928
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  string str;
  cin>>str;
  sort(str.begin(),str.end());
  bool flag = 1;
  for (int i = 0; i < str.size()-1; i++)
  {
    if(str[i] == str[i+1]) flag = 0;
  }

  cout<<(flag?"yes":"no")<<endl;
  
  return; 
}


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

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define nn 500000

typedef struct nnode_tbl{
	int k;
	int p;
	int l;
	int r;
} nnode;

const int nil=-1;
nnode t[nn];
int root;
int room;
int ix;

int tmin(int u){
  while (t[u].l!=nil)u=t[u].l;
	return u;
}

int find(int u, int k){
	while (u!=nil && k!=t[u].k){
		if (k<t[u].k)u=t[u].l;
		else u=t[u].r;
	}
	return u;
}

int trees(int u){
	if (t[u].r!=nil){
		return tmin(t[u].r);
  }
	int y=t[u].p;
	while (y!=nil && u==t[y].r){
		u=y;
		y=t[y].p;
	}
	return y;
}

void delete(int z){
	int y;
	int x;
	if (t[z].l == nil || t[z].r == nil)y = z;
	else y = trees(z);
	if (t[y].l!=nil)x=t[y].l;
	else{
		x=t[y].r;
  }
	if (x!=nil) t[x].p=t[y].p;
	if (t[y].p == nil)root=x;
	else{
		if (y==t[t[y].p].l){
			t[t[y].p].l=x;
    }
		else{
			t[t[y].p].r=x;
    }
	}
	if (y!=z)t[z].k=t[y].k;
	t[y].r=room;
	room=y;
}

void insert(int k){
	int z;
	int y = nil;
	int x = root;
	if (room==nil) z=ix++;
	else{
		z=room;
		room=t[room].r;
	}
	t[z].k=k;
	t[z].l=nil;
	t[z].r=nil;
	while (x!=nil){
		y=x;
		if (t[z].k<t[x].k)x=t[x].l;
		else x = t[x].r;
	}
	t[z].p=y;
	if (y==nil)root=z;
	else{
		if (t[z].k<t[y].k)t[y].l=z;
		else t[y].r = z;
	}
}

void inorder(int u){
	if (u==nil)return;
	inorder(t[u].l);
	printf(" %d", t[u].k);
	inorder(t[u].r);
}

void preorder(int u){
	if (u == nil) return;
	printf(" %d", t[u].k);
	preorder(t[u].l);
	preorder(t[u].r);
}

int main(int argc, char** argv){
	char com[8];
	int n;
	int x;
	int i;
	root=nil;
	room=-1;
	ix=0;
	scanf("%d", &n);
	for (i=0 ; i<n; i++){
		scanf("%s", com);
		switch (com[0]){
		case 'd':
			scanf("%d", &x);
			delete(find(root, x));
			break;

		case 'f':
			scanf("%d", &x);
			printf("%s\n", find(root, x) != nil ? "yes" : "no");
			break;

		case 'i':
			scanf("%d", &x);
			insert(x);
			break;

		case 'p':
		default:
			inorder(root);
			printf("\n");

			preorder(root);
			printf("\n");
			break;
		}
	}
  return 0;
}



Measured memory_bytes: 7988
from collections import deque

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

dic = []
que = deque()
for i in range(1, N+1):
    que.append([i])

while que:
    seq = que.popleft()
    if len(seq) == N:
        dic.append(seq)
        continue
    else:
        for i in range(1, N+1):
            if i in seq:
                continue
            seq_next = seq + [i]
            que.append(seq_next)

for i in range(len(dic)):
    if P == dic[i]:
        a = i
    if Q == dic[i]:
        b = i
print(abs(a-b))

Measured memory_bytes: 14944
#include <stdio.h>

int main (int argc, char *argv[]) {
	int a[3], i, j5 = 0, j7 = 0;
	scanf("%d %d %d[^\n]", &a[0], &a[1], &a[2]);
	for (i = 0; i < 3; i++) {
		if (a[i] == 5) j5++;
		else if (a[i] == 7) j7++;
	}
	if (j5 == 2 && j7 == 1) printf("YES\n");
	else printf("NO\n");
	return 0;
}


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

using namespace std;

int main(){
	int a,b,n,c;
	int d[10000];
	int sorts;
	int best,bests;
	cin>>n;
	cin>>a>>b;
	cin>>c;
	for(int i=0;i<n;i++){
		cin>>d[i];
	}
    for (int i=0;i<n;i++) { 
        for (int j=i+1; j<n; ++j) { 
          if (d[j] > d[i]) { 
            sorts =  d[j]; 
            d[j] = d[i]; 
            d[i] = sorts;
          } 
        } 
    }
	best=a/c;
	for(int i=0;i<n;i++){
		bests=(c+d[i])/(a+b+(b*i));
		c+=d[i];
		if(bests>best)
			best=bests;
		if(bests<=best)
			bests=best;
	}
	cout<<best<<endl;
	return 0;
}

Measured memory_bytes: 1168
while True:
    try:
        data1 = list(map(int, input().split()))
        #print(data1)
        data2 = list(map(int,input().split()))
        #print(data2)
    except:
        break
    
    h = 0
    b = 0
    for i in range(4):
        try:
            if i == data1.index(data2[i]):
                h = h + 1
            else:
                b = b + 1
        except:
            pass
    print('{} {}'. format(h, b))


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


int c[1111],w[1111];
int s[1111];
int sum(int l,int r){
	return s[r] - (l?s[l-1]:0);
}
int dp[1010][1010];
int dfs(int l,int r){
	if( r == l ) return 1;
	if( dp[l][r] != -1 ) return dp[l][r];
	int ans = 0;
	if( sum(l+1,r) <= c[l] ) ans |= dfs(l+1,r);
	if( sum(l,r-1) <= c[r] ) ans |= dfs(l,r-1);
	return dp[l][r] = ans;
}

int dp2[1010];
int N;

int dfs2(int x){
	if( x == N ) return 0;
	if( dp2[x] != -1 ) return dp2[x];
	int ans = 1e9;
	for(int i = x ; i < N ; i++)
		if( dfs(x,i) )
			ans = min(ans,dfs2(i+1)+1);
	return dp2[x] = ans;
}
int main(){
	memset(dp2,-1,sizeof(dp2));

	memset(dp,-1,sizeof(dp));
	cin >> N;
	for(int i = 0 ; i < N ; i++){
		cin >> c[i] >> w[i];
		s[i] = (i?s[i-1]:0)+w[i];
	}
	cout << dfs2(0) << endl;
}

Measured memory_bytes: 5212
#include <iostream>
#include <string>
#include <vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main(){
  int N, X, T;
  cin >> N >> X >> T;
  int count = N  / X + (N % X == 0 ? 0 : 1);
  cout << T * count << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    int i;
    for(i=0; i<N; i++) cin >> h.at(i);
    sort(h.begin(), h.end());
    int d = 1000000000;
    for(i=0; i<N-K+1; i++){
        if(d > h.at(i+K-1) - h.at(i)) d = h.at(i+K-1) - h.at(i);
    }
    cout << d << endl;
}

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

int dp[61][61][3001];

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> A(N+1),R(K+1),B(K+1);
    int sumA = 0,sumR = 0,sumB = 0;
    for(int i=1;i<=N;i++){
        cin >> A[i];
        sumA += A[i];
    }
    for(int i=1;i<=K;i++){
        cin >> R[i];
        sumR += R[i];
    }
    for(int i=1;i<=K;i++){
        cin >> B[i];
        sumB += B[i];
    }
    sort(A.begin()+1,A.end(),greater<int>());
    sort(R.begin()+1,R.end(),greater<int>());
    sort(B.begin()+1,B.end(),greater<int>());
    for(int i=0;i<=N;i++) for(int j=0;j<=N;j++) for(int k=0;k<=3000;k++) dp[i][j][k] = 1e9;
    dp[0][0][0] = 0;
    for(int i=1;i<=N;i++){
        for(int j=0;j<=i;j++){
            int rid = j,bid = i-j;
            for(int k=0;k<=3000;k++){
                if(1<=rid && rid<=K && k+A[i]<=3000){
                    dp[i][rid][k+A[i]] = min(dp[i][rid][k+A[i]],dp[i-1][rid-1][k]+max(0,A[i]-R[rid]));
                }
                if(1<=bid && bid<=K){
                    dp[i][i-bid][k] = min(dp[i][i-bid][k],dp[i-1][i-bid][k]+max(0,A[i]-B[bid]));
                }
            }
        }
    }
    int inf = 1e9;
    int res = inf;
    for(int j=0;j<=N;j++){
        for(int k=0;k<=3000;k++){
            int useR = k,useB = sumA-k;
            if(useR<=sumR && useB<=sumB) res = min(res,dp[N][j][k]);
        }
    }
    cout << (res!=inf? res:-1) << endl;
}


Measured memory_bytes: 46776
n,t = map(int,input().split())
ct=[]
for _ in range(n):
    ct.append(list(map(int,input().split())))
ct = sorted(ct,key=lambda x:x[0])
for i in range(n):
    if ct[i][1]<=t:
        print(ct[i][0])
        exit()
print("TLE")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

void print_a(VI v)
{
    if(v.size()) cout<<v[0];
    loop(i,1,v.size()) cout<<' '<<v[i];
    cout<<'\n';
}

VVI init_vvi(int n, int m, int val)
{
    return VVI(n,VI(m,val));
}

VVL init_vvl(int n, int m, LL val)
{
    return VVL(n,VL(m,val));
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n, k;
    cin>>n>>k;
    int a[n];
    loop(i,0,n) cin>>a[i];
    sort(a,a+n);
    int ans = 0;
    loop(i,0,k) ans += a[i];
    cout<<ans<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n) cin>>a[i];
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n) cin>>a[i];
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define repa(i, a, b) for (auto i = (a); i <= (b); i++)
#define repd(i, a, b) for (auto i = (a); i >= (b); i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define zero(a)  memset((a), 0, sizeof (a))
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back

constexpr auto inf = numeric_limits<int>().max();
constexpr auto llinf = numeric_limits<ll>().max();

template<typename ForwardIterator>
void dump(ForwardIterator st, ForwardIterator en) {
	for (auto it = st; it != en; it++) {
		cout << *it << " ";
	}
	cout << endl;
}

template<typename ForwardIterator>
void dump_map(ForwardIterator st, ForwardIterator en) {
	for (auto it = st; it != en; it++) {
		cout << (*it).first << ":" << (*it).second << " ";
	}
	cout << endl;
}

template<typename T>
void debug(initializer_list<T> list) {
  for (auto el : list) {
    cout << el << " ";
  }
  cout << endl;
}

void solve() {
  int n;
  cin >> n;
  map<int, int> nums;
  vi a(n);
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];
    nums[a[i]]++;
    sum += a[i];
  }
  int q, b, c;
  cin >> q;
  rep(i, q) {
    cin >> b >> c;
    auto cnt = nums[b];
    sum -= (ll) cnt * (ll) b;
    sum += (ll) cnt * (ll) c;
    cout << sum << "\n";
    nums[b] -= cnt;
    nums[c] += cnt;
  }
}

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


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


void solve(long long L){
    double ans = pow(static_cast<double>(L) / 3.0 , 3);
    printf("%lf\n", ans);
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long L;
    scanf("%lld",&L);
    solve(L);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cctype>

#define rep(i,start,n) for(int i=start;i<n;i++)                 //??????????????????

using namespace std;

int main(){

  int count=0;
  string word,sent;

  cin >> word ;                //???????????§?????????????????????

  rep(i , 0 , word.length()){                                  // ???????????????
    if(isupper(word[i])){
      word[i] = tolower(word[i]);                        //??????????°????????????????
    }
  }

  while(cin >> sent){                                      //???????????\???
    if(sent == "END_OF_TEXT") break;                       //?????????????????????
    rep(i , 0 , sent.length()){                         //??????????°??????????????????????????????????????????????
      if(isupper(sent[i])){
        sent[i] = tolower(sent[i]);
      }
    }
    if(word == sent){
      count++;                            //???????????????????????°?????????????????????
    }
  }

  cout << count << endl;

  return 0;

}

Measured memory_bytes: 1192
fun main(args: Array<String>) {
    abc065b()
}

fun abc065b() {
    val n = readLine()!!.toInt()
    val aList = (1..n).map { readLine()!!.toInt() - 1 }

    var curr = 0
    var cnt = 0
    for (i in aList.indices) {
        curr = aList[curr]
        cnt++
        if (curr == 1) break
    }

    val answer = if (curr == 1) cnt else -1

    println(answer)
}


Measured memory_bytes: 39048
(N, ) = [int(n) for n in input().split()]

l = 1
d = 26
N -= 1
while d <= N:
    N -= d
    d *= 26
    l += 1
    
ans = []
for _ in range(l):
    ans.append(N % 26)
    N //= 26

print(''.join(chr(ord('a')+a) for a in reversed(ans)))

    

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    ll N;
    cin >> N;
    vector<ll> v(N);
    ll minnum = 1e8;
    ll maxnum = -1e8;
    ll sum = 0;
    rep(i, N) { cin >> v[i];
        minnum = min(v[i], minnum);
        maxnum = max(v[i], maxnum);
        sum += v[i];
    }

    printf("%ld %ld %ld\n", minnum, maxnum, sum);
    // cout << minnum << " " << maxnum << " " << sum << endl;
}



Measured memory_bytes: 3236