akhauriyash/Code-Regression huggingface dataset:
s = int(input())

def fn(n):

    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1
        
for i in range(1, 10**8):
    if i == 1:
        a = s
    else:
        a = fn(a)
    if a ==1 or a == 2 or a == 4:
        print(i+3)
        break

Measured memory_bytes: 9124
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")

#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)
//#define for(int i=0;i<n;i++) for(ll i=0;i<n;i++)
using namespace std;
//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//const ll to[5]={0,4,6,7,9};
//const ll N=2*1e5+1;
const ll R=1e4;
//const ll to[7]={1,2,3,1,3,2,1};
const ll tx[4]={0,0,-1,1};
const ll ty[4]={-1,1,0,0};
const char rev_to[4]={'E','W','N','S'};
const ll N=2*1e5+4;

signed main(){
    fast_io;
    ll n;
    cin>>n;
    ll cur=100;
    ll ans=0;
    while(cur<n){
        ans++;
        cur+=cur/100;
    }
    cout<<ans;
    return 0;
}
/*

    если WA , то чекер говно, поэтому почекай l8 строчку

*/


Measured memory_bytes: 3648
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<string>
#include<time.h>
#include<list>
#include<random>
#include<bitset>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;


int main() {
    int n, m;
    cin >> n >> m;
    deque<ll> a[32];
    for (int i = 0; i < n; ++i) {
        ll inp;
        cin >> inp;
        a[0].push_back(inp);
    }
    std::sort(a[0].begin(), a[0].end(), std::greater<ll>());
    for (int i = 0; i < m; ++i) {
        ll max = 0;
        int max_ind = 0;
        for (int j = 0; j < 32; ++j) {
            if (!a[j].empty() && a[j].front() > max) {
                max = a[j].front();
                max_ind = j;
            }
        }
        if (max == 0)break;
        a[max_ind + 1].push_back(a[max_ind].front() / 2);
        a[max_ind].pop_front();
    }
    ll sum = 0;
    for (int i = 0; i < 32; ++i) {
        for (ll x : a[i]) {
            sum += x;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1152
package main

import "fmt"

func main() {
	var N, Y int
	fmt.Scan(&N, &Y)

	for i := 0; i <= N; i++ {
		for j := 0; j <= N-i; j++ {
			k := N - j - i
			if 10000*i+5000*j+1000*k == Y {
				fmt.Println(i, j, k)
				return
			}
		}
	}
	fmt.Println(-1, -1, -1)
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n,vector<int>(m,l));
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>;
#define pint pair<int,int>;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")

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

	double a, b, h;
	cin >> a >> b >> h;
	cout << (a + b)*h / 2. << endl;
	

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    //今から文字入力
    int W;
    int H;
    int x;
    int y;
    int r;
    //W-rからrまでの間にxがいる必要がある
    //H-rからrまでの間にyがいる必要がある
    cin>>W>>H>>x>>y>>r;
    if(W-r>=x&&x>=r)
    {
        if(H-r>=y&&y>=r)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    else
    {
        cout<<"No"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3104
/**
 *    author:  tourist
 *    created: 21.09.2019 16:14:18       
**/
#include <bits/stdc++.h>

using namespace std;

class dsu {
 public:
  vector<int> p;
  int n;

  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }

  inline int get(int x) {
    return (x == p[x] ? x : (p[x] = get(p[x])));
  }

  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  long long m;
  cin >> n >> m >> q;
  vector<int> x(q), y(q), z(q);
  for (int i = 0; i < q; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  dsu d(n);
  int cnt1 = 0;
  int ncomp = n;
  for (int i = 0; i < q; i++) {
    if (z[i] == 0) {
      if (d.unite(x[i], y[i])) {
        ncomp--;
      }
    } else {
      ++cnt1;
    }
  }
  for (int i = 0; i < q; i++) {
    if (z[i] == 1 && d.get(x[i]) == d.get(y[i])) {
      cout << "No" << '\n';
      return 0;
    }
  }
  long long L = n;
  long long R = (long long) ncomp * (ncomp - 1) / 2 + (n - ncomp);
  if (cnt1 == 0) {
    --L;
  }
  if (L <= m && m <= R) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}


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

int main()
{
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }

  vector<int> B(N);
  for (int i = 0; i < N; i++)
  {
    cin >> B[i];
  }
  vector<int> C(N-1);
  for (int i = 0; i < N-1; i++)
  {
    cin >> C[i];
  }

  int ans = 0;
  for (int i = 0; i < N-1; i++)
  {
    int r = A[i]-1;
    int r1 = A[i + 1]-1;
    ans += B[r];
    if (r - r1 == -1)ans += C[r];
  }
  int r = A[N - 1]-1;
  ans += B[r];

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORr(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORr(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

int keta(int n){
  int ret = 0;
  while(n != 0) {
    n /= 10;
    ret++;
  }
  return ret;
}

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

  int ans = 0;
  FOR(i, 1, n+1){
    if(keta(i) % 2) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	int n;

	scanf("%d\n", &n);
	loop(i, 0, n)
	{
		string line;
		std::getline(cin, line);
		int pos = 0;

		while( (pos = line.find("Hoshino", pos)) != string::npos )
		{
			line.replace(pos, 7, "Hoshina");
		}
		cout << line << endl;
	}
	return (0);
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
map<int,int> seen;
int n;
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		int x;
		scanf("%d",&x);
		if(!seen.count(x))seen[x]=1;
		else
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 9600
#include<iostream>
 using namespace std;
 int main() {
 int a, b, c, k;
 cin >> a >> b >> c >> k;
 if(k <= a) cout << k << endl;
 else if(k <= a + b) cout << a << endl;
 else cout << a-(k-a-b) << endl;
 return 0;
 }


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int main(){
    while(true){
        int h,w;
        cin >> h >> w;
        if(h == 0 && w == 0)break;
        
        rep(i,h){
            rep(j,w){
                if((i == 0 || i == h - 1)||(j == 0 || j == w -1)){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;

    }
}


Measured memory_bytes: 3112
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    vector<int> card(n);
    int a = 0;
    int b = 0;
    rep(i, n) {
      cin >> card[i];
    }
    sort(card.begin(), card.end(), greater<int>());
    rep(i, n) {
      if (!(i % 2)) {
        a += card[i];
      } else {
        b += card[i];
      }
    }

    cout << a - b << '\n';

    return 0;
}


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

int main(){
    string S,T;
    cin>>S;
    cin>>T;
    T=T.erase(S.size());
    //cout<<T<<endl;
    if(S==T) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3600
X = int(input())

if 400 <= X <= 599:
    print(8)
elif 600 <= X <= 799:
    print(7)
elif 800 <= X <= 999:
    print(6)
elif 1000 <= X <= 1199:
    print(5)
elif 1200 <= X <= 1399:
    print(4)
elif 1400 <= X <= 1599:
    print(3)
elif 1600 <= X <= 1799:
    print(2)
elif 1800 <= X <= 1999:
    print(1)

Measured memory_bytes: 61912
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

//蟻本，螺旋本参考
//DisjointSet
//整数配列に対応
class UnionFindTree {
public:
    vector<int> rank, p;
    vector<int> memnum;

    UnionFindTree() {}

    UnionFindTree(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        memnum.resize(size, 0);
        for (int i = 0; i < size; ++i) {
            makeSet(i);
        }
    }

    void makeSet(int x)
    {
        p[x] = x;
        rank[x] = 0;
        memnum[x] = 1;
    }

    bool same(int x, int y)
    {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y)
    {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y)
    {
        if (rank[x] > rank[y]) {
            memnum[x] += memnum[p[y]];
            p[y] = x;
        } else {
            memnum[y] += memnum[p[x]];
            p[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }

    int findSet(int x)
    {
        if (x != p[x]) {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }

    int maxUnion()
    {
        int size = p.size();
        int r = 0;
        REP(i,size) {
            r = max(r, (int)count(p.begin(), p.end(), i));
        }
        return r;
    }
};

vector<pair<int, int>> brg;
vector<ll> inconvinience;

int main()
{
    int n, m;
    cin>>n>>m;
    REP(i,m) {
        int a, b;
        cin>>a>>b;
        brg.push_back({a-1, b-1});
    }
    ll icv;
    icv = (ll)n * (n - 1) / 2ll;
    UnionFindTree uf(n);
    RREP(i,m) {
        inconvinience.push_back(icv);

        int x = brg[i].first, y = brg[i].second;
        if (uf.same(x,y) || i == 0)
            continue;

        icv -= (ll)(uf.memnum[uf.findSet(x)]) * (uf.memnum[uf.findSet(y)]);
        uf.unite(x,y);
    }

    RREP(i,m) {
        cout<<inconvinience[i]<<endl;
    }

    return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2020;

int A[MAX];
int B[MAX];

int S[MAX];
int L[MAX];
int R[MAX];

int MX[MAX];
int n;

int getOnes(int l, int r)
{
	if (l > r) return getOnes(0, r) + getOnes(l, n-1);

	int res = S[r];
	if (l) res -= S[l-1];
	return res;
}


int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	string s;
	cin>>s;
	bool aa = false, bb = false;
	FOR (i, 0, SZ(s))
	{
		A[i] = s[i] - '0';
		aa |= A[i];
	}

	cin>>s;
	FOR (i, 0, SZ(s))
	{
		B[i] = s[i] - '0';
		bb |= B[i];
	}

	if (!bb)
	{
		if (!aa) cout<<0<<endl;
		else cout<<-1<<endl;
		return 0;
	}

	int res = INF;

	n = SZ(s);

	FOR (it, 0, 2)
	{
		FOR (i, 0, n)
		{
			S[i] = B[i];
			if (i) S[i] += S[i-1];
		}

		int ind = -1;

		FOR (i, 0, n)
		{
			if (B[i]) ind = i;
		}

		FOR (i, 0, n)
		{
			if (B[i]) ind = i;
			L[i] = ind;
		}

		RFOR(i, n, 0)
		{
			if (B[i]) ind = i;
		}

		RFOR(i, n, 0)
		{
			if (B[i]) ind = i;
			R[i] = ind;
		}


		FOR (sh, 0, n + 1)
		{
			int cur = sh;

			vector<PII> a;

			FOR (i, 0, n)
			{
				int x = i;
				int y = i + sh;
				while (y >= n) y -= n;

				if (A[x] == B[y]) continue;
				cur++;

				int cnt = getOnes(x, y);
				if (cnt == 0)
				{
					int left = i - L[i];
					if (left < 0) left += n;

					int right = R[y] - y;
					if (right < 0) right += n;

					a.PB(MP(left, right));
				}
			}
			sort(ALL(a));

			MX[SZ(a)] = 0;

			RFOR(i, SZ(a), 0)
			{
				MX[i] = a[i].second;
				MX[i] = max(MX[i], MX[i+1]);
			}

			int add = MX[0];
			FOR (i, 0, SZ(a))
			{
				add = min(add, a[i].first + MX[i+1]);
			}

			cur += add * 2;
			res = min(res, cur);

		}

		reverse(A, A+n);
		reverse(B, B+n);
	}

	cout<<res<<endl;

}


Measured memory_bytes: 384
from collections import defaultdict
s = input()
n = len(s)
p = 2019
sur1 = [int(s[0]) % p]
sur2 = [int(s[-1]) % p]
sur10 = [1 % p]
for i in range(n - 1):
    sur1 += [(sur1[i] * 10 + int(s[i + 1])) % p]
    sur10 += [(sur10[i] * 10) % p]
    sur2 += [(sur2[i] + sur10[i + 1] * int(s[-i - 2])) % p]

ans = 0
d = defaultdict(int)
for x in sur2:
    d[x] += 1

for k, v in d.items():
    if k == 0:
        ans += v * (v + 1) // 2
    else:
        ans += v * (v - 1) // 2
print(ans)

Measured memory_bytes: 30968
#include <stdio.h>

int main(void) {
  int n, x, i, j, k, a = 0, count[100] = {0};
  while (1) {
    scanf("%d %d", &n, &x);

    if (n == 0 && x == 0) {
      break;
    }

    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        for (k = 1; k <= n; k++) {
          if (i + j + k == x && i < j && j < k) {
            count[a]++;
          }
        }
      }
    }
    a++;
  }

  for (i = 0; i < a; i++) {
    printf("%d\n", count[i]);
  }

  return 0;
}



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

int main() {
  string s;
  int res = 0;
  int cur = 0;
  cin >> s;

  for (int i = 0; i < 3; i++) {
    if (s[i] == 'R') {
      cur = cur + 1;
    } else {
      if (res < cur) {
        res = cur;
      }
      cur = 0;
    }
  }
  if (res < cur) {
    res = cur;
  }
  cout << res << endl;
  
}

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

int main() {
	string S, T;
	cin >> S >> T;
	int res = T.size();
	for (int start = 0; start <= S.size() - T.size(); start ++) {
	    int diff = 0;
	    for (int i = 0; i < T.size(); i++) {
	        if (T[i] != S[start + i]) {
	            diff++;
	        }
	    }
	    res = min(res, diff);
	}
	cout << res << endl;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=100000+5;
ll a[maxn];
ll n;
map<ll ,ll > vis;
priority_queue<ll > pq;
int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++) {scanf("%lld",&a[i]);vis[a[i]]++;}
	for(map<ll ,ll >::iterator ite=vis.begin();ite!=vis.end();ite++)
	{
		if(ite->second>=2) pq.push(ite->first);
		if(ite->second>=4) pq.push(ite->first);
	}
	if(pq.size()<2) printf("0\n");
	else{
		ll A=pq.top();pq.pop();
		ll B=pq.top();pq.pop();
		printf("%lld\n",(ll)A*B);
	}
	return 0;
}


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

int main(void){
  int SheetsNum;
  int card[4][13]; // スペード、ハート、ダイヤ、クラブ
  //初期化
  //すべての値に0を代入
  for (int a=0; a<4; a++) {
    for (int b=0; b<13; b++) {
      card[a][b] = 0;
    }
  }
  //初期化終了
  //カードの枚数
  cin >> SheetsNum;
  //入力されるやつ
  char CardType;
  int CardNum;
  //入力開始
  for (int c=0; c<SheetsNum; c++) {
    cin >> CardType >> CardNum;
    if (CardType=='S') {
      card[0][CardNum-1] = 1;
    } else if (CardType=='H') {
      card[1][CardNum-1] = 1;
    } else if (CardType=='C') {
      card[2][CardNum-1] = 1;
    } else if (CardType=='D') {
      card[3][CardNum-1] = 1;
    }
  }
  //入力完了
  //cout << endl << endl;
  for (int e=0; e<4; e++) {
    for (int f=0; f<13; f++) {
      if (card[e][f]==0) {
        if (e==0) {
          cout << 'S';
        } else if (e==1) {
          cout << 'H';
        } else if (e==2) {
          cout << 'C';
        } else if (e==3) {
          cout << 'D';
        }
        cout << " " << f+1 << endl;
      }
    }
  }
}



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

using namespace std;

int main() {
  int n; cin >> n;
  int a[100000], p = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > 0) ++p;
  }
  
  sort(a, a+n);
  
  if (p == 0) ++p;
  if (p == n) --p;
  
  int m = 0;
  for (int i = 0; i < n-p; ++i) m -= a[i];
  for (int i = n-p; i < n; ++i) m += a[i];
  
  cout << m << endl;
  
  int sm1 = a[n-1];
  for (int i = 1; i < n-p; ++i) {
    cout << sm1 << " " << a[i] << endl;
    sm1 -= a[i];
  }
  
  int sm2 = a[0];
  for (int i = n-p; i < n-1; ++i) {
    cout << sm2 << " " << a[i] << endl;
    sm2 -= a[i];
  }
  
  cout << sm1 << " " << sm2 << endl;
  return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>

int main(void){
    int h,w,i;
    char s[100];
    char a[102][102];
    scanf("%d %d",&h,&w);
    for(i=0;i<=w+1;i++)printf("#");
    printf("\n");
    for(i=0;i<h;i++){
        scanf("%s",s);
        printf("#%s#\n",s);
    }
    for(i=0;i<=w+1;i++)printf("#");
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
int main()
{
    int a,b,n;
    char op;
    for(;;){
    scanf("%d %c %d",&a,&op,&b);
    if(op == '+'){
        printf("%d\n",a+b);
    }
    else if(op == '-'){
        printf("%d\n",a-b);
    }
    else if(op == '*'){
        printf("%d\n",a * b);
    }
    else if(op == '/'){
        printf("%d\n",a / b);
    }
    else break;

    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;

llint N, X;
llint x[200005];
llint sum[200005];

int main(void)
{
	cin >> N >> X;
	for(int i = 1; i <= N; i++) cin >> x[i];
	sort(x+1, x+N+1);
	reverse(x+1, x+N+1);
	
	for(int i = 1; i <= N; i++) sum[i] = sum[i-1] + x[i];
	
	llint ans = inf, tmp;
	for(llint i = 1; i <= N; i++){
		tmp = i * X;
		llint c = 3;
		for(llint j = 1; j <= N; j += i){
			tmp += (sum[min(N, j+i-1)] - sum[j-1]) * max(5LL, c);
			if(tmp > inf) break;
			c += 2;
		}
		ans = min(ans, tmp);
	}
	ans += N * X;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3328
N = int(input())

answer = 0
for i in range(N):
    x_cand, u_cand = input().split()

    x_cand = float(x_cand)
    u_cand = str(u_cand)

    if u_cand == "JPY":
        answer += x_cand
    elif u_cand == "BTC":
        answer += x_cand * 380000.0

print(answer)

Measured memory_bytes: 2940
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val MOD = 1e9.toInt + 7

  val N, K = in.next().toInt
  val tree = Array.fill[List[Int]](N+1)(Nil)
  for (i <- 1 to N-1) {
    val a, b = in.next().toInt
    tree(a) = b :: tree(a)
    tree(b) = a :: tree(b)
  }

  //
  val dp = new Array[Boolean](N+1)

  val q = new Queue[Int]()
  q.enqueue(1)
  dp(1) = true

  var ans: Long = K
  var hoge = K-1
  while (!q.isEmpty) {
    val now = q.dequeue()

    for (e <- tree(now) if !dp(e)) {
      dp(e) = true
      ans *= Math.max(hoge, 0)
      ans %= MOD

      q.enqueue(e)
      hoge -= 1
    }

    hoge = K-2
  }

  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 58608
### main

cnum = 1

loop do
  n = gets.strip.to_i
  break if n == 0

  mtx = n.times.map{[]}

  maxsum = (n - 1) * 2
  id = 1
  prt = 0

  for sum in (0..maxsum)
    if prt == 0
      x = [sum - (n - 1), 0].max
      y = sum - x
      while x < n && y >= 0
        mtx[y][x] = id
        id += 1
        x += 1
        y -= 1
      end
    else
      y = [sum - (n - 1), 0].max
      x = sum - y
      while y < n && x >= 0
        mtx[y][x] = id
        id += 1
        y += 1
        x -= 1
      end
    end

    prt = 1 - prt
  end
  #p mtx

  puts "Case #{cnum}:"

  for hl in mtx
    puts hl.map{|id| sprintf("%3d", id)}.join('')
  end

  cnum += 1
end

Measured memory_bytes: 6140
# -*- coding: utf-8 -*-
import math

#入力
#S = str(input())
#a, b = map(int, input().split())
#N = int(input())

S1 = str(input())
S2 = str(input())
S3 = str(input())

print (S1[0] + S2[1] + S3[2])

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

int main() {
	int W, H;
	cin >> W >> H;

	char c;
	cin >> c;

	for ( int i = 0; i < H; i++ ) {
		for ( int j = 0; j < W; j++ ) {
			if ( (!i || i == H-1) && (!j || j == W-1) ) cout << '+';
			else if ( !i || i == H-1 ) cout << '-';
			else if ( !j || j == W-1 ) cout << '|';
			else if ( j == W/2 && i == H/2 ) cout << c;
			else cout << '.';
		}
		cout << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3088
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	bw = bufio.NewWriter(os.Stdout)
)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100100), 100100)
}

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func rs() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, q := ri(), ri()
	s := rs()

	ac := make([]int, n)
	for i := 0; i < n-1; i++ {
		if s[i] == 'A' && s[i+1] == 'C' {
			ac[i]++
			i++
		}
	}

	cumSum := make([]int, n+1)
	sum := 0
	for i := 1; i <= len(cumSum)-1; i++ {
		sum += ac[i-1]
		cumSum[i] = sum
	}
	// fmt.Println(cumSum)

	for i := 0; i < q; i++ {
		l, r := ri(), ri()
		fmt.Println(cumSum[r-1] - cumSum[l-1])
	}
}


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

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

    if (n<=k){
        printf("%d",n*x);
    }else if (n>=k){
    d=n-k;
    printf("%d",(k*x)+d*y);
    }

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
using namespace std;
int main(){
    unsigned int N;
    cin >> N;
    string u[N];
    double x[N];
    double otoshi = 0.0;
    for(int i = 0; i < N; i++){
        cin >> x[i] >> u[i];
        if(u[i] == "BTC"){
            x[i] *= 380000.0;
        }
        otoshi += x[i];
    }
    cout << otoshi << endl;
}

Measured memory_bytes: 256
#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=(int)(s);i<(int)(n);i++)
typedef long long ll;
const int INF = 1e+9+7;
const int H_MAX = 510;
const int W_MAX = 510;
int H,W;
vector<vector<int>> a(H_MAX,vector<int>(W_MAX,0));

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int tmp;
    rep(i,n){
        cin>>a[i];
    }

    sort(a.begin(),a.end());

    int a1,a2,a_cur;
    double ans=0;

    a1=a[n-1];
    if(a1%2==0){
        int num = lower_bound(a.begin(),a.end()-1,a1/2) - a.begin();
        
        if(num==0||a[num]- (a1/2)< a1/2 - a[num-1]){
            a2=a[num];
        }else{
            a2=a[num-1];
        }
    }else{
        int num = lower_bound(a.begin(),a.end()-1,(a1-1)/2) - a.begin();
        if(num==0||min(abs(a[num]-(a1-1)/2),abs(a[num]-(a1+1)/2))<min(abs(a[num-1]-(a1-1)/2),abs(a[num-1]-(a1+1)/2))){
            a2=a[num];
        }else{
            a2=a[num-1];
        }
    }

    cout << a1 << " " << a2 << endl;

}


Measured memory_bytes: 1792
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *TA = map(int, read().split())

    x, y = 1, 1

    for t, a in zip(*[iter(TA)] * 2):
        m1 = (x + t - 1) // t
        m2 = (y + a - 1) // a
        m = max(m1, m2)
        x, y = t * m, a * m

    print(x + y)
    return


if __name__ == '__main__':
    main()


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

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

vector<int> g[200];
int d[200][200];
int col[200];

bool check(int n, int c) {
    if (col[n] == 0) {
        col[n] = c;
    } else {
        return (col[n] == c);
    }
    int nc = 3 - c; //! flip between 1 and 2
    for (int next: g[n]) {
        if (!check(next, nc)) {
            return false;
        }
    }
    return true;
}

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

    rep(i, N) {
        string s;
        cin >> s;
        rep(j, N) {
            if (s[j] == '1') {
                g[i].push_back(j);
                d[i][j] = 1;
            } else {
                d[i][j] = (i == j) ? 0 : 1000;
            }
        }
    }

    LL ans = -1;
    if (check(0, 1)) {
        rep(k, N) rep(i, N) rep(j, N) {
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
        int diameter = 0;
        rep(i, N) rep(j, N) {
            diameter = max(diameter, d[i][j]);
        }
        ans = diameter + 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll M=3e6;
const ll mod=998244353;
ll fac[M],finv[M],inv[M];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    rep(2,i,M){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll mpow(ll x,ll n) {
  ll ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main(void){
    ll n,m,k;
    cin>>n>>m>>k;
    cominit();
    ll ans=0;
    rep(0,i,k+1){
        ans=(ans+(comb(n-1,n-1-k+i))*(m)%mod*mpow(m-1,n-1-k+i)%mod)%mod;
    }
    cout<<ans;
    
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (a <= c && d <= b) {
    cout << d - c << "\n";
    return 0;
  } else if (c <= a && b <= d) {
    cout << b - a << "\n";
    return 0;
  } else if (a <= c && c <= b && b <= d) {
    cout << b - c << "\n";
    return 0;
  } else if (c <= a && a <= d && d <= b) {
    cout << d - a << "\n";
    return 0;
  } else {
    cout << 0 << "\n";
    return 0;
  }
}

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

int main() {
  long long int n,k,i,h,y;
    cin >> n;
    y=1000000000000;
  
   for(i=1;i*i<=n;i++)
     {
        if((n%i)==0)
            {
                k=n/i;
           y=min(y,k+i);
            }
              
     }
    
     h=y-2;
     cout << h;
     
     
     
        return 0;
        
}

Measured memory_bytes: 3612
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

using ll = long long;

ll m, n, k;

#define Input(x) scanf("%lld",&(x))

struct coord
{
	ll x, y;
};
vector<coord>button;
struct edge
{
	ll to, cost;
};
vector<edge>graph[456789];
ll dist[456789];
void addedge(int a,int b,int cost)
{
	graph[a].push_back({ b,cost });
	graph[b].push_back({ a,cost });
}
void dijkstra(int start)
{
	using P = pair<ll, int>;
	priority_queue<P, vector<P>, greater<P>>que;//first:dist second:vertnum
	que.push({ 0,start });
	fill(dist, dist + 456789, 12345678901234567);
	dist[start] = 0;
	while (!que.empty())
	{
		P nowp = que.top(); que.pop();
		if (nowp.first > dist[nowp.second])continue;
		for (edge e : graph[nowp.second])
		{
			if (dist[e.to] > nowp.first + e.cost)
			{
				dist[e.to] = nowp.first + e.cost;
				que.push({ dist[e.to],e.to });
			}
		}
	}
}


map<ll, int>dict;
vector < ll > idlist;
ll trans(coord c)
{
	return c.x * 100000 + c.y;
}
void push_button(coord c)
{
	ll id = trans(c);
	dict.insert({id,idlist.size()});
	idlist.push_back(id);
}

int main(void)
{
	Input(m);
	Input(n);
	Input(k);
	bool startbut = false;
	for (int i = 0; i < k; ++i)
	{
		coord tmp;
		Input(tmp.x);
		Input(tmp.y);
		button.push_back(tmp);
		if (tmp.x == 1 && tmp.y == 1)startbut = true;
		push_button(tmp);
		int v = dict[trans(tmp)] * 2;
		addedge(v, v + 1, 1);
	}
	if (!startbut)
	{
		button.push_back({ 1,1 });
		push_button({ 1,1 });
	}
	sort(button.begin(), button.end(), [](const coord&c1, const coord&c2) {return (c1.x == c2.x) ? (c1.y < c2.y) : (c1.x < c2.x); });
	if (button.back().x != m || button.back().y != n)
	{
		button.push_back({ m,n });
		push_button({ m,n });
	}
	for (int i = 0; i < button.size() - 1; ++i)
	{
		if (button[i].x == button[i + 1].x)
		{
			addedge(dict[trans(button[i])] * 2, dict[trans(button[i + 1])] * 2, button[i + 1].y - button[i].y);
		}
	}
	sort(button.begin(), button.end(), [](const coord&c1, const coord&c2) {return (c1.y == c2.y) ? (c1.x < c2.x) : (c1.y < c2.y); });
	for (int i = 0; i < button.size() - 1; ++i)
	{
		if (button[i].y == button[i + 1].y)
		{
			addedge(dict[trans(button[i])] * 2 + 1, dict[trans(button[i + 1])] * 2 + 1, button[i + 1].x - button[i].x);
		}
	}
	dijkstra(dict[trans({ 1,1 })] * 2);
	ll answer = min(dist[dict[trans({ m,n })] * 2], dist[dict[trans({ m,n })] * 2 + 1]);
	if (answer >= 12345678901234567)return 0 * printf("-1\n");
	printf("%lld\n", answer);
	return 0;
}

Measured memory_bytes: 77984
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p=-1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}
 
int main() {
  int n, q;
  cin >> n >> q;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i,q) {
    int p, x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  rep(i,n) {
    cout << ans[i] << endl;
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int n, ans, def1=0, tmp;
	vector<int> v, d1, d2, d3, sc, cnt;
	char iv;
	LLi ds1=0, ds3=0;

	cin>> n;
	v.resize(n);
	d1.resize(n);
	//d2.resize(n);
	d3.resize(n);
	sc.resize(n);
	cnt.resize(n);
	
	rep(i, n){
		cin >> iv;
		v[i]=(int)(iv-'0');
		if(v[i]==1) def1++;
	}
	reverse(v.begin(), v.end());

	if(def1>0){
		tmp=1;
		for(int i=0;i<n;i++){
			if(def1==1) break;
			tmp=tmp%(def1-1);
			d1[i]=tmp;
			if(v[i]==1){
				ds1+=tmp;
				ds1=ds1%(def1-1);
			}
			tmp*=2;
			//cout<< d1[i] <<endl;
		}
	}else{
		rep(i, n) cout<< 1 <<endl;
		return 0;
	}

	tmp=1;
	for(int i=0;i<n;i++){
		tmp=tmp%(def1+1);
		d3[i]=tmp;
		if(v[i]==1){
			ds3+=tmp;
			ds3=ds3%(def1+1);
		}
		tmp*=2;
		//cout<< d3[i] <<endl;
	}
	//cout<< ds1 <<endl;
	//cout<< ds3 <<endl;

	rep(i, n){
		if(def1==1 && v[i]==1){
			cnt[i]=-1;
			continue;
		}
		if(v[i]==1){
			//cout<< "in1" <<endl;//
			sc[i]=ds1-d1[i]+def1-1;
			sc[i]=sc[i]%(def1-1);
		}else{
			//cout<< "in0" <<endl;//
			sc[i]=ds3+d3[i];
			sc[i]=sc[i]%(def1+1);
		}
	}

	//rep(i, n) cout<< sc[i] <<endl;

	rep(i, n){
		if(cnt[i]==-1){
			cnt[i]=0;
			continue;
		}
		ans=1;
		while(sc[i]!=0){
			int mod=__builtin_popcount(sc[i]);
			//cout<< sc[i] << "#" << mod << endl;
			sc[i]=sc[i]%mod;
			ans++;
		}
		cnt[i]=ans;
	}

	reverse(cnt.begin(), cnt.end());
	rep(i, n) cout<< cnt[i] <<endl;
 
	return 0;
}


Measured memory_bytes: 7200
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
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;}

ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
//////////////////////////////////////
bool ch(int n){
    vi tmp(5);
    rep(i,5){
        tmp[i]=n%10;
        n/=10;
    }
    return (tmp[0]==tmp[4]&&tmp[1]==tmp[3]);
}
int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    arep(i,a,b+1){
        if(ch(i))ans++;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-3;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int dp[1 << 17];
int c[1 << 17];
vector<int> G[1 << 17],rG[1<<17];
queue<int> q;
int n, m;
int main() {
	cin >> n >> m;
	rep(i, m) {
		int x, y; cin >> x >> y; x--; y--;
		G[x].push_back(y);
		rG[y].push_back(x);
		c[x]++;
	}
	rep(i, n) {
		if (c[i] == 0)q.push(i);
	}
	while (!q.empty()) {
		int x = q.front(); q.pop();
		rep(j, rG[x].size()) {
			int to = rG[x][j];
			dp[to] = max(dp[to], dp[x] + 1);
			c[to]--; if (c[to] == 0)q.push(to);
		}
	}
	int ans = 0;
	rep(i, n) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	//stop
	return 0;
}

Measured memory_bytes: 13440
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,k;
  cin>>n>>k;
  vi a(n);
  rep(i,n)cin>>a[i];
  int m=0;
  rep(i,n)m=max(m,a[i]);
  if(m<k){
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
  }
  int g=a[0];
  rep(i,n)g=__gcd(g,a[i]);
  if(k%g==0)
    cout<<"POSSIBLE"<<endl;
  else
    cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = n; i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;

int p[11];
int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> s(n);
	rep(i,m) {
		int k; cin >> k;
		rep(j,k) {
			int ss; cin >> ss;
			s[ss-1].push_back(i);
		}
	}
	int ans = 0;
	rep(i,m) cin >> p[i];
	rep(t, 1<<n) {
		vector<int> light(10,0);
		rep(i,n) {
			if (t>>i & 1) {for (int v: s[i]) light[v]++;}
		}
		bool can = true;
		rep(i,m) if (light[i]%2 != p[i]) {can = false; break;}
		if (can) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.nextLine());
		String b = sc.nextLine();
		String[] c = b.split(" ");
		int i = 0;
		int j = 1;
		for(String d:c) {
			if(Integer.parseInt(d)==j) {
				j++;
				continue;
			}
			i++;
		}
		if(i==c.length) {i=-1;}
		System.out.println(i);
	}
}


Measured memory_bytes: 57208
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
A = []
for i in range(M-1):
  A.append(X[i+1] - X[i])
A.sort()
if N >= M:
  print(0)
else:
  print(sum(A[i] for i in range(M - N)))

Measured memory_bytes: 13968
#include <cstdio>
const int mod = 1000000007;
int dp[110][3310], c[110][3310];
inline void add(int &v, int x) {
	v += x;
	if (v >= mod) v -= mod;
}
int re[110];
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	c[n][0] = 1;
	re[0] = 1;
	for (int i = 1; i <= n; i++) {
		re[i] = (long long)re[i-1] * (k + 1) % mod;
	}
	int ans = 0;
	for (int i = n; i >= 1; i--) {
		for (int j = 0; j < 3310; j++) {
			for (int l = 0; l <= i; l++) {
				if (l > k) break;
				int f = (l + j) / i;
				int r = l + j - f * i;
				if (j + f < 3310) {
					add(dp[i-1][j+f], dp[i][j]);
					add(dp[i-1][j+f], (int)((long long)r * c[i][j] % mod));
					add(c[i-1][j+f], c[i][j]);
				}
			}
			for (int l = i + 1; l <= k; l++) {
				add(dp[i-1][j], dp[i][j]);
				add(dp[i-1][j], (int)((long long)(l + j) * c[i][j] % mod));
				add(c[i-1][j], c[i][j]);
			}
		}
	}
	for (int j = 0; j < 3310; j++) {
		add(ans, dp[0][j]);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2688
A,B,N = map(int, input().split())

def f(a, b, n):
   # fl1 = (a * (n + 1)) // b
    #fl2 = (n + 1) // b
    #fl = fl1 - a * fl2
    #return fl
   return int(a * n / b) - a * int(n / b)

print(f(A, B, B-1) if N >= B-1 else f(A, B, N))

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

#include <math.h>
#include <stdlib.h>


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

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

struct edge{int to, cost;};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    vector<vector<edge>> graph(n+1);

    for(int i = 0; i < n-1; i++){
        int a, b, c; cin >> a >> b >> c;
        edge e = {b, c};
        graph[a].push_back(e);
        e = {a, c};
        graph[b].push_back(e);
    }

    int q, k; cin >> q >> k;
    vector<int> x(q), y(q);
    for(int i = 0; i < q; i++) cin >> x[i] >> y[i];

    //dijkstra
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pque;
    vector<ll> dist(n+1, LLONG_MAX);
    dist[k] = 0;

    pque.push(make_pair(0, k));
    while(!pque.empty()){
        pair<int, int> p = pque.top();
        pque.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;
        for(int i = 0; i < graph[v].size(); i++){
            edge e = graph[v][i];
            if(dist[e.to] > dist[v] + e.cost){
                dist[e.to] = dist[v] + e.cost;
                pque.push(make_pair(dist[e.to], e.to));
            }
        }
    }

    for(int i = 0; i < q; i++) cout << dist[x[i]] + dist[y[i]] << endl;

    return 0;
}


Measured memory_bytes: 10100
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <set>
#include <map>

using namespace std;

class AffineCipher
{
public:
	string decode (string, vector <int> );
	vector<int> make_alpha (void);
private:
	int gcd (int, int );
	bool decide_variable (int, int, string );
	bool check_code (string );
};

int AffineCipher::gcd (int a, int b )
{
	if (a > b){
		swap(a,b);
	} // end if
	while (b % a != 0 ){
		b = b % a;
		if (a > b ){
			swap(a, b );
		} // end if
	} // end while

	return a;
}
bool AffineCipher::decide_variable (int a, int b, string str )
{
	set <char> code; 
	set <char> source;
	int i;

	for (i = 0; i < str.length(); ++i ){
		if (isalpha(str[i]) ){
			source.insert (str[i] );
		} // end if
	} // end for
	set <char>::iterator it = source.begin();

	for (; it != source.end(); ++it ){
		char c = (a*((*it) - 'a' ) + b ) % 26 + 'a';
		if (code.count (c) ){
			return false;
		}else{
			code.insert (c);
		} // end if
	} // end for

	return true;
}
bool AffineCipher::check_code (string str )
{
	const string keyword[] = { "this", "that" };

	for (int i = 0; i < sizeof(keyword)/sizeof(keyword[0]); ++i){
		if (str.find(keyword[i] ) != string::npos ){
			return true;
		} // end if
	} // end for

	return false;
}
string AffineCipher::decode (string str, vector <int> alpha )
{
	int len = str.length();
	int a, b;
	multimap <int, int> table;
 	int i;

	for (i = 0; i < alpha.size(); ++i){		
		a = alpha[i];
		for (b = 0; b < 26; ++b){
			if (!decide_variable (a, b, str ) ){
				continue;
			}else{
				table.insert (make_pair (a, b ) );
			} // end if
		} // end for
	} // end for

	string res = "";
	multimap <int, int>::iterator it = table.begin();
	for (; it != table.end(); ++it){
		a = (*it).first;
		b = (*it).second;
		res = "";
		for (i = 0; i < len; ++i){
			char c = 0;
			if (isalpha(str[i] ) ){
				c = (a*(str[i] - 'a' ) + b ) % 26 + 'a';
			}else{
				c = str[i];
			} // end if
			res += c;
		} // end for
		if (!check_code (res ) ){
			continue;
		}else{
			break;
		} // end if
	} // end for

	return res;
}
vector <int> AffineCipher::make_alpha (void)
{
	vector <int> alpha;
	int i;

	for (i = 1; i < 26; ++i){
		if (gcd(i, 26 ) == 1 ){
			alpha.push_back(i);
		} // end if
	} // end for

	return alpha;
}
	
int main()
{
	AffineCipher AC;
//	cut here before submit 
//	freopen("testcase.ac", "r", stdin);
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;
	
	vector <int> alpha = AC.make_alpha();
	int i;

	for (i = 0; i < n; ++i){
		string res = "";
		getline (cin, str );
		res = AC.decode (str, alpha );
		cout << res << endl;
	} // end for
		
	return 0;
}

Measured memory_bytes: 0