akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
int a[10][10];
void floyd(int n = 10)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> a[i][j];
		}
	}
	for (int k = 0; k < n; k++)
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
			}
		}
	}
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int h, w;
	cin >> h >> w;
	h *= w;
	floyd();
	LL tot = 0;
	while (h--)
	{
		int x;
		cin >> x;
		if (x == -1) continue;
		tot += a[x][1];
	}
	cout << tot << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する

int main(){
    int n;
    cin>>n;
    vector<int64_t> a(n);
    int64_t min = 10000000000;
    int64_t max = 0;
    int64_t sum=0;
    rep(i,n){
        cin>>a[i];
        a[i] -= (i+1);
    }
    all(a);
    int64_t med;
    int64_t ans = 0;
    if(n%2!=0){
        med = a[n/2];
        rep(i,n){
            ans += abs(a[i]-med);
        }
    }
    else{
        int64_t M = 10000000000000000;
        for(int64_t med = a[n/2-1];med<=a[n/2];med++){
            int64_t sad = 0;
            rep(i,n){
                sad += abs(a[i]-med);
            }
            if(sad<M){
                M = sad;
            }
        }   
        ans = M;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
const main = (a,b) => {
    r = []
    r.push(a+b)
    r.push(a-b)
    r.push(a*b)
    return Math.max(...r)
}

const input = require('fs').readFileSync('/dev/stdin','utf8').split('\n')[0].split(" ")
const ab = input.map(x => parseInt(x,10))
console.log(main(ab[0],ab[1]))


Measured memory_bytes: 7372
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n!=0){
    int cnt=0,tmp;
    for(int i=1;i<n;i++){
      for(int j=i+1;j<n;j++){
        tmp = ((i+j)*(j-i+1))/2;
        if(tmp==n)cnt++;
        else if(tmp>n)break;
      }
    }
    cout << cnt << endl;
    cin >>n;
  }
}



Measured memory_bytes: 3064
import math

A, B = map(int, input().split())

while B > 0:
    A, B = B, A % B
N = A

ans = 1
for i in [2] + list(range(3, int(math.sqrt(N)) + 2, 2)):
    if N % i == 0:
        while N % i == 0:
            N //= i
        ans += 1
if N > 1:
    ans += 1
print(ans)


Measured memory_bytes: 26996
#include<stdio.h>

int main(void)
{
	int a,b,c;
	int i = 0;
	int check = 0;
	scanf("%d",&check);
	while(i < check){
		scanf("%d %d %d",&a,&b,&c);
		if(a*a + b*b == c*c){
			printf("YES\n");
		}else if(b*b + c*c == a*a){
			printf("YES\n");
		}else if(c*c + a*a == b*b){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
		i++;
	}

	return 0;
}


Measured memory_bytes: 1928
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n, q;
int a[100000];
int x[100000];
long long sumt[100001];
long long sum[100000];


pair<int, int> draw(int x, int k) {
	// 最大の差
	int lb = -1, ub = a[n - 1];
	while (ub - lb > 1) {
		int mid = (lb + ub) / 2;
		int le = lower_bound(a, a + n, x - mid) - a;
		int ri = upper_bound(a, a + n, x + mid) - a;

		if (ri - le >= k)ub = mid;
		else lb = mid;
	}

	int diff = ub;
	int le = lower_bound(a, a + n, x - diff) - a;
	int ri = upper_bound(a, a + n, x + diff) - a;
	if (ri - le > max(1, k) && x - a[le] == a[ri - 1] - x) {
		ri--;
	}
	return make_pair(le, ri); // [le,ri)
}

//にぶたん用軽量版
bool check(int x, int k) {
	if (k == 0)return true;
	int tail = a[n - k];
	int ri = n - k;
	int le = upper_bound(a, a + n, x - abs(tail - x)) - a;
	return le < ri && k <= ri - le;
}

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

	cin >> n >> q;
	rep(i, n)cin >> a[i];
	rep(i, q)cin >> x[i];

	sort(a, a + n);

	rep(i, n)sum[i] = a[i];
	for (int i = 2; i < n; i++)sum[i] += sum[i - 2];

	rep(i, n)sumt[i] = a[i];
	for (int i = n - 2; i >= 0; i--)sumt[i] += sumt[i + 1];

	rep(i, q) {
		int X = x[i];

		int lb = 0, ub = n;
		//高橋君が何枚衝突するまでにとれるか
		while (ub - lb > 1) {
			int mid = (lb + ub) / 2;

			/*auto p = draw(X, mid);

			if (p.second <= n - mid)lb = mid;
			else ub = mid;*/

			if (check(X, mid))lb = mid;
			else ub = mid;
		}

		
		int k = lb;
		long long ans = sumt[n - k];
		auto p = draw(X, k);
		if (p.second == n) {
			ans += sum[n - 1];
		}
		else if (p.second == n - k) {
			if (p.first >= 0)ans += sum[p.first - 1];
		}
		else {
			ans += a[p.second];
			if (p.first >= 2)ans += sum[p.first - 2];
		}
		cout << ans << endl;
	}



	return 0;
}

Measured memory_bytes: 4096
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws IOException {

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int a = Integer.parseInt(br.readLine());
	System.out.println(a + (a * a) + (a * a * a));
    }

}

Measured memory_bytes: 32444
#include<cstdio>
int main(){
	char c;
	scanf("%c",&c);
	if (c>='a' && c<='z'){
		if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
			printf("vowel\n");
        	else printf("consonant\n");
	return 0;}
}

Measured memory_bytes: 128
import sys
from pprint import pprint
import bisect

N, M, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))

ans = 0
max_read = N + M

S_a = [0 for _ in range(N+1)]
S_b = [0 for _ in range(M+1)]
for i in range(N):
    S_a[i+1] = A[i] + S_a[i]
for i in range(M):
    S_b[i+1] = B[i] + S_b[i]
# print(S_a)
# print(S_b)

ans = 0
for i in range(N+1):
    # A を i冊読んだ時、その時よめるBの最大値を二分探索
    sum_t = S_a[i]
    if sum_t > K:
        continue
    # print(K - sum_t)
    b_index = bisect.bisect_right(S_b, K - sum_t)
    # print(i, b_index)
    ans = max(ans, i + b_index - 1)
    
print(ans) 

Measured memory_bytes: 133344
/*
 * Created by Dipta Das on 20-04-2019
 * Title: 
 * Problem Link: 
 * Editorial: 
 * Source Code: 
 * Comments: 
*/

#include <bits/stdc++.h>
#include <stdio.h>
#define fin freopen("input", "r", stdin)
#define whatis(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

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

    int n;
    int k;
    string s;

    cin >> n;
    cin >> s;
    cin >> k;


    for (int i = 0; i < n; ++i) {
        if (s[i] != s[k - 1] && i != k - 1) {
            s[i] = '*';
        }
    }
    cout << s << endl;

    


    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define multitest 0
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pqgreater(x) x, vector<x>, greater<x>
const ll mod=998244353;
int solve();
int main(){ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	if(multitest) cin>>t;
	while(t--) solve();
	return 0;
}
int solve(){
	int n; string s; cin>>n>>s;
	if(s.size()<=n) cout<<s<<endl;
	else{
		for(int i=0; i<n; i++) cout<<s[i];
		cout<<"...\n";
	}
	return 0;
}

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

int main() {
  char c;
  cin >> c;
  if (c == 'a' | c == 'i' | c == 'u' | c == 'e' | c == 'o') {
    cout << "vowel" << endl;
  }
  else cout << "consonant" << endl;
}

Measured memory_bytes: 3640
import sys
from itertools import accumulate

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


def solve(A):
    ans = 0
    s = A[0]
    for a in A[1:]:
        prev, s = s, s + a
        if prev > 0 and s >= 0:
            ans += s + 1
            s = -1
        if prev < 0 and s <= 0:
            ans += -s + 1
            s = 1

    return ans


def main():
    N, *A = map(int, read().split())

    a0 = A[0]

    ans1 = 0
    if A[0] <= 0:
        ans1 = -A[0] + 1
        A[0] = 1
    ans1 += solve(A)

    A[0] = a0

    ans2 = 0
    if A[0] >= 0:
        ans2 = A[0] + 1
        A[0] = -1
    ans2 += solve(A)

    print(min(ans1, ans2))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 20292
<?php
fscanf(STDIN, '%d', $n);
$cnt = 0;
$arr = [];
for ($i  = 0; $i < $n; $i++) {
    $s = str_split(trim(fgets(STDIN)));
    sort($s);
    $s = implode('', $s);
    if (array_key_exists($s, $arr)) {
        $arr[$s]++;
        $cnt += $arr[$s] - 1;
    } else {
        $arr[$s] = 1;
    }
}
echo $cnt.PHP_EOL;

Measured memory_bytes: 13048
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100001

typedef struct{
  char name[100];
  int t;
}P;

P Q[MAX];
int head=0, tail=0, n,q;

int isEmpty(){
  if(head==tail) return 1;
  return 0;
}

int isFull(){
  if(head==((tail+1)%MAX)) return 1;
  return 0;
}

void enqueue(char name[],int time){
  if(isFull()) printf("error\n");
  strcpy(Q[tail].name,name);
  Q[tail].t = time;
  if((tail+1)==MAX) tail=0;
  else tail++;
}

P dequeue(){
  if(isEmpty()) printf("error\n");
  P x = Q[head];
  if((head+1)==MAX) head=0;
  else head++;
  return x;
}

void line(){
  int total=0;
  while(!isEmpty()){
    if(Q[head].t>q){
      Q[head].t-=q;
      P tmpc=dequeue();
      enqueue(tmpc.name,tmpc.t);
      total+=q;
    }else{
      total+=Q[head].t;
      printf("%s %d\n",Q[head].name,total);
      dequeue();
    }
  }
}

int main()
{
  int elaps = 0, c;
  int i;
  P u;
  scanf("%d %d", &n, &q);


  scanf("%d%d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s%d",Q[i].name,&Q[i].t);
    enqueue(Q[i].name,Q[i].t);
  }
  line();
  return 0;
}



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

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

    int ans = 0;
    rep(i, N) {
        if (i == A[A[i]])
            ans++;
    }

    cout << ans / 2 << endl;

    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#define puba push_back
#define ff first
#define ss second
#define bend(_x) begin(_x), end(_x)
#define szof(_x) ((int) (_x).size())
#define TASK_NAME ""

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const ll INFL = 1e18 + 123;
const double PI = atan2(0, -1);

mt19937 tw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(tw) % (y - x + 1) + x; }

const int MAXN = 2e5 + 5;
int amount[26];
char buf[MAXN];

int main() {
    //freopen(TASK_NAME ".in", "r", stdin);
    //freopen(TASK_NAME ".out", "w", stdout);
    cerr << fixed << setprecision(15);
    cout << fixed << setprecision(15);
    
    scanf("%s", buf);
           
    for (int i = 0; buf[i]; ++i) {
        amount[buf[i] - 'a']++;
    }                    

    ll ans = 1;

    for (int i = 0; i < 26; ++i) {
        for (int j = i + 1; j < 26; ++j) {
            ans += (ll) amount[i] * amount[j];
        }
    }
    
    cout << ans << "\n";
    
    #ifdef LOCAL
        cerr << "time: " << clock() << endl;
    #endif
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>
#include<cmath>
#include<deque>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

int main(){
    deque<char> deq;
    string S;
    cin>>S;
    ll Q;
    cin>>Q;
    rep(i,0,S.size()){
        deq.PB(S[i]);
    }
    int rev =0;
    rep(i,0,Q){
        int j;
        cin>>j;
        if(j == 1){
            rev ++ ;
        }
        else if(j == 2){
            int F;
            char C;
            cin>>F;
            cin>>C;
            if(F == 1 && rev %2 == 0){
                deq.push_front(C);
            }
            else if(F == 1 && rev %2 == 1){
                deq.PB(C);
            }
            else if(F == 2 && rev %2 == 0){
                deq.PB(C);
            }
            else{
                deq.push_front(C);
            }
        }
    }
    if(rev% 2 == 1){
        reverse(deq.begin(),deq.end());
    }
    rep(i,0,deq.size()){
        cout<<deq[i];
    }

    return 0;
}

Measured memory_bytes: 896
import random
from copy import deepcopy

d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(d)]
"""
def min_max(l):
    l_min = min(l)
    l_max = max(l)
    return [1+(i-l_min)/(l_max-l_min) for i in l]

dd = [max(s[i]) for i in range(d)]
qq = min_max(c)
dd = min_max(dd)

ddd = [i for i in range(d)]
qqq = [i for i in range(26)]
"""
ans = []
last = [0]*26
for i in range(d):
    ma_po = -10**10
    ma_di = 0
    for j in range(26):
        po = s[i][j]
        for k in range(26):
            if k == j:
                continue
            po -= c[k]*(i+1-last[k])
        if po > ma_po:
            ma_po = po
            ma_di = j
    last[ma_di] = i+1
    ans.append(ma_di+1)

def score(l):
    lastd = [0]*26
    point = 0
    for j,k in enumerate(l):
        kk = k-1
        point += s[j][kk]
        lastd[kk] = j+1
        for l in range(26):
            point -= c[l]*(j+1-lastd[l])
    return point

ma = score(ans)

def random_search():
    global ans,ma
    li = deepcopy(ans)
    D = random.randrange(d)
    Q = random.randrange(26)
    li[D] = Q+1
    if score(li) > ma:
        ans = deepcopy(li)
        ma = score(li)

for i in range(25000):
    random_search()

for i in ans:
    print(i)

Measured memory_bytes: 90260
#include <iostream>
#include <cstdio>

using namespace std;

int main(void) {
    int n = 0, m = 0, a, b, c;
    while (scanf("%d,%d,%d", &a, &b, &c) != EOF) {
        if (a * a + b * b == c * c) n++;
        else if (a == b) m++;
    }
    cout << n << endl;
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 1208
require 'pp'

N = readline.chomp.to_i
PI = readline.chomp.split.map(&:to_i)

ans = 0
(PI.size-2).times do |i|
  if PI[i] < PI[i+1] and PI[i+1] < PI[i+2]
    ans += 1
  elsif PI[i] > PI[i+1] and PI[i+1] > PI[i+2]
    ans += 1
  end
end

puts ans


Measured memory_bytes: 2044
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=10010010010010010

for i in range(1<<n-1):
  if bin(i).count("1")!=k-1:
    continue
  cnt=0
  cost=0
  #print("cnt i",i)
  prevh=a[0]
  for j in range(n-1):
    if 1<<j & i:
      if prevh>=a[j+1]:
        cost+=prevh+1-a[j+1]
        prevh+=1
        #print("cost",j,cost)
      else:
        prevh=a[j+1]
    else:
      prevh=max(prevh,a[j+1])
  ans=min(ans,cost)
  #print("ans",ans)
print(ans)

Measured memory_bytes: 9160
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(X, A);
  print((X < A) ? 0 : 10);
  return 0;
}

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

int main() {
	string str;
	int N,Q;
	cin >> N >> Q >> str;
	vector<int> ac(N);
	ac[0] = 0;
	for (int i = 1; i < N; i++) {
		if (str[i-1] == 'A' && str[i] == 'C') {
			ac[i] = ac[i-1] + 1;
		}
		else {
			ac[i] = ac[i-1];
		}
	}
	for (int i = 0; i < Q; i++) {
		int a,b;
		cin >> a >> b;
		a--; b--;
		int head,end,offset;
		if(a == 0 || ac[a-1] == ac[a]) { 
			head = ac[a];
			offset = 0;
		}
		else { 
			head = ac[a] - 1;
			offset = 1;
		}
		end = ac[b];
		cout << end - head - offset << endl;
	}
	return 0;
}


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

using namespace std;


int main()
{
	int n; cin >> n;
	string s; cin >> s;
	string tmp = s;
	sort(s.begin(), s.end());
	int ans = 0;
	for(int i = 0; i < (int)s.size(); i++){
		ans += tmp[i] != s[i];
	}
	cout << (ans+1)/2;
}


Measured memory_bytes: 3828
def sort():
    li= list(map(int, input().split()))
    len_li = len(li)
    for i in range(len_li):
        for j in range(len_li-1):
            if li[j] > li[j+1]:
                li[j], li[j+1] = li[j+1], li[j]
    print(' '.join(map(str, li)))


if __name__ == "__main__":
    sort()



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, x, count=0;
  cin >> N >> x;
  vector<int> a(N);
  REP(i,N) {
    cin >> a[i];
  }
  sort ALL(a);
  REP(i,N) {
    if(a[i]<=x) {
      x-=a[i];
      count++;
    }
    else break;
    if(i==N-1 && 0<x) count--;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
# include<iostream>
# include<algorithm>
# include<cctype>
# include<cstdio>
# include<cstring>
# include<cmath>
using namespace std;
int main()
{
      int r, d, x;
      cin >> r >> d >> x;
      for (int i=0; i<10; i++)
      {
            x = r*x-d;
            cout << x << endl;
      }
      return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int h = Integer.parseInt(sc.next());
    int w = Integer.parseInt(sc.next());
    char[][] map = new char[h][w];
    int[][] dist = new int[h][w];
    Queue<Pair> queue = new ArrayDeque<>();
    for(int i=0;i<h;i++){
      map[i] = sc.next().toCharArray();
      for(int j=0;j<w;j++){
        dist[i][j] = -1;
        if(map[i][j] == '#'){
          dist[i][j] = 0;
          queue.add(new Pair(i,j));
        }
      }
    }
    int[][] vec = {{1,0},{-1,0},{0,1},{0,-1}};
    int ans = 0,size,yto,xto;
    Pair p;
    while(!queue.isEmpty()){
      ans++;
      size = queue.size();
      for(int i=0;i<size;i++){
        p = queue.poll();
        for(int j=0;j<4;j++){
          yto = p.y + vec[j][0];
          xto = p.x + vec[j][1];
          if(yto>=0 && yto<h && xto>=0 && xto <w && dist[yto][xto]==-1 &&
             map[yto][xto] == '.'){
            dist[yto][xto] = ans;
            queue.add(new Pair(yto,xto));
          }
        }
      }
    }
    System.out.println(ans-1);
    
  }
}
class Pair{
  int x;
  int y;
  public Pair(int y,int x){
    this.x = x;
    this.y = y;
  }
}

Measured memory_bytes: 69552
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N,K=get_i
l=get_i.sort!{|x,y| y<=>x}
puts l[0..K-1].inject(:+)

Measured memory_bytes: 1916
s = input()[::-1]
t = input()[::-1]

def match(string,substring):
    for a,b in zip(string, substring):
        if a == '?':
            continue
        if a != b:
            return False
    return True

# なるべく後方で一致させる
LEN_S = len(s)
LEN_T = len(t)
ans = ''
for i in range(LEN_S - LEN_T + 1):
    sub = s[i:i+LEN_S]
    if match(sub, t):
        ans = s[:i] + t + s[i+LEN_T:]
        ans = ans[::-1].replace('?', 'a')
        break
else:
    print('UNRESTORABLE')
    exit()

print(ans)

Measured memory_bytes: 9140
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef pair < int , int > Pi;
typedef pair < int , Pi > Pii;
#define fr first
#define sc second

int M, N, D, ns, nc, nj;
char temp['z'+1],o;
int mas[20][20];
int go[20][20][20][20];
bool used[20][20][101];
Pi S, G;
int dy[] = { 0, 1, 0, -1}, dx[] = { -1, 0, 1, 0};

bool isover(int y, int x){
  return y < 0 || y >= M || x < 0 || x >= N;
}

bool isred(int y, int x, int time, bool istate){
  if(mas[y][x] == -1) return false; //そもそも信号がない
  const int kankaku = mas[y][x];
  if(istate) return time / kankaku % 2;
  else return !(time / kankaku % 2);
}

int Dijkstra(){
  fill_n(**used, 20 * 20 * 101, false);
  priority_queue< Pii , vector< Pii > , greater< Pii > > que;
  que.push(Pii( 0, S)); //時間,座標
  while(!que.empty()){
    Pii p = que.top();
    que.pop();
    if(p.sc == G) return p.fr; //ごーるついた
    if(used[p.sc.fr][p.sc.sc][p.fr]++) continue;
    for(int i = 0 ; i < 4 ; i++ ){
      int ny = p.sc.fr + dy[i], nx = p.sc.sc + dx[i];
      if(isover(ny,nx)) continue; //そといった
      if(go[p.sc.fr][p.sc.sc][ny][nx] == -1) continue; //工事中
      int nexttime = p.fr + D + go[p.sc.fr][p.sc.sc][ny][nx];
      if(isred(ny, nx, nexttime, i % 2)) continue; //交差点に侵入不可
      que.push(Pii(nexttime, Pi( ny, nx)));
    }
  }
  return -1;
}


int main(){

  for(int i = 'a', j = 1 ; i <= 'z' ; i++, j++ ){ //まっぷてきなかんじ
    temp[i] = j;
  }


  while( cin >> M >> N, M){

    fill_n(*mas, 400, -1);
    fill_n(***go, 20 * 20 * 20 * 20, 0);

    cin >> D;
    cin >> ns;
    for(int i = 0 ; i < ns ; i++ ){
      char h;
      int v, k;
      cin >> h >> o >> v >> k;
      mas[temp[h] - 1][v - 1] = k;
    }

    cin >> nc;
    for(int i = 0 ; i < nc ; i++ ){
      char h1, h2;
      int v1, v2;
      cin >> h1 >> o >> v1 >> h2 >> o >> v2; //入力面倒くさいね
      go[temp[h1] - 1][v1 - 1][temp[h2] - 1][v2 - 1] = -1;
      go[temp[h2] - 1][v2 - 1][temp[h1] - 1][v1 - 1] = -1;
    }

    cin >> nj;
    for(int i = 0 ; i < nj ; i++ ){
      char h1, h2;
      int v1, v2, d;
      cin >> h1 >> o >> v1 >> h2 >> o >> v2 >> d;
      go[temp[h1] - 1][v1 - 1][temp[h2] - 1][v2 - 1] = d;
      go[temp[h2] - 1][v2 - 1][temp[h1] - 1][v1 - 1] = d;
    }

    char h1, h2;
    int v1, v2;
    cin >> h1 >> o >> v1 >> h2 >> o >> v2;
    S = Pi( temp[h1] - 1, v1 - 1);
    G = Pi( temp[h2] - 1, v2 - 1);

    cout << Dijkstra() << endl;
  }
}

Measured memory_bytes: 1888
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    long long n,t,ans=0,s[200005];
    cin>>n>>t;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    for(int i=0;i<n;i++){
        if(s[i]+t>=s[i+1] && i!=n-1){
            ans+=s[i+1]-s[i];
        }
        else{
            ans+=t;
        }
    }
    cout<<ans<<endl;
    return(0);
}

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

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

  for (int i = 0; i < n.size(); i++) {
    if (n.at(i) == '1') n.at(i) = '9';
    else if (n.at(i) == '9') n.at(i) = '1';
  }
  cout << n << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readP(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public void readP(String str) {
		String[] strArr = str.split("\\s+");
		int cnt = 0;
		for (int i = 1; i < N - 1; i++) {
			int a = Integer.parseInt(strArr[i - 1]);
			int b = Integer.parseInt(strArr[i]);
			int c = Integer.parseInt(strArr[i + 1]);
			if ((a < b && b < c) || (a > b && b > c))
				cnt++;
		}
		System.out.println(cnt);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 23252
import math

# input
#
# n = 5
# k = 10
# a = [1, 2, 3, 2, 3]

n, k = map(int, input().split())
a = [int(ai) for ai in input().split()]

# make jumpto
#
# 0 -> 6 (6)
# 1 -> 4 (3)
# 2 -> 5 (3)
# 3 -> 7 (4)
# 4 -> 8 (4)

jumpto = [[-1] * n]
la = -1
li = -1
for (ca, ci) in sorted(zip(a, range(n))):
    if ca == la:
        jumpto[0][ci] = jumpto[0][li] + li - ci
        jumpto[0][li] = ci - li + 1
    else:
        jumpto[0][ci] = n + 1
    la = ca
    li = ci

# doubling jumpto
#
# 0 -> 6 ->  9 (9)
# 1 -> 4 ->  8 (7)
# 2 -> 5 -> 11 (9)
# 3 -> 7 -> 10 (7)
# 4 -> 8 -> 12 (8)
#
# 0 -> 6 ->  9 -> 13 -> 17 (17)
# 1 -> 4 ->  8 -> 12 -> 15 (14)
# 2 -> 5 -> 11 -> 14 -> 18 (16)
# 3 -> 7 -> 10 -> 16 -> 19 (16)
# 4 -> 8 -> 12 -> 15 -> 21 (17)

levels = int(math.log(k, 2))
for l in range(1, levels + 1):
    jumpto.append([-1] * n)
    for i in range(n):
        f = jumpto[l - 1][i]
        s = jumpto[l - 1][(i + f) % n]
        jumpto[l][i] = f + s

# step1 and step2
ret = []
s = 0
while s < n * k:
    jumped = False
    for l in range(levels, -1, -1):
        if s + jumpto[l][s % n] <= n * k:
            s += jumpto[l][s % n]
            jumped = True
            break
    if not jumped:
        ret.append(str(a[s % n]))
        s += 1

print(' '.join(ret))


Measured memory_bytes: 121940
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  string s;
  cin >>n>> s;
  
  bool flg=1;
  for(int i=0; i<s.size()/2; i++){
    flg=0;
   if(s[i]!=s[i+s.size()/2]){
     flg=1; break;
   }
  }
  if(s.size()%2!=0) flg=1;
  if(flg) cout << "No" << endl;
  else cout << "Yes" << endl;
  
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX=1e9;

int main(){
	int k;
	cin>>k;
	ll a[k];
	REP(i,k){
		cin>>a[i];
	}
	ll retmin=2;
	ll retmax=2;
	for(int i=k-1;i>=0;i--){
		//retmin:=retmin~retmaxでa[i]の倍数
		retmin+=a[i]-1;
		retmin-=retmin%a[i];
		//retmax:=
		retmax-=retmax%a[i];
		retmax+=a[i]-1;
		if(retmax<retmin){
			cout<<-1<<endl;
			return 0;
		}
		
	}
	cout<<retmin<<" "<<retmax<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c;
  cin >> a >> b >> c;

  c -= (a + b);
  if (c > 0 && 4 * a * b < c * c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){

    int x;
    cin >> x;
    if (x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

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

int main(){
    ll k; cin >> k;
    queue<ll> que;
    rep(i, 9) que.push(i+1);
    ll cnt = 0, x = 0;
    while(cnt != k){
        x = que.front(); que.pop();
        if(x%10 != 0) que.push(10*x + x%10 - 1);
        que.push(10*x + x%10);
        if(x%10 != 9) que.push(10*x + x%10 + 1);
        cnt++;
    }
    cout << x << endl;
    return 0;
}

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

signed main(){
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if(a + b + c >= 22){
		printf("bust\n");
	}
	else{
		printf("win\n");
	}
	return 0;
}

Measured memory_bytes: 3684
n = int(input())
a = [0] * 12
for i in range(11,0,-1):
    m = n // 26 ** i
    a[i] = m
    n -= m * (26 ** i)
a[0] = n
for i in range(11, - 1, - 1):
    if a[i] == 0:
        a.pop(i)
    else:
        break
b = "abcdefghijklmnopqrstuvwxyz"
c = []
for i in range(len(a)):
    if i == len(a) - 1 and a[i] == 0:
        break
    elif i != len(a) - 1 and a[i] == 0:
        a[i] = 26
        a[i + 1] -= 1
    elif i != len(a) - 1 and a[i] == - 1:
        a[i] = 25
        a[i + 1] -= 1
    c.append(b[a[i] - 1])
c.reverse()
print(*c, sep="")


Measured memory_bytes: 9164
#include <bits/stdc++.h>
#include <ios>
#include <iomanip>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

// 最大公約数
long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
// 最小公倍数
long long lcm(long long a, long long b) {
  return a / gcd(a, b) * b;
}

// x^y%p
long long modpow(long long x, long long y, long long p=1) {
    long long res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0) {
        if (y & 1) res = res * x % p;
        y = y>>1;
        x = x * x % p;
    }
    return res;
}

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

  long long N, K;
  cin >> N >> K;

  long long ans = pow(N / K, 3);
  
  if(K % 2 == 0) {
    ans += pow((N + K / 2) / K, 3);
  }
  cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4052
def selection_sort(A, n):
	count = 0

	for i in range(n-1):
		minj = i
		for j in range(i, n):
			if A[j] < A[minj]:
				minj = j

		if i != minj:
			A[i], A[minj] = A[minj], A[i]
			count += 1

	print(' '.join(map(str, A)))
	print(count)

if __name__ == '__main__':
	n = int(input())
	A = list(map(int, input().split()))

	selection_sort(A, n)

Measured memory_bytes: 7712
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
  vector<int> A(N);
  for(int a = 0;a < N;a++)cin >> A[a];
  long long count = 0;
  for(int a = 0;a < N;a++)count ^= A[a];
  for(int a = 0;a < N;a++)cout << (count ^ A[a]) << " ";
  

  
}

Measured memory_bytes: 3952
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;



int main(void) {
    int n,a,b;
	cin>>n>>a>>b;
	string s;
	cin>>s;
	int pass=0,rank=0;
	int A=0,B=0;
	for(int i=0;i<n;i++){
		if(s[i]=='a'){
			A++;
			if(pass<a+b){
				pass++;
				fin("Yes");
			} else {
				fin("No");
			}
		} else if(s[i]=='b') {
			B++;
			rank++;
			if(pass<a+b&&B<=b){
				pass++;
				fin("Yes");
			} else {
				fin("No");
			}
		} else {
			fin("No");
		}
	}

}



Measured memory_bytes: 896
A=[]
N=int(input())
D,X=map(int,input().split())
A=[int(input()) for i in range(N)]
sum=N

for i in range(1,N+1):
	for j in range(1,999999):
		if D<j*A[i-1]+1:
			break
		else: sum+=1
print(sum+X)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;

int main(){
	string str;

	map<string,string> encode;
	map<string,string> decode;

	encode[" "] = "101";
	encode["'"] = "000000";
	encode[","] = "000011";
	encode["-"] = "10010001";
	encode["."] = "010001";

	encode["?"] = "000001";
	encode["A"] = "100101";
	encode["B"] = "10011010";
	encode["C"] = "0101";
	encode["D"] = "0001";
	encode["E"] = "110";
	encode["F"] = "01001";
	encode["G"] = "10011011";

	encode["H"] = "010000";
	encode["I"] = "0111";
	encode["J"] = "10011000";
	encode["K"] = "0110";
	encode["L"] = "00100";
	encode["M"] = "10011001";
	encode["N"] = "10011110";

	encode["O"] = "00101";
	encode["P"] = "111";
	encode["Q"] = "10011111";
	encode["R"] = "1000";
	encode["S"] = "00110";
	encode["T"] = "00111";
	encode["U"] = "10011100";

	encode["V"] = "10011101";
	encode["W"] = "000010";
	encode["X"] = "10010010";
	encode["Y"] = "10010011";
	encode["Z"] = "10010000";

	decode["00000"] = "A";
	decode["00001"] = "B";
	decode["00010"] = "C";
	decode["00011"] = "D";
	decode["00100"] = "E";
	decode["00101"] = "F";
	decode["00110"] = "G";

	decode["00111"] = "H";
	decode["01000"] = "I";
	decode["01001"] = "J";
	decode["01010"] = "K";
	decode["01011"] = "L";
	decode["01100"] = "M";
	decode["01101"] = "N";

	decode["01110"] = "O";
	decode["01111"] = "P";
	decode["10000"] = "Q";
	decode["10001"] = "R";
	decode["10010"] = "S";
	decode["10011"] = "T";
	decode["10100"] = "U";

	decode["10101"] = "V";
	decode["10110"] = "W";
	decode["10111"] = "X";
	decode["11000"] = "Y";
	decode["11001"] = "Z";

	decode["11010"] = " ";
	decode["11011"] = ".";
	decode["11100"] = ",";
	decode["11101"] = "-";
	decode["11110"] = "'";
	decode["11111"] = "?";

	while(getline(cin,str)){

		string enc="";
		for(int i=0;i<str.size();i++){
			enc+=encode[str.substr(i,1)];
		}

		enc+="0000";

		string dec="";
		for(int i=0;i+5<=enc.size();i+=5){
			dec+=decode[enc.substr(i,5)];
		}

		cout << dec << endl;
	}

}

Measured memory_bytes: 0
from random import randint

D = int(input())
cl = list(map(int, input().split()))
sl = [list(map(int, input().split())) for _ in range(D)]

def score(d, ti, last):
    s = sl[d-1][ti]
    for i in range(len(cl)):
        c = cl[i]
        s -= c*(d-last[i])
    return s

def scores(tl):
    s = 0
    last = [0]*26
    for d in range(D):
        t = tl[d] - 1
        last[t] = d+1
        s += score(d+1,t,last)
    return s


tl = [randint(1,26)]*D
s = scores(tl)
for _ in range(1000):
    d = randint(1,D)
    q = randint(1,26)
    x = tl[d-1]
    tl[d-1] = q
    s2 = scores(tl)
    if s2>s:
        s = s2
    else:
        tl[d-1] = x


for t in tl:
    print(t)



Measured memory_bytes: 84492
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vecl = vector<ll>;
using Graph = vector<vector<int>>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  int N;
  cin >> N >> S;
  ll ans = 0;
  int r = 0, g = 0, b = 0;
  vector<vector<int>> vec(N, vector<int>(3, 0));
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'R')
      r++;
    else if (S.at(i) == 'G')
      g++;
    else
      b++;
    vec.at(i).at(0) = r;
    vec.at(i).at(1) = g;
    vec.at(i).at(2) = b;
  }
  int cha;
  char c;
  for (int i = 0; i < N - 2; i++) {
    char T = S.at(i);
    for (int j = i + 1; j < N - 1; j++) {
      char T2 = S.at(j);
      if (T == T2) continue;
      if (T != 'R' && T2 != 'R') {
        cha = 0;
        c = 'R';
      } else if (T != 'G' && T2 != 'G') {
        cha = 1;
        c = 'G';
      } else if (T != 'B' && T2 != 'B') {
        cha = 2;
        c = 'B';
      }
      ans += vec.at(N - 1).at(cha) - vec.at(j).at(cha);
      if (j + j - i < N) {
        if (S.at(j + (j - i)) == c) ans--;
      }
    }
  }
 // for (int x = 0; x < 3; x++) cout << vec[N - 1][x] << " " << endl;
  std::cout << ans << endl;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define N             (int)(1e6+5)
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int solve(){
    cin>>str;
    sort(all(str));
    if(str[0]==str[2]) cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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 reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);
    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int n, t; cin >> n >> t;
    vector<int> a(n+1, 0), b(n+1, 0);
    repr(i, 1, n+1) cin >> a[i] >> b[i];

    vector<vector<int>> dp_left(n+5, vector<int>(3030, 0)), dp_right(n+5, vector<int>(3030, 0));
    repr(i, 1, n+1) rep(j, t+1) {
        chmax(dp_left[i][j], dp_left[i-1][j]);
        if (j-a[i]>=0) chmax(dp_left[i][j], dp_left[i-1][j-a[i]]+b[i]);
    }
    reprrev(i, 1, n+1) rep(j, t+1) {
        chmax(dp_right[i][j], dp_right[i+1][j]);
        if (j-a[i]>=0) chmax(dp_right[i][j], dp_right[i+1][j-a[i]]+b[i]);
    }

    int ans = 0;
    repr(i, 1, n+1) rep(j, t) {
        chmax(ans, dp_left[i-1][j] + b[i] + dp_right[i+1][t-1-j]);
    }
    cout << ans << endl;
    
    return 0;
}



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

int main() {
    int m, f, r;    // 中間試験の点数 期末試験の点数 再試験の点数
    cin >> m >> f >> r;

    while(!(m == -1 && f == -1 && r == -1)) {
        char rank;
        int sum = m + f;

        if (m == -1 || f == -1) rank = 'F';
        else if (sum >= 80) rank = 'A';
        else if (sum >= 65) rank = 'B';
        else if (sum >= 50) rank = 'C';
        else if (sum >= 30) {
            rank = 'D';
            if (r >= 50) rank = 'C';
        } else if (sum < 30) {
            rank = 'F';
        }

        cout << rank << endl;
        cin >> m >> f >> r;
    }

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class T>
void chmax(T &a, T b) {
    if (b > a) a = b;
}

constexpr int M = 26, D = 365;

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

    int r[D];
    int c[M];
    int s[D][M];

    for (int j = 0; j < M; j++) {
        cin >> c[j];
    }
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < M; j++) {
            cin >> s[i][j];
        }
    }

    int l[M];
    for (int j = 0; j < M; j++) {
        l[j] = -1;
    }

    for (int i = 0; i < D; i++) {
        pair<int, int> p = { -1, -1 };
        for (int j = 0; j < M; j++) {
            int d = i - l[j];
            chmax(p, { min(5, D - i) * c[j] * d + s[i][j], j });
        }
        r[i] = p.second;
        l[r[i]] = i;
    }

    {
        ll sc = 0;
        int l[M];
        for (int j = 0; j < M; j++) {
            l[j] = -1;
        }
        for (int i = 0; i < D; i++) {
            sc += s[i][r[i]];
            l[r[i]] = i;

            for (int j = 0; j < M; j++) {
                sc -= c[j] * (i - l[j]);
            }
        }
        cerr << "satisfaction  " << sc << '\n';
    }

    for (int i = 0; i < D; i++) {
        cout << r[i] + 1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 3656
import numpy as np
n,m,x=map(int,input().split())
c=[]
A=[]
for _ in range(n):
    l = [int(i) for i in input().split()]
    c.append(l[0])
    A.append(l[1:])
c=np.array(c)
A=np.array(A)
ans = 20*10**9
bits =[]

for i in range(2 ** n):
    bag = []
    for j in range(n):
        if ((i >> j) & 1): 
            bag.append(j)
    ar = np.sum(A[bag],axis=0)
    if all(ar>=x):
        temp = np.sum(c[bag])
        ans = min(ans,temp)
if ans == 20*10**9:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 27352
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    public static void Main(string[] args)
    {
        var nm = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        Console.WriteLine(nm[0] == nm[1] ? "Yes" : "No");
    }
}

Measured memory_bytes: 13396