akhauriyash/Code-Regression huggingface dataset:
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#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>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
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;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int M, N, width[110];
int dp[110][110][25];

signed main() {
    while(cin >> M >> N, M) {
        fill(dp[0][0], dp[N][N], INF);
        for(int i=0; i<N; i++) {
            cin >> width[i];
        }

        for(int i=0; i<N; i++) {
            int sum = 0;
            for(int j=i; j<N; j++) {
                sum += width[j];
                dp[i][j+1][1] = sum;
            }
        }

        for(int d=2; d<=N; d++) {
            for(int l=0; l<N-d+1; l++) {
                int r = l + d;
                int mi = INF;
                for(int m=2; m<=M; m++) {
                    chmin(dp[l][r][m], mi);
                    for(int k=l+1; k<r; k++) {
                        for(int p=1; p<m; p++) {
                            int vl = dp[l][k][p  ];
                            int vr = dp[k][r][m-p];
                            chmin(dp[l][r][m], max(vl, vr));
                        }
                    }
                    chmin(mi, dp[l][r][m]);
                }
            }
        }
        cout << dp[0][N][M] << endl;
    }
    return 0;
}


Measured memory_bytes: 3964
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

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

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

    set<int> se;
    rep(i, k) {
        se.insert(p[i]);
    }
    int ans = 1;
    int now = 0;
    bool uu = true;
    rep(i, n-1) {
        if(p[i] < p[i+1]) now++;
        else {
            int x = now-k+2;
            if(x>0) {
                ans--; 
                if(uu) {
                    ans++;
                    uu = false;
                }
            }
            now = 0;
        }
    }
    int x = now-k+2;
    if(x>0) {
        ans--;
        if(uu) ans++;   
    }


    rep(i, n-k) {
        if(p[i] != *se.begin() or p[i+k] < *se.rbegin()) ans++;
        se.erase(p[i]);
        se.insert(p[i+k]); 
    }

    cout << ans << endl;
} 

Measured memory_bytes: 10368
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    int N;
    int L[11];
    int sum=0;
    int max_side = 0;
    cin >> N;
    rep(i,N){
        cin >> L[i];
        max_side = max(max_side,L[i]);
        sum = sum + L[i];
    }
    sum = sum - max_side;
    string answer = (sum > max_side) ? "Yes" : "No";
    cout << answer << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;



// 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 N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    
    vector<bool> flags(N,true);
    rep(i,M){
        int a,b;
        cin >>a >>b;
        a--;b--;
        if(H[a]<=H[b])flags[a]=false;
        if(H[b]<=H[a])flags[b]=false;
    }
    int ans=0;
    rep(i,N)if(flags[i])ans++;
    cout<<ans<<endl;
    return 0;
    
    
    return 0;
}


Measured memory_bytes: 4056
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
Main();
function Main(){
  var one = nextIntArray();
  var A = one[0];
  var B = one[1];
  var C = one[2];
  var list = getCommonDivisorList(A,B);
  list.sort(function(a,b){
  	return b - a;
  });
  myout(list[C - 1]);
}
function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}
function getCommonDivisorList(val1, val2){
        var list = [];
        var tmpGcd = gcd(val1,val2);
        for(var i = 1; i * i <= tmpGcd; i++){
                if(val1 % i == 0 && val2 % i == 0){
                        list.push(i);
                        if(i * i != tmpGcd){
                                list.push(tmpGcd / i);
                        }
                }
        }
        list.sort(function(a,b){ return a - b; });
        return list;
}

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#include <vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 1005
#define MOD 1000000007
#define INF 1000000000000000000
#define EPS 0.0000000001
#define CHAINS 18
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
int main()
{
    int n,i;
    scanf("%d",&n);
    long long A[n];
    long long sum=0,ans=0;
    for(i=0;i<n;i++)
    {
        scanf("%lld",&A[i]);
        ans=(ans+sum*A[i])%MOD;
        sum=(sum+A[i])%MOD;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 5420
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define all(v) v.begin(),v.end()
#define fi first
#define se second
const int inf = 1e9;
int mod = 1e9+7;

int Pow(int x, int k){
	int res = 1;
	while(k > 0){
		if(k&1)res = (x*res)%mod;
		x = (x*x)%mod;
		k >>= 1;
	}
	return res;
}

int a[1002];
signed main(){
	int n;
	scanf("%lld", &n);
	repi(i,2,n+1){
		int x= i;
		repi(j,2,x+1){
			while(x%j == 0){a[j]++;x /= j;}
		}
	}
	int ans = 1;
	rrep(i,n)if(a[i])ans = (ans*(a[i]+1))%mod;
	printf("%lld\n", ans);
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll MOD = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll a,b,h,m;
    cin>>a>>b>>h>>m;
    double rad=2*pi*(
        h/12.0 + (m/60.0)/12.0 - m/60.0
    );
    double ans=sqrt(a*a+b*b-2*a*b*cos(rad));
    printf("%.10lf\n",ans);
    return 0;
}

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


void solve(std::string s){
    for(int i = 0; i < s.size(); ++i){
        if(i % 2 == 0) cout << s[i];
    }
    cout << endl;
}

int main(){
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


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

int main() {
	int n,a,b,c;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b>>c;
		if(a>b&&a>c){
			if(b*b+c*c==a*a){
				cout<<"YES\n";
			}
			else{
				cout<<"NO\n";
			}
		}
		else if(b>a&&b>c){
			if(a*a+c*c==b*b){
				cout<<"YES\n";
			}
			else{
				cout<<"NO\n";
			}
		}
		else if(c>a&&c>b){
			if(a*a+b*b==c*c){
				cout<<"YES\n";
			}
			else{
				cout<<"NO\n";
			}
		}
		else{
			cout<<"NO\n";
		}
	}
}


Measured memory_bytes: 1124
for i in range(int(input())):
    n,k=map(int,input().split())
    l=[int(i) for i in input().split()]
    dif=sorted([l[i+1]-l[i] for i in range(n-1)])
    if k==1:
        print(sum(dif))
    else:
        print(max(0,sum(dif[:-k+1])))


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

int main() {
  vector<char>raw(5);
  for(int i = 0;i<4;i++){
    cin >> raw.at(i);
  }
  if(raw.at(0)==raw.at(1) && raw.at(1)==raw.at(2))
    cout<<"Yes"<<endl;
  
  else if(raw.at(1)==raw.at(2) && raw.at(2)==raw.at(3))
    cout<<"Yes"<<endl;
  
  else
    cout<<"No"<<endl;
      
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        char[] S = sc.next().toCharArray();

        int countRed = 0;
        int countBlue = 0;
        for(int i = 0; i < S.length; i++){
            if('0' == S[i]){
                countRed++;
            }
        }
        for(int i = 0; i < S.length; i++){
            if('1' == S[i]){
                countBlue++;
            }
        }

        System.out.println(Math.min(countRed,countBlue)*2);

    }
}

Measured memory_bytes: 30608
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    vi a(n);
    rep(i, n) cin >> a[i];
    int m = -INF;
    rep(i, n) {
      int c = 0;
      loop(j, i, n) {
        c += a[j];
        cmax(m, c);
      }
    }
    cout << m << endl;
  }
}

Measured memory_bytes: 3012
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>

using namespace std;

int main(){

	int n, k, ans=0;


	cin >> n >> k;
	int s[n];
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	sort(s,s+n);
	for(int i = k; 0 < i; i--){
		ans += s[n-i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N, L = map(int,input().split(" "))
Sum=0
if L >= 0:
    for i in range(2,N+1):
        Sum += (L + i -1)
else:
    if (L + N - 1)>0:
        for i in range(1,N+1):
            Sum += (L + i -1)
    else:
        for i in range(1,N):
            Sum += (L + i -1)
print(Sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 using namespace std;
 
int main(){
  int n=0,m=0,c=0;
  cin>>n>>m>>c;
  vector<int> b(m);
  vector<vector<int>> a(n,vector<int> (m));
  for(int i=0;i<m;i++){
   cin>>b.at(i); 
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
        cin>>a.at(i).at(j); 
    }
  }
  
  int count=0;
  for(int i=0;i<n;i++){
    int sum=0;
    for(int j=0;j<m;j++){
      sum+=a.at(i).at(j)*b.at(j);
    }
    if(sum+c>0) count++;
  }
  cout<<count;
}

Measured memory_bytes: 256
from collections import Counter
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = Counter(A)
values, counts = zip(*A.most_common())
counts = list(counts)
ans = 0

while K < len(counts):
  ans += counts[-1]
  counts.pop(-1)

print(ans)

Measured memory_bytes: 52244
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

n = load()
A = load_list()
B = load_list()

cnt = 0
for i in range(n):
    diff = min(B[i], A[i])
    A[i] -= diff
    cnt += diff
    B[i] -= diff
    diff = min(B[i], A[i+1])
    A[i+1] -= diff
    cnt += diff
    B[i] -= diff
print(cnt)
     


Measured memory_bytes: 19008
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int n,k,s,ans;

void dfs(int q,int sum,int now)
{
	if(sum > s)return;
	
	if(q == k)
	{
		if(sum == s)ans++;
		return;
	}
	
	for(int i = now;i <= n;i++)
	{
		dfs(q+1,sum+i,i+1);
	}
}

int main()
{
	while(cin>>n>>k>>s,n|k|s)
	{
		ans = 0;
		dfs(0,0,1);
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3008
package main
 
import (
	"fmt"
)
 
func main() {
	var S string
	fmt.Scanf("%s", &S)
	
	var N int = len(S)
	
	var A string = S[0:(N-1)/2]
	var B string = S[((N+3)/2)-1:N]
	
	// fmt.Printf(A)
	 //	 fmt.Printf(B)
	if(A!=B){
	    fmt.Printf("No")
	    return
	}
	
	for i:=0; i<len(A); i++{
	    if A[i:i] == A[len(A)-i:len(A)-i]{
	       
	    }else{
	        fmt.Printf("No")
	       return  
	    }
	}

     fmt.Printf("Yes")
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int, int>;
constexpr array<int, 4> dx = {1, 0, -1, 0};
constexpr array<int, 4> dy = {0, 1, 0, -1};
constexpr int INF = 1234567890;
constexpr int MOD = 1000000000 + 7;
// constexpr int MOD = 998244353;
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;
}
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int fact(int n) { return n > 1 ? n * fact(n - 1) % MOD : 1; }
int modinv(int a)
{
    int b = MOD, u = 1, v = 0;
    while (b)
    {
        int t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= MOD;
    if (u < 0)
        u += MOD;
    return u;
}
constexpr int modpow(int a, int n)
{
    int rtn = 1;
    while (n > 0)
    {
        if (n & 1)
            rtn = rtn * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return rtn;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    int n, m;
    string s;
    cin >> n >> m;
    cin >> s;

    int pos = n;
    vector<int> ans;
    // ゴールからスタートまで移動する
    // 出目の列を辞書順にするために，できるだけたくさんのマスを超えて戻るように貪欲的に移動する
    while (pos > 0)
    {
        // ルーレット 大きい出目から調べる
        for (int i = m; i >= 0; i--)
        {
            // i=0 は移動できるマスが無いことを意味する
            // 不可能判定する処理
            if (i == 0)
            {
                pos = -1;
                ans = {-1};
                break;
            }
            const int npos = pos - i; // 移動後のマス
            // 移動先が0なら移動
            if (npos >= 0 && s[npos] == '0')
            {
                pos = npos;
                ans.push_back(i);
                break;
            }
        }
    }

    // 答え出力 逆順
    for (int i = ans.size() - 1; i >= 0; i--)
    {
        cout << ans[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1480
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

#define DEBUG(x) cerr << #x << ": " << x << endl

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

int N;
vector<string> res;
void go(const string& s, int d) {
   if (SZ(s) == N) {
      res.push_back(s);
      return;
   }

   // use one of previous letters
   for (int i = 0; i < d; ++i)
      go(s + char('a'+i), d);

   // new letter
   go(s + char('a' + d), d+1);
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   cin >> N;

   go("", 0);

   sort(res.begin(), res.end());
   for (string s : res)
      cout << s << '\n';

   return 0;
}


Measured memory_bytes: 7796
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
using namespace std;

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef pair<int,int> pint;
typedef vector<pint> vping;

#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

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


int N,M, cnt;
bool tree[8][8];
bool vst[8];


void dfs(int v, int num){
  if(num == N){
    cnt++;return;
  }
  rep(i,N){
    if(tree[v][i] && !vst[i]){
      vst[i] = true;
      dfs(i, num+1);
      vst[i] = false;
    }
  }
}



int main() {
  rep(i,8) vst[i]=false;

  cin >> N >> M;
  rep(i,M){
    int a,b;
    cin >> a >> b;
    a--;b--;
    tree[a][b] = true;
    tree[b][a] = true;
  }

  vst[0] = true;
  dfs(0,1);


  cout << cnt << endl;



}


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

int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  
  for (int i = 0; i < s.size(); ++i) {
    int c = s[i] - 'A';
    c = (c + N) % 26;
    s[i] = 'A' + c;
  }
  cout << s << endl;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        Console.WriteLine(n * n);
    }
}


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


int main(){
    long long X, Y, ans=1;
    cin >>X >> Y;
    
    while(1){
        X = X * 2;
        if(X >Y) break;
        ans++;
    }
   
    
    cout << ans << endl;
    return 0;
}
    

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

int main() {
  int n; cin >> n;
  map<string,int>mp;
  vector<string>vec;
  rep(i,n){
    string s;
    cin >> s;
    mp[s]++;
    vec.push_back(s);
  }
  sort(vec.begin(),vec.end());
  vec.erase(unique(vec.begin(),vec.end()),vec.end());
  int m=0;
  rep(i,vec.size()){
    if(m<mp[vec[i]])m=mp[vec[i]];
  }
  
  vector<string>ans;
  for(auto itr=mp.begin();itr!=mp.end();itr++){
    if(itr->second==m)ans.push_back(itr->first);
  }
  sort(ans.begin(),ans.end());
  rep(i,ans.size()){
    cout<<ans[i]<<endl;
  }
  
}

Measured memory_bytes: 28400
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
class Node {
public:
    Node(int x, int y, int times) :x(x), y(y), times(times) {}
    int x;
    int y;
    int times;
    bool operator <(const Node& n) const {
        return this->times > n.times;
    }
};
int m, n, startx, starty, endx, endy;
priority_queue<Node> pq;
char matrix[3005][3005];
int vis[3005][3005];
//int cnt[3005][3005];
int dx[4] = { 0,0,-1,1 };
int dy[4] = { -1,1,0,0 };
void bfs(Node start, Node end) {
    pq.push(start);
    while (!pq.empty()) {
        Node top = pq.top();
        if (top.x == end.x && top.y == end.y) {
            cout << top.times << endl;
            return;
        }
        for (int i = 0; i < 4; i++) {
            int newX = top.x + dx[i];
            int newY = top.y + dy[i];
            if (newX > 0 && newX <= m && newY>0 && newY <= n && matrix[newX][newY] == '.' && vis[newX][newY]>top.times) {
                vis[newX][newY] = top.times;
                pq.emplace(Node(newX, newY, top.times));
            }
        }
        for (int i = top.x - 2; i <= top.x + 2; i++)
            for (int j = top.y - 2; j <= top.y + 2; j++) {
                if (matrix[i][j] == '.' && vis[i][j]>top.times+1 && i > 0 && i <= m && j>0 && j <= n) {
                    vis[i][j] = top.times+1;
                    pq.emplace(Node(i, j, top.times + 1));
                }
            }
        pq.pop();
        //cout << pq.size() << endl;
    }
    cout << -1 << endl;
    return;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> m >> n;
    cin >> startx >> starty >> endx >> endy;
    Node start(startx, starty, 0), end(endx, endy, 0);
    memset(vis, 0x7f, sizeof(vis));
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++) {
            cin >> matrix[i][j];
        }
    vis[startx][starty] = 0;
    bfs(start, end);
    return 0;
}

Measured memory_bytes: 41772
#include <bits/stdc++.h>
using namespace std;
int n, m;
int p[100001], y[100001];
vector<int> v[100001];
int main() {
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        p[i] = a;
        y[i] = b;
    }
    for (int i = 0; i < 100001; i++) {
        sort(v[i].begin(), v[i].end());
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        a = p[i];
        b = y[i];
        b = int(lower_bound(v[a].begin(), v[a].end(), b) - v[a].begin()+1);
        printf("%06d%06d\n", a, b);
    }

    return 0;
}


Measured memory_bytes: 7808
#include <iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int g,s,q,w;
	int ans=0;
	for(int i=a;i<=b;i++)
	{
		g=i%10;
		s=i%100/10;
		q=i/1000%10;
		w=i/10000;
		if(g==w&&s==q)
		ans++;
	}
	cout<<ans;
	return 0;
}
  

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

long long d[1<<20];
int main(){
	int n, w;
	cin >> n >> w;
	fill(d + 1, d + (1<<20)+1, (1LL<<50));
	
	for(int i = 0; i < n; i++){
		int ww , vv;
		cin >> ww >> vv;
		for(int j = (1<<20); j >= vv; j--){
			d[j] = min(d[j], d[j-vv] + ww);
		}
	}for(int i = (1<<20); i >= 0; i--){
		if(d[i] <= w){
			cout << i <<"\n";
			return 0;
		}
	}
}


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

#define int long long

int n;
int stage[21][21];
int dp[1000000];

void solve() {
    int to = (1<<n);
    for(int i=0; i<to+2; ++i) dp[i] = 1e+9;
    dp[0] = 0;

    for(int i=0; i<to; ++i) {
        if(dp[i]==1e+9) continue;
        for(int j=0; j<n; ++j) {
            if((i&(1<<j)) != 0) continue;
            int min_cost = stage[j][0];
            for(int k=0; k<n; ++k) {
                if((i&(1<<k)) != 0) min_cost = min(min_cost, stage[j][k+1]);
            }
        int bit = (i | (1<<j));
        dp[bit] = min(dp[bit], dp[i]+min_cost);
        }
    }
    cout << dp[to-1] << endl;
}

signed main()
{
    while(cin>>n, n) {
        for(int i=0; i<n; ++i) {
            for(int j=0; j<n+1; ++j) cin >> stage[i][j];
        }
        solve();
    }
    return 0;
}

Measured memory_bytes: 3608
from collections import deque

N, M = map(int, input().split())
P = list(map(int, input().split()))
G = [[] for i in range(N)]
check, group = [0 for j in range(N)], [-1 for k in range(N)]


def bfs(s, no):
    check[s] = group[P[s]] = no
    q = deque()
    q.append(s)

    while len(q) != 0:
        u = q.popleft()
        for v in G[u]:
            if check[v] == 0:
                check[v] = no
                group[P[v]] = no
                q.append(v)


def main():
    for i in range(M):
        x, y = map(int, input().split())
        G[x-1].append(y-1)
        G[y-1].append(x-1)

    for i in range(N):
        P[i] -= 1

    cnt = 1
    for i in range(N):
        if check[i] == 0:
            bfs(i, cnt)
            cnt += 1

    ans = 0
    for i in range(N):
        if check[i] == group[i]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


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

using i8   = int8_t;
using u8   = uint8_t;
using i16  = int16_t;
using u16  = uint16_t;
using i32  = int32_t;
using u32  = uint32_t;
using i64  = int64_t;
using u64  = uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;

using f32  = float;
using f64  = double;
using f80  = __float80;
using f128 = __float128;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'000LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

// {{{ util
#define FOR(i, start, end) for(i64 i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cc) { return (f)(begin(cc), end(cc), ## __VA_ARGS__); })(c))

template<typename T, typename U>
bool chmax(T& xmax, const U& x) {
    if(xmax < x) {
        xmax = x;
        return true;
    }
    else {
        return false;
    }
}

template<typename T, typename U>
bool chmin(T& xmin, const U& x) {
    if(x < xmin) {
        xmin = x;
        return true;
    }
    else {
        return false;
    }
}

template<typename T>
void RD(T& x) {
    cin >> x;
#ifdef PROCON_LOCAL
    assert(cin);
#endif
}

template<typename T>
void RD(vector<T>& v, int n) {
    v.reserve(n);
    REP(_, n) {
        T e; RD(e);
        v.emplace_back(e);
    }
}

template<typename T>
void PRINT(const T& x) {
    cout << x;
}

template<typename T>
void PRINT(const vector<T>& v) {
    for(auto first = begin(v), it = first; it != end(v); ++it) {
        if(it != first)
            cout << ' ';
        cout << *it;
    }
}

template<typename T>
void PRINTLN(const T& x) {
    PRINT(x);
    cout << '\n';
}

template<typename T>
void DBG_IMPL(i64 line, const char* expr, const T& value) {
#ifdef PROCON_LOCAL
    cerr << "[LINE " << line << "]: ";
    cerr << expr << " = " << value << "\n";
#endif
}

#define DBG(expr) DBG_IMPL(__LINE__, #expr, (expr))
// }}}

//--------------------------------------------------------------------

i64 A, B, C;

void solve() {
    i64 ans = min(C, B/A);

    PRINTLN(ans);
}

signed main() {
    RD(A);
    RD(B);
    RD(C);

    solve();

    return 0;
}


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


int main()
{
	int n, m;
	cin >> n >> m;
	int sum = 0;
	for (int i = 0; i < m; i++) {
		int a_in;
		cin >> a_in;
		sum += a_in;
	}

	int ans = n - sum;
	if (ans < 0) {
		ans = -1;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;

class Program {
    static void Main(string[] args) {

        string[] a = Console.ReadLine().Split(' ');
        int a1 = int.Parse(a[0]);
        int a2 = int.Parse(a[1]);
        int a3 = int.Parse(a[2]);

        string result = "bust";


        if (a1 + a2 + a3 <= 21) result = "win";

        Console.WriteLine(result);
    }
}

Measured memory_bytes: 13140
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
eat_bef=0
ans=0
for i in range(len(a)):
    ans+=b[a[i]-1]
    if i>=1:
        if eat_bef+1==a[i]:
            ans+=c[eat_bef-1]
    eat_bef=a[i]
print(ans)


Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<ll> > vvll;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
int main() {
	char ch;
  cin>>ch;
  if(ch>='A' && ch<='Z')
  {
    cout<<"A";
  }
  else
  {
    cout<<"a";
  }
	return 0;
}


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

#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

int solve(int y,vector <vector <int> >& g,vector <int>& dp){
	if(dp[y]>=0) return dp[y];
	int mx = 0;
	for(int i=0;i<(int)g[y].size();i++){
		mx=max(mx,1+solve(g[y][i],g,dp));
	}
	dp[y]=mx;
	return mx;
}
int main(){
	int n,m;
	cin>>n>>m;
	vector <vector <int> > g (n+1,vector <int > ());
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		g[y].push_back(x); // x-->y
		}
	vector <int> dp (n+1,-1);
	int ans=0;
	for(int i=1;i<=n;i++){
		dp[i]=solve(i,g,dp);
		ans=max(ans,dp[i]);
		}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 12160
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <string.h>
#include <map>
#include <iomanip>
#include <time.h>
using namespace std;
typedef long long ll;

int main() {
    int n, W;
    ll w[105], v[105], inf = 1e18;
    cin >> n >> W;
    for (int i = 0; i < n; i++) cin >> w[i] >> v[i];

    ll dp[105][100100];
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= 100000; j++) dp[i][j] = inf;
    }
    
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= 100000; j++) {
            if (j - v[i] >= 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }

    ll ans = 0;
    for (int i = 0; i <= 100000; i++) {
        if (dp[n][i] <= W) ans = i;
    }
    cout << ans << endl;

}

Measured memory_bytes: 81152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int>As(M);
    map<int,bool>mp;
    for(int i=0; i<M; i++){
        int ai;
        cin >> ai;
        mp[ai] = true;
    }
    int cost = 0;
    int cost2 = 0;
    for (int i=X; i<=N; i++){
        if (mp[i])cost++;
    }
    for (int i=X; i>=0; i--){
        if(mp[i])cost2++;
    }
    cout << min(cost, cost2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
typedef long long ll;


int main(){
  int n;
  cin >> n;
  if(n == 25) cout << "Christmas"<< endl;
  else if(n == 24) cout << "Christmas Eve" << endl;
  else if(n == 23)  cout << "Christmas Eve Eve" << endl;
  else if(n ==22) cout << "Christmas Eve Eve Eve" << endl;
  return 0;
}


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

int triple_max(int x, int y, int z){
    int ans = x;
    if (y > x && y > z) ans = y;
    else if (z > x && z > y) ans = z;

    return ans;
}

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b) cout << c << endl;
    else if (a == c) cout << b << endl;
    else cout << a << endl;


    return 0;
}



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

using namespace std;

const int MAX_N = 220, MAX_LOG = 20;

int n, m, sum[MAX_N][MAX_N], dp[2][MAX_N][MAX_N][MAX_N];
char str[MAX_N][MAX_N];

bool check(int i, int j, int l, int r)
{
    int acc = sum[j][r] - sum[i - 1][r] - sum[j][l - 1] + sum[i - 1][l - 1];
    return acc == 0 || acc == 1LL * (j - i + 1) * (r - l + 1);
}

int calc(int p, int i, int j, int k)
{
    int l = i, r = j - 1, res = 0;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        res = max(res, min(dp[p][i][mid][k], dp[p][mid + 1][j][k]));
        if (dp[p][i][mid][k] < dp[p][mid + 1][j][k])
            r = mid - 1;
        else
            l = mid + 1;
    }
    return res;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%s", str[i] + 1);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (str[i][j] == '#');
    if (check(1, n, 1, m))
        puts("0"), exit(0);
    for (int i = 1; i <= n; i++)
        for (int j = i; j <= n; j++)
            for (int k = 1, acc; k <= m; k = acc)
            {
                acc = k;
                while (acc <= m && check(i, j, k, acc))
                    acc++;
                for (int p = k; p < acc; p++)
                    dp[0][i][j][p] = acc - 1;
                if (acc == k)
                    dp[0][i][j][k] = k - 1, acc++;
            }
    for (int x = 1;; x++)
    {
        int c = x & 1, pc = !(x & 1);
        for (int i = 1; i <= n; i++)
            for (int j = i; j <= n; j++)
                for (int k = 1; k <= m; k++)
                {
                    int ret = dp[pc][i][j][k];
                    if (ret == m)
                        dp[c][i][j][k] = m;
                    else
                        dp[c][i][j][k] = max(dp[pc][i][j][ret + 1], calc(pc, i, j, k));
                }
        if (dp[c][1][n][1] == m)
            printf("%d\n", x), exit(0);
    }
    return 0;
}

Measured memory_bytes: 34996
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

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

const ll INF = -numeric_limits<ll>::max(),
         MOD = 1e9 + 7;

int MAX;
int n;
vll pre, dp;
ll f(int x, int b = 0) {
    if (b <= 1) return pre[x];
    ll &res = dp[x];
    if (res != INF) return res;
    const int m = 1 << b;
    res = pre[x];
    vii v;
    for (int i = 0; i < n; i++) {
        if (x & (1 << i)) {
            v.emplace_back(i);
            // cerr << i << ' ';
        }
    }
    // cerr << '\n';
    for (int i = 1; i < m; i++) {
        int y = 0, b_ = 0;
        for (int j = 0; j < b; j++) {
            if ((i & (1 << j)) and (x & (1 << v[j]))) 
                y |= (1 << v[j]), b_++;
        }
        if ((x ^ y) < y) continue;
        res = max(res, pre[y] + f(x ^ y, b - b_));
    }
    // cerr << x << ": " << b << ", " << res << '\n';
    return res;
}

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);

    cin >> n;
    MAX = 1 << n;
    
    
    ll arr[n][n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> arr[i][j];
        }
    }
    pre.assign(MAX, 0);
    dp.assign(MAX, INF);
    for (int i = 1; i < MAX; i++) {
        vii v;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) v.push_back(j);
        }
        pre[i] = 0;
        for (int j = 0; j < v.size(); j++) {
            for (int k = j + 1; k < v.size(); k++) {
                pre[i] += arr[v[j]][v[k]];
            }
        }
        // cerr << i << ": " << pre[i] << '\n';
    }
    // cerr << '\n';
    cout << f(MAX - 1, n) << '\n';
}

Measured memory_bytes: 1280
A = []
flag = False
for i in range(3):
    a = list(map(int, input().split()))
    A.append(a)
N = int(input())
for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if b == A[j][k]:
                A[j][k] = 0
                
for i in range(3):
    if A[0][i]+A[1][i]+A[2][i]==0:
        flag = True
    

if sum(A[0])==0 or sum(A[1])==0 or sum(A[2])==0 or A[0][0]+A[1][1]+A[2][2]==0 or A[0][2]+A[1][1]+A[2][0]==0:
    flag = True

if flag == True:
    print('Yes')
else:
    print('No')

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

int main(){
  int N;
  cin >> N;
  
  vector<pair<pair<string, int>, int>> res(N);
  for(int i = 0; i < N; i++){
    string a;int b;
    cin >> a >> b;
    b *= (-1);
    res.at(i) = make_pair(make_pair(a, b), i);
  }
  
  sort(res.begin(), res.end());
  
  for(int i = 0; i < N; i++){
    cout << res.at(i).second + 1 << endl;
  }
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
	int main(){
		int n=0;
		int i=0;
		long long int sum = 0;
		long long int min = 0,x=0;	
		int a[200000];
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(i=0;i<n;i++){
			sum += a[i];
		}
		min = labs(sum - 2*a[0]);
		for(i=0;i<n-1;i++){
			x = x + a[i];
				if( labs(sum - 2*x) < min){
					min = abs(sum - 2*x);
				}
		}
		printf("%d",min);
		return 0;
	}

Measured memory_bytes: 896
l=require('fs').readFileSync(0,'utf8').split('\n')
n=l[0].split(' ').map(n=>parseInt(n))
h=n[0]
w=n[1]
d='#'.repeat(w+2)
r=[d]
for(i=1;i<h+1;i++){r.push(`#${l[i]}#`)}
r.push(d)
console.log(r.join('\n'))

Measured memory_bytes: 17480
# -*- coding: utf-8 -*-
"""
D - Prediction and Restriction
https://atcoder.jp/contests/abc149/tasks/abc149_d

"""
import sys


def solve(N, K, R, S, P, T):
    d = {'r': P, 's': R, 'p': S}
    lost = set()
    ans = 0
    for i, ch in enumerate(T):
        if i < K:
            ans += d[ch]
        else:
            if T[i-K] != ch or i-K in lost:
                ans += d[ch]
            else:
                lost.add(i)
    return ans


def main(args):
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()
    ans = solve(N, K, R, S, P, T)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 6980
#include <iostream>

using namespace std;

int main() {
    long a, b, k;
    cin >> a >> b >> k;

    if (a < k) {
        k -= a;
        a = 0;
        b = (b < k) ? 0 : b-k;
    } else {
        a -= k;
    }

    cout << a << " " << b;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char a,b;
	scanf("%c %c",&a,&b);
	if(a == 'H')
	{
		if(b == 'H')
			printf("H\n");
		else
			printf("D\n");
	}
	else
	{		
		if(b == 'H')
			printf("D\n");
		else
			printf("H\n");
	}
	return 0;
}



Measured memory_bytes: 128
using Yorukatsu025.Questions;
using Yorukatsu025.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu025.Questions
{
    /// <summary>
    /// ABC064 C
    /// </summary>
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var colors = inputStream.ReadIntArray().Select(i => i / 400).ToArray(); // 0 ～ 12, 0～7は固定色

            var colorCount = colors.Where(i => i < 8).Distinct().Count();
            var wildColor = colors.Count(i => i >= 8);
            var min = Math.Max(colorCount, 1);
            var max = colorCount + wildColor;
            yield return $"{min} {max}";
        }
    }
}


namespace Yorukatsu025
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu025.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu025.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13408
while True:
    n, r = map(int, input().split())
    if (n,r) == (0,0):
        break
    else:
        cards = [i for i in range (1, n+1)]
        cards.reverse()
        for i in range (r):
            p,c = map(int,input().split())
            top = cards[0 : p-1]
            mid = cards[p-1 : p+c-1]
            btm = cards[p+c-1:]
            cards = mid + top + btm
        print(cards[0])
        



Measured memory_bytes: 5620
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scanln(&n)

	mochies := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &mochies[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(mochies)))

	below := 999
	count := 0
	for i := 0; i < n; i++ {
		if below > mochies[i] {
			count++
			below = mochies[i]
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int n,k;
  cin>>n>>k;
  int a[n],c;
  int i;
  for(i=0;i<n;i++)
    cin>>a[i];
  c=0;
  for(i=0;i<n;i++)
  {
    if(a[i]>=k)
      c++;
  }
  
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a;
	cin>>a;
	int b[1000];
	int c=0;
	int d=0;
	for(int i=0;i<a;i++){
		cin>>b[i];
	}
	sort(b,b+a);
	reverse(b,b+a);
	for(int i=0;i<a;i++){
		if(i%2==0){
			c=c+b[i];
		}
		else{
			d=d+b[i];
		}
	}
	if(c<d){
		cout<<d-c<<endl;
	}
	else{
		cout<<c-d<<endl;
	}
}


Measured memory_bytes: 256
h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
inf=10**4+2*10**3
dp=[10**8]*(inf)
dp[0]=0
for i in range(inf):
    for j in range(n):
        if i-a[j][0]>=0:
            dp[i]=min(dp[i],dp[i-a[j][0]]+a[j][1])
print(min(dp[h:]))

Measured memory_bytes: 42476