akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int n;
    cin>>n;
    int a[n+5];
    int i;
    FOR0(i, n) cin>>a[i];
    int ans = 0;
    FOR(i, 1, n-1)
    {
        vi cur;
        int j;
        FOR(j, -1, 2) cur.pb(a[i + j]);
        sort(cur.begin(), cur.end());
        if(a[i] == cur[1]) ans++;
    }
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n;
  int a[100001];
  int i;
  long long sum;
  long long ans1=0,ans2=0;
  long long ans;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  /*a[0]を正とするとき*/
  sum=0;
  for(i=0;i<n;i++){
    sum+=a[i];
    if(i%2==0){
      if(sum<=0){
        ans1+=-sum+1;
        sum=1;
      }
    }
    else if(i%2==1){
      if(sum>=0){
        ans1+=sum+1;
        sum=-1;
      }
    }
  }
  /*a[0]を負とするとき*/
  sum=0;
  for(i=0;i<n;i++){
    sum+=a[i];
    if(i%2==1){
      if(sum<=0){
        ans2+=-sum+1;
        sum=1;
      }
    }
    else if(i%2==0){
      if(sum>=0){
        ans2+=sum+1;
        sum=-1;
      }
    }
  }
  if(ans1>=ans2) ans=ans2;
  else ans=ans1;
  printf("%lld",ans);
  return 0;
}


Measured memory_bytes: 2100
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
adj = [[] for _ in range(200000)]
for x, y in p:
	adj[x-1].append(y+99999)
	adj[y+99999].append(x-1)

visited = [False for _ in range(200000)]

def dfs(orig):
	stack = [orig]
	edges = len(adj[orig])
	if orig < 100000:
		x_num, y_num = 1, 0
	else:
		x_num, y_num = 0, 1

	while stack:
		v = stack.pop()
		for w in adj[v]:
			if visited[w] == False:
				visited[w] = True
				if w < 100000:
					x_num += 1
				else:
					y_num += 1
				edges += len(adj[w])
				stack.append(w)
	return x_num * y_num - (edges // 2)

ans = 0
for i in range(200000):
	if visited[i] == False and adj[i]:
		visited[i] = True
		ans += dfs(i)
print(ans)

Measured memory_bytes: 51552
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ss := make([]int, n)
	for i := range ss {
		fmt.Scan(&ss[i])
	}

	sum := 0
	for _, s := range ss {
		sum += s
	}

	min := 101
	for _, s := range ss {
		if s < min && s%10 != 0 {
			min = s
		}
	}

	if sum%10 == 0 {
		if min == 101 {
			fmt.Println(0)
		} else {
			fmt.Println(sum - min)
		}
	} else {
		fmt.Println(sum)
	}
}


Measured memory_bytes: 512
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 15:38-

            int n = sc.nextInt();
            int max = 0;
            int cur = -1;
            int last = Integer.MAX_VALUE;

            for (int i = 0; i < n; i++) {
                int h = sc.nextInt();
                if (h <= last) {
                    cur++;
                    max = Math.max(max, cur);
                } else {
                    cur = 0;
                }
                last = h;
            }

            out.println(max);

        }
    }

}


Measured memory_bytes: 50520
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
typedef pair<int,int> pii;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second


void solve()
{
    double n;cin>>n;
    int n1=ceil(n/1.08),n2=floor(n/1.08);
    if((int)(n1*1.08)==n)cout<<n1<<endl;
    else if((int)(n2*1.08)==n)cout<<n2<<endl;
    else cout<<":("<<endl;
}

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


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

int main(){
  int n;
  cin >> n;
  vector<int> vec(0), rvec(0);
  for(int i=0; i<n; ++i){
    int x;
    cin >> x;
    if(i%2==0) vec.push_back(x);
    else rvec.push_back(x);
  }
  if(n%2==1){
    for(int i=vec.size()-1; i>=0; --i){
      cout << vec[i] << " ";
    }
    for(int i=0; i<(int)rvec.size(); ++i){
      cout << rvec[i] << " ";
    }
  }else{
    for(int i=rvec.size()-1; i>=0; --i){
      cout << rvec[i] << " ";
    }
    for(int i=0; i<(int)vec.size(); ++i){
      cout << vec[i] << " ";
    }
  }
  cout << endl;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,mod=1e9+7;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    unsigned long long n,b,r;
    cin>>n>>b>>r;
    cout<<n/(b+r)*b+min(b,n%(b+r))<<endl;
    return 0;
}


Measured memory_bytes: 256
/*Analysis Requires Calm*/
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <list>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <sstream>
#include <complex>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <climits>
#define T int test_case; scanf("%d",&test_case); while(test_case--)
#define FOR(i,a,n) for(i=a;i<n;i++)
#define FORD(i,a,n) for(i=a;i>=n;i--)
#define FORS(i,a) for(i=0;a[i];i++)
#define si(x) scanf("%d",&x)
#define sc(x) cin>>x
#define sd(x) scanf("%lf",&x)
#define sll(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define prs(x) printf("%d ",x)
#define pls(x) printf("%lld ",x)
#define pc(x) printf("%c",x)
#define pi(x) printf("%d\n",x)
#define pd(x) cout.precision(10) cout<<fixed<<x<<endl
#define pll(x) printf("%lld\n",x)
#define ps(x) printf("%s\n",x)
#define M 1000000007
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define pb push_back
#define fr first
#define se second
#define in insert
#define er erase
#define pii pair<int, int>
#define plll pair<long long, long long>
#define tr(x,it) for(auto it : x)
#define INF 1ll<<60
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230
using namespace std;
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n&1) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n&1) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
vector<int> prime;
bool primee[10000000];
void primegen(ll x) { for(ll i=2;i*i<=x;i++) if(!primee[i]) for(ll j=i*i;j<=x;j+=i) primee[j]=true; for(ll i=2;i<=x;i++) if(!primee[i]) prime.push_back(i);}


int main()
{
   int i,j;
   int o=0,e=0,n;
   si(n);
   FOR(i,0,n)
   {
   	si(j);
   	if(j%2==0)
   		e++;
   	else
   		o++;
   }
   if(o%2==1)
   	puts("NO");
   else
   	puts("YES");
   return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	nextReader = newScanner()
	k := nextInt()
	ans := 0
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			for c := 1; c <= k; c++ {
				ans += gcd(a, gcd(b, c))
			}
		}
	}
	fmt.Println(ans)
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}


Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define M 2000005
int n,k;
int main() {
	scanf("%d%d",&n,&k);
	if(k>(n-1)*(n-2)/2)return !printf("-1");
	int St=(n-1)*(n-2)/2,Add=St-k;
	printf("%d\n",Add+n-1);
	for(int i=2; i<=n; i++)printf("%d %d\n",1,i);
	for(int i=2; i<=n&&Add; i++) {
		for(int j=i+1; j<=n&&Add; j++)
			printf("%d %d\n",i,j),Add--;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int A[3];
int dp[211][211];

void MAIN() {
    REP (i, 3) scanf("%d", A+i);
    sort(A, A+3);
    A[1] -= A[0];
    A[2] -= A[0];

    memset(dp, 0x3f, sizeof dp);
    dp[A[1]][A[2]] = 0;
    queue<pair<int, int> > qu;
    qu.emplace(A[1], A[2]);
    while (!qu.empty()) {
	int x = qu.front().first;
	int y = qu.front().second;
	if (x == 0 && y == 0) break;
	qu.pop();
	REP (t, 6) {
	    int ny, nx;
	    if (t == 0) {
		nx = x + 1;
		ny = y + 1;
	    } else if (t == 1) {
		nx = x;
		ny = y - 1;
	    } else if (t == 2) {
		nx = x - 1;
		ny = y;
	    } else if (t == 3) {
		nx = x;
		ny = y + 2;
	    } else if (t == 4) {
		nx = x + 2;
		ny = y;
	    } else if (t == 5) {
		nx = x - 2;
		ny = y - 2;
	    }

	    int b[3] = {0, ny, nx};
	    sort(b, b+3);
	    b[1] -= b[0];
	    b[2] -= b[0];
	    nx = b[1];
	    ny = b[2];
	    if (dp[nx][ny] > dp[x][y] + 1) {
		dp[nx][ny] = dp[x][y] + 1;
		qu.emplace(nx, ny);
	    }
	}
    }

    printf("%d\n", dp[0][0]);

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define lli long long int
#define ulli unsigned long long int
#pragma GCC target ("sse4.2")
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define time cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";

int main()
{


    fast;
    char z;
    cin>>z;
    cout<<(char)(z+1);





    return 0;


}


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

int main() {
	int N, A[210];
	int ans = 0;

	cin >> N;
	for (int i = 0; i < N; i++)cin >> A[i];

	while (true) {
		bool Odd = false;
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 != 0)Odd = true;
		}

		if (Odd)break;
		
		for (int i = 0; i < N; i++) {
			A[i] /= 2;
		}
		ans++;
	}
	cout << ans << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
#define ELEMENT_CNT_MIN (1)
#define ELEMENT_CNT_MAX (100)
#define ELEMENT_MIN (0)
#define ELEMENT_MAX (100)
#define SUCCESS     (0)
#define FAILURE     (-1)
 
int bubble_sort(int *p_arr, int size);
void swap(int *px, int *py);
void put_arr(int *p_arr, int size);
int get_int_sequence(int *p_num, int min, int max, int size);
int get_int(int *p_num, int min, int max);
int judge_constraint(int test_num, int min, int max);
 
 
int main(void){
     
    int element_num;
    int element[ELEMENT_CNT_MAX];
    int cnt_exchange;
     
    if(get_int(&element_num, ELEMENT_CNT_MIN, ELEMENT_CNT_MAX) == FAILURE)
    {
        return FAILURE;
    }
     
    if(get_int_sequence(&element[0], ELEMENT_MIN, ELEMENT_MAX, element_num) == FAILURE)
    {
        return FAILURE;
    }
     
    cnt_exchange = bubble_sort(&element[0], element_num);
     
    put_arr(&element[0], element_num);
    printf("%d\n", cnt_exchange);
     
    return SUCCESS;
}
 
int bubble_sort(int *p_arr, int size)
{
    int i;
    int j;
    int cnt = 0;
     
    for(i = 0; i < size - 1; i++)
    {
        for(j = size - 1; j > i; j--)
        {
            if(p_arr[j] < p_arr[j - 1])
            {
                swap(&p_arr[j], &p_arr[j - 1]);
                cnt++;
            }
        }
    }
     
    return cnt;
}
 
void swap(int *px, int *py)
{
    int tmp = *px;
    *px = *py;
    *py = tmp;
     
    return;
}
 
void put_arr(int *p_arr, int size)
{
    int i;
     
    for(i = 0; i < size - 1; i++)
    {
        printf("%d ", p_arr[i]);
    }
    printf("%d\n", p_arr[size - 1]);
}
 
int get_int_sequence(int *p_num, int min, int max, int size)
{
    int i;
     
    for(i = 0; i < size; i++)
    {
        if(get_int(&p_num[i], min, max) == FAILURE)
        {
            return FAILURE;
        }
    }
     
    return SUCCESS;
}
 
int get_int(int *p_num, int min, int max)
{
    scanf("%d", p_num);
     
    if(judge_constraint(*p_num, min, max) == FAILURE)
    {
        return FAILURE;
    }
     
    return SUCCESS;
}
int judge_constraint(int test_num, int min, int max)
{
    if((test_num < min) || (test_num > max))
    {
        return FAILURE;
    }
     
    return SUCCESS;
}

Measured memory_bytes: 1860
#include<bits/stdc++.h>
using namespace std;
int main() {
 	int n, m;
  	cin>>n;
  	bool isok = true;
  	while(n--) {
      cin>>m;
      if(m&1) 
        continue;
      
      if(m%3 != 0 && m%5 != 0)
        isok = false;
    }
  	if(isok)
  		cout<<"APPROVED";
    else cout<<"DENIED";
  	return 0;
}

Measured memory_bytes: 256
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const n = Number(stdin.split('\n')[0])
const [_, ...s] = stdin.split('\n')

const ans = () => {
  let res = 0

  let sortedList = []
  for (let i = 0; i < n; i++) {
    const str = s[i]

    const sorted = str
      .split('')
      .sort()
      .join('')

    sortedList.push(sorted)
  }

  let obj = {}
  for (let i = 0; i < n; i++) {
    const str = sortedList[i]

    obj[str] = obj[str] === undefined ? 0 : obj[str] + 1

    res += obj[str]
  }

  console.log(res)
}

ans()


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

int main() {
  int a,b;
  string s;
  bool flag = true;
  cin >> a >> b >> s; 
  for(int i=0 ;i<s.size() ;i++){
    if(i != a && s[i] == '-'){
      flag = false;
    }else if(i == a && s[i] != '-'){
      flag = false;
    }
  }
  cout << (flag?"Yes":"No") << endl;
}

Measured memory_bytes: 256
//  Created by conan1024hao in 2020.
//  Copyright © 2020 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------
int c[110][110];
int n,m;
void warshall_floyd(){
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
        if(c[i][k]==IINF)continue;
      for (int j = 0; j < n; j++) {  // 終点
          if(c[k][j]==IINF)continue;
        chmin(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    cin>>n>>m;
    int a[110][110];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            c[i][j]=IINF;
        }
    }
    map<Pin,int>mm;
    for(int i=0;i<m;i++){
        int a1,b1,c1;cin>>a1>>b1>>c1;
        a1--;b1--;
       a[a1][b1]=c1;
       a[b1][a1]=c1;
        c[a1][b1]=c1;
        c[b1][a1]=c1;
        mm[mp(a1,b1)]++;
        mm[mp(b1,a1)]++;
    }
    
    warshall_floyd();
    
    int ans=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(mm[mp(i,j)]){
                if(c[i][j]!=a[i][j]){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------








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

int main(){
    ll n;
    cin >> n;
    vector<ll> even(100010, 0), odd(100010, 0);
    bool flag = true;
    ll ev = 0, ov = 0;
    rep(i, 0, n){
        ll t; cin >> t;
        if(i%2 == 0){
            even[t]++;
            if(even[t] > even[ev]) ev = t;
        }else{
            odd[t]++;
            if(odd[t] > odd[ov]) ov = t;
        }
    }
    sort(even.begin(),even.end(),greater<ll>());
    sort(odd.begin(),odd.end(),greater<ll>());
    if(ev == ov){
        cout << n - max(even[0]+odd[1],even[1]+odd[0]) << endl;
    }else{
        cout << n - even[0] - odd[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
import java.math.*;
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ans = 1;
        while(n>=k){
            n /= k;
            ans ++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22740
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define N 110
using namespace std;

char s[N],ss[N];

int main()
{
	char c;
	int j,k,temp,n,i,ans,flag;
	scanf("%d",&n);

		c=getchar();
		fgets(s,sizeof(s),stdin);
		s[n]='\0';
		ans=0;
		
		for (i=1;i<n;i++)
		{
			strcpy(ss,s);
			temp=0;
			
			for (j=0;j<i&&j<n;j++)
			{
				flag=1;
				
				for (k=i;k<n;k++)
				{
					if (ss[k]==s[j])
					{
						if (flag)
						{
							flag=0;
							temp++;
						}
						
						ss[k]='#';
					}
				}
			}
			
			ans=max(ans,temp);
		}
		
		printf("%d\n",ans);
	
	
	return 0;
 } 

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	string s[3];
	for (; cin >> s[0]&&s[0] != "0";) {
		cin >> s[1] >> s[2];
		bool b, w;
		b = w = false;
		rep(i, 0, 3) {
			if (s[i][0] == s[i][1] && s[i][1] == s[i][2]) {
				if (s[i][0] == 'b')b = true;
				if (s[i][0] == 'w')w = true;
			}
		}
		rep(j, 0, 3) {
			if (s[0][j] == s[1][j] && s[1][j] == s[2][j]) {
				if (s[0][j] == 'b')b = true;
				if (s[0][j] == 'w')w = true;
			}
		}

		if (s[0][0] == s[1][1] && s[1][1] == s[2][2]) {
			if (s[0][0] == 'b')b = true;
			if (s[0][0] == 'w')w = true;
		}

		if (s[0][2] == s[1][1] && s[1][1] == s[2][0]) {
			if (s[0][2] == 'b')b = true;
			if (s[0][2] == 'w')w = true;
		}
		if (b)cout << "b" << endl;
		else if (w)cout << "w" << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<int, int>;

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

    int h, w;
    cin >> h >> w;
    vector< string > field(h);
    int b = 0;
    rep (i, h)
    {
        cin >> field[i];
        rep (j, w)
        {
            if (field[i][j] == '#') ++b;
        }
    }

    int d[h][w];
    rep (i, h) rep (j, w) d[i][j] = 1e9;
    d[0][0] = 1;
    queue<P> q;
    q.push(P{0, 0});
    int dy[] = {-1, 0, 1, 0};
    int dx[] = {0, -1, 0, 1};
    while (!q.empty())
    {
        P p = q.front(); q.pop();
        int y = p.first;
        int x = p.second;
        rep (i, 4)
        {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (IN(0, h, ny) && IN(0, w, nx) && field[ny][nx] != '#' && d[ny][nx] > d[y][x] + 1)
            {
                q.push(P{ny, nx});
                d[ny][nx] = d[y][x] + 1;
            }
        }
    }

    int ans;
    if (d[h - 1][w - 1] == 1e9)
    {
        ans = -1;
    }
    else
    {
        ans = h * w - b - d[h - 1][w - 1];
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
n = int(input())

m = [[0 for i in range(n + 1)] for j in range(n + 1)]

for i in range(n):
    nums=list(map(int,input().split()))
    for j in range(nums[1]):
        m[i + 1][nums[j + 2]] = 1

for i in range(n):
    for j in range(n-1):
        print(m[i + 1][j + 1], end = " ")
    print(m[i + 1][n])
    


Measured memory_bytes: 6388
import sys

if __name__ == '__main__':
    n, k = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    lst = [0 for i in range(n)]
    for i in range(k):
        d = int(sys.stdin.readline())
        p = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
        for i in p:
            lst[i-1] += 1
    print(sum([1 if x == 0 else 0 for x in lst]))

Measured memory_bytes: 9204
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int x;cin>>x;
  int a=inf;int b=inf;
  rep(i,1000){
    rep(j,1000){
      if(i*i*i*i*i-j*j*j*j*j==x){
        a=i;
        b=j;
        goto FINE;
      }
      if(i*i*i*i*i+j*j*j*j*j==x){
        a=i;
        b=-j;
        goto FINE;
      }
    }
  }
  FINE:
  printf("%lld %lld\n",a,b);
  return 0;
}


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

int x,H,W,D,Q,A,L,R;
int px[90001],py[90001];
int d[90001];
int main(){
    cin>>H>>W>>D;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>A;
            px[A]=i,py[A]=j;
        }   
    }   
    for(int i=D+1;i<=H*W;i++){
        d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
    }
    cin>>Q;                                                
    while(Q--){
        cin>>L>>R;
        cout<<d[R]-d[L]<<"\n";
    
    }
    
}            

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int n;
char s[1000],t[1000];
int main()
{
    cin >> n; scanf("%s",s+1);scanf("%s",t+1);
    for(int i=1;i<=n;++i)cout<<s[i]<<t[i];
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//clock_t t=clock();
namespace my_std{
    using namespace std;
    #define pii pair<int,int>
    #define fir first
    #define sec second
    #define MP make_pair
    #define rep(i,x,y) for (int i=(x);i<=(y);i++)
    #define drep(i,x,y) for (int i=(x);i>=(y);i--)
    #define go(x) for (int i=head[x];i;i=edge[i].nxt)
    #define templ template<typename T>
    #define sz 102020
    typedef long long ll;
    typedef double db;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
    templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
    templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
    templ inline void read(T& t)
    {
        t=0;char f=0,ch=getchar();double d=0.1;
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
        if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
        t=(f?-t:t);
    }
    template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
    char sr[1<<21],z[20];int C=-1,Z=0;
    inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
    inline void print(register int x)
    {
        if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
        while(z[++Z]=x%10+48,x/=10);
        while(sr[++C]=z[Z],--Z);sr[++C]='\n';
    }
//    void file()
//    {
//        #ifndef ONLINE_JUDGE
//        freopen("a.in","r",stdin);
//        #endif
//    }
//    inline void chktime()
//    {
//        #ifndef ONLINE_JUDGE
//        cout<<(clock()-t)/1000.0<<'\n';
//        #endif
//    }
//    #ifdef mod
//    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
//    ll inv(ll x){return ksm(x,mod-2);}
//    #else
//    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
//    #endif
//  inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n,m;
struct hh{int u,v,w;}edge[sz];
inline bool cmp(const hh &x,const hh &y){return x.w<y.w;}

int fa[sz];
ll sum[sz];
int cnt[sz];
int getfa(int x){return x==fa[x]?x:fa[x]=getfa(fa[x]);}

int main()
{
//    file();
	read(n,m);
	rep(i,1,n) read(sum[fa[i]=i]);
	int x,y,z;
	rep(i,1,m) read(x,y,z),edge[i]=(hh){x,y,z};
	sort(edge+1,edge+m+1,cmp);
	int ans=0;
	rep(i,1,m)
	{
		int u=edge[i].u,v=edge[i].v;
		u=getfa(u),v=getfa(v);
		if (u!=v) fa[u]=v,sum[v]+=sum[u],cnt[v]+=cnt[u],cnt[u]=sum[u]=0;
		++cnt[v];
		if (sum[v]>=edge[i].w) ans+=cnt[v],cnt[v]=0;
	}
	cout<<m-ans;
	return 0;
}

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

long INF = 1e16;

long divPlusOneIfModExist(long target, long div) {
  return (target+div-1L)/div;
}

int main() {
  long N;
  cin >> N;

  long A[N+1];
  for (int i = 0; i <= (int)N; i++) {
    cin >> A[i];
  }  
  
  long maxNodes[N+1];
  maxNodes[0] = 1L;
  for (int i = 1; i <= N ; i++) {
    maxNodes[i] = min(2*(maxNodes[i-1] - A[i-1]),INF);
  }
  
  long ans = 0L;
  long currentNodes = 0L;
  for (int i = (int)N; i >= 0 ; i--) {
    // Check ng;
    if (divPlusOneIfModExist(currentNodes, 2L)>maxNodes[i]-A[i]) {
        cout << -1 << endl;
        return 0;
    }
    currentNodes = min(maxNodes[i],currentNodes+A[i]);
    ans+=currentNodes;
  }

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

Measured memory_bytes: 5180
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

ll siz;
ll ofst;
vll seg;
void segadd(ll i) {
  i += ofst;
  seg[i] += 1;
  while (true) {
    i /= 2;
    if (i == 0) break;
    seg[i] = seg[2 * i] + seg[2 * i + 1];
  }
}

ll segget(ll l, ll r) {
  ll s = 0;
  l += ofst, r += ofst + 1;
  while (l < r) {
    if (l % 2 == 1) {
      s += seg[l];
      l++;
    }
    l /= 2;
    if (r % 2 == 1) {
      s += seg[r - 1];
      r--;
    }
    r /= 2;
  }
  return s;
}

ll n;
vll as;
bool f(ll x) {
  vll mk(n);
  rep(i, n) {
    bool chr = as[i] >= x;
    mk[i] = chr * 1 + !chr * (-1);
  }
  vll csum(n + 1, 0);
  ll minv = 0;
  rep(i, n) {
    csum[i + 1] = mk[i] + csum[i];
    chmin(minv, csum[i + 1]);
  }
  ll invn = 0;
  rep(i, n+1) {
    ll c = csum[i] - minv;
    invn += segget(0, c);
    segadd(c);
  }
  ll nall = n * (n + 1) / 2;
  return (invn >= (nall + 1) / 2);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  cin >> n;
  as.resize(n);
  rep(i, n) cin >> as[i];

  siz = 4;
  while (siz < 2 * n) siz <<= 1;
  ofst = siz >> 1;

  ll l = 0;
  ll r = INF;
  while (l + 1 < r) {
    seg.assign(siz, 0);
    ll m = (l + r) / 2;
    if (f(m))
      l = m;
    else
      r = m;
  }
  cout << l << endl;

  return 0;
}


Measured memory_bytes: 4724
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()

for i in range(1, 10):
  if N%i == 0:
    tmp = N//i
    if tmp < 10:
      print("Yes")
      exit()
else:
  print("No")

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String str[];
		int rail[];
		int v1, v2;
		double sum;

		while (sc.hasNext()) {
			sum = 0.0;
			rail = new int[10];
			str = sc.next().split(",");
			for (int i = 0; i < 10; i++) {
				rail[i] = Integer.valueOf(str[i]);
				sum += rail[i];
			}
			v1 = Integer.valueOf(str[10]);
			v2 = Integer.valueOf(str[11]);
			sum = sum * v1 / (v1 + v2);
			for (int i = 0; i < 10; i++) {
				if (sum - rail[i] <= 0) {
					System.out.println(i + 1);
					break;
				}
				sum -= rail[i] * 1.0;
			}
		}
	}
}

Measured memory_bytes: 12000
#include <cstdint>
#include <cstddef>

using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

template<class T, class U>
bool chmin (T &a, const U &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

#include <iostream>
#include <vector>
#include <set>

constexpr i32 base = 200'000;
constexpr i32 SIZE = 400'001;
constexpr i32 INF = (1 << 30);

int main() {
	usize n;
	i32 ans = INF;
	std::cin >> n;
	std::vector<i32> x(n), y(n);
	std::vector<char> d(n);
	for (usize i = 0; i < n; i++) {
		std::cin >> x[i] >> y[i] >> d[i];
	}

	auto sweep1 = [&] () {
		std::vector<std::set<i32>> set(SIZE);
		for (usize i = 0; i < n; i++) {
			if (d[i] == 'L') set[y[i]].emplace(x[i]);
		}
		for (usize i = 0; i < n; i++) {
			if (d[i] == 'R') {
				auto it = set[y[i]].lower_bound(x[i]);
				if (it != set[y[i]].end()) {
					i32 value = ((*it) - x[i]) * 5;
					if (ans > value) ans = value;
				}
			}
		}
	};

	auto sweep2 = [&] () {
		std::vector<std::set<i32>> set(SIZE);
		for (usize i = 0; i < n; i++) {
			if (d[i] == 'U') set[x[i] + y[i]].emplace(x[i]);
		}
		for (usize i = 0; i < n; i++) {
			if (d[i] == 'R') {
				auto it = set[x[i] + y[i]].lower_bound(x[i]);
				if (it != set[x[i] + y[i]].end()) {
					i32 value = ((*it) - x[i]) * 10;
					if (ans > value) ans = value;
				}
			}
		}
	};
	
	for (int _ = 0; _ < 4; _++) {
		sweep1();
		sweep2();
		for (usize i = 0; i < n; i++) {
			std::swap(x[i], y[i]);
			x[i] = base - x[i];
			if (d[i] == 'R') d[i] = 'U';
			else if (d[i] == 'U') d[i] = 'L';
			else if (d[i] == 'L') d[i] = 'D';
			else if (d[i] == 'D') d[i] = 'R';
		}
	}
	
	if (ans == INF) std::cout << "SAFE" << '\n';
	else std::cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 33076
from collections import deque


H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
maze = [input() for _ in range(H)]

INF = 10 ** 12
path = [[INF] * W for _ in range(H)]  # path: 各マスへの移動コスト

# walk:移動A, warp:移動B
walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3)
        for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

q = deque()
path[Ch][Cw] = 0
q.append((Ch, Cw, 0))

while q:
    x, y, s = q.popleft()
    for dx, dy in walk:  # 移動A
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s:
            path[nx][ny] = s
            q.appendleft((nx, ny, s))  # 移動Aの場合はコスト0. キューの先頭に追加する.
    for dx, dy in warp:  # 移動B
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s + 1:
            path[nx][ny] = s + 1
            q.append((nx, ny, s + 1))  # 移動Bの場合はコスト1. キューの最後尾に追加する.

ans = path[Dh][Dw] if path[Dh][Dw] < INF else '-1'
print(ans)


Measured memory_bytes: 93892
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int n,q,sum=0;
  int l,r,cun[1000000]={};
  string s;
  cin>>n>>q>>s;
  for(int i=1;i<=n;i++){
    if(s[i-1]=='A' && s[i]=='C'){
      sum++;
    }
   cun[i]=sum;
  }
  for(int i=1;i<=q;i++){
  cin>>l>>r;
  cout<<cun[r-1]-cun[l-1]<<"\n";
  }
 return(0);
}

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

#define all(x) x.begin(),x.end()
#define pb(x) emplace_back(x)
#define forn(i,N) for(int i=0;i<N;i++)

using namespace std;
using ll=long long int;
using ld=long double;
using vi=vector<int>;
using vll=vector<ll>;
using vd=vector<double>;
int ctoi(char c) {return c-'0';}

int main() {
//freopen("input.txt","rt",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);

int N;
cin>>N;
vi a(N);
vi dp(N+5,1e9);
for(auto& x: a)
  cin>>x;

dp[0]=0;
forn(i,N) {
  for(int d: {1,2}) {
    dp[i+d]=min(dp[i+d],dp[i]+abs(a[i]-a[i+d]));
  }
}
cout<<dp[N-1]<<endl;
return 0;
}


Measured memory_bytes: 3940
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const H = readLong();
      const W = readLong();
      long ans;
      if (H == 1) {
        ans = 1;
      } else if (W == 1) {
        ans = 1;
      } else {
        ans = (H * W + 1) / 2;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;
string s;
int k;
int main() {
  cin >> s >> k;

  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'a') continue;
    int t = 'z' - s[i] + 1;
    if(t <= k) {
      s[i] = 'a';
      k -= t;
    }
  }
  k %= 26;

  s[s.size() - 1] = s[s.size() - 1] + k;
  if(s[s.size() - 1] > 'z') s[s.size() - 1] -= 'z';
  cout << s << endl;
}
  


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

int main()
{
	int N,x;
	int a[110]={};
	int ans=0;
	
	cin >> N >> x;
	for(int i=0;i<N;i++)
		cin >> a[i];
	
	sort(a,a+N);
	
	for(int i=0;i<N;i++)
	{
		if(x>=a[i])
		{
			ans++;
			x-=a[i];
		}
	}
	if(ans==N && x>0)ans--;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
int main(void){
	char a[210];
	int b;
	char c[110];
	int d;
	int z;
	for (int i = 0; i < 210; i++)a[i] = 0;
	for (int i = 0; i < 110; i++)c[i] = 0;
	scanf("%s", a);
	scanf("%s", c);
	b = strlen(a);
	d = strlen(c);
	for (int i = 0; i < b; i++)a[b + i] = a[i];
	for (int i = 0; i < b; i++){
		z = 0;
		for (int j = 0; j < d; j++){
			if (a[i + j] != c[j]){
				z = 1;
				break;
			}
		}
			if (z == 0){
				printf("Yes\n");
				return 0;
			}
	}
	printf("No\n");
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)



int main(){
	int N; cin >> N;
	vector<LL> A(N+1) , S(N+1);
	A[0] = S[0] = 0;
	repp(i,1,N+1){
		cin >> A[i];
		S[i] = S[i-1] + A[i];
	}
	sort(S.begin(),S.end());
	LL ans = 0;
	LL i = 0;
	while(i<=N){
		LL j = i;
		while(j <= N && S[i] == S[j]) ++j;
		ans += (j-i)*(j-i-1)/2;
		i = j;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3456
#横にn個入力
n, k = map(int, input().split())
a = input().split()
a = [int(m) for m in a]
#rr = max(a)
bina = [str(bin(m)) for m in a]
lenbina = [len(str(bin(m))) for m in a]

m = 61
x = 0
X = 0
y = 0
tmp0 = 0
tmp1 = 0
ff = [0 for _ in range(n)]
for v in range(m - 1, -1, -1):
    for i in range(n):
        if len(bina[i]) - 2 > v:
            if ff[i] == 0:
                ff[i] = 1
                lenbina[i] = v + 2
            t = int(bina[i][lenbina[i] - v])
            if int(bina[i][lenbina[i] - v]) ^ x == x:
                tmp0 += 1
            else:
                tmp1 += 1
        else:
            #if len(str(bin(k))) - 2 > v:
            tmp0 += 1
    if tmp0 > tmp1:
        X += 2 ** v
        y += 2 ** v
        if X > k:
            X -= 2 ** v
    tmp0 = 0
    tmp1 = 0

ans = 0
for i in range(n):
    ans += a[i] ^ X
print(ans)

Measured memory_bytes: 102488
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
   int n;cin>>n;
   int wow=0;
   for(int i=1;i<=n;i++){
       int a;cin>>a;
       if(a!=i)wow++;
   }
   if(wow==2||wow==0)cout<<"YES";
   else cout<<"NO";
}


Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations
n,m,r=map(int, input().split())
s=[[10**9]*n for i in range(n)]
t=list(map(int, input().split()))
for i in range(m):
    a,b,c=map(int, input().split())
    s[a-1][b-1]=c
    s[b-1][a-1]=c

s=floyd_warshall(s)   
ans=float('inf')
for i in permutations(t):
    an=0
    for j in range(r-1):
        an+=s[i[j]-1][i[j+1]-1]
    ans=min(ans,an)
print(int(ans))

Measured memory_bytes: 20172
// In the Name of God
#include<bits/stdc++.h>

#define test(t) int t; cin>>t; while(t--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long int
#define em emplace_back
#define pb push_back
#define INF 1e7+5
#define MOD int(1e9+7)
#define print printf
#define in scanf
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

template<class type>
void displaySingle(type &arr)
{
	for(auto i:arr)
		cout<<i<<" ";
	cout<<endl;
}

template<class type>
void displayDouble(type &arr)
{
	for(auto &&i : arr) 
	{
		for(auto &&j : i) 
			cout << j << " ";
		cout << std::endl;
	}
}

int main()
{
	fast
	int n;
	cin>>n;
	vector <int> arr(n);
	REP(i,n)
		cin>>arr[i];
	vector <int> dp(n);
	dp[0] = 0;
	dp[1] = abs(arr[1]-arr[0]);
	FOR(i,2,n)
	{
		int temp1 = abs(arr[i]-arr[i-2])+dp[i-2];
		int temp2 = abs(arr[i]-arr[i-1])+dp[i-1];
		dp[i] = min(temp1,temp2);
	}
	//displaySingle(dp);
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int mi = s.size();
    f(s.size() - 1) {
        if (s[i] != s[i + 1]) {
            mi = min(mi, max(i + 1, (int)s.size() - i - 1));
        }
    }
    cout << mi << '\n';
}

Measured memory_bytes: 512
import copy

n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))

tmp = copy.deepcopy(A)
tmp.sort(reverse=True)

M = max(A)
if A.count(M) >= 2:
    for _ in range(n):
        print(M)
else:
    for a in A:
        if a == M:
            print(tmp[1])
        else:
            print(M)

Measured memory_bytes: 14588
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN 2*int(1e5)+7
#define endl '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define max3(x, y, z) max(x, max(y, z))
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef pair<char, pair<int, int>> pcii;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
 
int main() {
	int n;
	cin >> n;
	cout << int(pow(n, 3)) << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    S = input()
    K = int(input())

    if K >= 1e3:
        K = 105

    T = ''
    for i in range(len(S)):
        if S[i] == '1':
            T += '1'
        else:
            T += S[i] * K

        if S[i] != '1':
            break

    print(T[K - 1])


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = 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;
  int a[9];
  FILL(a,9,0);
  REP(i,n){
    int x;cin >> x;
    if(x < 400){
      a[0]++;
    }else if(x < 800){
      a[1]++;
    }else if(x < 1200){
      a[2]++;
    }else if(x < 1600){
      a[3]++;
    }else if(x < 2000){
      a[4]++;
    }else if(x < 2400){
      a[5]++;
    }else if(x < 2800){
      a[6]++;
    }else if(x < 3200){
      a[7]++;
    }else{
      a[8]++;
    }
  }
  int res1 = 0;
  REP(i,8)if(a[i])res1++;
  cout << max(1,res1) << " " << res1+a[8] << endl;



  return 0;
}


Measured memory_bytes: 256
from collections import deque

class Graph(): #directed
    def __init__(self, n, edge, indexed=1):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.rev = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]
        for e in edge:
            self.graph[e[0] - indexed].append(e[1] - indexed)
            self.rev[e[1] - indexed].append(e[0] - indexed)
            self.deg[e[1] - indexed] += 1

    def topological_sort(self):
        deg = self.deg[:]
        res = [i for i in range(self.n) if deg[i] == 0]
        queue = deque(res)
        used = [False for _ in range(self.n)]
        while queue:
            node = queue.popleft()
            for adj in self.graph[node]:
                deg[adj] -= 1
                if deg[adj] == 0:
                    queue.append(adj)
                    res.append(adj)
        return res


import sys
input = sys.stdin.readline

N, M = map(int, input().split())
E = [tuple(map(int, input().split())) for _ in range(M)]

g = Graph(N, E, 0)
print('\n'.join(map(str, g.topological_sort())))


Measured memory_bytes: 18228