akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str1=Console.ReadLine().Split(' ');
      int N=int.Parse(str1[0]);
      int M=int.Parse(str1[1]);
      List<int> exc=new List<int>();
      for(int i=1;i<=N;i++){
       string[] A=Console.ReadLine().Split(' ');
        int[] Aint=A.Select(int.Parse).ToArray();
        Array.Clear(Aint,0,1);
        for(int j=1;j<=M;j++){
          if(Array.IndexOf(Aint,j)==-1){
            exc.Add(j);
          }
        }
      }
      int[] dis=exc.Distinct().ToArray();
      int count=dis.Length;
 
      Console.WriteLine(M-count);
    }
    
  }

}


Measured memory_bytes: 28344
#include <iostream>
using namespace std;
int main(void){
   int m,f,r;
   while(true){
    cin>>m>>f>>r;
    if(m==-1&&f==-1&&r==-1) break;
    if(m==-1||f==-1) cout<<"F";
    if(m>=0&&f>=0){
       if(m+f>=80)  cout<<"A";
       if(m+f>=65&&m+f<80)  cout<<"B";
       if(m+f>=50&&m+f<65)  cout<<"C";
       if(m+f>=30&&m+f<50&&r<50)  cout<<"D";
       if(m+f>=30&&m+f<50&&r>=50)  cout<<"C";
       if(m+f<30)   cout<<"F";
    }
    cout<<endl;
}
}



Measured memory_bytes: 3104
n = int(input())
s = list(map(int, input().split(" ")))

c = []
j = 0
if 1 not in s:
    print(-1)
elif len(s) == 1:
    print(0)
else:
    for i in s:
        if i - j == 1:
            j = i
            c.append(i)
    print(n - len(c))

Measured memory_bytes: 24744
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, M = LI()
    graph = []
    from collections import defaultdict
    reversed_graph_dict = defaultdict(list)
    for _ in range(M):
        u, v = LI()
        graph.append([u,v])
        reversed_graph_dict[v].append(u)
    S, T = LI()

    # print(reversed_graph_dict)

    import collections
    def bfs(graph, root):
        seen, queue = set([root]), collections.deque([[root, 0],])
        first_step_seen = set([])
        second_step_seen = set([])
        while queue:
            vertex, tries = queue.popleft()
            tries += 1

            # 三段先を見に行く。
            first_step = graph[vertex]

            second_step = []
            for x in set(first_step) - first_step_seen:
                second_step += graph[x]
            first_step_seen |= set(first_step)

            third_step = []
            for x in set(second_step) - second_step_seen:
                third_step += graph[x]
            second_step_seen |= set(second_step)

            for node in set(third_step):
                if node == S:
                    print(tries)
                    return
                if node not in seen:
                    seen.add(node)
                    queue.append([node, tries])
        print(-1)
        return

    bfs(reversed_graph_dict, T)


main()

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

int main(){
    int n;
    cin >> n;
    vector<int> array;
    for(int i = 1; i <= n; i++){
        array.push_back(i);
    }
    vector<int> p;
    vector<int> q;
    rep(i, n){
        int a; cin >> a;
        p.push_back(a);
    }
    rep(i, n){
        int a; cin >> a;
        q.push_back(a);
    }
    int nn = 1;
    for(int i = 1; i <= n; i++) nn*=i;
    vector<vector<int>> tmp(n, vector<int>(nn));

    int num = 0;
    int pnum = 0, qnum = 0;
    do{
        num++;
        bool flagP = true, flagQ = true;
        rep(i, array.size()){
            if(array[i] != p[i]) flagP = false;
            if(array[i] != q[i]) flagQ = false;
        }
        if(flagP) pnum = num;
        if(flagQ) qnum = num;
        // rep(i, n){
        //     cout << array[i];
        // }
        // cout << endl;
    }while(next_permutation(array.begin(), array.end()));

    cout << abs(pnum-qnum) << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

vv(v(f80)) dp;
f80 calc_dp(i64 i, i64 j, i64 k, i64 N){
  if(dp[i][j][k] != -1) return dp[i][j][k];
  f80 ret = f80(N)/(i+j+k);
  if(i>0) {
    ret += calc_dp(i-1,j,k,N) * i / (i+j+k);
  }
  if(j>0) {
    ret += calc_dp(i+1,j-1,k,N) * j / (i+j+k);
  }
  if(k>0) {
    ret += calc_dp(i,j+1,k-1,N) * k / (i+j+k);
  }
  dp[i][j][k] = ret;
  return ret;
}

void Main()
{
  i64 N;
  cin >> N;
  vi cnt(4,0);
  i64 a;
  rep(i,N){
    cin >> a;
    cnt[a]++;
  }

  dp.resize(N+1, vv(f80)(N+1, v(f80)(N+1, -1)));
  dp[0][0][0] = 0;

  cout << calc_dp(cnt[1],cnt[2],cnt[3],N) << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 431488
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, m;
vector<vector<i64>> g;

vector<bool> seen;
pair<i64, i64> dfs(i64 u) {
  if (seen[u]) return { 0, 0 };
  seen[u] = true;
  i64 cv = 1, ce = 0;
  for (i64 v : g[u]) {
    auto p = dfs(v);
    cv += p.first;
    ce += 1 + p.second;
  }
  return { cv, ce };
}

int main() {
  cin >> n >> m;
  init_n(g, n + 1);
  for (i64 i = 0; i < m; ++i) {
    i64 a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  init_n(seen, n + 1);

  auto p1 = dfs(1);
  auto p2 = dfs(2);

  if (p1.first < p2.first) swap(p1, p2);

  i64 v1 = n - p2.first, e1 = m - p2.second,
      v2 = p2.first, e2 = p2.second;

  i64 y = v1 * (v1 - 1) / 2 - e1
        + v2 * (v2 - 1) / 2 - e2;

  cout << y << '\n';
  return 0;
}



Measured memory_bytes: 10368
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {

	string s="";
	cin>>s;
	if(s[0]==s[1]&&s[2]==s[3] && s[0]!=s[2]){
		cout<<"Yes"<<endl;
	}else if(s[0]==s[2] &&s[1]==s[3] &&s[0]!=s[1]){
		cout<<"Yes"<<endl;
	}else if(s[0]==s[3]&&s[1]==s[2] && s[0]!=s[1]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


i64 n, q, k, x[101010], y[101010], kv[101010] = {0};
vector<P> v[101010];
bool used[101010] = {0};

void dfs(i64 now){
	used[now] = 1;
	for(int i = 0; i < v[now].size(); i++){
		i64 next = v[now][i].first, neval = v[now][i].second;
		if(used[next]) continue;
		kv[next] = kv[now] + neval;
		dfs(next);
	}
	return;
}

int main(){
	cin >> n;
	for(int i = 0; i < n-1; i++){
		int a,b,c; cin >> a >> b >> c;
		v[a].push_back(make_pair(b,c));
		v[b].push_back(make_pair(a,c));
	}
	cin >> q >> k;
	for(int i = 0; i < q; i++){cin >> x[i] >> y[i];}
	
	used[k] = 1;
	dfs(k);
	
	for(int i = 0; i < q; i++){
		cout << kv[x[i]] + kv[y[i]] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>
#include <functional>

typedef long long ll;
using namespace std;

ll m = pow(10, 9) + 7;

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

    ll sum = 0;
    for(int i = 0; i < n; i++){
        sum += a[i];
    }

    ll ans = 0;
    
    for(int i = 0; i < n; i++){
       sum -= a[i];
       ans = (ans + (a[i] * (sum % m)) % m) % m;
    }

    cout << ans << endl;
}

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

#define ll long long
#define mod 1000000007
#define pii pair<ll,ll>

#define debug(a) { cout << #a << " = " << a << endl;}

void sep() {
    cout << "-------------BLOCK-----------------\n";
}

template<typename T>
void debugv(vector<T> arr) {
    for (auto t: arr)
        cout << t << " ";
    cout << "\n";
}

template<typename T>
void debugarr(T arr, int n) {
    for (int i=0;i<n;i++) cout << arr[i] << " ";
    cout << "\n";
}

const int maxn = 1e5+1;
ll arr[maxn], n, m, t, k;
unordered_map<ll,ll> u;

ll __min(ll a, ll b) {
    return a < b ? a : b;
}

ll __max(ll a, ll b) {
    return a > b ? a : b;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    ll c=0;
    cin>>n;
    ll a,b;
    bool pos=false;
    for (int i=0;i<n;i++) {
        cin>>a>>b;
        if (a == b) c++;
        else c=0;
        if (c==3) pos=true;
    }
    if (pos) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 3648
n = gets.to_i

l =  [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

puts l[n-1]


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n,m;
int d[1001][10001];
int c[1001][1001];

int diff[3][1001];
ll ans = INF;

void dfs(int level, ll cnt, vector<int> v){
  if(level>=3){
    ans = min(ans,cnt);
    return;
  }
  FOR(i,1,m+1){
    ll tmp = 0;
    bool flag = false;
    REP(j,v.size()){
      if(i==v[j]) flag = true;
    }
    if(flag) continue;
    FOR(l,1,m+1) tmp += diff[level][l] * d[l][i];
    vector<int> k = v;
    k.push_back(i);
    dfs(level+1,cnt+tmp,k);
  }
}

int main(){
  cin >> n >> m;
  FOR(i,1,m+1){
    FOR(j,1,m+1){
      cin >> d[i][j];
    }
  }
  FOR(i,1,n+1)FOR(j,1,n+1) cin >> c[i][j];
  FOR(i,1,n+1){
    FOR(j,1,n+1){
      diff[(i+j)%3][c[i][j]]++;
    }
  }
  vector<int> tmp;
  dfs(0,0ll,tmp);
  cout << ans <<endl;
}


Measured memory_bytes: 6272
import bisect

N = int(input())
S = input()

index_map = {}
for i in range(10):
    index_map[str(i)] = []

for i, c in enumerate(S):
    index_map[c].append(i)

count = 0
for i in range(1000):
    K = "%03d" % i
    index = 0
    for c in K:
        next_index = bisect.bisect_left(index_map[c], index)
        if next_index == len(index_map[c]):
            index = -1
            break
        else:
            index = index_map[c][next_index] + 1
    if index != -1:
        count += 1
print(count)


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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

const int mod = 998244353;

int N;
int A[310];
int dp1[310][100000][1<<3];
int dp2[310][1<<3];
int S;

ll rec2(int pos, int mask){
    ll res = 0;
    if(dp2[pos][mask] >= 0) return dp2[pos][mask];
    if(pos == N){
        res = (mask == 7);
    }
    else{
        for(int i = 0; i < 3; i++){
            (res += rec2(pos + 1, mask | (1 << i))) %= mod;
        }
    }
    return dp2[pos][mask] = res;
}

ll rec1(int pos, int val, int mask){
    if(dp1[pos][val][mask] >= 0) return dp1[pos][val][mask];
    ll res = 0;
    if(pos == N){
        if(val * 2 >= S && mask == 7){
            res = 1;
        }
    }
    else{
        // X3に割当
        (res += rec1(pos + 1, A[pos] + val, mask | (1 << 2))) %= mod;
        // X1 or 2に割当
        (res += (rec1(pos + 1, val, mask | (1 << 0)))) %= mod;
        (res += (rec1(pos + 1, val, mask | (1 << 1)))) %= mod;
    }
    return dp1[pos][val][mask] = res;
}

int main(){

    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        S += A[i];
    }
    memset(dp1, -1, sizeof(dp1));
    memset(dp2, -1, sizeof(dp2));
    cout << (rec2(0, 0) - (3 * rec1(0, 0, 0)) % mod + mod) % mod << endl;

    return 0;
}


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

int main(){
	int N,W;
	vector<vector<int> > item;
	cin>>N>>W;
	item.resize(N+1);
	for(int i=0;i<=W;i++){
		item[0].push_back(0);
	}
	for(int i=1;i<=N;i++){
		int v,w;
		cin>>v>>w;
		for(int j=0;j<=W;j++){
			if(j>=w && (v+item[i-1][j-w])>item[i-1][j]){
				item[i].push_back(v+item[i-1][j-w]);
			}else{
				item[i].push_back(item[i-1][j]);
			}
		}
	}
	cout<<item[N][W]<<endl;
	
	
	return 0;
}

Measured memory_bytes: 5492
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	ll n;
	cin >> n;
	string t;
	rep(i, n) t += '-';
	ll m;
	cin >> m;
	rep(i, m){
		ll s;
		char c;
		cin >> s >> c;
		s--;
		if(t[s] == '-') t[s] = c;
		else if(t[s] != c){
			co(-1);
			return 0;
		}
	}

	if(n == 1){
		if(t[0] == '-') t[0] = '0';
		co(t);
		return 0;
	}

	if(t[0] == '0'){
		co(-1);
		return 0;
	}

	rep(i, n){
		if(t[i] == '-'){
			if(!i) t[i] = '1';
			else t[i] = '0';
		}
	}
	co(t);

	return 0;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

template<typename T> T mo(T x, T y) { x %= y; return x <= 0 ? x + y : x; }

const int MOD = 1000 * 1000 * 1000 + 7;

void ad(int& x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
}

int mul(int x, int y) {
    return (1ll * x * y) % MOD;
}

const int MX = 207;
const int MS = 100 * 1000 + 7;

int f[MX][MS];

int a[MX];

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int n, x;
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    reverse(a, a + n);
    f[0][x] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= x; j++) {
            if (j < a[i]) {
                ad(f[i + 1][j], mul(f[i][j], n - i));
            } else {
                ad(f[i + 1][j], mul(f[i][j], n - i - 1));
            }
            if (j >= a[i]) {
                ad(f[i + 1][j % a[i]], f[i][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i <= x; i++) {
        ad(ans, mul(i, f[n][i]));
    }

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



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

using ll=long long;

const ll MOD=1e9+7;
ll powm(ll a,ll b){
    ll res=1;
    while(b){
        if(b%2) res*=a;
        a*=a;
        a%=MOD;
        res%=MOD;
        b/=2;
    }
    return res;
}
int main(){
    int n,c;
    cin>>n>>c;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];

    vector<vector<ll>> dp(n+1,vector<ll>(c+1,0));
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        vector<ll> asum(c+1,0);
        for(int j=0;j<=c;j++){
            for(int k=a[i];k<=b[i];k++){
                asum[j]+=powm(k,j);
                asum[j]%=MOD;
            }
        }
        for(int j=0;j<=c;j++){
            for(int k=0;k<=j;k++){
                dp[i+1][j]+=dp[i][k]*asum[j-k];
                dp[i+1][j]%=MOD;
            }
        }
    }
    cout<<dp[n][c]<<endl;
    return 0;
}

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

using namespace std;

int n;
int A, B, C;
int D[100];
int main() {
    cin >> n;
    cin >> A >> B;
    cin >> C;
    for (int i = 0; i < n; i++) {
        cin >> D[i];
    }

    int ans = 0;
    
    // テ」ツδ暗」ツδε」ツδ氾」ツδウテ」ツつーテ」ツ?ョテ」ツつォテ」ツδュテ」ツδェテ」ツδシテ」ツ?ョテ・ツ青暗ィツィツ?
    int sum = 0;
    
    // テゥツ卍催ゥツ??10,9,8,...)テ」ツ?ォテ」ツつステ」ツδシテ」ツδ暗」ツ?凖」ツつ?
    sort(D, D + n);
    reverse(D, D + n);
    for (int i = 0; i < n; i++) {
    	sum+=D[i];
    	ans=max(ans,(sum+C)/(A+B*(i+1)));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3112
fs=require("fs");
l=fs.readFileSync("/dev/stdin","utf8").split("\n");
x=[];
for(i=0;i<6;i++){
  x.push(parseInt(l[i]));
}
if(x[4]-x[0]<=x[5]){
  console.log('Yay!');
}else{
  console.log(':(');
}

Measured memory_bytes: 7372
def gcd(a, b):
    if b>a:
        a,b = b,a
    if b==0:
        return a
    return gcd(b, a%b)

N = int(input())
ret = 1
for i in range(N):
    hoge = int(input())
    ret = (ret * hoge)//gcd(ret, hoge)
print(ret)


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

using namespace std;

typedef long long ll;

template<typename T> ostream& operator << (ostream& os, vector<T> v) {
  for (auto& i : v) os << i << " "; return os; 
}
template<typename T> istream& operator >> (istream& is, vector<T>& v) {
  for (auto& i : v) is >> i; return is;
}
template<typename T> inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template<typename T> inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

int dfs(vector<vector<int>>& G, vector<int>& dp, int v) {
  if (dp[v] != -1) {
    return dp[v];
  }
  int res = 0;
  for (auto& nv: G[v]) {
    chmax(res, dfs(G, dp, nv) + 1);
  }
  return dp[v] = res;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> G(n, vector<int>());
  for (int i=0; i<m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
  }
  vector<int> dp(n);
  for (int i=0; i<n; i++) {
    dp[i] = -1;
  }
  int res = 0;
  for (int i=0; i<n; i++) {
    chmax(res, dfs(G, dp, i));
  }
  cout << res;
  return 0;
}


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

int main(){
  int n,m;
  while(1){
    cin>>n>>m;
    if(n==0&&m==0)break;
    vector<int> h(n);
    vector<int> w(m);

    for(int i=0;i<n;i++)cin>>h[i];
    for(int i=0;i<m;i++)cin>>w[i];

    vector<int> hc(1500*1000+1,0);
    vector<int> wc(1500*1000+1,0);

    for(int i=1;i<=n;i++){
      int tmp=0;
      for(int j=0;j<i;j++)tmp+=h[j];
      hc[tmp]++;
      for(int j=0;j<n-i;j++){
        tmp+=h[j+i];
        tmp-=h[j];
        hc[tmp]++;
      }
    }

    for(int i=1;i<=m;i++){
      int tmp=0;
      for(int j=0;j<i;j++)tmp+=w[j];
      wc[tmp]++;
      for(int j=0;j<m-i;j++){
        tmp+=w[j+i];
        tmp-=w[j];
        wc[tmp]++;
      }
    }

    long long int ans=0;

    for(int i=0;i<1500*1000+1;i++){
      //if(i<8)cout<<hc[i]<<" "<<wc[i]<<endl;
      ans+=hc[i]*wc[i];
    }
    cout<<ans<<endl;

  }

  return 0;
}

Measured memory_bytes: 14456
n, k = map(int, input().split())
arr = []
for _ in range(n):
    a, b = map(int, input().split())
    arr.append((a, b))
arr = list(sorted(arr))
cnt = 0
i = 0
ans = arr[-1][0]
while cnt < k:
    ans = arr[i][0]
    cnt += arr[i][1]
    i += 1
print(ans)

Measured memory_bytes: 56792
def submit():
    n, k = (int(e) for e in input().split())
    a = [int(e) for e in input().split()]
    max_bit = 40
    bit_cnt = []
    
    b = 0
    bit = 1
    while b <= max_bit:
        cnt = sum(e & bit > 0 for e in a)
        bit_cnt.append(cnt)
        bit <<= 1
        b += 1

    isless = False
    curr_bit = 1 << max_bit
    ans = 0
    for i in range(max_bit + 1):
        # kの該当bitをみる
        k_bit = k & curr_bit > 0
        if not isless and k_bit == 0:
            # print("isless false and k = 0")
            # 0を選ぶしかない
            ans += bit_cnt[max_bit - i] * curr_bit
        elif not isless and k_bit == 1:
            # 0か1から選べる
            cnt1 = bit_cnt[max_bit - i]
            cnt0 = n - cnt1
            if cnt1 > cnt0:
                # print("isless false and k = 1, choice 0")
                # 0を選び、以下greedyにできる
                ans += cnt1 * curr_bit
                isless = True
            else:
                # print("isless false and k = 1, choice 1")
                ans += cnt0 * curr_bit
        else:
            # 0か1から選べる
            cnt1 = bit_cnt[max_bit - i]
            cnt0 = n - cnt1
            if cnt1 > cnt0:
                # print("isless true, choice 0")
                ans += cnt1 * curr_bit
            else:
                # print("isless true, choice 1")
                ans += cnt0 * curr_bit
        curr_bit >>= 1

    print(ans)


submit()
        


Measured memory_bytes: 14840
#include <iostream>
#include <algorithm>
using namespace std;
int v[100005];
int cm(int a,int b)
{
    int r;
    while(b)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int main()
{
    int n,k,c;
    cin>>n>>k;
    cin>>v[1];
    c=v[1];
    for(int i=2; i<=n; i++)
    {
        cin>>v[i];
        c=cm(c,v[i]);
    }
    sort(v+1,v+n+1);
    if(k>v[n])
    {
        cout<<"IMPOSSIBLE";
            return 0;
    }
    for(int i=n;v[i]>=k&&i>=1;i--)
    {
        if((v[i]-k)%c==0)
        {
            cout<<"POSSIBLE";
            return 0;
        }
    }
    cout<<"IMPOSSIBLE";
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
#define double long long
using namespace std;
signed main() {
	int N;
	cin >> N;
	int A=0;
	bool X = false;

	vector<int>L(N);
	for (int i = 0; i < N; i++) {
		cin >> L[i];
	}
	sort(L.begin(), L.end()); 
	reverse(L.begin(), L.end());
	for (int i = 1; i < N; i++) {
		A += L[i];
		if (L[0] < A) {
			X = true;
		}
	}
	if (X == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }



int main(){
    char N;
    int cnt=0;
    // cout << fixed << setprecision(5);
    for(int i=0;i<3;i++){
        scanf("%c",&N);
        if(N == '1') cnt++;
    }

    printf("%d\n",cnt);

    // Failed to predict input format
    return 0;
}



Measured memory_bytes: 256
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
const int MOD = 1000000007;

#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
#define s_exists(elem, s) s.find(elem)!=s.end()
#define mod_mul(x, y) x*y%MOD
#define mod_add(x, y) (x+y)%MOD
#define mod_sub(x, y) (x-y)%MOD
#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 10


long gcd(long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
}

long lcm( long m, long n ){
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}



int main(){
    int H,W; cin >> H >> W;
    int dp[10][10];
    REP(i,10){
        REP(j,10){
            cin >> dp[i][j];
        }
    }

    REP(k,10){
        REP(i,10){
            REP(j,10){
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
            }
        }
    }

    int ans = 0;
    REP(i,H*W){
        int a; cin >> a;
        if(a!= -1) ans += dp[a][1];
    }

    cout << ans << endl;





    return 0;

}


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

using namespace std;

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

	int n,t;
	vector <int> v;
	int res = 0;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		v.push_back(t);
	}

	int val = 1e9;

	for(int i=0;i<n;i++)
	{
		if(val > v[i])
		{
			res++;
			val = v[i];
		}
	}

	cout << res << '\n';

	return 0;
}

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

int main(){
    int N; cin >> N;
    while(1){
        bool flag = true;
        for(int i=2; i<N; i++){
            if(N % i == 0){
                flag = false;
                break;
            }
        }
        if(flag==true){
            cout << N << endl;
            return 0;
        }
        N++;
    }
}

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


void solve(string S){
    ll cnt0=0, cnt1=0;
    ll n = S.size();
    for(ll i=0; i< n; i++){
        if(S.at(i)=='0') cnt0++;
        else cnt1++;
    }
    cout << n - abs(cnt0-cnt1) << endl;
}

int main(){
    string S;
    cin >> S;
    solve(S);
    return 0;
}


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

int main()
{
	int N, K;
	cin >> N >> K;
	int count1 = 0, count2 = 0;
	int a = 1;
	for (int i = 1; i <= N; i++) {
		if (a + K <= a * 2) {
			a += K;
		}
		else {
			a *= 2;
		}
	}
	cout << a << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
constexpr int N_MAX=1e5;
// dp[i+1][j]
int dp[N_MAX+10][3] = {{0}};

int N, K, R, S, P;

int get_point(char c, int x, int prev=-1) {
  if (c=='r' && x == 2 && x != prev) {
    return P;
  } else if (c=='s' && x == 0 && x != prev) {
    return R;
  } else if (c=='p' && x != prev) {
    return S;
  }

  return 0;
}

int main(int argc, char** argv) {
  cin >> N >> K >> R >> S >> P;
  string T;
  cin >> T;

  vector<bool> banned(N);
  int ret = 0;
  REP(i, N) {
    char c = T[i];
    if (i>=K) {
      if (c == T[i-K] && !banned[i-K]) {
        banned[i] = true;
	continue;
      }
    }

    if (c == 'r') {
      ret += P;
    } else if (c == 's') {
      ret += R;
    } else {
      ret += S;
    }

//cerr << i << ": " << ret << endl;
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 512
mod = 10 ** 9 + 7
x, y = [int(i) for i in input().split()]
if (2*x - y) % 3 != 0 or (2*y - x) % 3 != 0:
  print(0)
  exit()
a = (2*x - y) // 3
b = (2*y - x) // 3
if a < 0 or b < 0:
  print(0)
  exit()
def mygcd(a_b, b, mod):
    b = min(a_b, b)
    cnt = 1
    for i in range(b):
        cnt = cnt * (a_b - i) * pow(i+1, mod-2, mod) % mod
    return cnt
print(mygcd(a+b, b, mod))

Measured memory_bytes: 9208
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
int N,M; // N:section M:budget
pair<int,int> buf[10010],PD[10010]; // P:prob. of raid D:distance
int solve();

int main() {
  while (cin >> N >> M && N) {
    int d,p;
    for (int i=0; i<N; ++i) {
      cin >> d >> p;
      buf[i] = make_pair(p,d);
    }
    sort(buf,buf+N);
    for (int i=N-1; i>=0; --i)
      PD[N-1-i] = make_pair(buf[i].first,buf[i].second);
    cout << solve() << endl;
  }
}

int solve() {
  int s = 0;
  for (int i=0; i<N; ++i)
    s += PD[i].first * PD[i].second;
  for (int i=0; i<N; ++i) {
    if (M<=0) break;
    int guarded = min(M,PD[i].second);
    s -= PD[i].first*guarded;
    M -= guarded;
  }
  return s;
}

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

int main() {
  int N, K, R, S, P;
  cin >> N >> K >> R >> S >> P;
  
  string T;
  cin >> T;
  
  int ans = 0;
  for (int i = 0; i < T.size(); i++) {
    if (i < K) {
      if (T[i] == 's') ans += R;
      if (T[i] == 'p') ans += S;
      if (T[i] == 'r') ans += P;
    } else {
      if (T[i - K] == T[i]) {
        T[i] = 'a';
      } else {
        if (T[i] == 's') ans += R;
        if (T[i] == 'p') ans += S;
        if (T[i] == 'r') ans += P;
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 512
n = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)
k = arr.min
min = arr.map{|i| (i - k)**2}.sum
while k <= arr.max
  if min > arr.map{|i| (i - k)**2}.sum
    min = arr.map{|i| (i - k)**2}.sum
  end
  k += 1
end
puts min

Measured memory_bytes: 14352
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;
import std.range;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() {
    auto xs = readints();
    int a = xs[0], b = xs[1], c = xs[2], d = xs[3];

    int start = max(a, c);
    int end = min(b, d);
    writeln(max(0, end - start));
}


Measured memory_bytes: 256
//AtCoder1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream> 
#include <algorithm>
#include <math.h> 
using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    if (A >= 9 || B >= 9) {
        cout << " :(" << endl;

    }
    else {
        cout << "Yay!" << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define rep(countName, left, right, up) for (ll countName = left; countName < right; countName += up)
#define rev(countName, right, left, down) for (ll countName = right - 1; countName >= left; countName -= down)

auto solve1(ll h, ll w)
{
    ll ans;

    if (h == 1 || w == 1)
    {
        ans = 1;
    }
    else
    {
        ans = (h * w + 1) / 2;
    }

    return ans;
}

int main(void)
{
    ll h, w;
    cin >> h >> w;

    cout << solve1(h, w) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    for(int i=n; i<=999; i++)
    {
        if(i%111 == 0)
        {
            printf("%d\n", i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define foreach(i,n) for(auto&i:(n))
#define all(x) (x).begin(),(x).end()
using ll = long long;

template<class t>
auto collect(int n,t f){
    vector<decltype(f())> res(n);
    for(auto &i:res){
        i = f();
    }
    return res;
}

template<class t,class f>
auto mapcar(t x,f func){
    int n = x.size();
    vector<typename t::value_type> res(n);
    auto itr = res.begin();
    for(auto &i:x){
        *itr = func(i);
        ++itr;
    }
    return res;
}
template<class t,class f>
void mapc(t x,f func){
    for(auto &i:x){
        func(i);
    }
}
template<class t,class u>
auto sellect(t x,u f){
    vector<typename t::value_type> res;
    for(auto &i:x){
        if(f(i)){
            res.push_back(i);
        }
    }
    return res;
}

ll in(){
    ll res;
    scanf("%lld",&res);
    return res;
}

int main(){
    ll n;
    ll k;
    n = in();
    k = in();
    vector<ll> health = collect(n,in);
    sort(all(health),greater<ll>());
    cout << accumulate(min(n,k)+all(health),0LL) << endl;
    return 0;
}

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

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

using namespace std;

int main(){
	int a[5];
	rep(i, 5)cin >> a[i];

	int ans = 0, mi = 10;
	rep(i, 5) {
		ans += (a[i] + 9) / 10 * 10;

		if (a[i] % 10 != 0)
			mi = min(mi, a[i] % 10);
	}

	ans -= 10 - mi;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

ans=0
for i in range(N):
  if x>=A[i]:
    x-=A[i]
    ans+=1
  else:
    break
  if i==N-1 and x>0:
    ans-=1
print(ans)

Measured memory_bytes: 3060
def calc(hand)
  i = hand.count(1)
  hand = hand - [1]
  point = 0
  while (a = hand.pop)
    point += case a
             when 2..9 then a
             else 10
             end
  end
  point1 = point2 = point + i
  point2 = point + 10 + i if i > 0
  if point2 <= 21
    point2
  elsif point1 <= 21
    point1
  else
    0
  end
end

until (n = $<.gets.chomp) == "0"
  puts calc(n.split.map(&:to_i))
end


Measured memory_bytes: 6880
import java.util.stream.IntStream;

public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int[] xa = new int[n], ya = new int[n], ha = new int[n];
        for (int i = 0; i < n; i++) {
            xa[i] = scanner.nextInt();
            ya[i] = scanner.nextInt();
            ha[i] = scanner.nextInt();
        }
        for (int x = 0; x <= 100; x++) {
            for (int y = 0; y <= 100; y++) {
                int x1 = x, y1 = y, h = IntStream.range(0, n).filter(k -> ha[k] != 0).reduce(0, (l, i) -> ha[i] + Math.abs(xa[i] - x1) + Math.abs(ya[i] - y1));
                if (IntStream.range(0, n).allMatch(k -> ha[k] == Math.max(h - Math.abs(xa[k] - x1) - Math.abs(ya[k] - y1), 0)))
                    System.out.printf("%s %s %s\n", x, y, h);
            }
        }
    }
}

Measured memory_bytes: 34972
#include<stdio.h>
 
#define MAX 100000
 struct Node{
   char c;
   int n;
 };

struct Node CardA[MAX],CardB[MAX];

void merge(struct Node A[],int n,int left,int mid ,int right){
  int i,j,k;
  int a1,a2;

  a1=mid-left;
  a2=right-mid;

  for(i=0;i<a1;i++){
    CardA[i]=A[left+i];
  }

  
  for(i=0;i<a2;i++){
    CardB[i]=A[mid+i];
  }


  CardA[a1].n=CardB[a2].n=10000;

  i=j=0;

  for(k=left;k<right;k++){
    if(CardA[i].n <= CardB[j].n){
      A[k]=CardA[i++];
    }
    else{A[k]=CardB[j++];}
  }

}


void mergesort(struct Node A[],int n,int left,int right){
  int mid;

  if(left+1 < right){
    mid=(left+right)/2;

    mergesort(A,n,left,mid);
    mergesort(A,n,mid,right);

    merge(A,n,left,mid,right);
  }

}

int Partition(struct Node A[],int n,int p,int r){

  int i,j;
  struct Node a,b;
  b=A[r];
  i=p-1;

  for(j=p;j<r;j++){
    if(A[j].n <= b.n){
      i++;
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }

  a=A[i+1];
  A[i+1]=A[r];
  A[r]=a;


  return i+1;
}


void quick(struct Node A[],int n,int p,int r){
  int n1;
  if(p<r){
    n1=Partition(A,n,p,r);
    quick(A,n,p,n1-1);
    quick(A,n,n1+1,r);
  }
}






int main(){

  int number;
  scanf("%d",&number);

  struct Node A[100000],B[100000];
  
  int i;
  for(i=0;i<number;i++){
    scanf(" %c%d",&A[i].c,&A[i].n);

    B[i].c=A[i].c;
    B[i].n=A[i].n;
    
    //printf("%c %d\n",B[i].c,B[i].n);
  }


  mergesort(A,number,0,number);//正確
  quick(B,number,0,number-1);//クイックそーと


  int stable=1;

  for(i=0;i<number;i++){
    if(A[i].c != B[i].c){stable=0;}//比較
  }


  if(stable ==1){printf("Stable\n");}

  else {printf("Not stable\n");}

  for(i=0;i<number;i++){
    printf("%c %d\n",B[i].c,B[i].n);
    
  }
  
  
  return 0;
}



Measured memory_bytes: 4056
import java.util.Scanner;
import java.util.HashMap;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		HashMap<String, String> H = new HashMap<String, String>();
		String h = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
		int n;
		while ((n = s.nextInt()) != 0) {
			for (int i = 0; i < h.length(); i++)
				H.put(h.substring(i, i+1), h.substring(i, i+1));
			for (int i = 0; i < n; i++)
				H.put(s.next(), s.next());

			int m = s.nextInt();
			for (int i = 0; i < m; i++) {
				System.out.print(H.get(s.next()));
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 0
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

x, y = [int(item) for item in input().split()]
if x in a and y in a:
    print("Yes")
    exit()
if x in b and y in b:
    print("Yes")
    exit()
if x in c and y in c:
    print("Yes")
    exit()
else:
    print("No")

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

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> vec (H);
	for(int i = 0;i < H;i++){
		cin >> vec.at(i);
	}
	
	int x = 0;
	int y = 0;
	while(x != W-1 || y != H-1){
		if(x == W-1){
			if(vec.at(y+1).at(x) == '.'){
				cout << "Impossible" << endl;
				return 0;
			}
			else{
				y++;
				continue;
			}
		}
		if(y == H-1){
			if(vec.at(y).at(x+1) == '.'){
				cout << "Impossible" << endl;
				return 0;
			}
			else{
				x++;
				continue;
			}
		}
		if(vec.at(y).at(x+1) == '#' && vec.at(y+1).at(x) == '#'){
			cout << "Impossible" << endl;
			return 0;
		}
		if(vec.at(y).at(x+1) == '#'){
			x++;
			if(x == W-1 && y != 0 && vec.at(y-1).at(x) == '#'){
				cout << "Impossible" << endl;
				return 0;
			}
			continue;
		}
		else{
			y++;
			if(y == H-1 && x != 0 && vec.at(y).at(x-1) == '#'){
				cout << "Impossible" << endl;
				return 0;
			}
			continue;
		}
	}
	if(vec.at(y-1).at(x) == '#' && vec.at(y).at(x-1) == '#'){
		cout << "Impossible" << endl;
	}
	else{
		cout << "Possible" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>

using namespace std;

vector<string> solve(long long n, long long k, long long q, vector<long long> a){
    vector<long long> player(n, 0);
    for(int i=0; i<q; ++i){
        player[a[i]-1]++;
    }

    vector<string> res(n, "Yes");
    for(int i=0; i<n; ++i){
        if(q-player[i]>=k) res[i] = "No";
    }

    return res;
}

int main(){
    long long N, K, Q; cin >> N >> K >> Q;
    vector<long long> A(Q); for(int i=0; i<Q; ++i) cin >> A[i];

    vector<string> res = solve(N, K, Q, A);

    for(int i=0; i<N; ++i){
        cout << res[i] << endl;
    }
    
}

Measured memory_bytes: 8064
import scala.io.StdIn.readLine

object Main extends App {
  val (x, y) = readLine.split(" ") match {
    case Array(x, y) => (x.toInt, y.toInt)
  }
  println(solve(x, y))

  def solve(x: Int, y: Int) = {
    if (x * y == 0) {
      if (x > y) x - y + 1
      else       y - x
    }
    else if ((x < 0) && (y > 0) || !(x < 0) && !(y > 0)) (x + y).abs + 1
    else {
      if (x > y) x - y + 2
      else       y - x
    }
  }
}


Measured memory_bytes: 21652
# -*- coding: utf-8 -*-

import sys
from collections import defaultdict
from bisect import bisect_right

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
T = input()
N = len(S)

d = defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i)
for k, v in d.items():
    d[k].append(INF)

cur = -1
ans = 0
for i, t in enumerate(T):
    if t not in d:
        print(-1)
        exit()
    idx = bisect_right(d[t], cur)
    if d[t][idx] == INF:
        ans += N
        cur = d[t][0]
    else:
        cur = d[t][idx]
ans += cur+1
print(ans)


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

string s, t;
int a, b;
string u;

int main(){

    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if(u == s){
        cout << a-1 << " " << b << endl;
    }
    else{
        cout << a << " " << b-1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
# Wrote in Mar 28, 2020 21:04 by reetok
require 'time'
require 'prime'
require 'bigdecimal'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=".to_i")
  t = []
  n.times do
    t.push(eval("gets.chomp#{datatype}"))
  end
  return t
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
class Integer
  def divisor_list
    devisors = [1]
    2.upto(self/2) do |i|
      devisors << i if self%i == 0
    end
    devisors << self
    return devisors.uniq.sort
  end
end
class Array
  def upper(a) #aより上
    self.sort.select{|n|n>=a}
  end
  def downer(a) #aより下
    self.sort.select{|n|n<=a}
  end
end
#---------------

a = gets.to_i

puts (a/500)*1000 + (a%500)/5*5

Measured memory_bytes: 4348
A11,A12,A13 = map(int,input().split())
A21,A22,A23 = map(int,input().split())
A31,A32,A33 = map(int,input().split())

Alist = []
Alist.append(A11)
Alist.append(A12)
Alist.append(A13)
Alist.append(A21)
Alist.append(A22)
Alist.append(A23)
Alist.append(A31)
Alist.append(A32)
Alist.append(A33)
bingolist =[0]*9

N = int(input())
#print (N)
for i in range(N):
  b = int(input())
  #print (b)
  for j in range(len(bingolist)):
    if b ==Alist[j]:
      bingolist[j] = 1

if sum(bingolist[0:3])==3 or sum(bingolist[3:6])==3 or sum(bingolist[6:9])==3 or (bingolist[0]+bingolist[3]+bingolist[6])==3 or (bingolist[1]+bingolist[4]+bingolist[7])==3 or (bingolist[2]+bingolist[5]+bingolist[8])==3 or (bingolist[0]+bingolist[4]+bingolist[8])==3 or (bingolist[2]+bingolist[4]+bingolist[6])==3:
  print ("Yes")
else :
  print ("No")
#print (bingolist[0:3])
#print (bingolist[3:6])
#print (bingolist[6:9])
#print (bingolist)

Measured memory_bytes: 9128