akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class AtCoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String at = in.next();
            String top = in.next();

            if (at.equals("H")) {
                out.println(top);
            } else {
                if (top.equals("H")) {
                    out.println("D");
                } else {
                    out.println("H");
                }
            }
        }

    }
}



Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;
 
/*--------------------template--------------------*/

int main(){
    REP1(i,10){
        REP1(j,10){
            cout << i << 'x' << j << '=' << i*j << endl;
        }
    }
}

Measured memory_bytes: 3072
import numpy as np
card = []
for _ in range(3):
    card.append(list(map(int, input().split())))
card = np.array(card)

N = int(input())

B = [int(input()) for _ in range(N)]


for b in B:
    for i in range(3):
        for j in range(3):
            if b == card[i][j]:
                card[i][j] = 0

count_by_row = (card == 0).sum(axis=1)
count_by_col = (card == 0).sum(axis=0)

if (3 in count_by_row) or (3 in count_by_col):
    print("Yes")
elif card[0][0] == 0 and card[1][1] == 0 and card[2][2] == 0:
    print("Yes")
elif card[0][2] == 0 and card[1][1] == 0 and card[2][0] == 0:
    print("Yes")
else:
    print("No")

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

#define ll long long int
#define mod (ll)(1e9 + 7)

char a[1005][1005];
ll n,m;
ll dp[1005][1005];

ll f(ll i, ll j){

    if(i == n+1 or j == m+1 or a[i][j] == '#') return 0;

    if(i == n and j == m) return 1;

    if(dp[i][j] != -1) return dp[i][j] % mod;

    return dp[i][j] = (f(i+1, j) + f(i, j+1))%mod;
}

int main() {

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    memset(dp, -1, sizeof dp);

    cin>>n>>m;

    for(ll x=1;x<=n;x++){
        for(ll y=1;y<=m;y++) cin>>a[x][y];
    }

    cout<<f(1,1);

    return 0;
}

Measured memory_bytes: 12560
#include <iostream>
#include <stdio.h>
#include <queue>
using namespace std;
int n, m, a[100005];
priority_queue< pair< int, int > > qu;
long long ans;
int main() {
	cin >> n >> m;
	for(int i= 1; i <= n; i++) cin >> a[i], ans+= a[i], qu.push(make_pair(a[i] - a[i] / 2, i));
	for(int i= 1, nown; i <= m; i++) {
		ans-= qu.top().first, nown= qu.top().second, qu.pop();
		a[nown]/= 2, qu.push(make_pair(a[nown] - a[nown] / 2, nown));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1656
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1e9;
#define put(n) cout<<(n)<<endl
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define pb(n) push_back(n)

int Q,sum[100100];

int main(){
    cin >> Q;
    vector<bool> is_sosu(100100,true);
    vector<bool> is_near(100100,false);
    is_sosu[0] = is_sosu[1] = false;
    for(int i=2;i*i<=100000;++i){
        if(!is_sosu[i]) continue;
        for(int j=i+i;j<=100000;j+=i){
            is_sosu[j] = false;
        }
    }

    for(int i=0;i<=100000;++i){
        if(i%2 == 0) continue;
        is_near[i] = is_sosu[i]&is_sosu[(i+1)/2];
        sum[i] += (is_near[i]);
    }

    for(int i=1;i<=100000;++i) sum[i] += sum[i-1];
    vector<int> ans;
    for(int i=0;i<Q;++i){
        int l,r;
        cin >> l >> r;
        int res =  sum[r] - sum[l];
        if(is_near[l]) ++res;
        ans.emplace_back(res);
    }

    for(int i=0;i<ans.size();++i){
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 1532
//Template
#include <bits/stdc++.h>
#define INF INT_MAX
#define MOD 100000007
#define MAX_N 100005

using namespace std;

int N, M;
vector<int> adj[MAX_N];
int disc[MAX_N], low[MAX_N], p[MAX_N], times;
bool ap[MAX_N];
void DFS(int v){
	times++;
	disc[v]=times;
	low[v]=disc[v];
	int d=adj[v].size();
	bool leaf=true;
	for(int i=0; i<d; ++i){
		if(disc[adj[v][i]]==0){
			p[adj[v][i]]=v;
			DFS(adj[v][i]);
			if(low[adj[v][i]]<low[v])low[v]=low[adj[v][i]];
			if(v==0 && i!=0)ap[v]=true;
			if(v!=0 && low[adj[v][i]]>=disc[v])ap[v]=true;
		}
		if(adj[v][i]!=p[v] && low[v]>disc[adj[v][i]])low[v]=disc[adj[v][i]];
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin>>N>>M;
	for(int i=0; i<M; ++i){
		int a, b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	DFS(0);
	for(int i=0; i<N; ++i)if(ap[i])cout<<i<<endl;
	return 0;
}


Measured memory_bytes: 6800
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair<int,int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=2e9;
const int magic=348;
const LB eps=1e-10;
const LB pi=3.14159265;

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

int n;
int a[100048];
int cnt1,cnt2,cnt4;

int main ()
{
	int i;
	n=getint();
	for (i=1;i<=n;i++) a[i]=getint();
	for (i=1;i<=n;i++)
	{
		if (a[i]%4==0) {cnt4++;continue;}
		if (a[i]%2==0) {cnt2++;continue;}
		cnt1++;
	}
	if (cnt2==0)
	{
		if (cnt4>=cnt1-1) cout<<"Yes"<<endl; else cout<<"No"<<endl;
		return 0;
	}
	if (cnt4>=cnt1) cout<<"Yes"<<endl; else cout<<"No"<<endl;
	return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int n;
    cin >> n;
    map<int,int> count;
    rep(i,0,n){
        int a;
        cin >> a;
        ++count[a];
    }
    int x=0,y=0;
    for(auto it=count.begin(); it!=count.end(); ++it){
        int k=it->second;
        if(k%2!=0) ++x;
        else ++y;
    }
    cout << x+y-y%2 << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  map<string, int> S;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    if (S.count(s)) ++S[s];
    else S[s] = 1;
  }
  int ma = 0;
  for (auto s : S) {
    if (s.second > ma) ma = s.second;
  }
  for (auto s : S) {
    if (s.second == ma) cout << s.first << "\n";
  }
}

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

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a == b)
        cout << "Draw";
    else if(a == 1)
        cout << "Alice";
    else if(b == 1)
        cout << "Bob";
    else if(a < b)
        cout << "Bob";
    else if(a > b)
        cout << "Alice";
        return 0;
    }


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

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

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

    int index_A=-1;
    int index_Z=-1;

    for(int  i = 0; i < s.size(); i++)
    {
        if (s[i] == 'A' and index_A == -1)
        {
            index_A = i;
        }
        else if (s[i] == 'Z' and index_A != -1)
        {
            index_Z = i;
        }
        
    }

    cout << index_Z - index_A + 1 << endl;
    
}

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

int main() {
    cin.tie(NULL); cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    int t; t=1;
while(t--){
	string s="No";
long long int n,x=0; cin>>n;
while(n--){
	string a,b; cin>>a>>b;
	if(a==b){
		x++;
	}
	else{x=0;
	}
	if(x>=3){s="Yes";
	}
}
cout<<s;
}
   
	return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<math.h>
int main(){
    int a, b, i, j, n, d;
    int count = 0;
    scanf("%d %d", &a, &b);
    if((a+b)%2 == 0){
        printf("%d\n", (a+b)/2);
    }else
    {
        printf("IMPOSSIBLE\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n,k;
    cin >> n >> k;
    ll ans = 1;

    while(true)
    {
        n/=k;
        if (n!=0)
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    cout << ans << endl;
    
    
}




Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        
        if(B==1){
            System.out.println(0);
            return ;
        }
        
        int ans=0;
        int num=1;
        
        while(num<B){
            num+=A-1;
            ans++;
        }
        
        System.out.println(ans);
    }
}


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

UL H[20001];
UL HH[20001];

int main() {
 string S; cin >> S;
 UL N=S.size();
 H[0]=HH[0]=100000;
 rep(i,N){
  if(S[i]=='/') H[i+1]=H[i]+1;
  if(S[i]=='\\') H[i+1]=H[i]-1;
  if(S[i]=='_') H[i+1]=H[i];
  HH[i+1]=max(HH[i],H[i+1]);
 }
 HH[N]=H[N];
 for(UL i=N; i!=0; i--){
  HH[i-1]=min(HH[i-1],max(H[i-1],HH[i]));
 }
 rep(i,N+1) HH[i]-=H[i];
 vector<UL> ans; ans.push_back(0);
 rep(i,N+1){
  if(HH[i]==0 && ans.back()!=0) ans.push_back(0);
  else if(HH[i]!=0) ans.back()+=HH[i];
 }
 ans.pop_back();
 UL A=0; for(UL a:ans) A+=a;
 printf("%u\n",A);
 printf("%u",ans.size());
 for(UL a:ans) printf(" %u",a);
 printf("\n");
 return 0;
}



Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,N;
  cin >> N >> A >> B;
  long long y = N / (A + B);
  long long x;
  if(N %(A+B) > A){
    x = A;
  }else{
    x = N%(A+B);
  }
  
  cout << y*A + x << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, K, AB):
    M = Mod(10**9+7)
    def P(n, k):
        ret = 1
        for i in range(n, n-k, -1):
            ret = M.mul(ret, i)
        return ret
    
    g = defaultdict(list)
    for a, b in AB:
        g[a].append(b)
        g[b].append(a)
    
    q = [1]
    done = set()
    ans = K
    while q:
        u = q.pop()
        
        for v in g[u]:
            if v not in done:
                done.add(v)
                q.append(v)
        c = len(g[u])-1
        if u == 1:
            c += 1
        
        done.add(u)
        if u == 1:
            ans = M.mul(ans, P(K-1, c))
        else:
            ans = M.mul(ans, P(K-2, c))
    return ans


def main():
    N, K = read_int_n()
    AB = [read_int_n() for _ in range(N-1)]
    print(slv(N, K, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 50884
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    D,G = map(int, input().split())
    qs = [list(map(int, input().split())) for _ in range(D)]
    q_totals = [100*(i+1)*q[0]+q[1] for i,q in enumerate(qs)]

    ans = float('inf')
    for bit in range(1<<D):
        total = 0
        target_qs = []
        another_q_idx = 0
        for i in range(D):
            if bit & 1<<i:
                total += q_totals[i]
                target_qs.append(qs[i])
            else:
                another_q_idx = i
        tmp_ans = sum([q[0] for q in target_qs])

        if total < G and G <= total + 100*(another_q_idx+1)*(qs[another_q_idx][0]-1):
            tmp_ans += ceil((G-total)/(100*(another_q_idx+1)))
        elif total + 100*(another_q_idx+1)*(qs[another_q_idx][0]-1) < G:
            tmp_ans = float('inf')

        ans = min(ans, tmp_ans)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 13584
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{


	int x, y;

	while (cin >> x >> y)
	{
		if (x == 0 && y == 0)break;
		if (x < y){
			cout << x << " " << y <<endl;

		}else{
			cout << y << " " <<  x <<endl;

		}












	}

	return 0;


}



Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, 1, 0, -1};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	if (n % 2) {
		rep(i, m) cout << i + 1 << " " << n - i << endl;
	} else {
		rep(i, (m + 1) / 2) cout << ((1 - i + n) % n == 0 ? n : (1 - i + n) % n) << " " << (2 + i) % n << endl;
		rep(i, m / 2) cout << (n / 2 - i) % n << " " << (n / 2 + 2 + i) % n << endl;
	}
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
/* Karen {{{
  ___  ____
 |_  ||_  _|
   | |_/ /    ,--.   _ .--.  .---.  _ .--.
   |  __'.   `'_\ : [ `/'`\]/ /__\\[ `.-. |
  _| |  \ \_ // | |, | |    | \__., | | | |
 |____||____|\'-;__/[___]    '.__.'[___||__]
}}} */
/* cpp template {{{*/
using namespace std;

#define endl '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()

typedef double D;
typedef long long ll;
typedef long double lb;
typedef complex<D> P;
typedef vector<P> VP;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;

inline bool inside(int y,int x,int H,int W){return(y>=0&&x>=0&&y<H&&x<W);}
inline int in() {int x; std::cin >> x; return x;}

template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T>
void print(T x) {
  std::cout << x << '\n';
}
/* }}} */
/* 定数 {{{*/
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const D EPS  = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* }}} */

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

  bool m[100][100];

  int w = in(), h = in(), n = in();
  REP(i, h) REP(j, w) m[i][j] = true;
  REP(i, n){
    int x = in() - 1, y = in() - 1, a = in();
    REP(j, h){
      REP(k, w) {
        if (a == 1 && k <= x) m[j][k] = false;
        if (a == 2 && k > x) m[j][k] = false;
        if (a == 3 && j <= y) m[j][k] = false;
        if (a == 4 && j > y) m[j][k] = false;
      } 
    }
  }

  int cnt = 0;
  REP(i, h) REP(j, w) if (m[i][j]) cnt++;

  cout << cnt << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  string s, t;
  cin >> s >> t;
  int c1[26]{}, c2[26]{};
  vector<int> k[26];
  for (int i = 0; i < s.length(); i++) {
    c1[s[i] - 'a']++;
    k[s[i] - 'a'].push_back(i + 1);
  }
  for (int i = 0; i < t.length(); i++) {
    c2[t[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (c2[i] != 0 && c1[i] == 0) {
      cout << "-1\n";
      return 0;
    }
  }
  ll idx = 1;
  ll l = s.length();
  ll ans = 0;
  for (int i = 0; i < t.length(); i++) {
    int j = t[i] - 'a';
    auto iter = lower_bound(k[j].begin(), k[j].end(), idx);
    int v = iter - k[j].begin();
    if (v == k[j].size()) {
      ans += (l -  idx + 1);
      ans += (ll)(k[j][0]);
      idx = k[j][0] + 1;
    } else {
      ans += (ll)(k[j][v] - idx + 1);
      idx = k[j][v] + 1;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1216
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

class UnionFind {
  vector<ll> par, h, sz;
public:
  UnionFind(ll size) : par(size, 0), h(size, 0), sz(size, 1) {
    rep(i, size) par[i] = i;
  }
  void unite(ll u, ll v) {
    u = root(u), v = root(v);
    if (u == v) return;
    if (h[u] < h[v]) {
      par[u] = v;
      sz[v] += sz[u];
    }
    else {
      par[v] = u;
      sz[u] += sz[v];
    }
    if (h[u] == h[v]) ++h[u];
  }
  ll size(ll v) {
    return sz[root(v)];
  }
  bool isUnited(ll u, ll v) {
    return root(u) == root(v);
  }
  ll root(ll v) {
    if (par[v] == v) return v;
    return par[v] = root(par[v]);
  }
};

void solve() {
  ll n, R; cin >> n >> R;
  vector<ll> a(n); cin >> a;
  each(x, a) --x;
  UnionFind uf(n);
  rep(i, n) if (a[i] != i) uf.unite(a[i], i);
  map<ll, ll> cnt;
  rep(i, n) cnt[uf.root(i)] = uf.size(i);
  vector<ll> v;
  each(p, cnt) v.pb(p.second);
  bitset<300001> b = false;
  b[0] = true;
  ll one = 0;
  each(x, v) {
    if (x == 1) one++;
    else {
      b |= (b<<x);
    }
  }
  bool ans = false;
  ll i0 = max(0LL, R-one);
  rep(i, i0, R+1) {
    if (b[i]) ans = true;
  }
  cout << ans << endl;
}



Measured memory_bytes: 35132
H,W,D=map(int,input().split())
A=[0]*(H*W)
for i in range(H):
  a=list(map(int,input().split()))
  for j in range(W):
    A[a[j]-1]=[i,j]

L=[[0]*(H*W//D+(H*W%D>=i)) for i in range(1,D+1)]
for i in range(D,H*W):
  n=i+1
  L[n%D-1][(n-1)//D]=L[n%D-1][(n-1)//D-1]+abs(A[i][1]-A[i-D][1])+abs(A[i][0]-A[i-D][0])

Q=int(input())
for _ in range(Q):
  l,r=map(int,input().split())
  print(L[r%D-1][(r-1)//D]-L[l%D-1][(l-1)//D])

Measured memory_bytes: 22060
#include <bits/stdc++.h>
 
#define infi            1e9
#define infl            1e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)
 
using namespace std;
 
inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
// inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}
// inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}
// inline ll gcd(ll a, ll b){if(a==0)return b;return gcd(b%a,a);}
 
// //*************************************  Bitmask Opereations  **********************************//
// int Set(int N,int pos){return N=N | (1<<pos);}
// int reset(int N,int pos){return N= N & ~(1<<pos);}
// bool check(int N,int pos){return (bool)(N & (1<<pos));}
// //********************************************************************************************//


int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //#ifdef rid.dle//freopen("in.txt", "r", stdin);//#endif
    //freopen("in.txt", "r", stdin);

    int n=rr;
    int ar[MX];
    loop1(i,n)ar[i]=rr;;

    sort(ar+1,ar+n+1);

    int mid = n/2;

    cout << ar[mid+1]-ar[mid] << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        
        int[][] arr = new int[3][];
        for(int i = 0; i < 3; i++) arr[i] = new int[3];
        
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++) arr[i][j] = scan.nextInt();
        }
        
        int[] diff = new int[9];
        
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++) diff[i*3+j] = arr[i][j] - arr[i][(j+1)%3];
        }
        
        for(int i = 0; i < 3; i++){
            if(diff[i] != diff[i+3] || diff[i+3] != diff[i+6]){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


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

int main(){
  
 vector <int> x(5);
  
  for(int i=0;i<5;i++){  
  cin >> x.at(i);

    if(x.at(i)==0){
     cout << i+1 << endl; 
    }
    
    else{
     continue; 
    }
  }
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
    int R[3];
    REP(i,3) cin >> R[i];
    sort(R, R+3);
    REP(i,3) {
        cout << R[i];
        if (i != 2) cout << " ";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3160
h, w, a, b = map(int, input().split())
for i in range(b):
    for j in range(a):
        print(0, end="")
    for j in range(w - a):
        print(1, end="")
    print()
for i in range(h - b):
    for j in range(a):
        print(1, end="")
    for j in range(w - a):
        print(0, end="")
    print()

Measured memory_bytes: 5364
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int a;
    cin >> a;
    cout << a + a*a + a*a*a;
}









Measured memory_bytes: 3632
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) //OUT(a)
#define DEBUG2(a,b) //OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL
using namespace std;
template<typename T> inline void maximize(T &a,T b){a=max(a,b);}
template<typename T> inline void minimize(T &a,T b){a=min(a,b);}
template<typename T> inline bool middle(T a,T b,T c){return b<=a && a<=c;}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
inline void outputVI(VI x){REP(i,SI(x)){cout << three(i," ","") << x[i];}OUT("");}
const int SIZE1=1e6+1000;
const int SIZE2=5010;
const int SIZE3=400;
const int SIZE=SIZE1;
const LL p=7+1e9;
const LL INF=1LL<<60;
const long double EPS=1e-7;
string s;
ut N,M,K,X,L,Y,Q;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE],nums[SIZE],maps[SIZE2][SIZE2],answer=zero;
char ss[SIZE];
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////////////////////////////////////////////////////////////////////////////////////
LL maxby(LL A ,LL B){
	if(A<0 or B<0) return INF;
	return (A+B)/(min(A,B)+1);
}
void init(){
 	
}
string solve2(LL A,LL B,LL C,LL D){
	int sizes=A+B;
	if(A<B){
		string ns=solve2(B,A,(A+B)-D-1,(A+B)-C-1);
		reverse(ALL(ns));
		REP(i,SI(ns)){
			if(ns[i]=='A') ns[i]='B';
			else ns[i]='A';
		}
		return ns;
	}
	LL maxim=maxby(A,B);
	LL s=0,e=A/maxim+1;
	DEBUG2(maxim,A);
	while(s<=e){
		int f=(s+e)/2;
		DEBUG2(f,maxby(A-f*maxim,B-f+1));
		if(maxim>=maxby(A-f*maxim,B-f+1))
			s=f+1;
		else
			e=f-1;
	}
	int fis=e*(maxim+1);
	A-=e*maxim;
	B-=e;
	int now=fis;
	DEBUG(e);
	DEBUG2(A,B);
	
	if(A) now+=(A*maxim-(B-1)+maxim-1)/maxim;
	
	int sec=now;
	string ns;
	DEBUG2(fis,sec);
	EFOR(i,C,D){
		if(i<fis){
			if(i%(maxim+1)==maxim) ns+='B';
			else ns+='A';
		}else if(i<sec){
			ns+='A';
		}else{
			//cat;
			//cout << A << " " << B << " " << i << endl;
			if((sizes-i)%(maxim+1)==0){
				ns+='A';
			}else{
				ns+='B';
			}
		}
	}
	return ns;
}
LL solve(){
	LL A,B,C,D;
	cin >> A >> B >> C >> D;
	C--;
	D--;
	OUT(solve2(A,B,C,D));
	
	return 0;
}
signed main(){
	cin >> Q;
	REP(i,Q){
		solve();
	}
	return 0;
}

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

int main()
{
    int h;
    int w;
    int n;
    cin >> h >> w >> n;
    
    int maxSize = max(h,w);
    
    
    int ans = 0;

    if (n % maxSize == 0)
    {
        ans = n / maxSize;
    }
    else
    {
        ans = n / maxSize + 1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REPZ(i, z, n) for(decltype(n) i = (z); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(all(v)))
#define MIN(v) (*min_element(all(v)))
#define INF 1000000000000 //1E+12
#define MOD 1000000007    //合同式の法

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

typedef long long ll;
typedef unsigned long long ul;
// 1s間で可能なループ回数2E+8回
// intの最大値2147483647~2E+9
// long longの最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<> push_back
// 連想配列map<key,value> insert,
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 setprecision()
// to_string<->stoi
// stoll(longlong)
// stod(double)
// 大文字65-90(-32)
// 小文字97-122(+32)
// for(string i:s) cout << i << endl;
using namespace std;
void dfs(){ 
  return;
}
bool check(vector<pair<int,int>> c){
  int h=0;
  for(pair<int,int> i:c){
    int b=h+i.first;
    if(b<0) return false;
    h+=i.second;
  }
  return true;
}

int main(){
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n; cin >> n;
  vector<string> s(n); REP(i,n) cin >> s[i];
  vector<pair<int,int>> mxminp,mxminm;

  int h=0;
  for(string i:s){
    int sum=0;
    int mins_temp=0;
    for(char k:i){
      if(k=='(') sum++;  
      else sum--;
      mins_temp=min(sum,mins_temp);
    }
    if(sum>0){
      mxminp.PB(MP(mins_temp, sum));
    }else{
 //     maxs_temp=max(maxs_temp-mins_temp,-maxs_temp);
 //     mins_temp=min(maxs_temp-mins_temp,-maxs_temp);

      mxminm.PB(MP(mins_temp-sum, -sum));
    }
    h+=sum;
  }
  sort(mxminm.rbegin(), mxminm.rend());
  sort(mxminp.rbegin(), mxminp.rend());
    //for(pair<int,int> i:mxminm) cout << i.first << " " <<  i.second << endl;
   //for(pair<int,int> i:mxminp) cout << i.first << " " <<  i.second << endl;
  if(h==0 and check(mxminp) and check(mxminm)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 50124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=1e5+5;

int main(){
     int i, j, k;
     int h1, m1, h2, m2;
     cin >> h1 >> m1 >> h2 >> m2 >> k;
     int s=h1*60+m1, f=h2*60+m2;
     cout << f-k-s << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
using namespace std;
long long n , mod = 1e9+7 ,s[2001]={1};
void sol()
{
	for(int i=3 ;i<=n ;i++)
		for(int j=3 ;j<=i ;j++)
		{
			s[i] = (s[i]+s[i-j])%mod;
		}							
}
int main() 
{	
	while(cin>>n)
	{
		sol();
		cout<<s[n]<<'\n';
	}	
}

Measured memory_bytes: 3152
#include <stdio.h>

int		main()
{
	int		N = 0, K = 0;
	int		count = 0;

	scanf("%d %d\n", &N, &K);
	while (N > 0)
	{
	    count++;
		N = N / K;
	}
	printf ("%d\n", count);
	return (0);
}


Measured memory_bytes: 128
# Node
class Node
  attr_accessor :id, :edges, :cost, :done

  def initialize(id, edges = [], cost = nil, done = false)
    @id, @edges, @cost, @done = id, edges, cost, done
  end
end

# Edge
class Edge
  attr_accessor :to, :cost

  def initialize(to, cost)
    @to, @cost = to, cost
  end
end

# Prim
class Prim
  attr_accessor :nodes

  def initialize(data)
    @nodes = {}
    data.each do |id, edges|
      edges.map! { |edge| Edge.new(*edge) }
      @nodes[id] = Node.new(id, edges)
    end
  end

  def start(id)
    cost = 0

    @nodes.each do |id, node|
      node.done = false
    end

    node = @nodes[id]
    node.done = true
    queue = node.edges

    until queue.empty?
      queue.sort! { |l, r| r.cost <=> l.cost }
      edge = queue.pop
      done_node = @nodes[edge.to]
      next if done_node.done
      done_node.done = true
      cost += edge.cost
      queue += done_node.edges
    end

    cost
  end
end

data = {}

n = gets.to_i

n.times do |i|
  data[i] = []
  gets.chop.split.each_with_index do |item, index|
    item = item.to_i
    next if item == -1
    data[i] << [index, item]
  end
end

prime = Prim.new data
puts prime.start 0

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

class UnionFind {
    public:
        UnionFind(){}
        UnionFind(int size) { Init(size); }
        // size: Union-Find で扱いたい要素の数
        void Init(int size) { m_Data.assign(size, -1); }

        // x と y の属する集合を併合
        // 既に一緒な集合内にいるなら false を
        // 新たに併合されたなら true を返す
        bool Unite(int x, int y) {
            x = Find(x), y = Find(y);
            if(x == y) { return (false); }
            if(m_Data[x] > m_Data[y]) { swap(x, y); }
            m_Data[x] += m_Data[y];
            m_Data[y] = x;
            return (true);
        }

        // 要素 k が属する集合の根を返す
        int Find(int k) {
            if(m_Data[k] < 0) { return (k); }
            return (m_Data[k] = Find(m_Data[k]));
        }

        // 要素 k と同じ集合の要素数を返す
        int Size(int k) { return (-m_Data[Find(k)]); }

        // 要素のうち独立しているグループの数 O(NlogN)
        int GetGroupNum() {
            map<int, bool> groups;
            for(int i = 0; i < m_Data.size(); ++i) {
                groups[Find(i)] = true;
            }
            return static_cast<int>(groups.size());
        }

    private:
        vector<int> m_Data;
};

ll N, M;

signed main()
{
    cin >> N >> M;
    UnionFind uf(N);

    REP(i, M) {
        ll x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        uf.Unite(x, y);
    }

    printf("%lld\n", uf.GetGroupNum());

    return 0;
}


Measured memory_bytes: 7296
from heapq import heappush, heappop, heapify

def main():
  N, M = map(int, input().split())
  A = list(map(int, input().split()))

  if N == 1: A[0] = A[0] // 2 ** M
  else:
    for i in range(N): A[i] *= -1

    heapify(A)

    for i in range(M):
      a = heappop(A)
      heappush(A, -(-a//2))

  print(-sum(A))  
  
if __name__ == '__main__':
  main()
  

Measured memory_bytes: 14180
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

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

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();


		BigInteger[] ans = new BigInteger[4];
		ans[0] = BigInteger.valueOf(a).multiply(BigInteger.valueOf(c));
		ans[1] = BigInteger.valueOf(a).multiply(BigInteger.valueOf(d));
		ans[2] = BigInteger.valueOf(b).multiply(BigInteger.valueOf(c));
		ans[3] = BigInteger.valueOf(b).multiply(BigInteger.valueOf(d));
		Arrays.sort(ans);
		System.out.println(ans[3]);

	}
}

Measured memory_bytes: 35980
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

class FenwickTree {
public:
    FenwickTree(int n):
        tree(vector<int>(n + 1, 0)) {}

    void update(int pos, int val) {
        for (++pos; pos < SZ(tree); pos += pos & -pos) {
            tree[pos] += val;
        }
    }
    
    int query(int pos) {
        int ret = 0;
        for (++pos; pos > 0; pos -= pos & -pos) {
            ret += tree[pos];
        }
        return ret;
    }

    void reset() {
        fill(tree.begin(), tree.end(), 0);
    }
private:
    vector<int> tree;
};

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<int> numbers[3];
    for (int i = 0; i < 3; ++i) {
        numbers[i] = vector<int>(n);
        for (int j = 0; j < n; ++j) {
            cin >> numbers[i][j];
        }
    }

    vector<int> A(n);
    vector<int> sign(n);
    int evenSigns = 0, oddSigns = 0;
    for (int i = 0; i < n; ++i) {
        if (numbers[0][i] == numbers[1][i] - 1 && numbers[1][i] == numbers[2][i] - 1) {
            sign[i] = 0;
        } else if (numbers[0][i] == numbers[1][i] + 1 && numbers[1][i] == numbers[2][i] + 1) {
            sign[i] = 1;
        } else {
            cout << "No\n";
            return 0;
        }
        A[i] = min(numbers[0][i], numbers[1][i]) / 3;
        if (A[i] % 2 != i % 2) {
            cout << "No\n";
            return 0;
        }
        ((i & 1) ? oddSigns: evenSigns) += sign[i];
    }
    evenSigns &= 1;
    oddSigns &= 1;
    FenwickTree even(n), odd(n);
    int evenInvs = 0, oddInvs = 0;
    for (int i = 0; i < n; ++i) {
        FenwickTree& t = ((i & 1) ? odd: even);
        int& invs = ((i & 1) ? oddInvs: evenInvs);
        invs += i / 2 - t.query(A[i]);
        t.update(A[i], 1);
    }
    int inv1 = (evenInvs + oddSigns) & 1;
    int inv2 = (oddInvs + evenSigns) & 1;
    if (inv1 || inv2) {
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";
}

Measured memory_bytes: 3072
#include<iostream>
using namespace std;
int main(){
  int k, a, b, f = 0;;
  cin >> k >> a >> b;
  
    for(int i = a; i <= b;i++){
      if(i % k == 0){
        f++;
        break;
      }
    }
    if(f == 0){
      cout << "NG\n";
      return 0;
    }
    else{
      cout << "OK\n";
      return 0;
    }
  
  
}
      

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
	--A; --B; --C; --D;
	string S; cin >> S;
	if (C < D) {
		int cnt = 0;
		for (int i = A; i <=D; ++i) {
			if (S[i] == '#') {
				cnt++;
			}
			else {
				cnt = 0;
			}

			if (cnt >= 2) {
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}
	else {
		int cnt = 0;
		for (int i = A; i <= C; ++i) {
			if (S[i] == '#') {
				cnt++;
			}
			else {
				cnt = 0;
			}

			if (cnt >= 2) {
				cout << "No" << endl;
				return 0;
			}
		}
		int c = 0;
		for (int i = B-1; i <= D+1; ++i) {
			if (S[i] == '.') {
				c++;
			}
			else {
				c = 0;
			}
			if (c >= 3) {
				cout << "Yes" << endl;
				return 0;
			}
		}
		cout << "No" << endl;
	}
	return 0;
}


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

using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
long long N=1e+5;

void solve()
{
    int n;
    cin>>n;
    int a[n];
    int cnt=0;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    for(int i=1; i<=n; i++)
    {
        if(i&1)
        {
            if(a[i]&1)
            {
                cnt++;
            }
        }
    }
    cout<<cnt<<endl;
}

int main()
{
    IO;

    solve();
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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

    int n=s.size();
    int m=t.size();
    if(n<m){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }

    for(int i=n-m;i>=0;i--){
        bool ok=true;
        for(int j=0;j<m;j++){
            if(s[i+j]=='?') continue;
            if(s[i+j]!=t[j]) ok=false;
        }
        if(ok){
            for(int j=0;j<m;j++){
                if(s[i+j]=='?') s[i+j]=t[j];
            }
            rep(i,n){
                if(s[i]=='?') s[i]='a';
            }
            cout<<s<<endl;
            return 0;
        }
    }
    cout<<"UNRESTORABLE"<<endl;

}


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

int main()
{
  int N;
  int ans=1;
  int A[110]={0};
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(A[i]%2==0){
      if(A[i]%3!=0&&A[i]%5!=0)ans=0;
    }
  }
  if(ans==0)cout<<"DENIED"<<endl;
  else cout<<"APPROVED"<<endl;
}

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

int main() {
    int n;
    int ans = 0;
    int v[100];
    int c[100];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &v[i]);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &c[i]);
    }
    for (int i = 0; i < n; i++) {
        if (v[i] > c[i]) {
            ans += (v[i] - c[i]);
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<deque>
#include<algorithm>
#include<functional>
using namespace std;
int n,w;
pair<int,int> tre[1005];

int dp[1005][1005];//現在調べてる宝ID,重さの総和
int solve(){

  for(int i=0;i<n;i++){
    for(int j=0;j<=w;j++){
      if(j<tre[i].second) dp[i+1][j]=dp[i][j];
      else dp[i+1][j]= max(dp[i][j],dp[i][j-tre[i].second] + tre[i].first);
    }
  }

  int temp=dp[n][w];
  int ret=w;
  for(int i=w;i>0;i--){
    if(temp <= dp[n][i]) ret=i;
    else break;
  }
  return ret;

}

main(){
  int cas=1;
  while(1){
    cin >> w;
    if(!w) break;
    cin >> n;
    for(int i=0;i<n;i++) scanf("%d,%d",&tre[i].first,&tre[i].second);
    int res=solve();
    printf("Case %d:\n",cas);
    printf("%d\n%d\n",dp[n][w],res);
    cas++;
  }

}

Measured memory_bytes: 0
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int leng = scan.nextInt();
        scan.close();
        double result = 0.0;

        double amari = leng % 3;
        double qubeAmari = amari / 3;

        double qubeLength = leng - amari;
        qubeLength = qubeLength / 3;

        if(leng >= 3){result = (qubeLength + qubeAmari) * (qubeLength + qubeAmari) * (qubeLength + qubeAmari);}
        else {result = qubeAmari * qubeAmari * qubeAmari;}

        System.out.println(String.format("%.12f", result));
    }
}

Measured memory_bytes: 21460
import numpy as np
from scipy.sparse.csgraph import bellman_ford, NegativeCycleError
from scipy.sparse import csr_matrix

import sys
input = sys.stdin.readline

N,M,P = map(int, input().split())

G = {}

for i in range(M):
  a,b,c = map(int, input().split())
  a,b,c = a-1, b-1, (-1) * (c-P) # 最短炉問題にするため。
  if (a,b) in G and G[(a,b)] > c:
    G[(a,b)] = c
  elif (a,b) not in G:
    G[(a,b)] = c

A,B,C = [],[],[]
for k,v in G.items():
  a,b = k
  c = v
  #G[a].append((b,c))
  A.append(a)
  B.append(b)
  C.append(c)
    
CC = [1] * len(A)
### https://atcoder.jp/contests/abc137/submissions/15987354
# とりあえず到達可能経路を探す、始点と終点から重み１にして辿っていき、双方登場した点が探すべき点。
# directedなので、A,Bを入れ替えているところもポイント
smat = bellman_ford(csr_matrix((CC, (A, B)), shape=(N, N)),
                    directed=True, unweighted=True, indices=0)
tmat = bellman_ford(csr_matrix((CC, (B, A)), shape=(N, N)),
                    directed=True, unweighted=True, indices=N-1)
r = set([i for i, v in enumerate(smat + tmat) if not np.isinf(v)])
A, B, C = zip(*[(a, b, c) for a, b, c in zip(A, B, C) if b in r])
try:
  csr_mat = csr_matrix((C, (A, B)), shape=(N, N))
  #csr_mat.data = P - csr_mat.data
  x = -int(bellman_ford(csr_mat, directed=True, indices=0)[N-1])
  if x < 0:
    x = 0
except NegativeCycleError:
  x = -1

print(x)

Measured memory_bytes: 39896
import java.util.*;
public class Main {
    
    static void solve(){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();        
        int B = sc.nextInt();        
        int C = sc.nextInt();        
        int K = sc.nextInt();        
        int count = 0;
        while(true){ 
            if(count>K) break;
            if(B<=A) {B*=2; count++;}
            else break;
        }
        while(true) {    
            if(count>K) break;
            if(C<=B) {C*=2; count++;}
            else break;
        }
        System.out.println((count<=K) ? "Yes" : "No");
        sc.close();
    }
    
    public static void main(String args[]) {
        solve();
    }
}

Measured memory_bytes: 35628
import sys
import socket
from collections import Counter

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    h, w = read_int_list()
    c = Counter()
    for i in range(h):
        a = read_str()
        c += Counter(a)

    n4 = (h - h % 2) * (w - w % 2) // 4
    n2 = 0
    if h % 2 == 1:
        n2 += w // 2
    if w % 2 == 1:
        n2 += h // 2
    n1 = 0
    if h % 2 == 1 and w % 2 == 1:
        n1 = 1

    v = [4] * n4 + [2] * n2 + [1] * n1
    l = list(c.values())
    for x in v:
        l.sort(reverse=True)
        if l[0] < x:
            print('No')
            return
        else:
            l[0] -= x
    print('Yes')


main()


Measured memory_bytes: 3568
n=input()

def change_1_9(n):
    answer=[]
    for i in range(len(n)):
        if n[i]=='1':
            answer.append(9)
        else:
            answer.append(1)   

    final_answer=''
    for n in range(len(answer)):
        final_answer+=str(answer[n])
    
    return final_answer  
  
print(int(change_1_9(n)))
 

Measured memory_bytes: 2940