akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll dp[3000];
ll N, M;
ll A[5005], B[5005], C[5005];
ll P;

void f() {
    for(int timer = 0; timer <= M; timer++) {
        for(int i = 1; i <= M; i++) {
            chmax(dp[B[i]], dp[A[i]] + C[i] - P);
        }
    }
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> P;
    for(int i = 1; i <= M; i++) {
        cin >> A[i] >> B[i] >> C[i];
    }
    for(int i = 1; i <= N; i++) {
        dp[i] = -1e17;
    }
    dp[1] = 0;
    f();
    ll ans = dp[N];
    //for(int i = 1; i <= N; i++) cerr << i << " " << dp[i] << endl;
    cerr << dp[N] << endl;
    f();
    cerr << dp[N] << endl;
    if(ans != dp[N]) ans = -1;
    else if(ans < 0) ans = 0;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
n, k = map(int, input().split())
r, s, p = map(int, input().split())

pr = input()
pool = []

def iWannaRemotework():
    for i, x in enumerate(pr):
        if i >= k:
            no = pool[i-k]
        else:
            no = ""

        if x == no:
            pool.append("")
            yield 0
        elif x == "r":
            pool.append("r")
            yield p
        elif x == "s":
            pool.append("s")
            yield r
        else:
            pool.append("p")
            yield s

print(sum(iWannaRemotework()))


Measured memory_bytes: 4084
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const int MAX=1e5+1;
const ll INF=1e9;

int main()
{
    ll n,a,b,c,d,e;
    cin>>n>>a>>b>>c>>d>>e;
    ll ans=max({(n-1)/a,(n-1)/b,(n-1)/c,(n-1)/d,(n-1)/e})+5;
    cout<<ans;

}

Measured memory_bytes: 256
import java.util.*;
class Main {
	public static void main (String[] args) throws java.lang.Exception {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int H = sc.nextInt(), W = sc.nextInt();
			if(H == 0 && W == 0) break;
			for(int i = 0; i < H; i++) {
				for(int j = 0; j < W; j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 34396
#include <iostream>
#include<memory.h>
using namespace std;
int a[1000001];
int main()
{
    memset(a,0,sizeof(a));
    int n;
    cin>>n;
    long long int count=0;
    for(int i=0;i<n;i++)
    {
    	int b;
    	cin>>b;
    	count+=b;
    	a[b]++;
	}
	int q;
	cin>>q;
	for(int i=0;i<q;i++)
	{
		int m,n;
		cin>>m>>n;		
		a[n]+=a[m];
		int c=a[m];
		a[m]=0;
		count=count+c*(n-m);
		cout<<count<<endl;
	}
} 

Measured memory_bytes: 7508
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  dump(c >= a && c <= b ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int a=N/100;
		int b=(N%100)/10;
		int c=N-(a*100+b*10);
		String ans="No";
		if(a==7||b==7||c==7){
			ans="Yes";
		}
		System.out.println(ans);

	}

}


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

int main() {
    int n;
    cin >> n;
    int p = 1, cnt = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if (a == p)
            p++;
        else {
            cnt++;
        }
    }
    if (p == 1) {
        puts("-1");
        return 0;
    } else
        cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

int n,a,b,c,p;

int main(){
	scanf("%d",&n);
	scanf("%d %d",&a,&b);
	scanf("%d",&c);
	std::vector<int> cal(n); 
	for(int j=0;j<n;j++) {
		scanf("%d",&cal[j]);
		}

	sort( cal.begin(), cal.end(),greater<int>() );
	
	float max=c/a; //値段当たりのカロリー
	for(int k=0;k<n;k++){
		int t=0;
		for(int l=0;l<k;l++) t=t+cal[l];
		p=(c+t)/(a+k*b);
		if(p>max) max=p;
	}
	int bp = int(max);
	printf("%d\n",bp);
	return 0;
}

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

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

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

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(){
 ll sum = 0;
 int K;
 cin >> K;
 for(int i = 1; i <= K; i++){
   for(int j = 1; j <= K; j++){
     for(int m = 1; m <= K; m++){
       sum += gcd(i, gcd(j, m));
     }
   }
 }
 cout << sum << "\n";
 return 0;
}


Measured memory_bytes: 3592
#include<iostream>
using namespace std;
typedef long long int ll;

int T;

ll GCD(ll a, ll b){
	if(b == 0) return a;
	else return GCD(b, a % b);
}

int main(){
	cin >> T;
	for(int i = 0; i < T; i++){
		ll A, B, C, D;
		cin >> A >> B >> C >> D;
		if(A < B || B > D){
			cout << "No" << endl;
			continue;
		}
		A %= B;
		if(A > C && C < B){
			cout << "No" << endl;
			continue;
		}
		ll g = GCD(B, D);
		if(B - g + (A % g) > C){
			cout << "No" << endl;
			continue;
		}
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next(), t = sc.next();
		int a = sc.nextInt(), b = sc.nextInt();
		String u = sc.next();
		if(u.equals(s)) {
			a--;
		}else {
			b--;
		}
		System.out.println(a+" "+b);
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<bitset>
#include<tuple>
#include<time.h>
#include<list>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

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; }




void solve(){
	int n, a[1010];
	cin >> n;
	bool b = 1;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] % 2 == 0){
			if(a[i] % 3 != 0 && a[i] % 5 != 0){
				b = 0;
			}
		}
	}
	if(b) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
}

int main(){
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int a, b; cin >> a >> b;

    vector<string> s(100);
    for (int i = 0; i < 50; i++) s[i] = string(100, '.');
    for (int i = 50; i < 100; i++) s[i] = string(100, '#');
    for (int i = 0; i < b - 1; i++) {
        s[(i / 25) * 2][(i % 25) * 2] = '#';
    }
    for (int i = 0; i < a - 1; i++) {
        s[(i / 25) * 2 + 51][(i % 25) * 2] = '.';
    }
    cout << 100 << ' ' << 100 << '\n';
    for (auto e: s) cout << e << '\n';
    return 0;
}


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

#define F first
#define S second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n, m;
    cin >> n >> m;
    pair<int, int> p;
    vector<pair<int, int>> v(m);
    for (int i = 0; i < m; i++) {
        cin >> p.S >> p.F;
        v[i] = p;
    }
    vsort(v);
    
    int cnt = 1, tmp = v[0].first;
    for (int i = 0; i < m; i++) {
        if (v[i].second >= tmp) {
            cnt++;
            tmp = v[i].first;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int rowtw[N],coltw[N],dpostw[2*N-1],dnegtw[2*N-1];

int Xtw[N][N];

void initialize(){
  for(int i=0;i<N;i++){
    rowtw[i]=FREE;
    coltw[i]=FREE;
  }
  for(int i=0;i<2*N-1;i++){
    dpostw[i]=FREE;
    dnegtw[i]=FREE;
  }
}

void printBoard(){
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(Xtw[i][j]){
	if(rowtw[i]!=j)return;
      }
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(rowtw[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  if(i==N){
    printBoard();
    return;
  }

  for(int j=0;j<N;j++){
    if(NOT_FREE==coltw[j]||
       NOT_FREE==dpostw[i+j]||
       NOT_FREE==dnegtw[i-j+N-1])continue;
    rowtw[i]=j;
    coltw[j]=dpostw[i+j]=dnegtw[i-j+N-1]=NOT_FREE;
    recursive(i+1);
    rowtw[i]=coltw[j]=dpostw[i+j]=dnegtw[i-j+N-1]=FREE;
  }
}

int main(){
  initialize();

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++)Xtw[i][j]=0;
  }

  int k;
  scanf("%d",&k);
  for(int i=0;i<k;i++){
    int r,c;
    scanf("%d %d",&r,&c);
    Xtw[r][c]=1;
  }

  recursive(0);

  return 0;
}



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

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define MAXX 200005


#define PI 3.14159265358979323846264338327950

#define ll  long long int
vector<pair<ll, ll> > v;
multiset<ll> ms;
multiset<ll>::iterator it;
ll a[MAXX], b[MAXX];
ll mod = 1000000007;
char c[MAXX];
bool used[MAXX];
int main()
{
	FAST;
	memset(used, true, sizeof(used));
	ll  ans = 0, a1 = 0, a2 = 0, n;
	cin >> n;
	for(ll i = 0; i < n; i++){
		cin >> a1;
		v.push_back({a1, i});
	}
	sort(v.begin(), v.end());
	while(!v.empty()){
        int x = v[0].first;
        int y = v[0].second;
        v.erase(v.begin());
        int s = 0;
        for(int i = 0; i < v.size(); i++){
            v[i].first -= x;
        }
        for(int i = 0; i < n; i++){
            if(used[i])
                s++;
            if(i && used[i] && used[i - 1])
                s--;
        }
        used[y] = false;
        ans += s * x;
    }
	cout << ans;
	
}

Measured memory_bytes: 512
n = int(input())
S=[]
for i in range(n):
    s=input()
    S.append(s)
S.sort()
import collections
c = collections.Counter(S)
values, counts = zip(*c.most_common())
print(values[0])
for i in range(len(counts)-1):
    if counts[i] == counts[i+1]:
        print(values[i+1])
    else:
        exit()
        

Measured memory_bytes: 62524
#include <stdio.h>
#include <bitset>
#include <vector>
using namespace std;
#define PB push_back
const int N=5e2+10;
vector<int> back[N],graph[N];
bitset<N> went,used;
int con[N],to[N];
bool dfs(int now){
    went[now]=true;
    for(int i:graph[now])if(con[i]==-1||(!used[con[i]]&&!went[con[i]]&&dfs(con[i]))){
        con[i]=now;
        to[now]=i;
        return true;
    }
    return false;
}
int main(){
    int n,temp;
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        con[i]=-1;
        for(int j=1;j<n;j++){
            scanf("%d",&temp);
            if(temp==1){
                graph[i].PB(j);
                back[j].PB(i);
            }
        }
    }
    for(int i=1;i<n;i++){
        went.reset();
        if(!dfs(i)){
            printf("no\n");
            return 0;
        }
    }
    used.reset();
    printf("yes\n");
    for(int i=1;i<n;i++){
        for(int j:back[i])if(!used[j]){
            if(j>=con[i])break;
            went.reset();
            went[j]=true;
            temp=con[i];
            con[i]=j;
            con[to[j]]=-1;
            if(dfs(temp))break;
            con[i]=temp;
            con[to[j]]=j;
        }
        used[con[i]]=true;
        printf("%d\n",con[i]);
    }
}


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

const int INF = 1e9;

int main() {
  int n,k;
  cin>>n>>k;
  int cnt[200001];
  for(int i=0;i<200001;i++){
    cnt[i]=0;
  }
  for(int i=0;i<n;i++){
    int ai;
    cin>>ai;
    ++cnt[ai];
  }
  sort(cnt,cnt+200001);
  reverse(cnt,cnt+200001);
  int ans=0;
  for(int i=k;i<n;i++){
    if(cnt[i]==0){
      cout<<ans<<endl;
      return 0;
    }
    ans+=cnt[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
int a,b,c;
cin>>a>>b>>c;
if(max({a,b,c})*2==a+b+c) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 int main(void)
{
 int a,b,i,d;
 while(1){ scanf("%d %d",&a,&b);
 if(a==0 && b==0) break;
 for(i=0;
i<a;
i++)
{
 for(d=0;
d<b;
d++)
 {
 printf("#");
 }
 printf("\n");
 }
 printf("\n");
 }
 return 0;
 } 


Measured memory_bytes: 2104
//#pragma GCC target ("avx2,sse2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>

using namespace std;

const int N = 2e6 + 14;
const int INF = 1e9;
const int mod = 1e9;
const int SZ = (1 << 17) - 1;
const int K = 320;

#define eb emplace_back
#define sz(s) (int)(s.size())
#define ppb pop_back

#define ll long long

#define int ll

int a[N], p[N];

void solve() {
	int n;
	cin >> n;
	int mn = INF;
	for (int i = 1; i <= n; ++ i) {
		cin >> a[i];
		mn = min(mn, a[i]);
		p[i] = mn;
	}
	int ans = 0;
	for (int i = 1; i <= n; ++ i)
		ans += (p[i] == a[i]);
	cout << ans;
}

main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cerr << "Ready\n";
	solve();
	return 0;
}

Measured memory_bytes: 5888
n = int(input())
s = [input() for i in range(n)]
t = []
for i in range(n):
    u = []
    for j in range(n):
        u.append(s[j][i])
    t.append("".join(u))

ans = 0
for i in range(n):
    a = []
    b = []
    for k in range(n):
        a.append(s[k][n-i:])
        a.append(s[k][:n-i])
        b.append(t[(k-i)%n])
    if "".join(a) == "".join(b):
        ans += 1

print(ans*n)


Measured memory_bytes: 3548
n = int(input())
a = [int(input()) for _ in range(n)]
if a[0] != 0 or any(a[i+1]-a[i]>1 for i in range(n-1)):
    print(-1)
    exit(0)
ans = 0
for i in range(1,n):
    if a[i] == a[i-1] + 1:
        ans += 1
    else:
        ans += a[i]
print(ans)

Measured memory_bytes: 11060
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  set<int> s;
  for(int i=0; i<n; i++){
    if(s.count(a[i])){
      s.erase(a[i]);
    }
    else s.insert(a[i]);
  }
  cout << s.size() << endl;
}

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

int main() {
  string a, b;
  cin >> a >> b;
  for(int i = 0; i < a.size(); i++) {
    int f = 1;
    for(int j = 0; j < b.size(); j++) {
      for(int k = i, l = 0; l < a.size(); l++, k++, k%=a.size()) {
        if(b[l] != a[k]) f = 0;
      }
    }
    if(f)
      puts("Yes"), exit(0);
  }
  puts("No");
  return 0;
}


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

using namespace std;

int main() {
  int m, a, b;
  bool primes[100005];
  for (int i = 0; i < 100005; i++) primes[i] = true;
  primes[0] = primes[1] = false;
  for (int i = 2; i < 100005; i++) {
    if (!primes[i]) continue;
    for (int j = 2 * i; j < 100005; j += i) {
      primes[j] = false;
    }
  }

  while (true) {
    cin >> m >> a >> b;
    if (m == 0) break;

    int res = 0, x, y;
    for (int p = 2; p < m; p++) {
      for (int q = p; q <= m / p; q++) {
        if (a * q > b * p) continue;
        if (primes[p] && primes[q]) {
          if (res <= p * q) {
            x = p;
            y = q;
            res = p * q;
          }
        }
      }
    }

    cout << x << " " << y << "\n";
  }

  return 0;
}


Measured memory_bytes: 3132
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
 
int main(void)
{
    ll N,K,S;
    cin >> N >>K >>S;
    vector<int> A(N);
    for(int a=0;a<N;a++){
        if(a<K){
            A[a]=S;
        }else{
            A[a]=S+1;
        }
    }
    for(int a=0;a<N;a++){
        if(A[a]<=1000000000){
            cout << A[a]<< " ";
        }else{
            cout <<"1"<< " ";
        }
    }
    cout << endl;
}

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

int main() {
    int n, q, A[25], B[400010] = {}, m[210];
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> A[i];
    cin >> q;
    for (int i = 0; i < q; ++i) cin >> m[i];

    for (int i = 0; i < 1 << n; ++i) {
        int sum = 0;
        for (int j = 0; j < n; ++j) {
            if (1 & i >> j) sum += A[j];
        }
        B[sum] = 1;
    }

    for (int i = 0; i < q; ++i) {
        if (B[m[i]]) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}


Measured memory_bytes: 4640
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    int n;
    vector<int> p;
    cin>>n;
    p.resize(n,0);
    for (int i = 0; i < p.size(); i++)
    {
        cin>>p[i];
    }
    vector<int> bufs;
    int count=0;
    for (int i = 1; i < p.size()-1; i++)
    {
        bufs.assign(&p[i-1],&p[i+2]);
        sort(bufs.begin(),bufs.end());
        if(bufs[1]==p[i])
        {
            count++;
        }
    }
    cout<<count<<endl;    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int A, B, T; cin >> A >> B >> T;

  int ans = 0;
  for (int i = 0; i < T+0.5; i+=A) {
    ans += B;
  }

  cout << ans-B << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.Closeable;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HBonsai
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BSumo solver = new BSumo();
        solver.solve(1, in, out);
        out.close();
    }

    static class BSumo {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String S = in.next();
            int win = 0;
            int lose = 0;
            for (int i = 0; i < S.length(); i++) {
                if (S.charAt(i) == 'o') win++;
                else lose++;
            }
            if (lose < 8) out.println("YES");
            else out.println("NO");
        }

    }

    static class FastScanner implements Closeable {
        private final InputStream in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public void close() {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}



Measured memory_bytes: 21588
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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 k;


void dfs(int d,ll cur,vector<ll>& a) {
	a.push_back(cur);
	if(d==10) return;

	
	for(int i = -1;i<=1;i++) {
		int add = cur%10;
		if(add+i>=0 && add+i<=9) dfs(d+1,cur*10+add+i,a);
	}
	return;
}


int main() {
	cin >> k;
	vector<ll>a;
	for(ll i = 1LL;i<=9LL;i++) {
		dfs(1,i,a);
	}
	sort(a.begin(),a.end());
	cout << a[k-1] << endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<double> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n - 1; i++) {
        v.at(i + 1) = (v.at(i + 1) + v.at(i)) / 2;
    }
    cout << fixed << setprecision(10) << v.at(n - 1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ar[55];
int main(){
	int n,k;cin>>n>>k;for(int i=1;i<=n;i++)cin>>ar[i];sort(ar+1,ar+n+1);
  	cout<<accumulate(ar+n-k+1,ar+n+1,0);
}

Measured memory_bytes: 256
n,m=map(int,input().split())
H=list(map(int,input().split()))
ans = [1]*n
for i in range(m):
  a,b=map(int,input().split())
  if H[a-1]>=H[b-1]:
    ans[b-1] = 0
  if H[a-1]<=H[b-1]:
    ans[a-1] = 0
print(sum(ans))


Measured memory_bytes: 20088
#include<bits/stdc++.h>
#define rep(i,N) for(ll i=0; i<N; i++)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll N_MAX = 100000;

int main(){
    ll n; cin >> n;
    ll d[n]; rep(i,n) cin >> d[i];

    ll sum = 0;
    rep(i,n) sum += d[i];

    ll ans = 0;
    rep(i,n) ans += d[i] * (sum - d[i]);
    cout << ans / 2 << endl;
}

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

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


int main(){
	ll n,k;
	ll r,s,p;
	string t;
	cin >> n >> k;
	cin >> r >> s >> p;
	cin >> t;

	ll max = 0;
	for(int i=0;i<t.length();i++){
		if(t[i]=='r') max += p;
		if(t[i]=='s') max += r;
		if(t[i]=='p') max += s;
	}

	for(int i=0;i<k;i++){
		for(int j=i;j+k<t.length();j+=k){
			if(t[j]==t[j+k]){
				if(t[j]=='r') max -= p;
				if(t[j]=='s') max -= r;
				if(t[j]=='p') max -= s;
				t[j+k] = 'x';
			}
		}
	}

	cout << max << endl;

	return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Changing a Character
            var line = ReadLine();
            int n = line[0];
            int k = line[1];

            var s = Console.ReadLine();

            var left = s.Substring(0, k - 1);
            var right = s.Substring(k, n - k);
            var lower = s[k - 1].ToString().ToLower();

            Console.WriteLine(left + lower + right);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1;
  int dy = y2 - y1;
  cout << x2 - dy << ' ' << y2 + dx << ' ' << x1 - dy << ' ' << y1 + dx << endl;
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 1e9+7,MAX = 1e6+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vector<int> MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
	for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////

int main()
{
	ll n;
	cin>>n;
	vector<char> V;

	while(n)
	{
		int x = n%26;
		if(x==0)
		{
			V.push_back('z');
			n/=26;
			n--;
		}
		else
		{
			x--;
			V.push_back('a'+x);
			n/=26;
		}
	}	
	reverse(all(V));
	for(int i=0;i<V.size();i++) cout<<V[i];
	cout<<endl;
}		

Measured memory_bytes: 7024
n = int(input())
cards = map(int, input().split(' '))
sorted_cards = sorted(cards,reverse=True)

alice_sum = 0
bob_sum = 0
for i in range(n):
    if i % 2 == 0:
        alice_sum += sorted_cards[i]
    else:
        bob_sum += sorted_cards[i]

print(alice_sum - bob_sum)

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rept(i,k,n) for(long long i = (k); i < (long long)(n); i++)
#define All(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Rsort(v) sort(v.begin(),v.end(),[](auto a, auto b) { return a > b; })
#define Reverse(v) reverse(v.begin(),v.end())
#define MAX 1000000007
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;
typedef tuple<int,int,int> Tii;

template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
    for(int i=0;i<vec.size();i++){
        if(i) s << ',';
        else s << '{';
        s <<setw(2)<< vec[i];
    }
    s << '}' << endl;
    return s;
}


ll mod = 1e9+7;
int main(){
    int h,w,m;
    cin>>h>>w>>m;
    vector<Pii> bm(m);
    vector<Pii> cnt(w,Pii(0,0));

    rep(i,m){
        int hh,ww;
        cin >> hh>>ww;
        bm[i]=Pii(hh-1,ww-1);
        cnt[ww-1].first++;
    }
    rep(i,w) cnt[i].second=i;
    Sort(bm);
    Rsort(cnt);
    int mx=cnt[0].first;
    vector<int> li(0);
    rep(i,w){
        if(cnt[i].first==mx) li.push_back(cnt[i].second);
        else break;
    }
    Sort(li);
    int ans=0;
    int k=0,n=0;
    rep(i,h){
        int c=0;
        bool b=false;
        vector<int> lii(0);
        for(;k<m;k++){
            if(bm[k].first!=i) break;
            lii.push_back(bm[k].second);
            c++;
        }
        Sort(lii);
        for(int x:li){
            if(!binary_search(lii.begin(),lii.end(),x)){
                b=true;break;
            }
        }
   //     cout<<c+mx+b-1;
        if(b) ans=max(ans,c+mx);
        else ans=max(ans,c+mx-1);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 12128
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main(){
  int n;
  char v;
  map<char,int> a;
  bool flag;
  while(cin >> n,n){
    a.clear();
    flag = false;
    int f = '0', s = '0';
    for(int i=0;i<n;i++){
      cin >> v;
      // cout << v << endl;
      a[v]++;
      if(a[v] > a[f]){s=f;f=v;}
      else if(a[v] > a[s] && v != f){s=v;}
      if(n-i-1<a[f]-a[s]){
        cout << (char)f << " " << i+1 << endl;
        while(i<n-1){cin >> v;i++;}
        flag = true;
      }
    }
    if(a[f]==a[s])cout << "TIE" << endl;
    else if(!flag) cout << (char)f << " " << a[f] << endl;
  }
}

Measured memory_bytes: 3064
class UnionFind:
    def __init__(self,N):
        self.par=[i for i in range(N)]
        self.siz=[1 for _ in range(N)]
        self.rank=[0 for _ in range(N)]
    def find(self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def union(self,a,b):
        a=self.find(a)
        b=self.find(b)
        if a==b:
            return 0
        else:
            if self.rank[a]>self.rank[b]:
                self.par[b]=a
                self.siz[a]+=self.siz[b]
            else:
                self.par[a]=b
                self.siz[b]+=self.siz[a]
                if self.rank[a]==self.rank[b]:
                    self.rank[b]+=1
    def size(self,a):
        return self.siz[self.find(a)]
    def same(self,a,b):
        return self.find(a)==self.find(b)

N,M=map(int,input().split())
DSU=UnionFind(N)
for _ in range(M):
    A,B=map(lambda x:int(x)-1,input().split())
    DSU.union(A,B)
s=set([DSU.find(i) for i in range(N)])
print(len(s)-1)

Measured memory_bytes: 92412
//k_k_dubey_
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define inf 999999999999
#define mx 200005
#define gcd __gcd
#define pb push_back
#define mk make_pair
#define bs binary_search
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define vl vector<ll>
#define vs vector<string>
#define non __builtin_popcount
#define ml map<ll, ll> 
#define ms map<string , ll> 
using namespace std;

bool isp[mx];

void sv(){

	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}

ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	//sv();
	
	ll n,i,j,a[mx];
	cin>>n;
	ll ct=0;
	for(i=1; i< n+1; i++)
	{
		cin>>a[i];
		if(a[i] != i)
		ct++;
	}
	
	if(ct==0 || ct==2)
	cout<<"YES\n";
	else
	cout<<"NO\n";
	
    return 0;
}























Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
    int a,b,c;
    string s;
    cin >> s;
    for (int i= s.size()-1;i > 0;i++){
        s.erase(s.size()-1,1);
        //cout << s.size() << " " << s << endl;

        if (s.size()%2 == 1) continue;
        bool f = true;
        for(int i=0;i < s.size()/2;i++){
            if (s[i] != s[s.size()/2+i]){
                f = false;
                break;
            }
        }
        if (f) {
            cout << s.size() << endl;
            return 0;
        }
    }   
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>
#include <iomanip>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

inline double dot(const P &a, const P &b) {
	return (conj(a) * b).real();
}

bool is_rect(P a[2], P b[2]) {
	double a_l = min(a[0].real(), a[1].real());
	double a_r = max(a[0].real(), a[1].real());
	double b_l = min(b[0].real(), b[1].real());
	double b_r = max(b[0].real(), b[1].real());
	double a_d = min(a[0].imag(), a[1].imag());
	double a_u = max(a[0].imag(), a[1].imag());
	double b_d = min(b[0].imag(), b[1].imag());
	double b_u = max(b[0].imag(), b[1].imag());
	if(a_l > b_r || a_r < b_l || a_d > b_u || a_u < b_d) return false;
	return true;
}

int main() {
	for (double x, y; cin >> x >> y; ) {
		P a[2], b[2];
		a[0] = P(x, y);
		rep(i, 3) {
			double x, y; cin >> x >> y;
			if (i == 0) a[1] = P(x, y);
			else b[i - 1] = P(x, y);
		}
		if (is_rect(a, b)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int main()
{
    ll a, b, c ;
    cin >> a >> b >> c ;
    if (a + b >= c) cout << "Yes" ;
    else    cout << "No" ;

    return 0 ;
}


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

// 最長N = 100,000 は
// 総和が(最長+1)*(最長/2)で10桁かなー
#define AN_LEN (10 + 1)  

// 要するに最小操作回数だけを求めるならば
// NとKだけで良い？
// 必ず1個ずれるみたいだから範囲-1の回数を
// 整数の数から引ける回数 = ans ということ？
int main(void)
{
    unsigned int  N, K;
    unsigned int  ans = 0;
    char An[AN_LEN];
    
    scanf("%d", &N);
    scanf("%d", &K);
    fgets(An, AN_LEN, stdin);

    while(1){
      if (N <= K){ 
        ans++;
        break;
      }else{
        N -= (K - 1);
        ans++;
      }
    }

    printf("%d", ans);
    return 0;
}



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

int main( void )
{
  int N, K;
  cin >> N >> K;
  vector<int> l( N );
  int sum = 0;

  for( int i = 0; i < N; i++ )
    cin >> l.at( i );

  sort( l.begin(), l.end(), greater<int>() );

  for( int i = 0; i < K; i++ )
    sum += l.at( i );

  cout << sum << endl;
}

Measured memory_bytes: 3604
ask=->n{$>.<<("? %d\n"%n).flush;gets.chomp=='Y'}
put=->n{$>.<<("! %d\n"%n).flush;exit}
if ask[10**9]
	i=1;loop{ask[i*2]&&put[i];i*=10}
else
	i=10**9;loop{ask[i]&&put[(i+1..i*10-1).bsearch{|e|ask[e*10+9]}];i/=10}
end

Measured memory_bytes: 4172
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b, k;
	cin >> a >> b >> k;

	int ans = 0;

//	vector<int> d(100);

	for (int i = 100; i > 0; i--) {
		if (a%i == 0 && b%i == 0) {
			ans++;
		}
		if (ans == k) {
			cout << i << endl;
			break;
		}
	}






	

	return 0;
}

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

using namespace std;

int main(){
    string x;
    cin >> x;
    int a, b;
    a = accumulate(x.begin(), x.end(), 0, [](int i, char j){ return i + (int)(j - '0'); });
    b = stoi(x);
    cout << (b % a == 0 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class StrongConnectedComponents:
    def __init__(self, n):
        self.n = n
        self.G = [[] for _ in range(n)]
        self.rG = [[] for _ in range(n)]
        self.cmp = [-1] * n

    def add_edge(self, frm, to):
        self.G[frm].append(to)
        self.rG[to].append(frm)

    def dfs(self, s):
        self.used[s] = 1
        for t in self.G[s]:
            if not self.used[t]:
                self.dfs(t)
        self.vs.append(s)

    def rdfs(self, s, k):
        self.used[s] = 1
        self.cmp[s] = k
        for t in self.rG[s]:
            if not self.used[t]:
                self.rdfs(t, k)

    def scc(self):
        self.vs = []
        self.used = [0] * self.n
        for v in range(self.n):
            if not self.used[v]:
                self.dfs(v)
        self.used = [0] * self.n
        k = 0
        for v in reversed(self.vs):
            if not self.used[v]:
                self.rdfs(v, k)
                k += 1
        return k, self.make_pair(k)

    def make_pair(self, k):
        res = [[] for _ in range(k)]
        for i, v in enumerate(self.cmp):
            res[v].append(i)
        return res


N, M = map(int, input().split())
g = StrongConnectedComponents(N)
for _ in range(M):
    a, b = map(int, input().split())
    g.add_edge(a, b)
label, group = g.scc()

print(label)
for x in group:
    print(len(x), end=" ")
    print(*x, sep=" ")

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

#define MAX 20
#define PMAX 10
#define rep(i, n) for ( int i = 0; i < (int)n; i++ )
#define INFTY (1<<21)

struct State{ int a, b, cur; };

int H, W;
string P;
char G[MAX][MAX];

int getDi( char ch ){
    if ( ch == '5' || ch == '4' || ch == '6') return 0;
    else if ( ch == '2' ) return 1;
    else if ( ch == '8' ) return -1;
}

int getDj( char ch ){
    if ( ch == '5' || ch == '2' || ch == '8') return 0;
    else if ( ch == '6' ) return 1;
    else if ( ch == '4' ) return -1;
}

int bfs(int as, int bs, int &g){
    int D[MAX*MAX][MAX*MAX][PMAX];
    rep(i, H*W) rep(j, H*W) rep(k, P.size()) {
	D[i][j][k] = INFTY;
    }
    State s;
    s.a = as;
    s.b = bs;
    s.cur = 0;
    queue<State> Q;

    Q.push(s);
    D[s.a][s.b][s.cur] = 0;

    static const int di[5] = {0, 0, -1, 0, 1};
    static const int dj[5] = {0, 1, 0, -1, 0};

    State u, v;
    while( !Q.empty() ){
	u = Q.front(); Q.pop();
	if ( u.a == u.b ) {
	    g = u.a;
	    return D[u.a][u.b][u.cur];
	}
	
	int ni, nj;
	for ( int r = 0; r < 5; r++ ){
	    ni = u.a/W + di[r];
	    nj = u.a%W + dj[r];
	    if ( ni < 0 || nj < 0 || ni >= H || nj >= W ) continue;
	    if ( G[ni][nj] == '#' ) continue;

	    v = u;
	    v.a = ni*W + nj;

	    ni = v.b/W + getDi(P[v.cur]);
	    nj = v.b%W + getDj(P[v.cur]);
	    
	    if ( ni < 0 || nj < 0 || ni >= H || nj >= W ){
		ni = v.b/W;
		nj = v.b%W;
	    }

	    v.cur = (v.cur+1)%P.size();
	    v.b = ni*W + nj;
	    
	    if ( D[v.a][v.b][v.cur] == INFTY ){
		D[v.a][v.b][v.cur] = D[u.a][u.b][u.cur] + 1;
		Q.push(v);
	    }
	}
    }

    return INFTY;
}

main(){
    while( cin >> H >> W && H && W ){	
	int s, g, p;
	rep(i, H) rep(j, W) {
	    cin >> G[i][j];
	    if ( G[i][j] == 'A' ){ G[i][j] = '.'; s = i*W+j; }
	    if ( G[i][j] == 'B' ){ G[i][j] = '.'; p = i*W+j; }
	}
	cin >> P;
	int cost = bfs(s, p, g);
	if ( cost == INFTY ) cout << "impossible" << endl;
	else cout << cost << " " << g/W << " " << g%W << endl;
    }
}

Measured memory_bytes: 7184
n,k = map(int, input().split())

def Base_10_to_n(X,n):
    if(int(X/n)):
        return Base_10_to_n(int(X/n),n)+str(X%n)
    return str(X%n)

ans = len(str(Base_10_to_n(n,k)))

print(ans)

Measured memory_bytes: 2940
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;

int main() {
  //char in[120];
  int n; cin>>n;
  //std::vector<int> v(n);
  int vmin; cin>>vmin;
  int ans = 1;
  int num;
  for (int i=1; i<n; i++) {
    cin>>num;
    if (num <= vmin) {
      ans++;
      vmin = num;
    }
  }
  cout << ans << endl;
}


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

int P[300000];
vector<vector<int>> G;
vector<bool> seen;
void dfs(int a) {
    seen[a]=true;
    for (auto b : G[a]) {
        if (seen[b]) continue;
        P[b]+=P[a];
        dfs(b);
    }
}
int main() {
   int N,Q;
   cin >> N >> Q;
    G.resize(N+1);
   for (int i=0; i<N-1; i++) {
       int a,b;
       cin >> a >> b;
       G[a].push_back(b);
       G[b].push_back(a);
   }
   for (int i=0; i<N; i++) {
       P[i+1]=0;
   }
   for (int i=0; i<Q; i++) {
       int p,x;
       cin >> p >> x;
       P[p]+=x;
   }
   seen.assign(N+1,false);
   dfs(1);
   for (int i=0; i<N; i++) {
       cout << P[i+1] ;
       if (i==N-1) cout << endl;
       else cout << " " ;
   }
}

Measured memory_bytes: 24324
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
    string s;
    cin >> s;
    vector<int> v;
    //int k = 0;
    for(int i = 0; i+3 <=s.size(); ++i){
        v.push_back(stoi(s.substr(i, 3)));
        //cout << v[k++] << endl;
    }
    for(int i = 0; i < v.size(); ++i){
        v[i] -= 753;
    }
    int tmp = 1e9;
    for(int i = 0; i < v.size(); ++i){
        if(tmp>abs(v[i])) tmp = abs(v[i]);
    }
    cout << tmp << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define N 100005
#define ll long long
using namespace std;
ifstream in("in.txt");
int main(){
    ll a, b;
    cin>>a>>b;
    if(a==1 || b==1){
        cout<<1;
    }
    else{
        cout<<a*b/2+(a*b)%2;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<string, string>;
const long double PI = acos(-1.0L);
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; }

int m;

int main() {
    cin >> m;
    while(m--) {
        string s; cin >> s;
        int slen = s.length();
        set<string> st;
        for(int i = 1; i < slen; ++i) {
            string l = s.substr(0, i);
            string r = s.substr(i, slen-i);
            string sl, sr;
            int llen = l.length();
            int rlen = r.length();
            for(int j = 0; j < llen; ++j) sl.push_back(l[llen-j-1]);
            for(int j = 0; j < rlen; ++j) sr.push_back(r[rlen-j-1]);
            st.insert(l+r); st.insert(r+l);
            st.insert(l+sr); st.insert(sr+l);
            st.insert(sl+r); st.insert(r+sl);
            st.insert(sl+sr); st.insert(sr+sl);
        }
        cout << (int)st.size() << endl;
    }
}


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

#define ll long long
#define MAX 300005
#define pp pair<int,pair<int,pair<int,int>>>
#define pb push_back
#define mod 1000000007

using namespace std;

/*
 * author: Kruti_20
 */

ll power(ll x, ll y);

ll gcd(ll a, ll b);


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int m, d;
    cin >> m >> d;
    int ans = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = 10; j <= d; j++) {
            if (j % 10 >= 2 && j / 10 >= 2 && ((j % 10) * (j / 10)) == i) {
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}

ll power(ll x, ll y) {
    ll res = 1;
    x = x % mod;
    while (y > 0) {
        if (y & 1) res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

long long mgcd(int x,int y){
  if(x<y) return mgcd(y,x);
  if(x%y==0) return y;
  return mgcd(y,x%y);
}

int main() {
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  a--;
  long long cd=c*d/mgcd(c,d);
  long long xa=a-a/c-a/d+a/cd;
  long long xb=b-b/c-b/d+b/cd;
  cout<<xb-xa<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int N, M, i, max, min, ans;
  N = M = i = max = ans = 0;
  scanf("%d%d", &N, &M);
  min = N;
  int L[M];
  int R[M];
  for(i = 0; i < M; ++i){
    scanf("%d%d", &L[i], &R[i]);
    if(max < L[i]){
      max = L[i];
    }
    if(min > R[i]){
      min = R[i];
    }
  }
  
  ans = min - max + 1;
  if(ans < 0){
    ans = 0;
  }
  
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>

using namespace std;

int h, w, sum_hash = 0;
char mass[9][9];

int move(int x, int y, int hash){

	if(hash == sum_hash && x == h -1 && y == w -1)
		return 1;
	if(mass[x + 1][y] != '#'  && mass[x][y + 1] != '#')
		return 0;

	return max(move(x + 1, y, hash + 1),move(x, y + 1, hash + 1)); 

}

int main(){
	
	cin >> h >> w;
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++){
			cin >> mass[i][j];
			if(mass[i][j] == '#')
				sum_hash++;
		}

	
	if(move(0, 0, 1)){
		cout << "Possible" <<endl;
		return 0;
	}

	cout << "Impossible" << endl;

	return 0;
}


Measured memory_bytes: 256