akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = list(map(int,input().split()))
t = {}
o = 0
for i in range(n):
    if s[i] not in t.keys():
        t[s[i]] = 1
    else:
        t[s[i]] += 1

for i,j in t.items():
    if i > j:
        o += j
    else:
        o += j - i

print(o)

Measured memory_bytes: 18168
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static Scanner scan;

    private static void start() {
        scan = new Scanner(java.lang.System.in);

    }

    private static void finish() {
    }


    public static void main(String[] args) {
        start();

        int h = scan.nextInt();
        int w = scan.nextInt();
        scan.nextLine();

        char[][] papan = new char[h][w];
        for (int i = 0; i < h; i++) {
            String s = scan.nextLine();
            for (int j = 0; j < w; j++) {
                papan[i][j] = s.charAt(j);
            }
        }
        char[][] papan2 = new char[2 * h][w];
        for (int i = 0; i < (2 * h); i++) {
            for (int j = 0; j < w; j++) {
                int floor = (int) Math.floor((i) / 2);
                papan2[i][j] = papan[floor][j];
            }
        }
        for (int i = 0; i < 2 * h; i++) {
            for (int j = 0; j < w; j++) {
                System.out.print(papan2[i][j]);
            }
            System.out.println();
        }
        finish();
    }
}


Measured memory_bytes: 27388
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
	long long a,b,c;
	cin>>a>>b>>c;
    long long now=c-a-b;
    if(now<0) 
	{ 
		puts("No"); 
		return 0;
	}
    if(4*a*b>=now*now) 
		puts("No");
    else 
		puts("Yes");
    return 0;
}


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

using namespace std;

int main(){
    string str;
    cin >> str;
    if(!!count(begin(str), end(str), 'N') == !!count(begin(str), end(str), 'S')){
        if(!!count(begin(str), end(str), 'W') == !!count(begin(str), end(str), 'E')){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
#define MP make_pair
#define PB emplace_back
#define all(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int INF = 1e18L;
const double eps = 1e-9;
const int mod = 1e9 + 7;

int32_t main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    IOS;
    int n, ans = 0;
    cin >> n;
    if(n >= 500)
    {
        ans += (n / 500) * 1000;
        n %= 500;
    }
    if(n >= 5)
    {
        ans += (n / 5) * 5;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  const int MAX_V = 10000;
  int prime[MAX_V+1];
  int i, k, v, ans, dif;
  for(i = 2; i <= MAX_V; i++){
    prime[i] = 1;
  }
  for(i = 2; i*i <= MAX_V; i++){
    if(prime[i]){
      for(k = 2 * i; k <= MAX_V; k += i){
        prime[k] = 0;
      }
    }
  }
  while(scanf("%d", &v) != EOF){
    if(v == 0) break;
    for(k = v; k >= 2; k--){
      ans = prime[k];
      if(ans == 1){
        dif = prime[k - 2];
        if(dif == 1){
          printf("%d %d\n", k - 2, k);
          break;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1068
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define Mod 1000000007
int main()
{
    ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    string a, b;
    cin>>a>>b;
    ll prev=0;
    string res="";
    ll dp[a.size()+1][b.size()+1]={};
    for(ll i=1; i<=a.size(); i++)
        for(ll j=1; j<=b.size(); j++)
        {
            if(a[i-1]==b[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    ll i=a.size(), j=b.size();
    while(i && j)
    {
        if(dp[i-1][j]==dp[i][j])
            i-=1;
        else if(dp[i][j-1]==dp[i][j])
            j-=1;
        else
        {
            res+=a[i-1];
            i-=1;
            j-=1;
        }
    }
    reverse(res.begin(),res.end());
    cout<<res<<endl;
}


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

int main() {
    int H, W;
    char c[2];
    c[0] = '#';
    c[1] = '.';
    for (;;) {
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        
        for (int h = 0; h < H; h++) {
            int i = h%2;
            for (int w = 0; w < W; w++) {
                cout << c[i];
                i=1-i;
            }         
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3100
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

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

    int n;
    cin >>n;
    ll a[87];
    a[0]=2;
    a[1]=1;
    rep(i,n+1){
        if(i==0||i==1){
            continue;
        }
        else{
            a[i]=a[i-1]+a[i-2];
        }
    }
    // rep(i,n+1){
    //     cout << a[i] << endl;
    // }
    cout << a[n];

    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0

if n >= 3:
    for i in range(0, n-2):
        for j in range(i+1, n-1):
            for k in range(j+1, n):
                if l[i] + l[j] > l[k] and l[i]!=l[j] and l[i]!=l[k] and l[j]!=l[k]:
                    ans += 1
print(ans)


Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
  // 整数の入力
  ll N;
  cin >> N;
  vector<ll> A(N);
  for(int i = 0;i < N;i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  if (A[0] == 0){
    cout << 0 << endl;
  }else{
    ll ans = 1;
    for(int i = 0;i < N;i++){
      if (A[i] > 1000000000000000000ll/ans){
        ans = -1;
        break;
      }else{
        ans *= A[i];
        // cout << ans << endl;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3996
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    for (ll i = 0; i < X; i++) {
        cin >> A[i];
    }
    for (ll i = 0; i < Y; i++) {
        cin >> B[i];
    }
    for (ll i = 0; i < Z; i++) {
        cin >> C[i];
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll ok = 0, ng = A.back() + B.back() + C.back() + 1;
    while (ok + 1 != ng) {
        ll mid = (ok + ng) / 2;

        //mid以上のものがk個作れるか？
        ll num = 0;
        for (ll i = 0; i < X; i++) {
            for (ll j = 0; j < Y; j++) {
                ll t = mid - A[i] - B[j];
                num += (C.end() - lower_bound(C.begin(), C.end(), t));
            }
        }

        (num >= K ? ok = mid : ng = mid);
    }

    multiset<ll> st;
    for (ll i = 0; i < X; i++) {
        for (ll j = 0; j < Y; j++) {
            ll t = ok - A[i] - B[j];
            for (ll k = (upper_bound(C.begin(), C.end(), t) - C.begin()); k < Z; k++) {
                st.insert(A[i] + B[j] + C[k]);
            }
        }
    }

    for (auto itr = st.rbegin(); itr != st.rend(); itr++) {
        cout << *itr << endl;
        K--;
    }

    for (ll i = 0; i < K; i++) {
        cout << ok << endl;
    }
}

Measured memory_bytes: 384
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())

    if N % 2 == 0:
        print(0.5)
    else:
        print((N // 2 + 1) / N)

sol()

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

int main(){
    ll x; cin >> x;
    ll ans=0;
    ll sum=0;
    rep2(i,100000000){
        ans++;
        sum+=i;
        if(sum>=x){
            cout << ans << endl;
            return 0; 
        }
    }
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
    printf(" ");
    int total = 0,total_max = 0,n;
    char s[10000];
    scanf("%d",&n);
    scanf("%s",s);
    for(int i =0; i< n; i++){
        if(s[i]=='I'){
            total++;
        }
        else if(s[i]=='D'){
            total--;
        }
        if(total_max<total){
            total_max = total;
        }
    }
    printf("%d\n",total_max);
}


Measured memory_bytes: 128
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back

char S[10];
signed main(){
    scanf("%s",S);
    sort(S,S+4);
    if(S[0]==S[1]&&S[2]==S[3]&&S[0]!=S[2])printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 128
A, B, K = map(int, input().split())
L_1 = set([i for i in range(A, min(A+K, B+1))])
L_2 = set([i for i in range(max(A, B-K+1), B+1)])
L = sorted(L_1|L_2)
for l in L:
  print(l)

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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;



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

    string s, t;
    cin >> s >> t;
    
    int ans=0;
    for (int i=0; i <s.size(); ++i) {
        if (s[i]!=t[i]) {
            ++ans;
        }
    }
    
    cout << ans;


    return 0;
}


Measured memory_bytes: 3780
#!python3

iim = lambda: map(int, input().rstrip().split())

def cmb(a, b):
    if a == b or b == 0: return 1
    c = a - b
    if b > c:
        return cmb(a, c)

    ans = 1
    for i in range(a, a - b, -1):
        ans *= i
    from math import factorial
    return ans // factorial(b)

def resolve():
    N, K = iim()
    mod = 10**9 + 7

    if N < K:
        print(0)
        return

    print(cmb(N-1, N-K) % mod)

if __name__ == "__main__":
    resolve()



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

using namespace std;

int main(void) {
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }

  long long int sum = 0;
  for(int i = 0; i < n; i++) {
    sum += a[i];
  }
  
  long long int diffmin = 2000000000000000;
  long long int snuke = 0;
  for(int i = 0; i < n - 1; i++) {
    snuke += a[i];
    long long int diff = sum - 2 * snuke;
    if(diff < 0) {
      diff *= -1;
    }
    diffmin = min(diff, diffmin);
  }

  cout << diffmin << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

void make_prime_table(void);

_Bool is_prime[10000010];

int cnt;
int scale[1000];

int main()
{
    make_prime_table();

    for (int i = 2; i <= 10000000 - 8; i++) {
        if (is_prime[i] &&
            is_prime[i + 2] &&
            is_prime[i + 6] &&
            is_prime[i + 8]) {
            
            scale[cnt] = i + 8;
            cnt++;
        }
    }
    scale[cnt] = 1 << 30;

    int n;
    while (scanf("%d", &n), n != 0) {
        int i = 0;
        while (scale[i] <= n) i++;
        i -= 1;

        printf("%d\n", scale[i]);
    }

    return 0;
}

void make_prime_table(void)
{
    memset(is_prime, 1, sizeof(is_prime));

    is_prime[0] = is_prime[1] = 0;
    for (int i = 2; i <= 10000000; i++) {
        if (is_prime[i]) {
            for (int j = i + i; j <= 10000000; j += i) {
                is_prime[j] = 0;
            }
        }
    }
}



Measured memory_bytes: 11468
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    vector<int64_t> x(N), y(N), h(N);
    for(int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }
    for(int Cy = 0; Cy <= 100; Cy++) {
        for(int Cx = 0; Cx <= 100; Cx++) {
            int64_t H = -1, i = 0;
            for(i = 0; i < N; i++) {
                if(h[i] != 0) {
                    H = h[i] + abs(x[i] - Cx) + abs(y[i] - Cy);
                    break;
                }
            }
            for(i = 0; i < N; i++) {
                int64_t d = abs(x[i] - Cx) + abs(y[i] - Cy);
                if(h[i] != max(H - d, int64_t(0))) break;
            }
            H = max(H, int64_t(1));
            if(i == N) {
                cout << Cx << " " << Cy << " " << H << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
L = []
for A in range(2,2 * 10**2):
    for B in range(2,2 * 10 ** 2):
        for C in range(2,2 * 10 ** 2):
            tmp = A * A + B * B + C * C
            if tmp > 2 * 10 ** 4: break
            x = (A + B + C) //2 - A  
            y = (A + B + C) //2 - B
            z = (A + B + C) //2 - C  
            if x >= 1 and y>=1 and z >= 1 and \
                (x+y)**2+(y+z)**2+(z+x)**2 == tmp:
                L.append(tmp//2)
L.sort()
def counter(array):
    from collections import Counter
    return Counter(array)
c = counter(L)
N = int(input())
for i in range(1,N+1):
    print(c[i])




Measured memory_bytes: 19880
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<cmath>
#include<bitset>
using namespace std;


int main(){

  int d,g; cin >>d>>g;
  int p[d],c[d];
  for(int i=0;i<d;i++)
  cin >>p[i]>>c[i];

  int min =10000;
  for(int bit =0 ; bit <(1<<d);bit++){
    int sum =0;
    int num=0;
    for(int i=0; i<d; i++){
      if(bit & (1<<i)){sum += (i+1)*100*p[i]+c[i]; num+=p[i]; }
    }
    if(sum >= g ){if(min>num) min=num;}
    else{
      int index=20;
      for(int i=d-1;i>=0;i--){
        if(!(bit &(1<<i))) {index=i; break;}
      }
      for(int j=1; j<p[index];j++) {sum+=100*(index+1); num+=1;
      if(sum >= g && min > num )  min=num;
    }
  }
}
cout << min <<endl;
}


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

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define __m int mid=(l+r)/2;

template<class T>
inline bool read(T &num)  
{
    char in;bool IsN=false;
    while(in=getchar(),in!='-'&&(in<'0'||in>'9'))if(in==EOF)return false;
    in=='-'?(IsN=true,num=0):num=in-'0';
    while(in=getchar(),in>='0'&&in<='9')num=num*10+in-'0';
    return IsN?num=-num:num,true;
}
#define DEBUG

#define read2(a,b) read(a)&read(b)
#define read3(a,b,c) read(a)&read(b)&read(c)
#ifdef DEBUG
    #define debug(a) cout<<"nico : "<<a<<endl;
#else
    #define debug(a) ;
#endif

const int maxn =2e5+7;
const int inf  =2e9+7;
const int mod  =1e9+7;

int a[3][maxn],ans[3][maxn];

int main() {
#ifdef LOCAL
    freopen("sample.in", "r", stdin);
#endif

    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[1][i];
    }
    for(int i=1;i<=n;i++){
        cin>>a[2][i];
    }
    for(int j=1;j<=n;j++){
            ans[1][j]=max(ans[1][j-1],ans[2][j])+a[1][j];
            ans[2][j]=max(ans[2][j-1],ans[1][j])+a[2][j];
    }
    cout<<ans[2][n]<<endl;
    return 0;
} 


Measured memory_bytes: 2304
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
      int n;
      long long s=1;
      cin >>n;
      long long a[n];
      for(int i=0;i<n;i++)
      {   cin >> a[i];
      }
      sort(a,a+n);
      for(int i=1;i<n;i++)
      {  
           a[i]=a[i]*a[i-1];
      }
      if(a[0]==0)
      {
          cout << 0 <<endl;
          return 0;
      }
      if(a[0]>1000000000000000000)
      {
          cout << -1 <<endl;
          return 0;
      }
      for(int i=1;i<n;i++)
      {   
          if(a[i]>1000000000000000000)
          {
              cout << -1 <<endl;
              return 0;
          }
          if(a[i]<a[i-1])
          {
              cout << -1 <<endl;
              return 0;
          }
      }

        cout << a[n-1]  <<endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){

  int n;
  cin >> n;
  n < 1000 ? cout << "ABC" << endl : cout << "ABD" << endl;

  

  return 0;
}


Measured memory_bytes: 256
from collections import deque

s = deque(input())
n = int(input())
l = [input().split(" ") for _ in range(n)]

x = 0
for i in range(n):
    if l[i][0]=='1':
        if x == 0:
            x = 1
        else:
            x = 0
    elif l[i][0]=='2':
        if x == 0:
            if l[i][1]=='1':
                s.appendleft(l[i][2])
            else:
                s.append(l[i][2])
        else:
            if l[i][1]=='1':
                s.append(l[i][2])
            else:
                s.appendleft(l[i][2])

if x == 0:
    print(''.join(s))
else:
    print(''.join(reversed(s)))

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

int main() {
  string s;
  cin >> s;
  vector<string> week(7);
  week = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
  for (int i = 0; i < 7; i++) {
    if (s == week.at(i)) {
      cout << i + 1 << endl;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MAXX 1000000000000000000

int32_t main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, i, j, x=0, y, a[200005];

	map<int,int> values;

	cin >> n;

	for(i=1;i<=n;i++)
	{
		cin >> a[i];
		if(a[i] < i)
		{
			x += values[i-a[i]];
		}
		values[i + a[i]] += 1;
	}
	cout << x;
	return 0;
}

Measured memory_bytes: 19048
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const auto INF =(long long)1e7;
using v = vector<int>;
using ll =long long;
ll gcd(ll a,ll b){
  return b==0 ? a : gcd(b,a%b);
}

ll lcm(ll a,ll b){
  cout << a/gcd(a,b)<<endl;
  return a/gcd(a,b)*b;
}

template<typename ITE>
ll lcmr(ITE begin,ITE end){
   accumulate(begin,end,1,lcm);
}

int main()
{
  ll a,b;
  cin >> a>>b;
  ll c = gcd(a,b);
  ll ans =1;
  
  for (ll i = 2; i*i <= c; i++)
  {
    if(c%i==0){
      while(c%i==0){
        c/=i;
      }
      ans++;
    }
  }
  
  if(c!=1){
  	cout << ++ans;
  }else{
  	cout << ans;
  }

  return 0;
}

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

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}

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

int main() {
    ll N, M;
    cin >> N >> M;
    ll A, B;
    vector<vector<ll>> G(N);
    for (ll i=0; i<M; i++) {
        cin >> A >> B;
        A--;
        B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    vector<ll> dist(N,-1); // 未訪問に初期化
    queue<ll> q;

    dist[0] = 0;
    q.push(0);
    vector<ll> ans(N);

    while(!q.empty()) {
        ll v = q.front();
        q.pop();

        for (ll nv : G[v]) {
            if (dist[nv] != -1) {
                continue;
            }
            dist[nv] = dist[v] + 1;
            ans[nv] = v+1;
            q.push(nv);
        }
    }
    
    for (ll i=1; i<N; i++) {
        if (dist[i]==-1) {
            cout << "No" << endl;
            exit(0);
        }
    }
    
    cout << "Yes" << endl;
    for (ll i=1; i<N; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 13800
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')
from collections import deque
def solve():
    n, q = MI()
    e = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = MI1()
        e[a].append(b)
        e[b].append(a)

    point = [0] * n
    for _ in range(q):
        p, x = MI()
        p -= 1
        point[p] += x

    d = deque([(0, point[0])])
    used = [False] * n
    used[0] = True

    l = 1
    while l > 0:
        v, p = d.popleft()
        l -= 1
        for nv in e[v]:
            if used[nv]: continue
            used[nv] = True
            point[nv] += p
            d.append((nv, point[nv]))
            l += 1

    printlist(point, " ")

if __name__ == '__main__':
    solve()


Measured memory_bytes: 67308
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
 
  for (int i = 0; i < N; i++) {
    string a;
    cin >> a;
    if (a == "Y"){
      cout << "Four" << endl;
      return 0;
    }
  }

  cout << "Three" << endl;
 
}

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

typedef long long ll;
const int maxn=1e5+5;
vector<char> fr,ba;
int main() {
    string buff;cin>>buff;
    char tem[2];
    int Q;cin>>Q;
    bool rev=0;
    while(Q--){
        int t,f,c;
        cin>>t;
        if(t==1) {rev^=1;continue;}
        else{
            cin>>f>>tem;f--;
            f^=rev;
            if(f==1) ba.push_back(*tem);
            else fr.push_back(*tem);
        }
    }
    if(rev){
        swap(fr,ba);
        reverse(buff.begin(),buff.end());
    }
    if(fr.size())
    for(auto x=fr.end()-1;;x--){
        cout<<*x;
        if(x==fr.begin()) break;
    }
    cout<<buff;
    for(auto x:ba) cout<<x;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<set>
#define lli long long int
#define pb push_back
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define rep(i,a,n) for(i=a;i<n;i++)
#define all(v) (v.begin(),v.end())
#define ppb pop_back
#define vsz v.size()
#define pi 3.141592653589793238
using namespace std;
int main()
{
	lli t,k,n;
	cin>>n>>k;
	t=n*(n-1)/2+k*(k-1)/2;
	cout<<t;	
	return 0;
}

Measured memory_bytes: 3632
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    val (d, x) = listOfInt()

    var eaten = 0

    repeat(n) {
        val a = nextInt()
        eaten += (d / a) + Math.min((d % a), 1)
    }

    println(x + eaten)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

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

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

long long modInverse(long long n, long long p)
{
    return power(n, p-2, p);
}

long long nCrModPFermat(long long n, long long r, long long p)
{
   if (r==0)
      return 1;
    long long fac[n+1];
    fac[0] = 1;
    for (long long i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;
    return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p;
}

int main()
{
	int n,k;
    cin>>n>>k;
    string t; long long ans=0;
    int r,s,p; cin>>r>>s>>p;
    cin>>t;
    int x=t.size(); bool z[x]={0};
    for(int i=0; i<k; i++)
    {
        if(t[i]=='r') ans+=p;
        else if(t[i]=='p') ans+=s;
        else ans+=r;
        z[i]=1;
    }
    for(int i=k; i<n; i++)
    {
        if(t[i]==t[i-k] && z[i-k]) continue;
        else
        {
            if(t[i]=='r') ans+=p;
            else if(t[i]=='p') ans+=s;
            else ans+=r;
            z[i]=1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

const int MAXN = 300000 + 5;
int w2e[MAXN];
int e2w[MAXN];

int main() 
{
    // freopen("./input.txt", 'r', stdin);
    // freopen("./output.txt", 'w', stdout);

	int N;
	string S;
	cin >> N >> S;

	memset(w2e, 0, sizeof(w2e));
	memset(e2w, 0, sizeof(e2w));
	int len = S.length();
	
	if (S[0] == 'W') {
		w2e[0] = 1;
	}	
	for (int i = 1; i < len; i++) {	
		if (S[i] == 'W') {
			w2e[i] = w2e[i - 1] + 1;
		} else {
			w2e[i] = w2e[i - 1];
		}
	}
	if (S[len - 1] == 'E') {
		e2w[len - 1] = 1;
	}	
	for (int i = len - 2; i >= 0; i--) {	
		if (S[i] == 'E') {
			e2w[i] = e2w[i + 1] + 1;
		} else {
			e2w[i] = e2w[i + 1];
		}
	}
	
	int ans = min(e2w[1], w2e[len - 2]);
	for (int i = 1; i < len - 1; i++) {
		ans = min(ans, w2e[i - 1] + e2w[i + 1]);
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 2948
import collections
def resolve():
    N = int(input())
    VVW = [list(map(int, input().split())) for _ in range(N-1)]
    adjs = [[] for _ in range(N)]
    for vvw in VVW:
        adjs[vvw[0]-1].append([vvw[1]-1, vvw[2]])
        adjs[vvw[1]-1].append([vvw[0]-1, vvw[2]])

    result = [None for _ in range(N)]
    deq = collections.deque([[0, 0]])
    result[0] = "0"

    while deq:
        node, cost = deq.popleft()
        for adj in adjs[node]:
            nextnode, nextcost = adj[0], adj[1]
            if result[nextnode] is not None:
                continue
            if nextcost%2 == 0:
                result[nextnode] = result[node]
            else:
                result[nextnode] = "1" if result[node] == "0" else "0"
            deq.append([nextnode, nextcost])
    
    [print(r) for r in result]



if '__main__' == __name__:
    resolve()

Measured memory_bytes: 103640
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


# show_flg = True
show_flg = False


# エラトステネスのふるい 素数の列挙
def primes(n):
    is_prime = [1] * (n + 1)
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = 0
    return is_prime


def main():
    Q = I()
    l = [0] * Q
    r = [0] * Q

    for i in range(Q):
        l[i], r[i] = MI()

    prime_list = primes(10**5+1)
    arr = []
    for i in range(10**5+1):
        if i % 2 == 1:
            arr.append(int(prime_list[i] and prime_list[(i+1)//2]))
        else:
            arr.append(0)
    ARR = list(accumulate([0] + arr))

    for i in range(Q):
        # print(r[i]+1, l[i], ARR[r[i]+1], ARR[l[i]])
        # print(ARR[:r[i]+1])
        print(ARR[r[i]+1] - ARR[l[i]])


if __name__ == '__main__':
    main()


Measured memory_bytes: 78552
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define ll long long int
#define pb push_back
#define llu unsigned long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define eb emplace_back
#define M 1000000007
#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int,int>
#define mp make_pair
#define mapi map<int,int>

using namespace std;
ll max(ll x,ll y)
{
	if(x>y)
		return x;
	return y;
}
ll min(ll x,ll y)
{
	if(x<y)
		return x;
	return y;
}
int binaryToDecimal(string n) 
{ 
    string num = n; 
    int dec_value = 0;
    int base = 1; 
    int len = num.length(); 
    for (int i = len - 1; i >= 0; i--) 
	{ 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
    return dec_value; 
} 
ll findProductSum(ll A[], ll n) 
{ 
    ll array_sum = 0; 
    for (ll i = 0; i < n; i++) 
        array_sum = array_sum + A[i]; 
    ll temp = array_sum;
    ll array_sum_square = temp * temp;
    ll individual_square_sum = 0;
    for (ll i = 0; i < n; i++) 
        individual_square_sum += A[i]*A[i]%1000000007; 
    return (array_sum_square - individual_square_sum)/2 %1000000007; 
}
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin.ignore(numeric_limits<streamsize>::max(),'\n');
    //const unsigned ll M=1000000007;
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max( a*c , max( b*d, max(b*c , a*d))) << endl;
    return 0;
}



Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


//! ツ甘按単ツづ按ポツイツδ督トツクツδ可ス
struct P{ double x, y; };
bool operator > (P x, P y)
{ return x.x > y.x || (x.x == y.x && x.y > y.x); }

//! ツ湘」ツ記ツづ個クツδ可スツづ個オツブツジツェツクツト3ツづつづヲツづィツ、ツつサツづェツづーツ陳クツ点ツづつキツづゥツ三ツ角ツ形ツづ個姪環静渉づーツ仰づ淞づゥ
double CalcArea(P a, P b, P c)
{
	double A = sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
	double B = sqrt(pow(b.x - c.x, 2.0) + pow(b.y - c.y, 2.0));
	double C = sqrt(pow(c.x - a.x, 2.0) + pow(c.y - a.y, 2.0));

	double s = (A + B + C) / 2;

	return sqrt(s * (s - A) * (s - B) * (s - C));
}


int main()
{
	int vn;
	
	for(int i = 0; cin >> vn && vn; i++)
	{
		vector<P> vs(vn);
		rep(j, vn)
			cin >> vs[j].x >> vs[j].y;

		double res = 0;

		rep(j, vn-1)
		{
			res += (vs[j].x * vs[j+1].y - vs[j].y * vs[j+1].x) / 2;
		}

		res += (vs[vn-1].x * vs[0].y - vs[vn-1].y * vs[0].x) / 2;

		printf("%d %.1f\n", i+1, -res);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-10
//#define p 2173412051LL
#define sz 2

using namespace std;

pair< ll, ll > a[ 100000 ];

int main() {
	int n, ans = 1;
	ll x, y, lst;
	scanf( "%d", &n );
	for( int i = 0; i < n; ++i ) {
		scanf( "%lld%lld", &x, &y );
		a[ i ].first = x - y;
		a[ i ].second = x + y;
	}
	sort( a, a + n );
	lst = a[ 0 ].second;
	for( int i = 1; i < n; ++i ) {
		if( a[ i ].first >= lst ) {
			++ans;
			lst = a[ i ].second;
		} else {
			lst = min( lst, a[ i ].second );
		}
	}
	printf( "%d", ans );
	return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    pair<ll, int> job[N];
    rep(i, N){
        int a; ll b;
        cin >> a >> b;
        job[i] = pair<ll, int>(b, a);
    }
    sort(job, job+N);
    ll acc = 0;
    rep(i, N){
        acc += job[i].second;
        if(acc > job[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const int mxn = 2e5+7;

int n, k;
int a[mxn];

int main(){
	setIO();
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int l = 1, r = (int)1e9;
	while (l < r){
		int m = (l+r)>>1, ct = 0;
		for (int i = 0; i < n; i++) if (a[i] > m) {
			ct += a[i]/m;
		}
		if (ct > k) l = m+1;
		else r = m;
	}
	cout << l << endl;
}

Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
 
    ll ans = LINF;
    rep(i, 100005) {
        ll cost = c*i*2;
        cost += max(0, x-i)*a;
        cost += max(0, y-i)*b;
        ans = min(ans, cost);
    }
 
    cout << ans << endl;
    return 0;
}

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

char F[102][102];

bool isEnabled(int y, int x){
    char c = F[y][x];
    return (c == '@' || c == '#' || c == '*');
}              

void DFS(int y, int x, char c) {
    if(F[y][x] != c) return;

    F[y][x] = '.';

    DFS(y - 1, x, c);
    DFS(y + 1, x, c);
    DFS(y, x -1, c);
    DFS(y, x + 1, c);
}

void print(int h, int w){
    for(int y = 1;y <= h;y++){
        for(int x = 1;x <= w;x++){
            cout << F[y][x];
        }
        cout << endl;
    }
    cout << endl;
}

int main(){
    while(true) {
        int H, W;
        cin >> H >> W;
        if(!H && !W) break;
        for(int y = 1;y <= H;y++) {
            for(int x = 1;x <= W;x++){
                cin >> F[y][x];
            }
        }

        int ans = 0;
        for(int y = 1;y <= H;y++){
            for(int x = 1;x <= W;x++){
                if(isEnabled(y, x)){
                    ans++;
                    DFS(y, x, F[y][x]);
                }
            }
        }

        cout << ans << endl;
    }
    return 0;
}

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

bool t[7][200020],vis[7][200020];
long long n,m,q,a;

void DFS(int x,int y,int lim){
	vis[x][y]=true;
	int dx[]={-1,0,0,1},dy[]={0,1,-1,0};
	for(int i=0;i<4;i++){
		int a=x+dx[i],b=y+dy[i];
		if(a>=0&&b>=0&&a<7&&b<lim){
			if(!vis[a][b])DFS(a,b,lim);
		}
	}
}
int Sol(int lim){
	int ret=0;
	for(int i=0;i<7;i++){
		for(int j=0;j<lim;j++){
			vis[i][j]=t[i][j];
			//cout<<t[i][j]<<" ";
		}
		//cout<<endl;
	}
	for(int i=0;i<7;i++){
		for(int j=0;j<lim;j++){
			if(!vis[i][j]){
				ret++;
				DFS(i,j,lim);
			}
		}
	}
	return ret;
}

int main(){
	cin>>n>>m>>q;
	for(int i=0;i<7;i++){
		for(int j=0;j<m;j++){
			t[i][j]=0;
		}
	}
	while(q--){
		cin>>a;
		for(int i=a;i<14*m;i+=m){
			t[i%7][i/7]=1;
		}
	}

	long long k=Sol(m),w=Sol(m*2),ans;
	int g=n/m-1;
	if(g<=0)ans=Sol(n);
	else ans=(g)*(w-k)+Sol(n-(g*m));
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    
    int i = 0;
    int n = 1;
    while (true){
        n *= 2;
        if (n > N){
            break;
        }
        i += 1;
    }
    cout << pow(2, i) << endl;
}

Measured memory_bytes: 256
import bisect
n,m,q=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(m)]
pq=[list(map(int,input().split())) for _ in range(q)]

lr.sort()
t=[[0 for _ in range(n)] for _ in range(n)]

for slr in lr:
    t[slr[0]-1][slr[1]-1] += 1

nt = [[0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        nt[i].append(nt[i][j] + t[i][j])

for spq in pq:
    p,q = spq[0],spq[1]
    res = 0
    for i in range(p-1,q):
        res += nt[i][q] - nt[i][p-1]
    print(res)

Measured memory_bytes: 117464
#include <bits/stdc++.h>
using namespace std;
#define	rep(i,n)	for(int i=0;i<n;i++)
int main(){
  int n,x;	cin >> n >> x;
  int len=0;
  int ans=1;
  rep(i,n){
    int l;	cin >> l;
    len+=l;
    if(len>x)	continue;
    ans++;
  }
  cout << ans;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int inf = 1e9 + 5;
const int nax = 1e6 + 5;

char sl[nax];

int main() {
	scanf("%s", sl);
	int n = strlen(sl);
	int k;
	scanf("%d", &k);
	REP(i, n) {
		int need = ('z' - sl[i]) + 1;
		if(sl[i] == 'a') need = 0;
		if(k >= need) {
			k -= need;
			sl[i] = 'a';
		}
	}
	int tmp = sl[n-1] - 'a';
	sl[n-1] = 'a' + (tmp + k) % 26;
	printf("%s\n", sl);
	return 0;
}


Measured memory_bytes: 512
n, m, x = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(n)]
ans = []
for i in range(2 ** n):
    price = 0
    und = [0 for _ in range(m)]
    for j in range(n):
        if (i >> j) & 1:
            price += c[j][0]
            for k in range(m):
                und[k] += c[j][k+1]
    if all(und[i] >= x for i in range(m)):
        ans.append(price)

if ans == []:
    print(-1)
else:
    print(min(ans))

Measured memory_bytes: 9220
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


const int N = (int) 2e4 + 100;

int a[N], b[N];
int p[N];

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &p[i]);
        p[i]--;
    }
    
    for (int i = 0; i < n; i++)
    {
        a[i] = (i + 1) * N;
        b[i] = a[i];
    }
    reverse(b, b + n);

    for (int i = 0; i < n; i++)
        a[p[i]] += i;


    for (int i = 0; i < n; i++)
        printf("%d ", a[i]);
    printf("\n");
    for (int i = 0; i < n; i++)
        printf("%d ", b[i]);
    printf("\n");


	return 0;
}




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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n,m;
	cin>>n>>m;
	vector<double> a(n);
	rep(i,n)cin>>a[i];

	int cnt=0;
	double sum=accumulate(all(a),0.0);
	rep(i,n){
		if(a[i]-sum/(4*m)>=0)cnt++;
	}
	cout<<(cnt>=m?"Yes":"No")<<endl;

	return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip> 
#include <bits/stdc++.h>
using namespace std;
double pi=3.14159265358979323846264338;


bool issqt(long long k){
	if(k<=3)return true;
	long long s=(long long)sqrt(k);
	//cout<<k<<" "<<s<<endl;
	for(long long i=2;i<=s;i++)
		if(k%i==0)return false;
	return true;
}
 
 
int main() {
	string s;
	cin>>s;
	cout<<s[0]<<s[1]<<s[2]<<endl;
  return 0;
}



Measured memory_bytes: 3676
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

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


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi p(n);
		int ans=0, p_max=0;

		for(int i=0;i<n;i++)
		{
			scanf("%d", &p[i]);
			if(p_max<p[i]) p_max=p[i];
			ans+=p[i];
		}
		ans-=p_max/2;
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	H, W := ReadInt(), ReadInt()
	c := make([][]int, 10)
	for i := 0; i < 10; i++ {
		c[i] = ReadInts(10)
	}
	A := make([][]int, H)
	for y := 0; y < H; y++ {
		A[y] = ReadInts(W)
	}

	for k := 0; k < 10; k++ {
		for i := 0; i < 10; i++ {
			for j := 0; j < 10; j++ {
				c[i][j] = Min(c[i][j], c[i][k]+c[k][j])
			}
		}
	}

	sum := 0
	for y := 0; y < H; y++ {
		for x := 0; x < W; x++ {
			v := A[y][x]
			if v == -1 {
				continue
			}
			sum += c[v][1]
		}
	}
	fmt.Println(sum)
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 2328
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int v = (N * 100)/108;
        for (int i = v; i < v + 3; i++) {
            int X = i * 108 / 100;
            if(X == N) {
                System.out.println(i);
                return;
            }
        }
        
        System.out.println(":(");
        return;
    }

}

Measured memory_bytes: 23892
import itertools
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
per=list(itertools.permutations(range(1,n+1)))
a=0
b=0
for num,i in enumerate(per):
    if i==p: a=num+1
    if i==q: b=num+1
print(abs(a-b))

Measured memory_bytes: 8052