akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int H = Integer.parseInt(scan.next());
		int W = Integer.parseInt(scan.next());
		String[] S = new String[H];
		for(int i = 0; i < H; i++) {
			S[i] = scan.next();
		}
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				search(H, W, i, j, S);
			}
			System.out.println();
		}
		scan.close();

	}
	
	public static void search(int H, int W, int i, int j, String[] S) {
		int sum = 0;
		boolean R = true;
		boolean L = true;
		boolean U = true;
		boolean D = true;
		boolean RU = true;
		boolean RD = true;
		boolean LU = true;
		boolean LD = true;
		
		if(i == 0) {
			U = false;
			RU = false;
			LU = false;
		}
		if(i == H - 1) {
			D = false;
			RD = false;
			LD = false;
		}
		if(j == 0) {
			L = false;
			LU = false;
			LD = false;
		}
		if(j == W - 1) {
			R = false;
			RU = false;
			RD = false;
		}
		
		if(R) {
			if(S[i].substring(j + 1, j + 1 + 1).equals("#")) {
				sum++;
			}
		}
		if(L) {
			if(S[i].substring(j - 1, j - 1 + 1).equals("#")) {
				sum++;
			}
		}
		if(U) {
			if(S[i - 1].substring(j, j + 1).equals("#")) {
				sum++;
			}
		}
		if(D) {
			if(S[i + 1].substring(j, j + 1).equals("#")) {
				sum++;
			}
		}
		if(RU) {
			if(S[i - 1].substring(j + 1, j + 1 + 1).equals("#")) {
				sum++;
			}
		}
		if(RD) {
			if(S[i + 1].substring(j + 1, j + 1 + 1).equals("#")) {
				sum++;
			}
		}
		if(LU) {
			if(S[i - 1].substring(j - 1, j - 1 + 1).equals("#")) {
				sum++;
			}
		}
		if(LD) {
			if(S[i + 1].substring(j - 1, j - 1 + 1).equals("#")) {
				sum++;
			}
		}
		if(S[i].substring(j, j + 1).equals("#")) {
			System.out.print("#");
		} else {
			System.out.print(sum);
		}
	}

}


Measured memory_bytes: 24788
def main():
    N = int(input())

    def to_bin(n):
        """
        n:10進数 -> 2進数
        """
        if n == 0:
            return 0
        digits = []
        i = 0
        base = 1
        while n != 0:
            if n % (base*-2) == 0:
                digits.append("0")
            else:
                digits.append("1")
                n -= base
            i += 1
            base *= -2
        return "".join(digits[::-1])

    print(to_bin(N))


if __name__ == '__main__':
    main()


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}

using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

constexpr char sp = ' ';
constexpr char cmm = ',';
constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s<<'[';for(size_t i=0;i<v.size();++i){s << v[i];if(i < v.size()-1) s << ", ";}s<<']';return s;
}

int main(){

    int n, m;
    scanf("%d%d", &n, &m);
    string s;
    cin >> s;

    reverse(s.begin(), s.end());
    stack<int> res;
    for(int i = 0; i < n; ++i){
        if(n-i <= m) {
            res.emplace(n-i);
            break;
        }
        bool ok = false;
        for(int j = m; j > 0; --j){
            if(i+j > n+1) {ppp(-1); return 0;}
            if(s[i+j] == '0'){
                res.emplace(j);
                i += j-1;
                ok = true;
                break;
            }
        }
        if(!ok){
            ppp(-1);
            return 0;
        }
    }
    while(!res.empty()){
        int x = res.top(); res.pop();
        printf("%d ", x);
    }
    putchar('\n');

    return 0;
}


Measured memory_bytes: 868
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<vector<int>>ki(N);
    for(int i = 0; i < N-1; i++) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        ki[a].push_back(b);
        ki[b].push_back(a);
    }
    vector<int>cnt(N,INF);
    queue<int>que;
    que.push(0);
    cnt[0] = 0;
    vector<int>road;
    while(!que.empty()) {
        int x = que.front();
        que.pop();
        for(int i = 0; i < ki[x].size(); i++) {
            if(cnt[ki[x][i]] == INF) {
                cnt[ki[x][i]] = cnt[x]+1;
                que.push(ki[x][i]);
            }
        }
    }
    que.push(N-1);
    road.push_back(N-1);
    while(!que.empty()) {
        int x = que.front();
        que.pop();
        for(int i = 0; i < ki[x].size(); i++) {
            if(cnt[ki[x][i]] == cnt[x]-1) {
                road.push_back(ki[x][i]);
                que.push(ki[x][i]);
            }
        }
    }
    reverse(road.begin(),road.end());
    int now = 0;
    vector<bool>used(N,false);
    for(int i = 0; i < (road.size()+1)/2; i++) {
        now = road[i];
        used[now] = true;
        for(int j = 0; j < ki[now].size(); j++) {
            queue<int>que;
            if(ki[now][j] == road[i+1]) {
                continue;
            }
            que.push(ki[now][j]);
            used[ki[now][j]] = true;
            while(!que.empty()) {
                int x = que.front();
                que.pop();
                for(int k = 0; k < ki[x].size(); k++) {
                    if(!used[ki[x][k]]) {
                        used[ki[x][k]] = true;
                        que.push(ki[x][k]);
                    }
                }
            }
        }
    }
    int res = 0;
    for(int i = 0; i < N; i++) {
        if(used[i]) {
            res++;
        }
    }
    if(res > N/2) {
        cout << "Fennec" << endl;
    }
    else {
        cout << "Snuke" << endl;
    }
}


Measured memory_bytes: 10444
from collections import deque
x = input()
n = len(x)
st = deque()

for i in range(n):
    if x[i] == "S":
        st.append("S")
    else:
        if st == deque([]):
            st.append("T")
        else:
            a = st.pop()
            if a == "T":
                st.append("T")
                st.append("T")
            else:
                continue
                
print(len(st))

Measured memory_bytes: 42460
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define fore(i, a) for (auto &i:a)

#define ll long long
#define pll vector<pair<ll, ll>>
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
using namespace std;

const long double PI = acos(-1);

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}

bool isInteger(double x){return floor(x) == x;}

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

    int N;cin >> N;
    if(N >= 1000){
        cout << "ABD" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

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

void solve()
{
    long long int n;
    cin >> n;
    long long int i = 0;
    long long int val = 7 % n;
    for (i = 1; i < 1e7; i++)
    {
        if (val == 0)
        {
            cout << i << endl;
            return;
        }
        val = (val * 10 + 7) % n;
    }
    cout << -1 << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
}

Measured memory_bytes: 3628
import sys
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    a_list = []
    input_raw = read_func().strip().split()
    for i in range(N):
       
        a_list.append(int(input_raw[i]))

    a_list.sort(reverse = True)

    alice_score = 0
    bob_score = 0
    for i in range(N):
        if i % 2 == 0:
            alice_score += a_list[i]
        else:
            bob_score += a_list[i]

    print alice_score - bob_score



if __name__ == '__main__':
    main()

Measured memory_bytes: 2692
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solveA();
		// new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();

			int res = numA - 1;
			res += numB >= numA ? 1 : 0;

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 20820
#include <fstream>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <cassert>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <regex>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

//#define LOCAL_DEBUG


int main() {
#ifdef LOCAL_DEBUG
	freopen("input1.txt","r", stdin);
#endif
	int A, B;
	cin >> A >> B;
	if (A == 1) A += 13;
	if (B == 1) B += 13;
	if (A > B) cout << "Alice" << endl;
	if (A < B) cout << "Bob" << endl;
	if (A == B) cout << "Draw" << endl;
 	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A, B, M;
  cin >> A >> B >> M;
  int INF = 1e9;
  int AMIN = INF;
  int BMIN = INF;
  vector<int> a(A);
  vector<int> b(B);
  for(int i=0; i<A; i++){
    cin >> a.at(i);
    AMIN = min(AMIN,a.at(i));
  }
  for(int i=0; i<B; i++){
    cin >> b.at(i);
    BMIN = min(BMIN,b.at(i));
  }
  int ans = AMIN + BMIN;
  for(int i=0; i<M; i++){
    int x, y, z;
    cin >> x >> y >> z;
    x--; y--;
    ans = min(ans, a.at(x) + b.at(y) - z);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main(){
    int n,l;
    string t;
    map<string,int> M;
    map<string,int>::iterator it;

    scanf("%d %d",&n,&l);
    for( int i = 0 ; i < n ; ++i ){
        cin>>t;
        M[t]++;
    }

    t.resize(0);
    for( it = M.begin() ; it != M.end() ; ++it ){
        for( int i = 0 ; i < it->second ; ++i )
            t += it->first;
    }
    cout<<t<<"\n";
    return 0;
}


Measured memory_bytes: 256
<?php
$str = trim(fgets(STDIN));

while(true){
    $str = substr($str,0,-1);
    if(isOK($str)){
        echo strlen($str);
        exit;
    }
}

function isOK($str){
    return substr($str,0,strlen($str)/2) == substr($str,strlen($str)/2);
}

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;                                                            
#define pb push_back                                                            
#define mp make_pair                                                                                                                                
#define sqr(a) ((a) * (a))                                                      
#define io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   
#define co() cout.precision(10);                                                
#define F for(li i=0;i<n;i++)
#define fo(i,a,n) for(i=a;i<n;i++)
#define ne cout<<"\n"; 
#define test int t;cin>>t;while(t--)
//#define oj #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif

typedef long long li;
typedef long double ld;

const li mod = 1000000007; 

int main() 
{
	io();
	li n;cin>>n;
	if(n%1000==0)
	cout<<0;else
	cout<<1000-n%1000;
	
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


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

    int n,m;cin>>n>>m;
    vec br(n);
    rep(i,m) {int a;cin>>a; br[a]=1;}

    vec dp(n+2);
    const int mod=1000000007;
    dp[n]=1;
    for(int i=n-1; i>=0; i--){
        if(br[i]){
            dp[i]=0;
            continue;
        }

        dp[i]=(dp[i+1]+dp[i+2])%mod;

    }

    cout<<dp[0]<<endl;
}

Measured memory_bytes: 3984
n = int(input())
p = list(map(int,input().split()))
check = {}
cnt = 0
ans = [i for i in range(n)]
for i in range(n):
    if(p[i]==ans[i]+1):
        continue
    elif(p[i]!=ans[i]):
        check[i] = p[i]
        if(cnt<3):
            cnt += 1
        else:
            break
if(cnt==0):
    print("YES")
elif(cnt==2):
    print("YES")
else:
    print("NO")
        
        
    

Measured memory_bytes: 3064
#include <iostream>

int main()
{
  int64_t x;
  std::cin >> x;
  int64_t money = 100;
  int64_t count = 0;
  while (money < x)
  {
    ++count;
    money *= 1.01;
  }
  std::cout << count << std::endl;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string str;
  
  cin >> n;
  
  for(int i=0;i<=n;i++){
    getline(cin,str);
    
    while(str.find("Hoshino") != string::npos){
      str.replace(str.find("Hoshino"),7,"Hoshina");
    }
    
    if(i!=0) cout << str << endl;
    
  }
  
  return (0);
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int n,sum=0,cnt=0;
int p,q,r,s;
int a[400000];
signed main(){
    cin>>n;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    rep(i,n){
        cnt+=a[i];
        if(cnt>=sum/2){
            if(i==0){
                cout<<sum<<endl;
                return 0;
            }
            p=cnt-a[i];q=sum+a[i]-cnt;r=cnt;s=sum-cnt;
            break;
        }
    }
    int x=min(abs(p-q),abs(r-s));
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h> 
using namespace std;
int *a;
int dp[500001];
int n,k;
int main(){
 cin>>n>>k;
 a=new int[n+1];
 for(int i=1;i<=n;i++){
     cin>>a[i];
 }
 dp[2]=abs(a[1]-a[2]);
for(int i=3;i<=n;i++){
    dp[i]=dp[i-1]+abs(a[i-1]-a[i]);
    for(int j=2;j<=min(k,i-1);j++)
    {dp[i]=min(dp[i],dp[i-j]+abs(a[i-j]-a[i]));
        
    }
}cout<<dp[n];
 return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h> 
using namespace std;  
long INF=1000000000000000;
int main() {
    long N;
    cin>>N;
    
    vector<string> s(N+1);
    s.at(N)="!";
    for(int i=0;i<N ;i++){
        cin>>s.at(i);
        sort(s.at(i).begin(),s.at(i).end());
    }
    sort(s.begin(),s.end());
    long ans=0,count;
    for(int i=1;i<=N;i++){
        if(s.at(i-1)!=s.at(i)) count=0;
        else count++;
        
        ans+=count;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 7296
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int N=2005;
const int MOD=1e9+7;
int add (int x,int y)   {x=x+y;return x>=MOD?x-MOD:x;}
int mul (int x,int y)   {return (LL)x*y%MOD;}
int dec (int x,int y)   {x=x-y;return x<0?x+MOD:x;}
int Pow (int x,int y)
{
	if (y==0) return 1;
	if (y==1) return x;
	int lalal=Pow(x,y>>1);
	lalal=mul(lalal,lalal);
	if (y&1) lalal=mul(lalal,x);
	return lalal;
}
int C[N][N];
int g[N][N];//前缀和
int h[N][N];
void Init (int n)
{
	C[0][0]=1;for (int i=0;i<=n;i++) g[0][i]=1;
	for (int u=1;u<=n;u++)
	{
		C[u][0]=1;
		for (int i=1;i<=u;i++)	C[u][i]=add(C[u-1][i-1],C[u-1][i]);	
		g[u][0]=1;
		for (int i=1;i<=u;i++) g[u][i]=add(g[u][i-1],C[u][i]);
		for (int i=u+1;i<=n;i++) g[u][i]=g[u][u];
	}
	for (int u=0;u<=n;u++)
	for (int i=0;i<=n;i++)
	{
		if (u==0&&i==0)	{h[u][i]=1;continue;}
		h[u][i]=0;
		if (u>0) h[u][i]=add(h[u][i],h[u-1][i]);
		if (i>0) h[u][i]=add(h[u][i],g[i-1][u]);
	}
}
int n,m;
int main()
{
	Init(2000);
//	printf("%d %d %d\n",h[2][1],h[1][1],g[0][2]);
	scanf("%d%d",&n,&m);
	int ans=0;
	for (int u=0;u<=n;u++)
	for (int i=1;i<=m;i++)//填了多少个 
	{
		int j=m-i;//白球又用了多少个 
		if (n-u-j<0) continue;
	//	printf("%d %d %d %d\n",u,i,C[m-1][i-1],h[n-u-j][m-i]);
		ans=add(ans,mul(C[m-1][i-1],h[n-u-j][m-i]));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 47360
def partial_match_table(word):
    table = [0] * (len(word) + 1)
    table[0] = -1
    i, j = 0, 1
    while j < len(word):
        matched = word[i] == word[j]
        if not matched and i > 0:
            i = table[i]
        else:
            if matched:
                i += 1
            j += 1
            table[j] = i
    return table

def kmp_search(text, word):
    table = partial_match_table(word)
    i, p = 0, 0
    results = []
    while i < len(text) and p < len(word):
        if text[i] == word[p]:
            i += 1
            p += 1
            if p == len(word):
                p = table[p]
                results.append((i-len(word), i))
        elif p == 0:
            i += 1
        else:
            p = table[p]
    return results

inf = 10**18
s = input().strip()
t = input().strip()
m=(len(t)+len(s)-1+len(s)-1)//len(s)
d = [-1] * (len(s)+1) 
for a, b in kmp_search(m*s, t):
    a, b = a%len(s)+1, b%len(s)+1
    d[a] = b


ls = [-1]*(len(s)+1)
vs = set()
for i in range(1, len(s)+1):
    if i in vs:
        continue
    c = 0
    j = i
    while True:
        vs.add(i)
        i = d[i]
        if i == -1:
            break
        c += 1
        if i == j:
            c = inf
            break
        if ls[i] != -1:
            c += ls[i]
            break
    if c == inf:
        break
    ls[j] = c
print(max(ls) if c != inf else -1)


Measured memory_bytes: 97040
N = gets.to_i
A = gets.strip.split(/ /).collect{|num| num.to_i}

width = A.max.to_s(2).length

prev_index = []
last_index = []
appeared = []

count = 0

A.each_with_index{|a, i|
	last_max = 0
	
	width.times{|j|
		c = a % 2
		a = a / 2
		if appeared[j] == nil
			appeared[j] = 0
		end
		if c == 1
			if appeared[j] > 0
				if last_max < last_index[j] + 1
					last_max = last_index[j] + 1
				end
			end
			appeared[j] += 1
			prev_index[j] = last_index[j]
			last_index[j] = i
		else
			if appeared[j] > 1
				if last_max < prev_index[j] + 1
					last_max = prev_index[j] + 1
				end
			end
		end
		j += 1
	}
	count += i - last_max + 1
}

puts count


Measured memory_bytes: 17292
#include <iostream>

using namespace std;

int main() {
    int w , h , x , y , r;
    cin >> w >> h >> x >> y >> r;
    if (x-r >=0 && x+r <= w && y-r >=0 && y+r <= h)
         cout << "Yes" << endl;
    else 
        cout<<"No" << endl;
}


Measured memory_bytes: 3100
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int A,B;

int main() {
  INCANT;
  cin >> A >> B;
  cout << A*B << "\n";
  return 0;
}

Measured memory_bytes: 3652
n = int(input())
s = [input() for _ in range(n)]
s.sort()

a = {}
ans = []

for i in s:
	if i in a:
		a[i] 	+= 1
	else:
		a[i] = 1

leargest = max(a.values())
for k in a.keys():
	if a[k] == leargest:
 		ans.append(k)

[print(i) for i in ans]

Measured memory_bytes: 39252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200003,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    string S;cin>>N>>S;
    
    ll cnt1=0,cnt2=0,cnt3=0;
    
    for(int i=0;i<N;i++){
        if(S[i]=='R') cnt1++;
        if(S[i]=='G') cnt2++;
        if(S[i]=='B') cnt3++;
    }
    
    ll ans=cnt1*cnt2*cnt3;
    
    for(int d=1;d<=N;d++){
        for(int m=0;m<N;m++){
            if(m-d<0||m+d>=N) continue;
            
            if(S[m-d]!=S[m+d]&&S[m]!=S[m+d]&&S[m-d]!=S[m]) ans--;
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 3656
#include<cstdio>
#include<iostream>
using namespace std;
char grade(int m, int f, int r) {
 if (m == -1 || f == -1 ){
  return 'F';
 }
 if (m + f >= 80) {
 return 'A';
 }
 if (m +f >= 65 ) {
  return 'B';
 }
 if (m + f  >= 50 ) {
  return 'C'; 
}
 if(m + f >= 30 && r >= 50) return 'C';
 if(m + f >= 30) return 'D';
  return 'F';
}

int main() {
 int m, f, r;
 while(cin >> m >> f >> r, m + f + r != -3) {
  cout << grade(m, f, r) << endl;
 }
}

Measured memory_bytes: 3076
A, B, C ,K = map(int, input().split())
ans = 0
flg = True


if A <= K:
    ans += A*1
    K -= A
else:
    ans += K*1
    flg = False

if flg:
    if B <= K:
        ans += B*0
        K -= B
    else:
        ans += K*0
        flg = False

if flg:
    if C <= K:
        ans -= C*1
        K -= C
    else:
        ans -= K*1
        flg = False


print(ans)


Measured memory_bytes: 9136
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

LL A, B, C, D, E, F;
int dp[33] = {};
int su[3333] = {};

int main(void)
{
	cin >> A >> B >> C >> D >> E >> F;
	dp[0] = 1;
	for (int i = 1; i <= 30; ++i)
	{
		if (i - A >= 0)dp[i] |= dp[i - A];
		if (i - B >= 0)dp[i] |= dp[i - B];
	}
	su[0] = 1;
	for (int i = 1; i <= 3000; ++i)
	{
		if (i - C >= 0)su[i] |= su[i - C];
		if (i - D >= 0)su[i] |= su[i - D];
	}
	int total = 0, sugar = 0;
	for (int i = 1; i <= F / 100; ++i)
	{
		if (dp[i])
		{
			for (int j = 0; j <= i * E; ++j)
			{
				if (su[j])
				{
					int sum = (i * 100) + j;
					int sug = j;
					if (sugar * sum <= total * sug && sum <= F)
					{
						total = sum;
						sugar = sug;
					}
				}
			}
		}
	}
	cout << total << " " << sugar << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;

using namespace std;

int main(){
    string s, t;
    cin >> s >> t;

    pair<int,pair<int,int> > dp[s.size()+1][t.size()+1];
    for(int i = 0; i <= s.size(); i++){
        for(int j = 0; j <= t.size(); j++){
            dp[i][j] = make_pair(0,make_pair(-1,-1));
        }
    }

    for(int i = 0; i < s.size(); i++){
        for(int j = 0; j < t.size(); j++){
            if(s[i] == t[j]){
                if(dp[i+1][j+1].first < dp[i][j].first+1){
                    dp[i+1][j+1].first = dp[i][j].first+1;
                    dp[i+1][j+1].second = make_pair(i,j);
                }
            } else {
                if(dp[i][j].first > dp[i][j+1].first && dp[i][j].first > dp[i+1][j].first){
                    dp[i+1][j+1] = dp[i][j];
                } else if(dp[i][j+1].first > dp[i][j].first && dp[i][j+1].first > dp[i+1][j].first){
                    dp[i+1][j+1] = dp[i][j+1];
                } else {
                    dp[i+1][j+1] = dp[i+1][j];
                }
            }
        }
    }

    int i = dp[s.size()][t.size()].second.first;
    int j = dp[s.size()][t.size()].second.second;
    string ans = "";
    while(i != -1 && j != -1){
        ans = s[i] + ans;
        int t_i = dp[i][j].second.first;
        j = dp[i][j].second.second;
        i = t_i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 105856
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL;
  typedef pair<ll,char> PLC;
  typedef pair<char,ll> PCL;

int main(void){
  int N,K;cin >> N >> K;
  int i;
  double ans = 0;
  REP(i,N){
    int x = i+1;
    double prob = 1.0/N;
    while(x<K){
      x*=2;
      prob/=2.0;
    }
    ans+=prob;
  }
  printf("%.12f\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;

const int MOD = 1000000007;
const int INF = 1000000000;

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

int main(){
    string s, t, u; cin >> s >> t >> u;
    cout << s[0] << t[1] << u[2] << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define SQ(a) (a)*(a)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
int main()
{
	ll a,b,n,k;
	vector<pair<ll,ll>> vec;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&a,&b);
		vec.PB(MP(a,b));
	}
	sort(vec.begin(),vec.end());
	REP(i,0,n){
		k-=vec[i].second;
		if(k<=0){
		printf("%lld\n",vec[i].first);
		break;
		}
	}
	 return 0;
}




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

using namespace std;

vector <int> arr;

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

	int n;

	cin >> n;
	arr.resize(n);

	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		arr[i] -= (i + 1);
	}

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

	int thr = arr[n / 2];

	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		arr[i] -= thr;
		sum += abs(arr[i]);
	}

	cout << sum;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

const int MAX_V = 25;
const int INF = 1e8;

void init(int m[MAX_V][MAX_V]){
    rep(i,MAX_V) rep(j,MAX_V) m[i][j] = INF;
    rep(i,MAX_V) m[i][i] = 0;
}

void warshallFloyd(int m[MAX_V][MAX_V], int n, bool ignore[MAX_V]){
    rep(k,n){
        rep(i,n){
            rep(j,n){
                if(ignore[i] || ignore[j] || ignore[k]) continue;
                m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
            }
        }
    }
}

int main(){
    int n;
    while(cin >> n,n){
        int g[MAX_V][MAX_V] = {0};
        vector<int> v[MAX_V];
        rep(i,n - 1){
            int a, b, c;
            cin >> a >> b >> c;
            a--; b--;
            g[a][b] = g[b][a] = c;
            v[a].emplace_back(b);
            v[b].emplace_back(a);
        }

        bool ignore[MAX_V] = {0};
        range(i,1,n){
            if(v[i].size() == 1) ignore[i] = true;
        }

        int m[MAX_V][MAX_V];
        rep(i,n) rep(j,n) m[i][j] = g[i][j] == 0 ? INF : g[i][j];
        rep(i,n) m[i][i] = 0;
        warshallFloyd(m, n, ignore);

        int sum = 0;
        int maxi = 0;
        rep(i,n){
            rep(j,n){
                if(ignore[i] || ignore[j]) continue;
                sum += g[i][j];
            }
        }
        rep(i,n){
            if(ignore[i]) continue;
            maxi = max(maxi, m[0][i]);
        }
        //show(sum)
         //   show(maxi)
        cout << sum - maxi << endl;
    }
}

Measured memory_bytes: 3124
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
 
#define fi first
#define se second
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
 
const int MAXN = 1e5 + 5;
const int ha = 1e9 + 7;
int x[MAXN],y[MAXN];
int n,m;
P a[MAXN];
int N;
std::vector<int> S;
int f[MAXN];
 
struct BIT{
    #define lowbit(x) ((x)&(-(x)))
    int tree[MAXN];
 
    inline void add(int pos,int d){
        while(pos < MAXN){
            (tree[pos] += d) %= ha;
            pos += lowbit(pos);
        }
    }
 
    inline int query(int pos){
        int res = 0;
        while(pos){
            (res += tree[pos]) %= ha;
            pos -= lowbit(pos);
        }
        return res;
    }
}bit;
 
inline bool cmp(P x,P y){
    return x.fi == y.fi ? x.se > y.se : x.fi < y.fi;// 同列不得转移
}
 
int main(){
    scanf("%d%d",&n,&m);
    FOR(i,1,n) scanf("%d",x+i);
    FOR(i,1,m) scanf("%d",y+i);
    std::sort(x+1,x+n+1);std::sort(y+1,y+m+1);
    FOR(i,1,n){
        if(x[i] <= y[1] || x[i] >= y[m]) continue;
        int p = std::lower_bound(y+1,y+m+1,x[i]) - y;
        if(x[i] == y[p]) continue;
        a[++N] = MP(x[i]-y[p-1],y[p]-x[i]);
    }
    std::sort(a+1,a+N+1,cmp);
    FOR(i,1,N) S.pb(a[i].se);
    std::sort(all(S));
    S.erase(std::unique(all(S)),S.end());
    FOR(i,1,N) a[i].se = std::lower_bound(all(S),a[i].se)-S.begin() + 2;
    f[0] = 1;
    N = std::unique(a+1,a+N+1)-a-1;
//    FOR(i,1,N) printf("%d %d\n",a[i].fi,a[i].se);
    FOR(i,1,N){
        f[i] = bit.query(a[i].se-1)+1;f[i] %= ha;
        DEBUG(f[i]);
        bit.add(a[i].se,f[i]);
    }
    int ans = 0;
    FOR(i,0,N) (ans += f[i]) %= ha;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2808
#include <iostream>

using namespace std;

int main()
{
    int S, h, m, s;
    cin >> S ,
    h = S / 3600;
    m = (S - 3600 * h) / 60;
    s = (S - 3600 * h - 60 * m);
   cout << h << ":" << m << ":" << s << endl; 
   
   return 0;
}


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

#define OUT(x)  cerr << #x << " = " << x << endl;
#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define pll     pair<long long, long long>
#define ll      long long

int main() {
        string s;
        cin >> s;
        for (int i = 0; i < s.size(); i ++) if (i % 2 == 0) cout << s[i];
        cout << endl;
        return 0;
}



Measured memory_bytes: 512
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll i,n,a[100010],b[100010];
  cin >> n;
  ll sum=0;
  for(i=0;i<n+1;i++){
    cin >> a[i];
    sum+=a[i];
  }
  for(i=0;i<n;i++){
    cin >> b[i];
  }
  for(i=0;i<n;i++){
    if(a[i]>=b[i]){
      a[i]=a[i]-b[i];
    }
    else{
      b[i]=b[i]-a[i];
      a[i]=0;
      a[i+1]=max(ll(0),a[i+1]-b[i]);
    }
  }
  ll sum1=0;
  for(i=0;i<n+1;i++){
    sum1+=a[i];
  }
  cout << sum-sum1 << endl;
  return 0;
}

Measured memory_bytes: 5112
require 'prime'

PN = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97].freeze

# 素因数分解の結果pns から、指数が expo 以上の因数をカウントする
def count_pn(pns, expo)
  cnt = 0
  pns.count do |k, v|
    cnt += 1 if expo <= v
  end
  cnt
end

def main
  n = gets.chomp.to_i

  # 75数とは以下p,q,rの数式で表現できる数
  # ※以下、p, q, r は任意の素数を表す。
  #
  # 5*5*3 -> p^4 * q^4 * r^2
  # 15*5  -> p^14 * q^4
  # 25*3  -> p^24 * q^2
  # 75*1  -> p^74

  # n! を素因数分解
  pns = Hash.new(0)
  2.upto(n) do |x|
    a = Prime.prime_division(x) #=> [[5, 1], [197, 1], [461, 1]]
    # pp "#{x}: #{a}"
    pns.merge!(a.to_h) do |k, old_val, new_val|
      old_val + new_val
    end
  end
  # pp "#{n}: #{pns}"

  # 4通りのパターンいずれかに当てはまる n! の約数を数える
  # p^74 -> 74以上の指数を持つ素因数を数える
  # p^24 * q^2 -> 24以上の指数を持つ素因数の数 + (2以上の指数をもつ素因数の数 - 1)
  #               ※末尾 -1 は24以上の指数を持つ素因数の数を除くため
  # p^14 * q^4      -> 同上
  # p^4 * q^4 * r^2 -> 同上 / 2 ★pとqを入れ替えても同じ数になるので2で割っておく
  c74 = count_pn(pns, 74)

  c24 = count_pn(pns, 24)
  c2 = count_pn(pns, 2)

  c14 = count_pn(pns, 14)
  c4 = count_pn(pns, 4)

  # puts "75: #{c74}"
  # puts "25*3: #{c24} * #{c2-1}"
  # puts "15*5: #{c14} * #{c4-1}"
  # puts "5*5*3: #{c4} * #{c4-1} * #{c2-2}" / 2

  puts c74 + (c24 * (c2-1)) + (c14 * (c4-1)) + (c4 * (c4-1) * (c2-2) / 2)
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 2044
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  string s;
  int n, k;
  cin >> n >> k >> s;
  k--;
  s[k] = s[k] - 'A' + 'a';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict


def solve():
    N = int(input())
    w_dict = defaultdict(int)
    pw = input()
    w_dict[pw] = 1
    for _ in range(N - 1):
        cw = input()
        if cw[0] != pw[-1] or w_dict[cw] == 1:
            print('No')
            exit()
        w_dict[cw] = 1
        pw = cw
    print('Yes')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3316
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();

		System.out.println(Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)));
	}
}



Measured memory_bytes: 27952
s = input()
l = 0
r = len(s)-1
ans = 0
while r-l > 0:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x':
        ans += 1
        l += 1
    elif s[r] == 'x':
        ans += 1
        r -= 1
    else:
        ans = -1
        break
print(ans)


Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        String[] str = br.readLine().split(" ");
        String s = br.readLine();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i += 2) {
            sb.append(s.charAt(i));
        }
        System.out.println(sb.toString());
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<(_loop_int)v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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



int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    string s;
    int k;
    cin>>s;
    cin>>k;

    int n = s.size();
    REP(i,n){
        int tmp = (26 - (s[i]-'a')) % 26; 
        if(k >= tmp){
            s[i] = 'a';
            k -= tmp;
        }
    }

    k %= 26;

    while(k>0){
        s[n-1] = s[n-1]+1;
        if(s[n-1]>'z'){
            s[n-1]='a';
        }

        k--;
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3752
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if(abs(a - c) <= d){
    printf("Yes\n");
  }else if(abs(a - b) <= d && abs(b - c) <= d){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
  int a,b,n=0;
  while(cin>>a>>b&&a){
    bool f=true;
    for(int i=a-a%4;i<=b;i+=4){
      if(i==a-a%4){
	if(n){
	  cout<<endl;
	}
	n++;
	if(a%4) continue;
      }
      if(i%100||!(i%400)){
	cout<<i<<endl;f=false;
      }
    }
    if(f) cout<<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define sqr(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; i++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())

#define FI first
#define SE second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define PB push_back

typedef map<int, int> MII;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long ll;
const int M = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const ll linf = 1e18;
const int N = 1e6+10;
// header

int n, a[N];

int main(){
    cin >> n;
    rep(i, n) {
        scanf("%d", &a[i]);
        a[i]--;
    }
    int ans = 0;
    rep(i, n-1){
        if(a[i] == i) {
            swap(a[i], a[i+1]);
            ans++;
        }
    }
    if(a[n-1] == n-1) ans++;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long 
using namespace std;

signed main() {
	int A,B,H;
	cin >> A >> B >> H;
	cout << (A + B) * H / 2 << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque


def IN_I(): return int(sys.stdin.readline().rstrip())
def IN_LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def IN_S(): return sys.stdin.readline().rstrip()
def IN_LS(): return list(sys.stdin.readline().rstrip().split())


H, W = IN_LI()
s = [IN_S() for _ in range(H)]

dh = [-1, 0, 1, 0]
dw = [0, -1, 0, 1]

dist = [[-1] * W for j in range(H)]
dist[0][0] = 0

q = deque()
q.append([0, 0])

while q:
    now = q.popleft()
    now_h = now[0]
    now_w = now[1]

    for i in range(4):
        next_h = now_h + dh[i]
        next_w = now_w + dw[i]

        if not (0 <= next_h < H and 0 <= next_w < W):
            continue
        if s[next_h][next_w] == '#':
            continue

        if dist[next_h][next_w] == -1:
            q.append([next_h, next_w])
            dist[next_h][next_w] = dist[now_h][now_w] + 1

if dist[-1][-1] == -1:
    print(-1)
    exit()

black = sum([i.count('#') for i in s])
ans = (H * W - black) - (dist[-1][-1] + 1)
print(ans)


Measured memory_bytes: 9424
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, a, c = 0;
  
  std::cin >> N;

  for (int i = 0; i < N; i ++) {
    std::cin >> a;

    for ( ; a % 2 == 0; a >>= 1)
      c ++;
  }

  std::cout << c << std::endl;

  return 0;
}


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

typedef long long ll;

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

// chmax, chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int N;
    cin >> N;
    vector<vector<ll>> A(N,vector<ll>(N));
    vector<vector<bool>> used(N,vector<bool>(N,true));
    REP(i,N) REP(j,N) cin >> A[i][j];
    REP(i,N) used[i][i] = false;
    
    bool exist = true;
    
    REP(k,N) REP(i,N) REP(j,N) {
        if ( i == j or j == k or k == i ) continue;
        if ( A[i][j] > A[i][k] + A[k][j] ) {
            exist = false;
        }
        if ( A[i][j] == A[i][k] + A[k][j] ) {
            used[i][j] = false;
        }
    }
    
    ll ans = 0;
    REP(i,N) REP(j,N) {
        if ( used[i][j] ) ans += A[i][j];
    }
    
    if ( exist ) cout << ans/2 << endl;
    else cout << -1 << endl;
    
    return 0;
}

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

int main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

void code() {
    int k;
    cin>>k;
    int ans=0;
    if(k%2==0) {
        cout << "-1\n";
        return;
    }
    unordered_set<int> s;
    int rem = 7%k;
    int i=1;

    while(1) {
        if(rem == 0) {
            cout << i << '\n';
            return;
        }
        if(s.find(rem)!=s.end()){
            cout << "-1\n";
            return;
        }
        s.insert(rem);
        rem = (rem*10)%k;
        rem = (rem+7)%k;
        i++;

    }



    cout << ans << "\n";
}

signed main() {
    std::ios_base::sync_with_stdio(false);
    int t=1;
    // cin>>t;
    for(int i=0; i<t; i++) {
        code();
    }
}


Measured memory_bytes: 42720
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;


//二進数に変換
void change(int n, vector<bool> &V){
  int i = 0;
  while(n > 0){
    int x;
    x = n%2;
    V[i] = x;
    n /= 2;
    i++;
  }
}

int main(){
  int N;
  cin >> N;
  int ans = -10000000000;
  
  vector<vector<bool>> inf(100, vector<bool> (10, false));
  rep(i, N){
    rep(j, 10){
      int F;
      cin >> F;
      if(F == 1){
        inf[i][j] = true;
      }
    }
  }
  
  vector<vector<int>> benefit(N, vector<int> (11));
  rep(i, N){
    rep(j, 11){
      int P;
      cin >> P;
      benefit[i][j] = P;
    }
  }
  
  for(int i = 1; i < 1024; i++){//営業時間を決める
    vector<bool> V(10, false);//初期化
    change(i, V);
    //チェック
     //rep(i, 10){
       //cout << V[i];
   // }
    //cout << endl;
    
    int sum = 0;
    
    rep(j, N){//店を決める      
      //被っている回数を数える
      int counter = 0;
      rep(k, 10){
        if(V[k] == true && inf[j][k] == true){
          counter++;
        }
      }
     //cout << j << " " << counter << endl;//テスト
      
      //cout << benefit[j][counter] << endl;
      sum += benefit[j][counter];
    }
    
   //cout << sum << endl;//テスト
    
    ans = max(ans, sum);
  }
  
  cout << ans << endl;
}
       

Measured memory_bytes: 256