akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T,class U>
ostream& operator << (ostream& os,pair<T,U>& p){
	os << p.fi << ',' << p.sec; return os;
}
template<class T,class U>
istream& operator >> (istream& is,pair<T,U>& p){
	is >> p.fi >> p.sec; return is;
}
template<class T>
ostream& operator << (ostream &os,const vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		os << vec[i];
		if(i+1<vec.size())os << ' ';
	}
	return os;
}
template<class T>
istream& operator >> (istream &is,vector<T>& vec){
	for(int i=0;i<vec.size();i++)is >> vec[i];
	return is;
}
void fastio(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
}
struct UnionFind{
  int par[100100];
  UnionFind(){
    for(int i=0;i<100100;i++){
      par[i] = i;
    }
  }
  int find(int x){
    if(par[x]==x)return x;
    else return par[x] = find(par[x]);
  }
  void unite(int x,int y){
    if(find(x)==find(y))return;
    par[find(x)] = find(y);
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
}uf;
int N,M;
vector<int> talk[100100];
int main(){
  cin >> N >> M;
  for(int i=0;i<N;i++){
    int K;
    cin >> K;
    for(int j=0;j<K;j++){
      int lang;
      cin >> lang;
      lang--;
      talk[lang].pb(i);
    }
  }
  for(int i=0;i<M;i++){
    for(int j=0;j+1<talk[i].size();j++){
      uf.unite(talk[i][j],talk[i][j+1]);
    }
  }
  bool ans = true;
  for(int i=0;i<N;i++){
    if(!uf.same(0,i)){
      ans = false;
      break;
    }
  }
  if(ans)cout << "YES" << endl;
  else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 5244
#include <bits/stdc++.h>
#define N 1000050
using namespace std;

char a[N],b[N];
int flag,ans,n;
queue<int> q;

int main() {
	scanf("%d%s%s",&n,a+1,b+1);
	for (int _=1;_<=n;_++) if (a[_] != b[_]) flag = 1;
	if (!flag) return puts("0"), 0;
	
	int p = n;
	for (int _=n;_>=1;_--) {
		if (b[_-1] == b[_]) continue;
		p = min(p, _);
		while (p && a[p] != b[_]) p--;
		if (!p) return puts("-1"), 0;
		
		#define sz (int)q.size()
		while (!q.empty())
			if (q.front()-sz >= _) q.pop(); else break;
		q.push(p);
		_!=p ? ans = max(ans,sz) :0;
	}
	printf("%d\n",ans+1);
	return 0;
}

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

using namespace std;

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

const int MOD = 100000;
const int INF = 1000000000;
const ll LINF = 1000000000000000000L;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

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

int extgcd(int a, int b, int& x, int&y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else {
        x = 1;
        y = 0;
    }
    return d;
}

int inv(int a) {
    int x, y;
    extgcd(a, MOD, x, y);
    return (x + MOD) % MOD;
}

int main() {
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    if(s == "Cloudy") cout << "Rainy" << endl;
    if(s == "Rainy") cout << "Sunny" << endl;
}


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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int x,a;cin>>x>>a;
  cout<<(x<a ? 0 : 10)<<endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
score = list(map(int, input().split()))
t = input()
self = [0] * n
for i in range(n):
    if t[i] == 'r':
        self[i] = 2
    elif t[i] == 's':
        self[i] = 0
    elif t[i] == 'p':
        self[i] = 1
    if i >= k and self[i] == self[i - k]:
        self[i] = 3
ans = 0
for x in self:
    if x != 3:
        ans += score[x]
print(ans)


Measured memory_bytes: 4084
s = list(input())

mina = float('inf')
for c in range(97, 123):
    c = chr(c)
    if c not in s:
        continue
    maxa = 0
    tmpa = 0
    for i in range(len(s)):
        if s[i] == c:
            maxa = max(maxa, tmpa)
            tmpa = 0
        else:
            tmpa += 1
    else:
        maxa = max(maxa, tmpa)
    mina = min(mina, maxa)
print(mina)

Measured memory_bytes: 3064
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

S = rs()
T = rs()

if S == T[:-1]:
	print('Yes')
else:
	print('No')


Measured memory_bytes: 61880
import numpy as np
from string import ascii_lowercase
s = list(input())
t = list(input())

s_c = []
t_c = []

for a in ascii_lowercase:
  if s.count(a) != 0:
    s_c.append(s.count(a))
  if t.count(a) != 0:
    t_c.append(t.count(a))

if np.array_equal(sorted(s_c), sorted(t_c)):
	print('Yes')
else:
	print('No')

Measured memory_bytes: 21904
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Yulian
 */



#include <iostream>

#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
#include <limits>




#include <ostream>
#include <sstream>


using namespace std;
class B {
public:
	void solve(std::istream& in, std::ostream& out) {
    ios::sync_with_stdio(false);
		int n, m, a, b;
		in >> n >> m;
		vector<int> v(n);
		for(int i = 0; i < m; ++i){
			in >> a >> b;
			++v[a-1];
			++v[b-1];
		}
		for(int i = 0; i < n; ++i){
			out << v[i] << endl;
		}


	}
};


int main() {
	B solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
while(True):
    try:
        s = input()
    except:
        break
    ec = dict([t,str(bin(i))[2:].zfill(5)] for i,t in enumerate("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"))
    c = "".join(ec[e] for e in s)
    dc = {"101":" ","000000":"'","000011":",","10010001":"-","010001":".","000001":"?",
    "100101":"A","10011010":"B","0101":"C","0001":"D","110":"E","01001":"F",
    "10011011":"G","010000":"H","0111":"I","10011000":"J","0110":"K","00100":"L",
    "10011001":"M","10011110":"N","00101":"O","111":"P","10011111":"Q","1000":"R",
    "00110":"S","00111":"T","10011100":"U","10011101":"V","000010":"W","10010010":"X",
    "10010011":"Y","10010000":"Z"}
    ans = ""
    i=0
    while(i<len(c)):
        for j in range(3,9):
            try: ans += dc[c[i:i+j]]; i+=j; break
            except: continue
        else:
            break
    print(ans)
    


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

int main() {
  int H,W;
  cin>>H>>W;
  char S[H+2][W+2];
  int k[H+2][W+2];
  for(int h=0;h<H+2;h++){
    for(int w=0;w<W+2;w++){
      if(h==0||w==0||w==W+1){
        S[h][w]=0;
      }else{
        cin>>S[h][w];
      }
      k[h][w]=0;
    }
  }
  for(int h=0;h<H;h++){
    for(int w=0;w<W;w++){
      if(S[h][w]=='#'){
        k[h+1][w+1]++;
      }
      if(S[h][w+1]=='#'){
        k[h+1][w+1]++;
      }
      if(S[h][w+2]=='#'){
        k[h+1][w+1]++;
      }
      if(S[h+1][w]=='#'){
        k[h+1][w+1]++;
      }
      if(S[h+1][w+2]=='#'){
        k[h+1][w+1]++;
      }
      if(S[h+2][w]=='#'){
        k[h+1][w+1]++;
      }
      if(S[h+2][w+1]=='#'){
        k[h+1][w+1]++;
      }
      if(S[h+2][w+2]=='#'){
        k[h+1][w+1]++;
      }
    }
  }
  for(int h=0;h<H;h++){
    for(int w=0;w<W;w++){
      if(S[h+1][w+1]=='.'){
      cout<<k[h+1][w+1];
      }else{
        cout<<'#';
      }
    }  cout<<"\n";
  }
}
    
    
  

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n; scanf("%d", &n);
	if(n == 1){
		scanf("%d", &n);
		printf("%d\n", n);
		return 0;
	}
	vector<int> positive, negative;
	for(int i(1), tmp; i <= n; ++i){
		scanf("%d", &tmp);
		if(tmp <= 0) negative.push_back(tmp);
		else positive.push_back(tmp);
	}
	sort(positive.begin(), positive.end());
	sort(negative.begin(), negative.end());
	reverse(positive.begin(), positive.end());
	int siz1 = positive.size(), siz2 = negative.size();
	
	if(siz1 == 0){
		positive.push_back(negative.back());
		++siz1; --siz2;
	}
	if(siz2 == 0){
		negative.push_back(positive.back());
		--siz1; ++siz2;
	}
	
	vector<pair<int,int> > ans;
	for(int i(1); i < siz1; ++i){
		ans.push_back(make_pair(negative[0], positive[i]));
		negative[0] -= positive[i];
	}
	for(int i(0); i < siz2; ++i){
		ans.push_back(make_pair(positive[0], negative[i]));
		positive[0] -= negative[i];
	}
	printf("%d\n", positive[0]);
	for(int i(0); i < n - 1; ++i){
		printf("%d %d\n", ans[i].first, ans[i].second);
	}
	return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n;cin >>n;
    string s;cin >>s;
    ll ans=0;
    ll now=0;
    for (int i = 0; i < n; ++i) {
        if(s[i]=='I')now++;
        else now--;
        ans=max(ans,now);
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	double r; cin >> r;
	double ans = r * 6.2831853;
	cout << ans << fixed << setprecision(10);
	return 0;
}


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

int main() {
  
  int n,m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> nbool(n);
  vector<int> a(m);
  vector<int> b(m);
  int ans = 0;
  
  for(int i = 0;i<n;i++){
    cin >> h.at(i);
  }
  for(int i = 0;i<m;i++){
    cin >> a.at(i);
    cin >> b.at(i);
    if (h.at(a.at(i)-1) < h.at(b.at(i)-1)){
      nbool.at(a.at(i)-1) = true;
    }else if(h.at(a.at(i)-1) == h.at(b.at(i)-1)){
      nbool.at(a.at(i)-1) = true;
      nbool.at(b.at(i)-1) = true;
    }else{
      nbool.at(b.at(i)-1) = true;
    }
  }
  for(int i = 0;i<n;i++){
    if(nbool.at(i) == false){
      ans = ans + 1;
    }
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 4508
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 mod = 1000000007;
    std::string s;
    std::cin >> s;
    int n = s.size();
    std::vector<i64> a(n + 10);
    a[0] = 1;
    for (int i = 1; i < n; i++) {
        a[i] = (a[i - 1] * 3) % mod;
    }
    i64 co = 1, ret = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') continue;
        ret = (ret + a[n - i - 1] * co % mod) % mod;
        co = co * 2 % mod;
    }
    ret = (ret + co) % mod;

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 1280
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

int n;
string s;
uint64_t ans;

int main(void) {
    cin >> n;
    map<string, uint64_t> m;

    for (int i = 0; i < n; i++) {
        cin >> s;
        sort(s.begin(), s.end());
        ans += m[s]++;
    }

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


Measured memory_bytes: 11136
S = input()
S = list(S)

tmp = [0 for i in range(len(S))]

for i in range(len(S)):
    if S[i] == '1':
        tmp[i] = 1
    elif S[i] == '0':
        tmp[i] = 0
     
flag = False
for i in range(len(S)-1):
    if S[i] != S[i+1] and flag == False:
        tmp[i] = -1
        tmp[i+1] = -1
        flag = True
    else:
        flag = False
  
count1 = 0
count0 = 0
res = 0
for i in range(len(S)):
    if tmp[i] == 1:
        count1 += 1
        
    elif tmp[i] == 0:
        count0 += 1
        
    else:
        res += 1
        
print(res + min(count0, count1) * 2)

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

#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define FOR(i,a,b) for(long long i=(a);i<=(b);i++)

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int ans = min(B / A, C);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

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

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

	int dai = a[0];
	long long ans = 0;

	for (int i = 1;i < n;i++) {
		if (dai > a[i]) {
			ans += dai - a[i];
		}
		else {
			dai = a[i];
		}

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4044
def main():
    n = int(input())
    num_list = list(map(int, input().split()))
    
    ls = [num_list[0]]

    for i in range(n-1):
        if i != n - 2 and num_list[i+1] < num_list[i]:
            ls.append(num_list[i+1])
        else:
            ls.append(num_list[i])

    print(sum(ls))

if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;
int main() {
    string s;
    cin >> s;
    if(s=="Sunny"){
        cout << "Cloudy" << endl;
    }else if(s=="Cloudy"){
        cout << "Rainy" << endl;
    }
    else{
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		int l = s.length();

		if(l == 26) {
			int[] p = new int[l];
			for(int i = 0; i < l; i++) {
				p[i] = s.charAt(i) - 'a';
			}
			if(next_permutation(p)) {
				for(int i = 0; i < 26; i++) {
					if(s.charAt(i) - 'a' == p[i]) {
						System.out.print(s.charAt(i));
					}else {
						System.out.println((char)(p[i] + 'a'));
						break;
					}
				}
			}else {
				System.out.println(-1);
			}
		}else {
			int[] a = new int[26];
			for(int i = 0; i < l; i++) {
				a[s.charAt(i) - 'a']++;
			}
			for(int i = 0; i < 26; i++) {
				if(a[i] == 0) {
					System.out.print(s);
					System.out.println((char)(i + 'a'));
					break;
				}
			}
		}
	}
	static boolean next_permutation(int[] p) {
		for(int a = p.length - 2; a >= 0; --a) {
			if(p[a] < p[a + 1]) {
				for(int b = p.length - 1;; --b) {
					if(p[b] > p[a]) {
						int t = p[a];
						p[a] = p[b];
						p[b] = t;
						for(++a, b = p.length - 1; a < b; ++a, --b) {
							t = p[a];
							p[a] = p[b];
							p[b] = t;
						}
						return true;
					}
				}
			}
		}
		return false;
	}
}

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

using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> w(N);
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }
  vector<long long> dp((N + 1) * (W + 1));
  const int col = W + 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      if (j + w[i] <= W) {
        dp[col * (i + 1) + j + w[i]] =
            max(dp[col * (i + 1) + j + w[i]], dp[col * i + j] + v[i]);
      }
      dp[col * (i + 1) + j] = max(dp[col * (i + 1) + j], dp[col * i + j]);
    }
  }
  cout << dp[col * N + W] << endl;
  return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 998244353;

struct mint {
    ll x;
    mint(ll x=0):x(x%MOD){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
};

int main() {
    int n;
    cin >> n;
    vint d(n);
    vint tr(n, 0);
    rep(i, n) cin >> d[i];
    rep(i, n) tr[d[i]]++;

    if (tr[0] != 1 || d[0] != 0) {
        puts("0");
        return 0;
    }
    
    int mx = vmax(d);
    mint ans = 1;
    for (int i = 1; i <= mx; ++i) {
        rep(j, tr[i]) ans *= tr[i-1];
    }

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

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
  int n;
  std::cin >> n;
  if(n == 1){
    std::cout << "Hello World" << '\n';
  }else{
    int a, b;
    std::cin >> a >> b;
    std::cout << a + b << '\n';
  }
  return 0;
}


Measured memory_bytes: 888
#include<iostream>

using namespace std;

int main(void) {
	int a, b, G, R, L, r;
	while (cin >> a >> b) {
		R = a;
		L = b;
		int tmp;
		if (b > a) {
			tmp = a;
			a = b;
			b = tmp;
		}
		while (1) {
			r = a%b;
			if (r == 0)break;
			a = b;
			b = r;
		}
		G = b;
		R = R / G;
		L = L / G;
		cout << G << " " << R*L * G << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <queue>
#include <vector>
#define int long long
typedef long long ll;
using namespace std;

ll N, count=0;

ll bfs(){
    queue<ll> Q;
    Q.push(1);
    Q.push(2);
    Q.push(3);
    Q.push(4);
    Q.push(5);
    Q.push(6);
    Q.push(7);
    Q.push(8);
    Q.push(9);
    int u;
    while(count<N){
        u = Q.front();
        Q.pop();
        if(u%10==0){
            Q.push(10*u);
            Q.push(10*u+1);
        }
        else if(u%10==9){
            Q.push(10*u-1+u%10);
            Q.push(10*u+u%10);
        }
        else {
            Q.push(10*u-1+u%10);
            Q.push(10*u+u%10);
            Q.push(10*u+1+u%10);
        }
        count++;
        //cout << u << endl;
    }
    return u;
}

signed main(){
    cin >> N;
    cout << bfs() << endl;
    return 0;
}

Measured memory_bytes: 1792
function main(input) {
  input=input.trim();
  const n = parseInt(input.split("\n")[0], 10);
  const s = input.split("\n")[1];
  var ansArr=[]
  for(var i=0; i<n-1; i++){
    var temp1=s.substr(0,i+1)
    var temp2=s.substr(i+1)

    //以下、iで切断した場合の共通文字数を調べる
    var arr1=[]
    var arr2=[]
    for(var j=0; j<temp1.length; j++){
      if(arr1.indexOf(temp1.substr(j,1))==-1){
        arr1.push(temp1.substr(j,1))
      }
    }
    for(var j=0; j<temp2.length; j++){
      if(arr2.indexOf(temp2.substr(j,1))==-1){
        arr2.push(temp2.substr(j,1))
      }
    }

    var ans=0
    for(var j=0; j<arr1.length; j++){
      if(arr2.indexOf(arr1[j])!=-1){
        ans++
      }
    }
    ansArr.push(ans)
  }
  console.log(Math.max.apply(null, ansArr));
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 11576
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

############

N, K = s_inpl()
S = input()

ans = ""

for i, s in enumerate(S):
    if i+1 == K:
        s = s.lower()
    ans = ans + s

print(ans)

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

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int n;
string s;

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

    rep(i, s.length()){
        int tmp = n;
        if(s[i] + n > 'Z'){
            tmp = n - ('Z' - s[i] + 1);
            s[i] = 'A' + tmp;
        }else{
            s[i] += tmp;
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 3656
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let s: Vec<char> = itr.next().unwrap().chars().collect();

    let mut one = 0;
    let mut zero = 0;
    for &c in s.iter() {
        if c == '0' {
            zero += 1;
        } else {
            one += 1;
        }
    }
    println!("{}", std::cmp::min(zero, one) * 2);
}


Measured memory_bytes: 4352
//MLE
#include <cstdio>
#include <map>
using namespace std;

int mp[144], m, n, hs, ch;
int dir[] = { -12, -1, 1, 12 };
map<int,int> memo;

int func( int p, int d, int u ){
	while(1){
		int h = mp[p];
		if( h >= 0 ){
			int s = 0;
			mp[p] = -1;
			hs ^= 1 << h;
			if( u > 9 ){
				for(int i = 0; i < 4; i++ )
					s += func( p + dir[i], dir[i], u - 1 );
			}else{
				int mi = h << 23 | hs;
				map<int,int>::iterator it = memo.find(mi);
				if( it == memo.end() ){
					for(int i = 0; i < 4; i++ )
						s += func( p + dir[i], dir[i], u - 1 );
					memo[mi] = s;
				}else{
					s = it->second;
				}
			}
			hs |= 1 << h;
			mp[p] = h;
			return s;
		}
		if( h == -9 )break;
		p += d;
	}
	return 0;
}

int main(void){
	int i,j,p,t;
	for(; scanf("%d%d",&m,&n),m;){
		hs = 0;
		memo.clear();
		for( i = 0; i < 144; i++ ) mp[i] = -9;
		for( i = 1; i <= n; i++ )
			for( j = 1; j <= m; j++ ){
				p = i * 12 + j;
				scanf("%d",&t);
				switch( t ){
					case 2:
						ch = p;
					case 0:
						mp[p] = -1; break;
					case 1:
						memo[hs<<23] = 0;
						mp[p] = hs++;
						break;
				}
			}
		for( i = 0; i < 4; i++ ){
			t = dir[i];
			for( j = ch; mp[j+=t] != -9; )
				if( mp[j] >= 0 )memo[ mp[j]<<23 ] = 1;
		}
		j = hs;
		hs = ( 1 << hs ) - 1;
		t = 0;
		for( i = 0; i < 4; i++ ){
			t += func( ch + dir[i], dir[i], j );
		}
		printf("%d\n", t );
	}
}

Measured memory_bytes: 21000
#include <cstring>
#include <cstdlib>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define ABS(a) ((a)<0?(-(a)):(a))
#define CS while(cases())
#define I(n) int n = gi()
#define II(n) n = gi()
#define L(n) ll n = gli()
#define LL(n) n = gli()
#define F(i, n) for (int i = 0; i < n; i++)
#define Fa(n, a) for (int i = 0; i < n; i++) a[i] = gi()
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

template<class T>
T gcd(T a, T b) {
    return (b == 0 ? a : gcd(b, a%b));
}

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int cases() {
    static int t = gi();
    return t--;
}

#define MD 1000000007
int f[10004];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(f, 0, sizeof(f));
    I(n);
    for (int x = 1; x <= 100; x++)
    for (int y = 1; y <= 100; y++)
    for (int z = 1; z <= 100; z++) {
        int s = x*x + y*y + z*z + x*y + y*z + z*x;
        if (s <= n)
            f[s]++;
    }
    F(i, n) printf("%d\n", f[i+1]);

    return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 100000000;
typedef pair<int, int> P;
const int MAX_N = 1000000;

int N, M;
vector<int> vo(31);

int main() {
	cin >> N >> M;
	rep(i, N) {
		int K;
		cin >> K;
		rep(i, K) {
			int A;
			cin >> A;
			vo.at(A-1)++;
		}
	}
	int ans = 0;
	rep(i, 31) {
		if (vo.at(i) == N) {
			ans++;
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 3616
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1;; i++) {
    if (i * i > n) {
      cout << (i - 1) * (i - 1) << endl;
      return 0;
    } else if (i * i == n) {
      cout << i * i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define PUTS(x) cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
#define MOD 998244353

struct Node {
    vector<Int> adjacents;
    Int ans = -1;
};

int main() {
    Int n, m;
    cin >> n >> m;
    auto g = vector<Node>(n);
    rep(i, m) {
        Int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].adjacents.push_back(b);
        g[b].adjacents.push_back(a);
    }

    auto q = queue<Int>();
    q.push(0);
    while (q.size() > 0) {
        auto targetIndex = q.front();
        auto &targetNode = g[targetIndex];
        q.pop();
        for (auto &nextIndex : targetNode.adjacents) {
            if (nextIndex == targetIndex) {
                continue;
            }
            auto &nextNode = g[nextIndex];
            if (nextNode.ans >= 0) {
                continue;
            } else {
                nextNode.ans = targetIndex;
                q.push(nextIndex);
            }
        }
    }

    PUTS("Yes")
    rep(i, n) {
        if (i == 0) continue;
        PUTS(g[i].ans + 1)
    }
}


Measured memory_bytes: 12872
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}
// head

int x,n,m,t,a,q,res;
int p[101000] = {};
int y[101000] = {};
string s;
vector<vector<int>> vec;
signed main() {
	std::cin >>n>>m;
	vec.resize(n);
	rep(i,0,m){
		std::cin >> p[i]>>y[i];
		p[i] -= 1;
		vec[p[i]].pb(y[i]);
	}
	rep(i,0,n){
		sort(all(vec[i]));
	}
	rep(i,0,m){
		res = lower_bound(all(vec[p[i]]),y[i])-vec[p[i]].begin()+1;
		string mae = "000000";
		string usi = "000000";
		string ken = to_string(p[i]+1);
		string si = to_string(res);
		reverse(ken.begin(), ken.end());
		reverse(si.begin(), si.end());
		rep(i,0,si.length()){
			usi[i] = si[i];
		}
		rep(i,0,ken.length()){
			mae[i] = ken[i];
		}
		reverse(mae.begin(), mae.end());
		reverse(usi.begin(), usi.end());
		std::cout << mae + usi << '\n';
	}
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	if(c-a-b <= 0) {
		return !(cout << "No");
	}
	cout << (4*a*b < (c-a-b)*(c-a-b) ? "Yes" : "No");
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    ans = 0
    word = input().strip()
    while True:
        s = input().strip()
        if s == "END_OF_TEXT":
            break
        for w in s.split():
            if word == w.lower():
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5560
import java.util.Scanner;

public class Main {

	static long mod = 1_000_000_007;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(), K = in.nextInt();
		int a[] = new int[N + 1];
		for ( int i = 1; i <= N; i++ ) {
			a[i] = in.nextInt();
		}
		in.close();

		long dp[][] = new long[N + 1][K + 1];
		for ( int n = 0; n <= N; n++ ) {
			dp[n][0] = 1;
		}

		for ( int n = 1; n <= N; n++ ) {
			for ( int k = 1; k <= K; k++ ) {
				dp[n][k] = (dp[n][k - 1] + dp[n - 1][k]) % mod;

				if ( a[n] < k ) {
					dp[n][k] -= dp[n - 1][k - a[n] - 1] % mod;
				}
			}
		}
		System.out.println((dp[N][K] + mod) % mod);
	}
}

Measured memory_bytes: 127572
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll y[1003];
void prime(ll n) {
    vector<ll> p,e;
    ll m=n;
    for (ll i=2;i*i<=n;i++) {
        if (m%i!=0) continue;
        int c=0;
        while (m%i==0) c++, m/=i;
        y[i]+=c;
    }
    if (m>1) {
        y[m]+=1;
      }
}
int main(){
  ll n,ans=1;
  cin >>n;
  for(ll i=n;i>=1;i--) prime(i);
  for(ll i=1;i<=1001;i++){
    if(y[i]!=0) ans*=(y[i]+1);
    ans%=1000000007;
  }
  cout <<ans<<endl;
  }


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

int main() {
    string s;
    cin >> s;
    deque<char> q;
    rep(i,s.size()) {
        q.push_back(s[i]);
    }
    int n;
    cin >> n;
    bool rev = false;
    rep(i,n) {
        int t;
        cin >> t;
        if (t == 1) rev = !rev;
        if (t == 2) {
            int f;
            char c;
            cin >> f >> c;
            if (!rev) {
                if (f == 1) q.push_front(c);
                else q.push_back(c); 
            } else {
                if (f == 1) q.push_back(c);
                else q.push_front(c);
            }
        }
    }
    if (rev) reverse(q.begin(), q.end());
    for (auto itr = q.begin(); itr != q.end(); itr++)
    {
        cout << *itr;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
#define MAX_N 999999
bool prime_check(int n, int k = 2){
	if (n < k * k) return true;
	if (n % k == 0) return false;
	return prime_check(n, k + 1);
}
int main(){
  int n;
  bool isprime[MAX_N+1];
  for(int i=2; i<=MAX_N; i++) isprime[i] = prime_check(i);
  while(cin >> n){
    int cnt=0;
    for(int i=2; i<=n; i++){
        if(isprime[i] == true) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}



Measured memory_bytes: 4016
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    map<ll, ll> mp;
    ll ans = 0;
    exrep(i, 1, n) {
        ll a;
        cin >> a;
        mp[i+a]++;
        ans += mp[i-a];
    }
    
    out(ans);
    re0;
}

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

int main() {
  int H,W;
  while(1){
    cin >> H >> W;
    if(H==0 && W==0)
      break;
    for(int i=1; i<=H; i++){
      for(int j=1; j<=W; j++){
        if(i==1 || i==H || j==1 || j==W){
          cout << '#';
        }
        else{
          cout << '.';
        }
      }
      cout << endl;
    }
    cout << endl;
  }
}



Measured memory_bytes: 3084
#include <cstdio>
#include <queue>

using namespace std;

typedef long long ll;

const int Maxn = 500;
char field[Maxn][Maxn];
bool used[Maxn][Maxn];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int h, w;
typedef pair<int, int> P;


ll bfs(int sx, int sy) {
    used[sx][sy] = true;
    ll cnt_b = 1, cnt_w = 0;

    queue<P> que;
    que.push(P(sx, sy));
    while (!que.empty()) {
        P p = que.front();
        que.pop();
        for (int i = 0; i < 4; ++i) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && nx < h && 0 <= ny && ny < w
                && field[p.first][p.second] != field[nx][ny] && !used[nx][ny]) {
                if (field[nx][ny] == '#')cnt_b++;
                else cnt_w++;
                que.push(P(nx, ny));
                used[nx][ny] = true;
            }
        }
    }

    return cnt_b * cnt_w;
}

int main() {
    scanf("%d %d", &h, &w);
    for (int i = 0; i < h; ++i) {
        char s[w];
        scanf("%s", s);
        for (int j = 0; j < w; ++j) {
            field[i][j] = s[j];
        }
    }

    ll ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (field[i][j] == '#' && !used[i][j]) ans += bfs(i, j);
        }
    }

    printf("%lld\n", ans);
}

Measured memory_bytes: 640
/*
author: shah_entrance
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<(a*b)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n, d; cin >> n >> d;
  vvi points(n, vi(d, 0));
  rep(i,n) {
    vi temp(d);
    rep(j,d) {
      cin >> temp[j];
    }
    points[i] = temp;
  }
  auto getDist = [] (vi p1, vi p2) {
    double sum = 0;
    rep(i, p1.size()) {
      sum += (p1[i] - p2[i]) * (p1[i] - p2[i]);
    }
    return sum;
  };
  int ans =0;
  rep(i, n) {
    for (int j=i+1; j<n; j++) {
      double dist = getDist(points[i], points[j]);
      if (floor(sqrt(dist)) == sqrt(dist)) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    long long a = 2,b = 1;
    int N;
    cin >> N;
 
    if(N == 0){
        cout << 2 <<endl;
    }
    else if(N == 1){
        cout << 1 << endl;
    }
    else{
        for(int i=1;i<N;i++){
            long long c;
            c = a+b;
            a = b;
            b = c;
        }
        cout << b << endl;
 
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;
 
 
 
public class Main{
	
	public int num;
	public int vol;
 
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd(long a, long b) {
		if (b == 0) {
			return a;			
		}
		return gcd(b, a % b);
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}
 
 
 
	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}
 
 
	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}
 
 
	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}
 
 
	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int N=sc.nextInt(),M=sc.nextInt();
	int[] num=new int[N];
	Arrays.fill(num,1);
	Set<Integer> set=new HashSet<Integer>();
	set.add(1);
	for(int i=0;i<M;i++) {
		int x=sc.nextInt();
		int y=sc.nextInt();
		num[x-1]--;
		num[y-1]++;
		if(set.contains(x)) {
			if(num[x-1]==0) {
				set.remove(x);
			}
			set.add(y);
		}
	}
	System.out.println(set.size());
	
	
    
}
}

Measured memory_bytes: 87392
use proconio::input;

fn main() {
    input! {
        a: f64,
        b: f64,
        h: f64,
        m: f64,
    };
    let th = (h * 60_f64 + m) / (60_f64 * 12_f64) * 2_f64 * std::f64::consts::PI;
    let tm = m / 60_f64 * 2_f64 * std::f64::consts::PI;
    let dx = th.cos() * a - tm.cos() * b;
    let dy = th.sin() * a - tm.sin() * b;
    let ans = (dx * dx + dy * dy).sqrt();
    println!("{}", ans);
}


Measured memory_bytes: 2916
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cstring>

using namespace std;

int main()
{
	set<string> list;
	long long left[2][2019] = { 0, };
	string str;
	char input[200001];

	scanf("%s", &input);
	str = input;

	const int n = str.size();

	long long sol = 0;

	for (int i = 0; i < n; i++)
	{
		int num;

		num = str[i] - '0';

		for (int j = 0; j < 2019; j++)
		{
			left[i % 2][(j * 10 + num) % 2019] = left[!(i % 2)][j];
		}

		left[i % 2][num]++;

		sol += left[i % 2][0];
	}

	printf("%lld\n", sol);

	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {
	
	string s;
	cin >> s;
	int k = 0;
	rep(i, s.size()) {
		k += s[i] - '0';
		k %= 9;
	}
	cout << (k == 0 ? "Yes" : "No") << endl;

}

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

string replaceAll(string s,string f,string t){
  string r;
  for(int pos=0; (pos = s.find(f)) != s.npos; ){
    r+=s.substr(0,pos)+t;
    s = s.substr( pos+f.size() );
  }
  return r+s ;
}


int main() {
    string s;
    getline(cin,s);
    s = replaceAll(s,"apple","~~~");
    s = replaceAll(s, "peach", "apple");
    s = replaceAll(s, "~~~", "peach");
    cout<<s<<endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int h, w;
pii C, D;
const int INF = 1e9;
char grid[1001][1001];

struct state
{
	int i, j, magicused;
	state(int a = 0, int b = 0, int c = 0)
	{
		i = a;
		j = b;
		magicused = c;
	}
	bool operator<(const state &a) const
	{
		return magicused > a.magicused;
	}
};

bool inbounds(int i, int j)
{
	return (1 <= i && i <= h && 1 <= j && j <= w && grid[i][j] == '.');
}

int dijkstra(pii src, pii end)
{
	priority_queue<state> pq;
	vector<vector<int>> d(1001, vector<int>(1001, INF));
	vector<vector<bool>> visited(1001, vector<bool>(1001, false));

	pq.push(state(src.first, src.second, 0));
	d[src.first][src.second] = 0;

	while (!pq.empty())
	{
		state cur = pq.top();
		pq.pop();
		if (visited[cur.i][cur.j])
			continue;
		visited[cur.i][cur.j] = true;

		for (int x = -2; x <= 2; x++)
		{
			for (int y = -2; y <= 2; y++)
			{
				if (abs(x) + abs(y) == 0)
					continue;
				if (!(inbounds(cur.i + x, cur.j + y)))
					continue;
				if (abs(x) + abs(y) == 1)
				{
					if (d[cur.i][cur.j] < d[cur.i + x][cur.j + y])
					{
						d[cur.i + x][cur.j + y] = d[cur.i][cur.j];
						pq.push(state(cur.i + x, cur.j + y, d[cur.i][cur.j]));
					}
				}
				else if (d[cur.i][cur.j] + 1 < d[cur.i + x][cur.j + y])
				{
					d[cur.i + x][cur.j + y] = d[cur.i][cur.j] + 1;
					pq.push(state(cur.i + x, cur.j + y, d[cur.i][cur.j] + 1));
				}
			}
		}
	}

	return d[end.first][end.second];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> h >> w;
	cin >> C.first >> C.second;
	cin >> D.first >> D.second;
	for (int i = 1; i <= h; i++)
	{
		for (int k = 1; k <= w; k++)
		{
			cin >> grid[i][k];
		}
	}
	int res = dijkstra(C, D);
	cout << (res == INF ? -1 : res);
}

Measured memory_bytes: 8752
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        string[] input1 = Console.ReadLine().Split(' ');
        string[] input2 = Console.ReadLine().Split(' ');
        int n = int.Parse(input1[0]);
        int m = int.Parse(input1[1]);
        int[] a = Array.ConvertAll(input2, int.Parse);
        int ans = 0, sum = a.Sum();
        for (int i = 0; i < n; i++)
        {
            if (a[i] >= sum / (4.0 * m))
            {
                ans++;
            }
        }
        if (ans >= m)
        {
            Console.WriteLine("Yes");
        } else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

int n, m, q;
vector<int> G[100009];
int v[100009], d[100009], c[100009];

int dp[100009][15];

void dfs(int V, int D, int C) {
    if(dp[V][D] || D < 0) return;
    dp[V][D] = C;
    dfs(V, D - 1, C);
    for(auto &&u : G[V])
        dfs(u, D - 1, C);
}

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

    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    cin >> q;
    rep(i, q) cin >> v[i] >> d[i] >> c[i];

    FORR(i, q)
    dfs(v[i], d[i], c[i]);

    FOR(i, 1, n + 1) cout << dp[i][0] << "\n";

    return 0;
}

Measured memory_bytes: 16152
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll NN;

  std::cin >> NN;

  int len = 0;

  int each_dig[20];


  while (NN > 0) {
      each_dig[len] = NN% 10;
      NN /= 10;
      len++;
  }

  // for (size_t i = 0; i < len; i++) {
  //   std::cout << each_dig[i] << '\n';
  // }

  int ans_min = 100000;


  for (size_t i = 0; i < len -2; i++) {
    int tet = each_dig[len-i-1] * 100 + each_dig[len-i-2] * 10+each_dig[len-i-3] ;
    // std::cout << tet << '\n';
    tet = abs(753 - tet);
    if (ans_min > tet) {
      ans_min = tet;
    }
  }

  std::cout << ans_min << '\n';


  return 0;
}


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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    int n; cin >> n;
    cout << n*800-(n/15)*200;
}

Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

rad = 0
deg_long = M * 6
deg_short = 30 * H + M / 2

print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(abs(deg_long - deg_short)))))

Measured memory_bytes: 9360