akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;
const int mod = 1e9 + 7;
    
vector<long long int> fac;

long long int mypow(long long int a, long long int b) {
    if (b == 0) return 1;
    if (b == 1) return a;
    long long int res = mypow(a, b / 2);
    res = res * res % mod;
    if (b % 2 == 1) res = res * a % mod;
    return res;
}


long long int myc(long long int a, long long int b) {
    return fac[a] * mypow(fac[b], mod - 2) % mod * mypow(fac[a - b], mod - 2) % mod;
}

int main() {
    long long int n;
    cin >> n;
    fac.push_back(1);
    for (int i = 1; i <= n; i++) {
        fac.push_back(fac.back() * i % mod);
    }
    long long int res = 0;
    for (int i = 1; i < n; i++) {
        res += myc(n, i) * ((mypow(9, n - i) - mypow(8, n - i)) % mod);
        res %= mod;
    }
    cout << res << endl;
}




Measured memory_bytes: 11632
N, K = map(int, input().split())
# テーブルをまず作成。0で初期化3人いるとする
t = [0] * N
for _ in range(K):
    d = int(input())
    # 1と3がお菓子持ってるリストAとする
    A = list(map(int, input().split()))
    # A全員aにぶち込んでガガガってやる
    for a in A:
        #お菓子を持っている子のindexを+1
        t[a-1] += 1
print(t.count(0))

Measured memory_bytes: 9080
using System;

namespace AtCoder103C
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;
            int N = int.Parse(Console.ReadLine());

            string[] s = Console.ReadLine().Split(' ');

            for (int i = 0; i < N; i++)
            {
                ans += int.Parse(s[i]);
            }

            ans -= N;

            Console.WriteLine(ans.ToString());
        }
    }
}


Measured memory_bytes: 11164
#include <stdio.h>
#include <string.h>
 
#define LEN 100000
 
typedef struct pp{
  char name[100];
  int t;
}P;
P Q[LEN+1];

void enqueue(P x);
P dequeue();
 
int head, tail, n;
int min(int a, int b) {return a < b ? a : b;}

int main(){

  int c, i, q;
  int col = 0;
  P u;
  scanf("%d %d", &n, &q);
 
  for (i = 1; i <= n; i++){
    scanf("%s %d", Q[i].name, &Q[i].t);
  }

  head = 1;
  tail = n+1;
 
  while(head != tail){
    u = dequeue();
    c = min(q, u.t);
 
    u.t -= c;
    col += c;
 
    if(u.t > 0){
      enqueue(u);
    }
    else{
      printf("%s %d\n", u.name, col);
    }
  }

  return 0;
}


void enqueue(P x){
  Q[tail] = x;
  if ( tail == LEN ) tail = 1;
  else tail++;
}

P dequeue(){
  P x = Q[head];
  if (head == LEN){
    head = 1;
  }
  else head++;
  return x;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll MAX = 510000;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll N, M;
  cin >> N >> M;
  ll Mp = M;
  map<ll, ll> m;
  for(int i = 2; i*i <= M; i++){
    if(M % i) continue;
    while(!(M % i)){
      m[i]++;
      M /= i;
    }
  }
  if(M != 1) m[M]++;
  ll ans = 1;
  COMinit();
  for(auto x : m){
    ans = ans*COM(x.second+N-1, x.second) % MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12288
#include<cstring>
#include<algorithm>
#include<functional>
#include<iostream>
#define rep(i,a) for(int i=1;i<=a;i++)
#define LL long long int
using namespace std;
int main(void)
{
	LL n,m,sum;
	cin>>n>>m;//n==s m==c
	if(n>=m) cout<<m/2<<endl;
	else {
		sum=n;
		m=m-(n*2);
		sum+=m/4;
		cout<<sum<<endl;
	}
	return 0;
}
		

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);	
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll qw(ll x,ll y){ll res = 1;while(y){if(y & 1) res *= x;x = x * x;y >>= 1;}return res;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int a,b;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> a >> b;
	cout << a * b << endl;
	return 0;
}
//do smt instead of nothing! never give up!


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
	int n,i=0;
	cin>>n;
	while(1){
		if(n==2){
			i++;
			break;
		}
		if(n%3==1){
		n=n/3;
		n++;
		}else if(n%3==2)
		n=(n+1)/3;
		else
		n=n/3;
		i++;
		if(n==1)
		break;
	}
	cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
    cin >> n;
  vector<double> a(n);
  for(int i = 0; i < n; i++)
  {
	cin >> a[i];
  }
  double ans = 0;
  for(int i = 0; i < n; i++)
  {
    ans += 1.0/a[i];
  }
  printf("%.5f", 1/ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mk make_pair
#define ft first
#define sd second
#define double long double
using namespace std;
int n,l;
deque<pair<int,double> >q;
pair<int,double>t,s;
double sum;
signed main()
{
    scanf("%lld%lld",&n,&l);
    for(int i=1;i<=n;i++)
    {
        int t1,t2;
        scanf("%lld%lld",&t1,&t2);double t5=t1*t2;sum+=t1*t2;
        if(i!=1)
        {
            int now=l;
            while(now>l-t2)
            {
               t=q.back();q.pop_back();now-=t.ft;sum-=t.sd;
            }
            if(now<l-t2)
            {
                double t4=t.sd/t.ft;
                q.push_back(mk(l-t2-now,t4*(l-t2-now)));sum+=t4*(l-t2-now);
            }
        }
        while(q.size()>=1)
        {
            t=q.front();
            if(t.sd/t.ft<t5/t2)break;
            t2+=t.ft;t5+=t.sd;q.pop_front();
        }
        q.push_front(mk(t2,t5));
        printf("%.7Lf\n",sum/l);
    }
    return 0;
}








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

typedef long long ll;

const int maxN=2*1e5+10;
ll fac[maxN], finv[maxN], inv[maxN];
ll mod=998244353;

void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<maxN;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}

ll Com(int n, int k){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main(){
    int N,M,K;
    cin >> N >> M >> K;
    cominit();
    ll res=0, col=M;
    for(int x=N-1;x>=0;x--){
        ll now=col;
        now *= Com(N-1, x);
        now %=mod;
        if(x<=K){
            res+=now;
            res%=mod;
        }
        col*=(M-1);
        col%=mod;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 7884
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

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

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 21) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

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

char s[MAXN];

int main()
{
	 
	ll k;
	cin >> s+1 >> k;
	int n = strlen(s+1);
	for (int i = 1; i <= n; ++ i)
	{
		if (s[i] != '1')
		{
			if (k >= i)
				putchar(s[i]);
			else
				puts("1");
			return 0;
		}
	}
	puts("1");
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
	vector<ll> v;
	string s;
	cin>>s;
	rep(i,0,s.sz){
		v.pb(s[i]-'A');
	}
	sort(all(v));
	if(v[0]==v[1]&&v[2]==v[3]&&v[1]!=v[2]){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

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

int x;

int gcd(int a, int b){
    if(a < b) return gcd(b, a);
    if(b == 0) return a;
    else return gcd(b, a%b);
}

int main(void){
    cin >> x;
    cout << 360/gcd(360, x) << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef pair<int, pii> pip;
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
 



int main(){
	int n,k,m;
	while(cin>>n>>k>>m){
		if(n == 0 && k == 0 && m == 0) break;
		vi v(n);
		rep(i, n) v[i] = i + 1;
		vi::iterator it = v.begin() + m -1;
		if(it == v.end()) it = v.begin();
		while(v.size() > 1){
			//cout<<" "<<*it<<endl;
			it = v.erase(it);
			if(it == v.end()) it = v.begin();
			for(int i = 0; i < k - 1; i++){
				++it;
				if(it == v.end()) it = v.begin();
			}
		}
		cout<<v[0]<<endl;
	}

}

Measured memory_bytes: 1252
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str,ans="";
    while(getline(cin,str)){
    for(int i=0;i<str.size();i++){
        if(str[i]=='@'){
            for(int j=0;j<str[i+1]-'0';j++){
                ans+=str[i+2];
            }
            i+=2;
        }
        else{
            ans+=str[i];
        }
    }
    cout<<ans<<endl;
        ans="";
    }
    return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
typedef long long ll;
ll a[N],b[N];
int n;
ll sum1,sum2;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%lld",a+i);
    for(int i=1;i<=n;i++)scanf("%lld",b+i);
    for(int i=1;i<=n;i++){
        if(a[i]>b[i])sum1+=(a[i]-b[i]);
        if(a[i]<b[i])sum2+=(b[i]-a[i])/2;
    }
    if(sum1<=sum2)puts("Yes");
    else puts("No");
}

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

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))

typedef std::stack<int> IntStack;
typedef std::queue<int> IntQueue;
typedef std::vector<int> IntVector;
typedef std::list<int> IntList;

using namespace std;
  
int main(){
  int H, N;
  cin >> H >> N;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  
  int sum = 0;
  for(int i=0;i<N;i++){
    sum += A[i];
  }
  string ans;
  if(H-sum <= 0){
    ans = "Yes";
  }else{
    ans = "No";
  }
  
  
  
  cout << ans << endl;
}

Measured memory_bytes: 640
use text_io::*;
use std::collections::*;
use std::process::exit;

fn main() {
    let mut n:usize = read!();
    let mut v:String = read!();
    let mut v:Vec<char> = v.chars().collect();
    let mut ans = 1;
    for i in 0..n-1 {
        if v[i]!=v[i+1] {
            ans+=1;
        }
    }
    println!("{}",ans);
}

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

int main(){
    int n;
    cin >> n;
    for(int i=0; i < n; i++){
        string input;
        cin >> input;

        string ans = input.substr(0, 1);
        input = input.substr(1);
        int pointer = 0;
        while(input.size() != 0){
            if(input.substr(0, 2) == "->"){
                if(ans.size() > pointer+1) ans.replace(pointer+1, 1, input.substr(2, 1));
                else ans += input.substr(2, 1);
                pointer++;
            }
            else {
                if(pointer == 0) ans = input.substr(2, 1) + ans;
                else pointer--;
            }
            input = input.substr(3);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n, i;
    cin >> n >> i;

    cout << n - i + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	char n[1000000];
  	int a=0;
  	scanf("%s",n);
  	for(int i=0;n[i];i++){
      a += n[i] - '0';
    }
  	if(a%9==0)
      	puts("Yes");
  	else
      	puts("No");
}

Measured memory_bytes: 2256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N; cin >> N;
  bool f = 1;
  while (N--) {
    int t; cin >> t;
    f ^= t & 1;
  }
  if (f) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
from sys import stdin
from itertools import combinations
N, M, X = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for i in range(N):
    tmp = [int(x) for x in stdin.readline().rstrip().split()]
    data.append(tmp)

ans = 10**18
for i in range(1, N+1):
    for j in combinations(data, i):
        C = 0
        rikai = [0]*M
        for l in j:
            C += l[0]
            for ind, k in enumerate(l[1:]):
                rikai[ind] += k
        if len([i for i in rikai[:] if i >= X]) == M:
            ans = min(C, ans)
if ans == 10**18:
    ans = -1
print(ans)

Measured memory_bytes: 9216
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin >> N;
  ll cnt = 0;
  repn(i,1000){
    if( i * (i + 1) / 2 == N){
      cout << "Yes" << endl;
      cnt = i;
      break;
    }
    if( i == 1000 ){
      cout << "No" << endl;
      return 0;
    }
  }
  // 中身をつめる　(cnt + 1) * cnt のベクトル
  vector<vector<ll> > ans(cnt + 1);
  rep(i, cnt) ans[0].pb(i + 1);
  repn(i , cnt) ans[i].pb(i);
  ll tmp = cnt + 1;
  ll to = 0;
  repn(i , cnt){
    for(ll j = i + 1 ; j <= cnt; j++){
      // i, j行目 に tmp を追加したい
      ans[i].pb(tmp);
      ans[j].pb(tmp);
      tmp++;
    }
  }

  // 出力
  ll k = cnt + 1; cout << k << endl;
  rep(i,k){
    cout << cnt << " ";
    rep(j, cnt){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }

}


Measured memory_bytes: 3200
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

constexpr LL kInf = 1e18;
constexpr LL kNegativeLoop = -kInf;

struct Edge {
  int from;
  int to;
  LL cost;
};

vector<LL> belman_ford(int s, int V, const vector<Edge>& es) {
  vector<LL> d(V, kInf);
  d[s] = 0;

  for (int i = 0; i < 2 * V; ++i) {
    bool update = false;
    for (const Edge& e : es) {
      if (d[e.from] == kInf) continue;
      if (d[e.to] > d[e.from] + e.cost) {
        d[e.to] = (i < V - 1) ? d[e.from] + e.cost
                              : kNegativeLoop;
        update = true;
      }
    }
    // finish
    if (!update) {
      break;
    }
  }
  return d;
}

int main() {
  int N, M; cin >> N >> M;
  vector<Edge> es;
  for (int i = 0; i < M; ++i) {
    int a, b, c; cin >> a >> b >> c;
    --a, --b;
    es.push_back({a, b, -c});
  }

  auto d = belman_ford(0, N, es);
  if (d[N-1] != kNegativeLoop) {
    cout << -d[N-1] << endl;
  } else {
    cout << "inf" << endl;
  }
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  Solver(LL n) : n(n){};

  void solve() {
  }
};
class Solver2 {
 public:
  int x, y;
  Solver2(LL x, LL y) : x(x), y(y){};

  void solve() {
    if (x == 1 && y == 1) {
      cout << 1000000 << endl;
    } else {
      int ans = 0;
      if (x <= 3) ans += (4 - x) * 100000;
      if (y <= 3) ans += (4 - y) * 100000;
      cout << ans << endl;
    }
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;

        static void SolveA()
        {
            var o = ReadAndParseIntArr();
            int n = o[0];
            int m = o[1];
            long ans = Calc(n, m);
            Console.WriteLine(ans);
        }
        private static long Calc(int n , int m)
        {
            if( Math.Abs(n-m) >= 2) { return 0; }

            int coef = n == m ? 2 : 1;
       
                return (coef * Factorial(n) % MOD) * Factorial(m) % MOD;
          
        }

        private static long Factorial(int n)
        {
            long f = 1;
            for(int i=n;i>=2;--i)
            {
                f = f * i % MOD;
            }
            return f;
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 13140
def sub_count(S,N,M):
    S_dict,S_set = {},set()

    for i in range(N):
        if S[i] not in S_set:
            S_set.add(S[i])
            S_dict[S[i]] = 1
        else:
            S_dict[S[i]] += 1

    output = 1
    for s in S_set:
        output *= (S_dict[s]+1)
        output %= M
    output -= 1
    return output

def main():
    N = int(input())
    S = input()
    M = 10**9+7

    ans = sub_count(S,N,M)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define x first
#define y second

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

template <class T>
void read(T &x)
{
	char ch;
	for (ch=getchar();(ch<'0'||ch>'9')&&ch!='-';) ch=getchar();
	x=0;int t=1;if (ch=='-') {ch=getchar();t=-1;}
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	x*=t;
}

int main()
{
	int q,h,s,d,n;scanf("%d%d%d%d%d",&q,&h,&s,&d,&n); 
	int t=min(min(q*4,h*2),s);
	cout<<min(ll(n)/2*d,ll(n)/2*2*t)+n%2*t<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
#define endl '\n'
#define F first
#define S second
const int MAX_N=3e3+3;

int n;
double p[MAX_N];
double dp[MAX_N][MAX_N];
double ans;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lf",&p[i]);
	dp[0][0]=1.0;
	for(int i=1;i<=n;i++) for(int j=0;j<=i;j++)
		if(j!=0) dp[i][j]=dp[i-1][j]*(1.0-p[i])+dp[i-1][j-1]*p[i];
		else dp[i][j]=dp[i-1][j]*(1.0-p[i]);
	for(int i=(n+1)/2;i<=n;i++) ans+=dp[n][i];
	printf("%.12lf\n",ans);
	return 0;
}



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

const int N = 1 << 20;

vector<int> adj[N], con[N];
int chk[N], vis[N], cnt;
long long val[N];
map<long long, int> M;

void dfs(int u) {
	for (int v : adj[u]) {
		if (chk[v]) continue;
		chk[v] = cnt;
		dfs(v);
	}
}

void DFS(int u) {
	for (int v : con[u]) {
		if (vis[v]) continue;
		vis[v] = cnt;
		DFS(v);
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, K, L; cin >> n >> K >> L;
	for (int i = 0; i < K; i++) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for (int i = 0; i < L; i++) {
		int u, v; cin >> u >> v;
		con[u].push_back(v);
		con[v].push_back(u);
	}
	cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (chk[i]) continue;
		chk[i] = ++cnt;
		dfs(i);
	}
	cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (vis[i]) continue;
		vis[i] = ++cnt;
		DFS(i);
	}
	for (int i = 1; i <= n; i++) {
		val[i] = chk[i] * 1000000LL + vis[i];
		M[val[i]]++;
	}
	for (int i = 1; i <= n; i++) cout << M[val[i]] << " \n"[i == n];
	return 0;
}



Measured memory_bytes: 72020
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,bool>> v[100000];
int c[100000];
void init(int n){
  fill(c,c+n,-1);c[0] = 0;
}
void dfs(int f){
  int next;
  for(int i=0;i<v[f].size();i++){
    next = v[f][i].first;
    if(c[next]==-1){
      c[next] = c[f]^v[f][i].second;dfs(v[f][i].first);
    }
  }
}
int main(){
  int n,i,x,y,z;scanf("%d",&n);
  init(n);
  for(i=0;i<n-1;i++){
    scanf("%d%d%d",&x,&y,&z);x--;y--;
    v[x].push_back(make_pair(y,z%2));
    v[y].push_back(make_pair(x,z%2));
  }
  dfs(0);
  for(i=0;i<n;i++) printf("%d\n",c[i]);
  return 0;
}

Measured memory_bytes: 8320
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        System.out.println(String.valueOf((char)a.charAt(0)) + String.valueOf((char)b.charAt(0)) + String.valueOf((char)c.charAt(0)));
    }
}

Measured memory_bytes: 21844
N, K = map(int, input().split())
mod = 10**9+7

red = N-K+1
blue = 1
print(N-K+1)
for i in range(1, K):
    # red = (red * (N-K+1-i) // (i+1)) % mod
    # blue = (blue * (K-i) // i) % mod
    red = (red * (N-K+1-i) // (i+1))
    blue = (blue * (K-i) // i)
    print(red * blue % mod)
    # print(i, red, blue)



Measured memory_bytes: 3316
//B
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int m = stdIn.nextInt();
        
        int a[] = new int[n];
        
        int sum = 0;
        
        for(int i = 0; i < n; i++){
            a[i] = stdIn.nextInt();
            sum += a[i];
        }
        
        Arrays.sort(a);
        
        boolean flag = true;
        
        for(int i = n - 1; i > n - 1 - m; i--){
            if((double)(a[i]) < (double)(sum * 1) / (double)(4 * m)){
                
                flag = false;
            }
            //System.out.println(a[i] + " " + sum * 1 / (4 * m));
        }
        
        if(flag){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
inline double distance(double y1, double x1, double y2, double x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy = { 0, 1, 0, -1 }, dx = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）

using namespace std;


vector<vector<int>> dp;
int func(int i, int state, int n, vector<vector<int>> &graph) {
    if (dp[state][i] >= 0) {
        return dp[state][i];
    }

    if (state == (1 << n) - 1 and i == 0) {
        return dp[state][i] = 0;
    }

    int res = INF;
    for (int a = 0; a < n; ++a) {
        if (graph[i][a] == INF) { continue; }
        if (!(state >> a & 1)) {
            res = min(res, func(a, state | 1 << a, n, graph) + graph[i][a]);
        }
    }

    return dp[state][i] = res;
}


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

    int V, E;
    cin >> V >> E;

    vector<vector<int>> graph(V, vector<int>(V, INF));
    FOR(i, 0, E) {
        int s, t, d;
        cin >> s >> t >> d;
        graph[s][t] = d;
    }

    dp.resize(1 << V, vector<int>(V, -1));
    int ans = func(0, 0, V, graph);

    if (ans == INF) {
        print(-1);
    }
    else {
        print(ans);
    }

    return 0;
}


Measured memory_bytes: 6248
n,k=map(int, input().split())
x=list(map(int, input().split())) 
v=[]
for i in range(n-k+1):
    a=abs(x[i])+abs(x[i+k-1]-x[i])
    b=abs(x[i+k-1])+abs(x[i]-x[i+k-1])
    v.append(min(a,b))
print(min(v))

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

using namespace std;

typedef long long ll;

#define MAXN 100000

vector<ll> A(MAXN);

int main(void) {
  ll H, N;
  cin >> H >> N;
  
  for(int i=0; i<N; ++i) cin >> A[i];
  
  ll sum = 0;
  for(int i=0; i<N; ++i) sum += A.at(i);
  
  if(sum >= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int ans = 0;
    int rest = K;
    if(rest > A){
        rest -= A;
        ans += A;
    }else{
        cout << rest << endl;
        return 0;
    }

    if(rest > B){
        rest -= B;
    }else{
        cout << ans << endl;
        return 0;
    }

    ans -= rest;
    printf("%d\n", ans);

    return 0;
}


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

//types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[8] = {0, -1, 0, 1, -1, 1, -1, 1};

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

  ll x,y;
  cin>>x>>y;
  if(x%y==0)
    cout<<-1<<endl;
  else
    cout<<x<<endl;

}



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

int main(){
	int n, m, l;
	long long int sum;
	cin >> n >> m >> l;
	int **a = new int*[n];
	for(int i = 0; i < n; i++){
		a[i] = new int[m];
	}
	int **b = new int*[m];
	for(int i = 0; i < m; i++){
		b[i] = new int[l];
	}
	for(int y = 0; y < n; y++){
		for(int x = 0; x < m; x++){
			cin >> a[y][x];
		}
	}
	for(int y = 0; y < m; y++){
		for(int x = 0; x < l; x++){
			cin >> b[y][x];
		}
	}
	for(int z = 0; z < n; z++){
		for(int y = 0; y < l; y++){
			sum = 0;
			for(int x = 0; x < m; x++){
				sum += a[z][x] * b[x][y];
			}
			if(y == l - 1) cout << sum;
			else cout << sum << " ";
		}
		cout << endl;
	}
	return 0;
}


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

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k) {
    while (u != NIL && k != u->key) {
        if (k < u->key) {
            u = u->left;
        } else {
            u = u->right;
        }
    }
    return u;
}

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->left);
    cout << " " << u->key;
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) return;
    cout << " " << u->key;
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, x;
    string com;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> com;
        if (com == "find") {
            cin >> x;
            Node *t = find(root, x);
            if (t != NIL) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        } else if (com == "insert") {
            cin >> x;
            insert(x);
        } else if (com == "print") {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }
}



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

string s_reverse(string s){
	string ret = "";
	for(int i = s.length()-1; i >= 0; i--){
		ret += s[i];
	}
	return ret;
}


int main(){
	int n, pre_num, af_num;
	cin >> n;
	pre_num = af_num = n;

	string pre_s = to_string(pre_num), pre_s_r = s_reverse(pre_s);
	string af_s = to_string(af_num), af_s_r = s_reverse(af_s);



	if(pre_s == pre_s_r){
		cout << pre_s << endl;
	}else if(af_s == af_s_r){
		cout << af_s << endl;
	}else{
		while(1){
			if(pre_num == 0) break;

			pre_num--;
			af_num++;
			pre_s = to_string(pre_num), pre_s_r = s_reverse(pre_s);
			af_s = to_string(af_num), af_s_r = s_reverse(af_s);

			if(pre_s == pre_s_r){
				cout << pre_s << endl;
				break;
			}else if(af_s == af_s_r){
				cout << af_s << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1240
import collections

n,p=map(int,input().split())
s=input()
arr=[int(s[i]) for i in range(len(s))]
if p==2 or p==5:
  ans=0
  for i in range(n):
    if arr[i]%p==0:
      ans+=i+1
  print(ans)
else:
  dic=collections.defaultdict(int)
  tmp=0
  for i in range(n-1,-1,-1):
    tmp+=arr[i]*pow(10,n-1-i,p)
    tmp%=p
    dic[tmp]+=1
  ans=0
  rem=0
  for i in range(n-1,-1,-1):
    ans+=dic[rem]
    rem+=arr[i]*pow(10,n-1-i,p)
    rem%=p
    dic[rem]-=1
  print(ans)

Measured memory_bytes: 6128
n,a,b = map(int, raw_input().split())
s = raw_input()

p = 0
g = 0
for i in s:
    if i == 'a':
        if p < a + b:
            print 'Yes'
            p += 1
        else:
            print 'No'
    elif i == 'b':
        g += 1
        if p < a + b and g <= b:
            print 'Yes'
            p += 1
        else:
            print 'No'
    elif i == 'c':
        print 'No'
    else:
        print 'No'

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

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define ldb long double 
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const ll INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n)
{
 ll res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a*=a;
  n/=2;
}
return res;
}

ll abst(ll a)
{
 return ((a<0)?(-1*a):(a));
}

int main()
{
    ll h,n;
    cin>>h>>n;
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        sum+=x;
    }
    if(sum>=h)
     cout<<"Yes\n";
     else
      cout<<"No\n";
      return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define MAX 100010

int N, M;
vector<int> G[MAX];

int dfs(int v, int prev) {
    if ((int)G[v].size() > 2) return v;
    for (int i=0; i<(int)G[v].size(); ++i) {
        if (G[v][i] != prev) {
            return dfs(G[v][i], v);
        }
    }
    return -1;
}

int main(){
    cin >> N >> M;
    int a, b;
    for (int i=0; i<M; ++i) {
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for (int i=1; i<=N; ++i) {
        int d = G[i].size();
        if (d % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
    }

    vector<int> v_d4;
    for (int i=1; i<=N; ++i) {
        int d = G[i].size();
        if (d >= 6) {
            cout << "Yes" << endl;
            return 0;
        }
        if (d == 4) {
            v_d4.push_back(i);
        }
    }

    int v_d4_count = v_d4.size();
    if (v_d4_count >= 3) {
        cout << "Yes" << endl;
        return 0;
    } else if (v_d4_count <= 1) {
        cout << "No" << endl;
        return 0;
    }

    for (int i=0; i<(int)G[v_d4[0]].size(); ++i) {
        if (dfs(G[v_d4[0]][i], v_d4[0]) == v_d4[0]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 5760
import sys
input = sys.stdin.readline
N=int(input())
S=input()
R=S.count("R")
G=S.count("G")
B=S.count("B")
ans=R*G*B
for i in range(N):
    for j in range(i+1,N):
        k=j+j-i
        if k>=N:
            continue
        if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
            ans-=1
print(ans)

Measured memory_bytes: 68112
#include <stdio.h>

int main()
{
    int F[45],n;
    F[0] = F[1] = 1;
    for (int i = 2; i <= 44; i++)
        F[i] = F[i - 1] + F[i - 2];
    scanf("%d", &n);
    printf("%d\n", F[n]);
    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

int main(){
    int n,m,d;
    cin>>n>>m>>d;
    double ans=(double)(n-d)*(m-1)/n/n;
    if(d!=0)ans*=2;
    cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 256
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    else:
        x=[]
        x=[int(input()) for i in range(n)]
        l=len(x)
        b=[]
        if l<k:
            pass
        else:
            s=sum(x[0:k])
            b.append(s)
            for j in range(n-k):
                s=s-x[j]+x[j+k]
                b.append(s)
        m=max(b)
        print(m)


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

int main(){
  string s;
  long long k;
  cin >> s >> k;
  int n = s.size();

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

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

/*
int main() {
  string str,sentence[1000];
  int i=0;
  while(cin >> str) {
    if(str == "apple")
      str = "peach";
    else if(str == "peach")
      str = "apple";
    sentence[i] = str;
    i++;
  }
  for(int k=0;k<i-1;k++)
    cout << sentence[k] << " ";
  cout << sentence[i-1] << endl;
}
*/

int main() {
  string str;
  int k=0,size;
  getline(cin,str);
  size = str.size();
  for(int i=0;i<size;i++) {
    if(str.substr(i,5) == "apple") {
      str.replace(i,5,"peach");
    }
    else if(str.substr(i,5) == "peach") {
      str.replace(i,5,"apple");
    }
  }
  cout << str << endl;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
 
int main() {
    int a, b, c;
    int x;
    int flg;
 
    while (1) {
        cin>>a;
        if (cin.eof()) break;
        cin>>b;
 
        c=a+b;
 
        x = 1;
        flg = 1;
        while (flg) {
            if ((c=c/10)>0)
                x++;
            else
                flg = 0;
        }
        cout<<x<<endl;
    }
    return 0;
}

Measured memory_bytes: 0
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
from bisect import bisect_left
def resolve():
    n = int(input())
    direction = {'U' : 0, 'R' : 1, 'D' : 2, 'L' : 3}
    X = defaultdict(lambda:[[] for _ in range(4)])
    Y = defaultdict(lambda:[[] for _ in range(4)])
    YminusX = defaultdict(lambda:[[] for _ in range(4)])
    XplusY = defaultdict(lambda:[[] for _ in range(4)])

    for _ in range(n):
        x, y, u = input().split()
        x = int(x)
        y = int(y)
        u = direction[u]
        X[x][u].append(y)
        Y[y][u].append(x)
        YminusX[y - x][u].append(x)
        XplusY[x + y][u].append(x)

    ans = INF

    for x in X:
        up = sorted(X[x][direction['U']])
        down = sorted(X[x][direction['D']])
        for u in up:
            idx = bisect_left(down, u)
            if idx == len(down):
                continue
            ans = min(ans, 5 * (down[idx] - u))

    for y in Y:
        right = sorted(Y[y][direction['R']])
        left = sorted(Y[y][direction['L']])
        for r in right:
            idx = bisect_left(left, r)
            if idx == len(left):
                continue
            ans = min(ans, 5 * (left[idx] - r))

    for c in YminusX:
        right = sorted(YminusX[c][direction['R']])
        down = sorted(YminusX[c][direction['D']])
        for r in right:
            idx = bisect_left(down, r)
            if idx == len(down):
                continue
            ans = min(ans, 10 * (down[idx] - r))
        up = sorted(YminusX[c][direction['U']])
        left = sorted(YminusX[c][direction['L']])
        for u in up:
            idx = bisect_left(left, u)
            if idx == len(left):
                continue
            ans = min(ans, 10 * (left[idx] - u))

    for c in XplusY:
        right = sorted(XplusY[c][direction['R']])
        up = sorted(XplusY[c][direction['U']])
        for r in right:
            idx = bisect_left(up, r)
            if idx == len(up):
                continue
            ans = min(ans, 10 * (up[idx] - r))
        down = sorted(XplusY[c][direction['D']])
        left = sorted(XplusY[c][direction['L']])
        for d in down:
            idx = bisect_left(left, d)
            if idx == len(left):
                continue
            ans = min(ans, 10 * (left[idx] - d))

    if ans == INF:
        print("SAFE")
    else:
        print(ans)
resolve()

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

using namespace std;

int main(){
	int N;
	double total = 0;
	double x[10];
	string u[10];
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> x[i] >> u[i];
		if(u[i] == "BTC"){
			x[i] *= 380000;
		}
		total += x[i];
	}
	cout << total;
	return 0;
}

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

int main(){
  int W,H,x,y,r;
  cin>>W>>H>>x>>y>>r;
  if(x+r>W||x-r<0||y+r>H||y-r<0){
    cout<<"No\n";
  }else{
    cout<<"Yes\n";
  }
  return 0;
}

Measured memory_bytes: 1128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
ll p[100010],sum[100010],a[100010],b[100010],c[100010];
int main(){
	int n,m;	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>p[i];	p[i]--;
	}
	for(int i=0;i<n-1;i++)	cin>>a[i]>>b[i]>>c[i];
	for(int i=1;i<m;i++){
		int s=p[i-1],t=p[i];
		if(s>t)	swap(s,t);
		sum[s]++;	sum[t]--;
	}
	for(int i=1;i<n-1;i++)	sum[i]+=sum[i-1];
	ll ans=0;
	for(int i=0;i<n-1;i++)	ans+=min(sum[i]*a[i],sum[i]*b[i]+c[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5068
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adjlist[100005];
int inc[100005];
bitset<100005> vis;
int dist[100005];
bool flag=true;

void dfs(int v, int d) {
	if (dist[v]==-1) dist[v]=d;
	else if (dist[v]!=d) flag=false;
	//printf("%d %d\n", v, dist[v]);
	vis[v]=true;
	for (auto it:adjlist[v]) {
		if (!vis[it.first]) dfs(it.first, d+it.second);
		if (d+it.second!=dist[it.first]) flag=false;
	}
}

int main() {
	memset(dist,-1,sizeof(dist));
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i=0; i<m; i++) {
		int l,r,d;
		scanf("%d%d%d", &l, &r, &d);
		l--; r--;
		adjlist[l].push_back({r,d});
		inc[r]++;
	}
	for (int i=0; i<n; i++) {
		if (vis[i]||inc[i]) continue;
		dfs(i,0);
	}
	for (int i=0; i<n; i++) flag &= vis[i];
	printf("%s\n", flag?"Yes":"No");
}


Measured memory_bytes: 12800
import java.util.*;
class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int r=0;
		for(int i=0;i<n;++i)
			r^=s.nextInt();
		System.out.println(r==0?"Yes":"No");
	}
}


Measured memory_bytes: 48716
#include <iostream>
using namespace std;
int main(void)
{
	int a,b,c,d,e;
	c=0;
	d=0;
	for (a=0;a<4;a++)
	{
		cin>>e;
		c=c+e;
	}
	for (a=0;a<4;a++)
	{
		cin>>b;
		d=d+b;
	}
	if (d>=c)
	{
		cout<<d<<endl;
	}
	else if (d<=c)
	{
		cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include<stdio.h>

int array[20], n;
int solve(int, int);

int main(){

  int i, m, num;
  
  scanf("%d",&n);

  for(i = 0; i < n; i++)scanf("%d",&array[i]);

  scanf("%d",&m);

  for(i = 0; i < m; i++)
    {
      scanf("%d",&num);
      
      if(solve(0,num) == 1)printf("yes\n");
      else printf("no\n");
    }
  
  return 0;
}

int solve(int cnt, int num)
{
  if(num == 0)return 1;
  else if(cnt == n || num < 0)return 0;
  
  if(solve(cnt + 1, num - array[cnt]) == 1 || solve(cnt + 1, num) == 1)return 1;
  else return 0;
}



Measured memory_bytes: 2108