akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


int main(){
    int A,B,C,X;
    int count = 0;
    cin>>A>>B>>C>>X;
    for (int i = 0; i <= A; i++)
    {
       for (int j = 0; j <= B; j++)
       {
           for (int k = 0; k <= C; k++)
           {
               if(X==500*i+100*j+50*k)
               {
                   count++;
               }
           }
           
       }
        
    }
    cout<<count<<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 rep1(i,n) for(int i=1;i<=int(n);++i)

int main(void){
    int Y,X;
    cin>>Y>>X;
    vector<string> s(Y+2);
    s[0] = s[Y+1] = string(X+2,'.');
    rep(y,Y){
        cin>>s[y+1];
        s[y+1] = "#"+s[y+1]+"#";
    }
    rep1(y,Y)rep1(x,X){
        if(s[y][x] == '.')continue;
        int dy[] = {1,-1,0,0};
        int dx[] = {0,0,1,-1};
        bool ng = true;
        rep(i,4){
            if(s[y+dy[i]][x+dx[i]] == '#'){
                ng = false;
            }
        }
        if(ng){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

int main() {
  long S;
  cin >> S;
  long x1=0,y1=0;
  long x2=1e9,y2=1;
  long x3,y3;
  // 1e9*y3-x3=S
  long B=1000000000;
  //if(S/B+S%B==S) cout<<"yes"<<endl;
  x3=(B-S%B)%B;
  y3=(x3+S)/B;
  cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<x3<<" "<<y3<<endl;
 // cout<<abs(x2*y3-x3*y2)<<endl;
  }


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
int memo[10][2001];
vector<int>v[10];
int F(int n,int K)
{
	if(n>=10||!K)return 0;
	int&r=memo[n][K];
	if(r>=0)return r;
	r=F(n+1,K);
	for(int i=0;i<K&&i<v[n].size();++i)
		r=max(r,F(n+1,K-i-1)+v[n][i]+(i+1)*i);
	return r;
}
int main()
{
	memset(memo,-1,sizeof(memo));
	int N,K,C,G,i,j;
	for(scanf("%d%d",&N,&K);N--;)
	{
		scanf("%d%d",&C,&G);
		v[G-1].push_back(C);
	}
	for(i=0;i<10;++i)
	{
		sort(v[i].rbegin(),v[i].rend());
		for(j=1;j<v[i].size();++j)v[i][j]+=v[i][j-1];
	}
	printf("%d\n",F(0,K));
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    string ans;
    rep(i, s.length()){
        if(i == 3) ans += '8';
        else ans += s[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int t,n,l,r;
	while(true){
		cin >> t;
		if(t == 0)break;
		cin >> n;
		int sum = 0;
		for(int i = 0; i < n; i++){
			cin >> l >> r;
			sum += r - l;
		}
		if(sum >= t)cout << "OK" << endl;
		else cout << t - sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
# ABC107B - Grid Compression
def main():
    H, W, *A = open(0).read().split()
    H, W = int(H), int(W)
    X, Y = [0] * H, [0] * W
    for i, a in enumerate(A):
        for j, x in enumerate(a):
            if x == "#":
                X[i], Y[j] = 1, 1
    ans = []
    for i, x in enumerate(X):
        cur = ""
        for j, y in enumerate(Y):
            if x and y:
                cur += A[i][j]
        if cur:
            ans.append(cur)
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <utility>
#include <queue>

int r, c;
int arr[11][10010];

int main() {
    while(std::cin >> r >> c, r + c) {

    for(int i = 0; i < r; ++i) {
        for(int j = 0; j < c; ++j) {
            std::cin >> arr[i][j];
        }
    }

    int max = 0;
    for(int i = 0; i < (1 << r); ++i) {
        int sum = 0;
        for(int x = 0; x < c; ++x) {
            int cnt = 0;
            for(int y = 0; y < r; ++y) {
                cnt += arr[y][x] == !!((1 << y) & i);
            }
            sum += std::max(r - cnt, cnt);
        }
        max = std::max(max, sum);
    }

    std::cout << max << std::endl;
    }
}

Measured memory_bytes: 3356
#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;

#define mygetchar getchar
void reader(int *x) {
	int k = mygetchar(); *x = k - '0';
	while (1) {
		k = mygetchar();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}

int N, L, a[100009], c[50009], d[100009], dp[100009]; vector<int> x[50009];
int main() {
	reader(&N); reader(&L);
	for (int i = 0; i < N; i++) reader(&a[i]), c[L - a[i]]++;
	for (int i = 1; i < L; i++) c[i] += c[i - 1];
	for (int i = 0; i < N; i++) d[c[L - a[i] - 1]++] = i;
	for (int i = 0; i < N; i++) dp[d[i] + 1] = max(dp[d[i]], dp[d[i] + 2]) + (L - a[d[i]]);
	printf("%d\n", *max_element(dp, dp + N + 1));
	return 0;
}

Measured memory_bytes: 5132
from collections import deque
import sys

N_MAX = 200000 + 5

H, W, K = map(int, input().split())
sth, stw, glh, glw = map(int, input().split())

INF = 10**6 * K

dp = [[INF for _ in range(W+2)] for _ in range(H+2)]

dp[0] = [-1]*(W+2)
dp[H+1] = [-1]*(W+2)
for h in range(1, H+1):
    s = sys.stdin.readline()
    dp[h][0] = -1
    dp[h][W+1] = -1
    for w in range(1, W+1):
        if s[w-1] == "@":
            dp[h][w] = -1

dp[sth][stw] = 0


# Seen = [[INF]*W for _ in range(H)]
XY = {(1, 0), (-1, 0), (0, 1), (0, -1)}


def bfs(sth, stw, glh, glw):
    next_q = deque()
    next_q.append((sth, stw))

    while len(next_q) != 0:
        # キュー取り出し(先頭)
        h, w = next_q.popleft()
        for dh, dw in XY:
            for sk in range(1, K+1):
                hs, ws = h + dh*sk, w + dw*sk
                if dp[hs][ws] == -1:
                    break
                if dp[hs][ws] == INF:
                    next_q.append((hs, ws))
                    dp[hs][ws] = dp[h][w] + 1
                elif dp[hs][ws] <= dp[h][w]:
                    break
                if hs == glh and ws == glw:
                    return dp[h][w] + 1
    return -1


def main():
    ret = bfs(sth, stw, glh, glw)
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 53288
def divisor(N:int):
    res = set()
    i = 1
    while i * i <= N:
        if N % i == 0:
            res.add(i)
            if i != N // i:
                res.add(N // i)
        i += 1
    return res

def check(N:int, K:int):
    while N % K == 0:
        N //= K
    return True if N == (N // K * K) + 1 else False

def main():
    N = int(input())

    ans = set()
    for K in divisor(N):
        if K == 1: continue
        if check(N, K):
            ans.add(K)

    ans |= divisor(N - 1)

    ans.remove(1)

    print(len(ans))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3828
N=int(input())
list=[]
flag=True
for i in range (N):
    tuple=input()
    input_list=tuple.split()
    input_list=[int(i) for i in input_list]
    list.append(input_list)
for i in range(N):
    time=list[i][0]
    distance=abs(list[i][1])+abs(list[i][2])
    if distance<=time:
        if distance%2==time%2:
            continue
        else:
            flag=False
    else:
        flag=False
if flag:
    print("Yes")
else:
    print("No")


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

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<bool> A(n);
    for (int i = 0; i < k; i++){
        int d;
        cin >> d;
        for (int j = 0; j < d; j++){
            int a;
            cin >> a;
            A[--a] = true;
        }
    }

    int ans = 0;
    for (const auto &a: A){
        if (!a)
            ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3580
N, M = map(int,input().split())
A_list = list(map(int,input().split()))
A_list.sort(reverse=True)

sum_A = sum(A_list)

border = sum_A/(4*M)
cnt = 0

for i in range(N):
    if A_list[i] >= border:
        cnt += 1
    else:
        break
    
if cnt >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,t;
	cin >> n >> t;
	vector<pair<int,int>> p(n);
	for(int i{0};i < n;i++){
		cin >> p[i].first >> p[i].second;
	}
	sort(p.begin(),p.end());
	for(int i{0};i < n;i++){
		if(p[i].second <= t){
			cout << p[i].first;
			return 0;
		}
	}
	cout << "TLE";
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
    ll n,k; cin>>n>>k;
    ll ans=n%k;
    ans=min(ans, abs(k-ans));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
func nextText() string {
    sc.Scan()
    return sc.Text()
}

func main() {
  // input
  sc.Split(bufio.ScanWords)
  s := nextText()
  n := len(s)

  // output
  for i := 0; i < n; i++ {
    fmt.Print("x")
  }
  fmt.Println()

}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <cstdlib>
#include <iterator>
#include <algorithm>
#include <functional>
#include <random>
#include <bits/stdc++.h>

#include <stdio.h>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <math.h>
#include <ctime>
#include <cstring>
#define INF 1e18
using namespace std;

#define FOR(i,N) for(int i=0;i<N;i++) 
#define COUT(str) cout << str << endl
#define MAX_N 1000
 
//入力
int n,t,a ;
int h[MAX_N+4] = {};
double dis[MAX_N+4] = {};
double ans[MAX_N+4] = {};

int main() {

	cin >> n >> t >> a;

	FOR(i, n) {
		cin >> h[i];
	}

	FOR(i, n) {
		dis[i] = abs(a - (t - 0.006*h[i]));

		ans[i] = dis[i];

	}

	sort(ans, ans + n);

	FOR(j, n) {
		FOR(i, n) {
			if (ans[j] == dis[i]) {
				cout << i + 1 << endl;
				return 0;
			}
		}
	}
}


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

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

	int a, b;
	cin >> a >> b;
	int x=(a+b)/2;
	if ((a + b) % 2 == 0) {
		cout << x;
		return 0;
	}
	else cout << x + 1;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
    int S, h, m, s;
    scanf("%d", &S);
    h = S / 3600;
    m = S % 3600 / 60;
    s = S % 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

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

const int N=110000;
const ll INFTY=1e18;

ll x[N], s[N], sp[N];

int main() {
    ll i, n, k, ans;
    scanf("%lld%lld", &n, &k);
    for(i=1; i<=n; i++) {
        scanf("%lld", &x[i]);
        s[i]=s[i-1]+x[i];
        sp[i]=sp[i-1]+max(x[i], 0LL);
    }
    ans=-INFTY;
    for(i=1; i+k-1<=n; i++) {
        ans=max(ans, sp[i-1]+sp[n]-sp[i+k-1]);
        ans=max(ans, sp[i-1]+sp[n]-sp[i+k-1]+s[i+k-1]-s[i-1]);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

void solve()
{
	ll n,k;
	cin>>n>>k;
	ll a[n];
	ll p = 1;
	for (int i = 0; i < n; ++i)
	{
		/* code */
		cin>>a[i];
	}
	for (int i = k; i < n; ++i)
	{
		ll pre = p;
		// p /= a[i-k];
		// p *= a[i];
		// cout<<p<<endl;
		if(a[i]>a[i-k])
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}

}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> output(H);
  for (int i = 0; i < H; i++) cin >> output[i];
  for (int i = 0; i < W + 2; i++)cout << '#';
  cout << endl;
  for (int i = 0; i < H; i++) cout << '#' << output[i] << '#' << endl;
  for (int i = 0; i < W + 2; i++)cout << '#';
  cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

const int MAX_N = 100000;
const int MAX_P = 100;
const int MAX_PRIME = (MAX_N+MAX_P)*2+100;

int prime[MAX_N];
int n_prime;

void init_prime() {
  prime[0] = 2;
  n_prime = 1;
   for (int i=3;i<MAX_PRIME;i++) {
    if (i%2 == 0) continue;
    bool ok = true;
    for (int j=3;j<=sqrt(i);j+=2) {
      if (i%j == 0) {
        ok = false;
        break;
      }
    }
    if (ok) prime[n_prime++] = i;
  }
}

int main() {
  init_prime();
  while (true) {
    int N, P;
    scanf("%d %d", &N, &P);
    if (N == -1 && P == -1) break;
    const int* p = upper_bound(prime, prime+n_prime, N);
    vector<int> t;
    for (int i=0;i<P;i++) {
      for (int j=i;j<P;j++) t.push_back(p[i]+p[j]);
    }
    sort(t.begin(), t.end());
    printf("%d\n", t[P-1]);
  }
  return 0;
}

Measured memory_bytes: 2912
import sys
def input():
  return sys.stdin.readline()[:-1]


n = input()
a = input().split()
r = 1

if '0' in a:
  print(0)
  exit()

for i in range(len(a)):
  aa = int(a[i])
  r *= aa
  if r > pow(10, 18):
    print(-1)
    exit()

print(r)

Measured memory_bytes: 78340
#include<iostream>

using namespace std;

int main()
{
	int a[101]={0};
	int n;
	int c=0;
	while(cin>>n){
		a[n]++;
		if(c<a[n])
			c=a[n];
	}
	for(int i=1;i<101;i++)
		if(a[i]==c)
			cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main() {
    fastio
    
	ll n,i,j,x=0,t,k,w;
	cin>>n>>w;
	
	ll a[n+1],b[n+1];
	
	for(j=1;j<=n;j++){
	    cin>>a[j]>>b[j];
	    x+=b[j];
	}
	vector<vector<ll> > dp(n+1,vector<ll> (x+1,1e12));
	ll ans=0;
	dp[0][0]=0;
	
	for(i=1;i<=n;i++){
	    for(j=0;j<=x;j++){
	        if(j==0) dp[i][j]=0;
	        
	        else if(b[i]<=j)
	        dp[i][j]=min(a[i]+dp[i-1][j-b[i]],dp[i][j]);
	        
	        dp[i][j]=min(dp[i-1][j],dp[i][j]);
	    }
	}
	
	for(i=1;i<=n;i++)
	for(j=0;j<=x;j++)
	if(dp[i][j]!=1e12 && ans<j && dp[i][j]<=w)
	ans=j;
	
	cout<<ans<<endl;
	
	return 0;
}



Measured memory_bytes: 83176
#include <algorithm>
#include <bitset>
#include <complex>
#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>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
//#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
//#define EXIST(s, e) ((s).find(e)!=(s).end())
//#define SORT(c) sort(begin(c),end(c))
//#define pb emplace_back
//#define MP make_pair
//#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int N;
    cin >> N;
    int ans = 0;
    rep(i,1,N+1){
        rep(p,2,11){
            int beki = round(pow(i,p));
            if(beki <= N){
                ans = max(ans,beki);
            }
        }
    }
    cout << ans << endl;




    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ret = 0;
    while (true) {
        bool ok = true;
        for (char c = 'a'; c <= 'z'; c++) {
            ok = true;
            for (int i = 0; i < n - ret; ++i) {
                bool okk = false;
                for (int j = i; j <= i + ret; ++j) {
                    if (s[j] == c)
                        okk = true;
                }
                if (!okk) {
                    ok = false;
                    break;
                }
            }
            if (ok)
                break;
        }
        if (ok)
            break;
        ret++;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

LL sum[55];
LL dp[55];

LL go(int l, LL a) {
  if (sum[l] <= a) {
    return dp[l];
  }
  if (a <= 0) {
    return 0;
  }

  LL res = 0LL;
  a--;
  res += go(l-1, a);
  a -= sum[l-1];
  if (a>=1) res++;
  a--;
  res += go(l-1, a);
  return res;
}

void init() {
  sum[0] = 1;
  FOR(i, 1, 55) {
    sum[i] = sum[i-1]*2 + 3;
  }
  REP(i, 55) dp[i] = -1;
  dp[0] = 1;
  FOR(i, 1, 55) {
    dp[i] = dp[i-1]*2 + 1;
  }
}

LL n, x;
void input() {
cin >> n >> x;
}

void solve() {
  cout << go(n, x) << endl;
}

int main() {
	init();
	input();
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef pair<int, string>IS;

int main(){

    for(int N; cin>>N, N;){
        string s1, s2;
        cin>>s1>>s2;
        string st(N, '0'), goal(N, '0');
        for(int i=0;i<N;i++)st[i] += (s2[i] + 10 - s1[i]) % 10;
        set<string>S;
        S.insert(st);
        priority_queue<IS, vector<IS>, greater<IS> >Q;
        Q.push(IS(0, st));
        while(true){
            int step = Q.top().first;
            string str = Q.top().second;
            Q.pop();
            if(str==goal){
                cout<<step<<endl;
                break;
            }
            int idx = 0;
            while(str[idx]=='0')idx++;
            int tmp = '0' + 10 - str[idx];
            for(int i=idx;i<N;i++){
                str[i] = (str[i] - '0' + tmp) % 10 + '0';
                if(S.find(str)==S.end()){
                    S.insert(str);
                    Q.push(IS(step+1, str));
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3780
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
string s;
matrix dp;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>s;
    dp.resize(2,Vi(s.size()+1,INF));
    dp[0][0]=s[s.size()-1]-'0';
    if(dp[0][0]!=0)dp[1][0]=10-dp[0][0];
    rep(i,s.size()-1){
        chmin(dp[0][i+1],dp[0][i]+s[s.size()-i-2]-'0');
        if(s[s.size()-i-2]!='9'){
            chmin(dp[1][i+1],dp[0][i]+10-s[s.size()-i-2]+'0');
            chmin(dp[0][i+1],dp[1][i]+s[s.size()-i-2]-'0'+1);
            chmin(dp[1][i+1],dp[1][i]+10-s[s.size()-i-2]+'0'-1);
        }else{
            chmin(dp[1][i+1],dp[1][i]);
            chmin(dp[1][i+1],dp[0][i]+1);
        }
    }
    ll ans = dp[0][s.size()-1];
    chmin(ans,dp[1][s.size()-1]+1);
    print(ans);
    return 0;
}

Measured memory_bytes: 24860
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

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

    REP(i,4-1){
        if(s[i]==s[i+1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

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

int main() {
  int N, L; cin >> N >> L;
  vector<string> str(N);
  for (int i = 0; i < N; i++) cin >> str[i];
  sort(str.begin(), str.end());
  for (int i = 0; i < N; i++)
    cout << str[i];
  cout << endl;
}



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

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

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

	ll n,t,q; cin >> n >> t >> q;
	ll a[100005],d[100005];
	vector<ll> p;
	cin >> a[0] >> d[0];
	for (int i = 1;i < n;i++){
		cin >> a[i] >> d[i];
		if(d[i] != d[i-1]){
			p.push_back((a[i]+a[i-1])/2);
		}
	}

	ll x;

	for (int j = 0;j < q;j++){
		cin >> x; x--;
		bool f = true;
		if(d[x] == 1){
			for (int i = 0;i < p.size();i++){
				if(p[i] > a[x] && p[i] - a[x] <= t){ 
					cout << p[i] << endl;
					f = false;
					break;
				}
			}
			if(f) cout << a[x] + t << endl;
		}else{
			for (int i = p.size()-1;i >= 0; i--){
				if(p[i] < a[x] && a[x] - p[i] <= t){
					cout << p[i] << endl;
					f = false;
					break;
				}
			}
			if(f) cout << a[x] - t << endl;	
		}
	}

	return 0;

}



Measured memory_bytes: 4876
import Control.Monad
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV

main=B.interact $ B.pack.g.take 2.B.lines
g [s,t]=mk "" (ls-1) (lt-1) where
    ls = B.length s
    lt = B.length t
    rd si ti = (aa V.! si) UV.! ti
    mk as si ti
        | si<0 || ti<0 = as
        | B.index s si == B.index t ti = mk (B.index s si : as) (si-1) (ti-1)
        | rd (si+1) ti > rd si (ti+1) = mk as si (ti-1)
        | otherwise = mk as (si-1) ti
    aa :: V.Vector (UV.Vector Int)
    aa = V.scanl' p (UV.replicate (lt+1) 0) $ V.enumFromTo 1 ls
    p v0 i = UV.scanl' m 0 $ UV.enumFromTo 1 lt where
        m pj j = if B.index s (i-1) == B.index t (j-1)
            then 1 + v0 UV.! (j-1)
            else max pj $ v0 UV.! j


Measured memory_bytes: 75388
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
ll ans=0,n;
void dfs(ll a,ll b,ll c,ll x) {
  if(x>n) {
    return ;
  }
  if(a&&b&&c) {
    ans++;
  }
  dfs(a+1,b,c,x*10+7);
  dfs(a,b+1,c,x*10+5);
  dfs(a,b,c+1,x*10+3);
}
signed main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  dfs(0,0,0,0);
  cout << ans << endl;
}

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

int main()
{
    string S;
    int XY[2];
    cin >> S >> XY[0] >> XY[1];

    vector<vector<int>> F(2);

    int ind = 0, cnt = 0;
    for (auto ch : S) {
        if (ch == 'F') {
            cnt++;
        } else {
            F[ind].push_back(cnt);
            cnt = 0;
            ind ^= 1;
        }
    }
    if (cnt > 0) F[ind].push_back(cnt);    

    bool yes = true;
    for (int i = 0; i < 2; i++) {
        unordered_set<int> s;
        s.insert(i == 0 && F[i].size() > 0 ? F[0][0] : 0);
        for (int j = i == 0 ? 1 : 0; j < F[i].size(); j++) {
            unordered_set<int> t;
            for (int pos : s) {
                t.insert(pos + F[i][j]);
                t.insert(pos - F[i][j]);
            }
            s = t;
        }
        if (s.count(XY[i]) == 0) {
            yes = false;
            break;
        }
    }

    cout << (yes ? "Yes" : "No") << endl;
}


Measured memory_bytes: 768
#include <stdio.h>

int less(int x, int y)
{
	if (x > y) {
		return y;
	} else {
		return x;
	}
}

int main()
{
	int N, T, i, min, j;
	
	scanf("%d%d", &N, &T);
	
	int c[N], t[N];
	
	for (i = 0; i < N; i++) {
		scanf("%d%d", &c[i], &t[i]);
	}
	
	int flag= 0;
	for (i = 0; i < N; i++) {
		min = c[i];
		for (j = 0; j < N; j++) {
			if (min > c[j]) {
				min = c[j];
			}
		}
		for (j = 0; j < N; j++) {
			if (c[j] == min) {
				break;
			}
		}
		if (t[j] <= T) {
			printf("%d\n", c[j]);
			flag = 1;
			break;
		} else {
			c[j] = 1000;
		}
	}
	if (flag == 0) {
		printf("TLE\n");
	}
	
	return 0;
}
	

Measured memory_bytes: 128
#include "stdio.h"
int main(void)
{
	int len = 0;
	int i;
	int start = 0;
	int next = 0;
	int maxCnt = 0;
	int newCnt = 0;
	
	
	scanf("%d", &len);
	
	for (i = 0; i < len; i++) {
		scanf("%d", &next);
		
		if ( start >= next ) {
			newCnt++;
		}
		else {
			newCnt = 0;
		}
		if (newCnt > maxCnt) {
			maxCnt = newCnt;
		}
		start = next;
	}
	

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

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bitset>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

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

int main(){
    cin>>N>>M;
    ll x, y;
    vec a(N);
    rep(i,N) cin>>a[i], a[i] /= 2;
    ll lcm = a[0];
    reps(i,1,N) {
        ll temp = extgcd(lcm, a[i], x, y);
        lcm = lcm * a[i] / temp;
        if(lcm > M){
            cout<<0<<endl;
            return 0;
        }
    }
    int rest = (lcm / a[0])%2;
    reps(i, 1, N){
        if(rest != (lcm / a[i])%2){
            cout<<0<<endl;
            return 0;
        }
    }
    cout<<1 + (M - lcm) / (lcm * 2)<<endl;
}

Measured memory_bytes: 1024
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, t;
  cin >> n >> t;
  int ans = 1e9;
  for(int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if(b <= t) ans = min(ans, a);
  }
  if(ans == int(1e9)) {
    cout << "TLE" << endl;
  } else 
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// Copyright 2020 yaito3014
#include <iostream>
#include <set>

int main() {
  int K;
  std::cin >> K;
  std::set<int> s;
  int ans = -1;
  long long j = 7 % K;
  for (int i = 0; ; ++i, j = (j * 10 + 7) % K) {
  	if (j == 0) {
  	  ans = i + 1;
  	  break;
  	}
  	if (s.find(j) != s.end()) break;
  	s.insert(j);
  	
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 50500
def main():
    S = input()
    T = input()
    start = [-1 for _ in range(26)]
    goal  = [-1 for _ in range(26)]
    
    for i in range(len(S)):
        fr = ord(S[i]) - ord('a')
        to = ord(T[i]) - ord('a')
        
        if (start[fr] != -1) or (goal[to] != -1):
            if (start[fr] != to) or (goal[to] != fr):
                print('No')
                return
        else:
            start[fr] = to
            goal[to]  = fr

    print('Yes')
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 41712
#include<stdio.h>

int main() {
	int a, b;
	scanf("%d %d", &a,&b);
	
	if (a < b)
		printf("a < b\n");
	else if (a > b)
		printf("a > b\n");
	else
		printf("a == b\n");
	return 0;
}

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

int main()
{
    int A,B;

    cin>>A>>B;
    int temp = 0;

    B = B<<1;

    if(A > B) temp = A - B;
    //cout<<"B = ";

    cout<<temp<<"\n";

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    vector<int>B(N);
    for (int i = 0; i < N; ++i) {
      cin >> A[i] >> B[i];
    }
    vector<pair<int, int>> job(N);
    for (int i = 0; i < N; ++i) {
        job[i] = make_pair(B[i], A[i]);
    }
    sort(job.begin(), job.end());
    int t = 0;
    for (int i = 0; i < N; ++i) {
        t += job[i].second;
        if(t > job[i].first){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if((a<=7&&a%2!=0||a>=8&&a%2==0)&&(b<=7&&b%2!=0||b>=8&&b%2==0))
  cout << "Yes" <<endl;
  else if((4<=a&&a<=6&&a%2==0||a>=9)&&(a%2!=0&&4<=b&&b<=6&&b%2==0||b>=9&&b%2!=0))
           cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
def main():
    H, W = map(int, input().split())
    field = [input().rstrip("\r\n") for _ in range(H)]
    dv = 201
    counts = [[dv for _ in range(W)] for _ in range(H)]
    que = deque([(0, 0)])
    if field[0][0] == "#":
        counts[0][0] = 1
    else:
        counts[0][0] = 0
    while len(que) > 0:
        h, w = que.popleft()
        for dh, dw in [(1, 0), (0, 1)]:
            nh, nw = h + dh, w + dw
            if nh >= H or nw >= W:continue
            if counts[nh][nw] == dv:que.append((nh, nw))
            if field[h][w] != field[nh][nw]:
                counts[nh][nw] = min(counts[nh][nw], counts[h][w]+1)
            else:
                counts[nh][nw] = min(counts[nh][nw], counts[h][w])
    if field[-1][-1] == "#":counts[-1][-1] += 1
    print(counts[-1][-1]//2)
if __name__ == "__main__":
    main()

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if (a <= 5) cout << 0 << endl;
  else if (a <= 12) cout << b / 2 << endl;
  else cout << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f[200005];
int main()
{
    ll a,b,i;
    ll INT=1e18;
    cin>>a;
    if(a%2)cout<<'0'<<endl;
    else
    {
        ll sum=0;
        for(i=10;i<=INT;i=i*5)
        {
            sum=sum+a/i;
        }
        cout<<sum<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    A, B, C, D = map(int, input().split())
    if C//B+(C%B>0) <= A//D+(A%D>0):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9172
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int H, W;
  cin >> H >> W;
  vector<vector<int> > a(H, vector<int>(W, 0));
  rep(i, H) {
    rep(j, W) { cin >> a[i][j]; }
  }
  vector<pair<pii, pii> > op;
  rep(i, H) {
    rep(j, W - 1) {
      if (a[i][j] & 1) {
        a[i][j]--;
        a[i][j + 1]++;
        op.push_back(
            make_pair(make_pair(i + 1, j + 1), make_pair(i + 1, j + 2)));
      }
    }
  }
  rep(i, H - 1) {
    if (a[i][W - 1] & 1) {
      a[i][W - 1]--;
      a[i + 1][W - 1]++;
      op.push_back(make_pair(make_pair(i + 1, W), make_pair(i + 2, W)));
    }
  }
  cout << op.size() << endl;
  rep(t, op.size()) {
    pair<pii, pii> o = op[t];
    cout << o.first.first << " " << o.first.second << " " << o.second.first
         << " " << o.second.second << endl;
  }
  return 0;
}


Measured memory_bytes: 5232
#include<bits/stdc++.h>
using namespace std;
vector<long long> sum;
vector<vector<long long>> dp;
long long solve(vector<long long>&v, int i, int j)
{
    if(i > j)
        return 0;
    if(i == j)
        return 0;
    if(i + 1 == j)
        return (long long)v[i] + v[j];
    if(dp[i][j] != -1)
        return dp[i][j];
    else
    {
        long sumij = sum[j] - (i - 1 >= 0 ? sum[i - 1] : 0);
        long long cost = LONG_MAX;
        for(int k = i; k < j; k++)
        {
            cost = min(cost, solve(v, i, k) + solve(v, k + 1, j) + sumij);
        }
        dp[i][j] = cost;
        return cost;
    }
    return LONG_MAX;
}

int main()
{
    int n;
    cin >> n;
    vector<long long> v(n);
    sum = vector<long long> (n);
    for(int i = 0; i < n; i++)
        cin >> v[i];
    dp = vector<vector<long long>> (n, vector<long long>(n, -1));
    for(int i = 0; i < n; i++)
    {
        if(i == 0)
            sum[0] = (long long)v[0];
        else
            sum[i] = sum[i - 1] + v[i];
    }
    cout << solve(v, 0, v.size() - 1);
    return 0;
}
/*
(10, 10, 10, 10)
 


*/

Measured memory_bytes: 1536
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
const ll C = 1000000007;

int N, M;
ll dp[3010][3010][2];

int main () {
  cin >> N >> M;
  for (auto i = 0; i <= M; ++i) {
    for (auto j = 0; j <= N; ++j) {
      for (auto k = 0; k < 2; ++k) {
        dp[i][j][k] = 0;
      }
    }
  }
  for (auto j = 0; j <= N; ++j) {
    if (j == 0) {
      dp[0][j][0] = 0;
      dp[0][j][1] = 1;        
    } else {
      dp[0][j][0] = 1;
      dp[0][j][1] = 0;
    }
  }
  for (auto i = 0; i < M; ++i) {
    for (auto j = 0; j <= N; ++j) {
      // dp[i][j][0]
      if (j == 1) {
        dp[i+1][j-1][1] += dp[i][j][0];
        dp[i+1][j-1][1] %= C;        
      } else if (j > 0) {
        dp[i+1][j-1][0] += dp[i][j][0];
        dp[i+1][j-1][0] %= C;    
      }
      if (j < N) {
        dp[i+1][j+1][0] += dp[i][j][0];
        dp[i+1][j+1][0] %= C;        
      }
      if (j == 1) {
        dp[i+1][j][1] += dp[i][j][0];
        dp[i+1][j][1] %= C;      
      } else if (j > 0) {
        dp[i+1][j][0] += dp[i][j][0];
        dp[i+1][j][0] %= C;        
      }
      if (j < N) {
        dp[i+1][j][0] += dp[i][j][0];
        dp[i+1][j][0] %= C;
      }
      // dp[i][j][1]
      if (j > 0) {
        dp[i+1][j-1][1] += dp[i][j][1];
        dp[i+1][j-1][1] %= C;        
      }
      if (j < N) {
        dp[i+1][j+1][1] += dp[i][j][1];
        dp[i+1][j+1][1] %= C;        
      }
      if (j > 0) {
        dp[i+1][j][1] += dp[i][j][1];
        dp[i+1][j][1] %= C;
      }
      if (j < N) {
        dp[i+1][j][1] += dp[i][j][1];
        dp[i+1][j][1] %= C;
      }
    }
  }
  ll ans = 0;
#if DEBUG == 1
  for (auto i = 0; i <= M; ++i) {
    for (auto j = 0; j <= N; ++j) {
      for (auto k = 0; k < 2; ++k) {
        cerr << "dp[" << i << "][" << j << "][" << k << "] = "
             << dp[i][j][k] << endl; 
      }
    }
  }  
#endif
  for (auto j = 0; j <= N; ++j) {
    ans += dp[M][j][1];
    ans %= C;
  }
  cout << ans << endl;
}


Measured memory_bytes: 141568
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

map<pair<int, int>, int> mp;
int k = 0;

// G
// n 対象のノード
// parent 親のノード
// col: 親と自分の間の色
void dfs(const vector<vector<int>>& G, const int& n, const int& parent, const int& col) {
  int color = 0;
  for (auto& v : G[n]) {
    if (v == parent) continue;
    color++;
    if (color == col) color++;
    if (color > k) color = 1;
    int a = min(v, n);
    int b = max(v, n);
    mp[{a, b}] = color;
    dfs(G, v, n, color);
  }
}

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

  int n;
  cin >> n;

  vector<vector<int>> G(n, vector<int>());
  vector<pair<int, int>> edges(n-1);

  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    edges[i] = make_pair(a, b);
  }

  int max_node = 0;
  rep(i, n) {
    if (chmax(k, int(G[i].size()))) max_node = i;
  }

  cout << k << endl;

  dfs(G, max_node, -1, 0);

  for (auto& p : edges) {
    cout << mp[p] << endl;
  }

  return 0;
}


Measured memory_bytes: 14080
#include <iostream>

using namespace std;

int main(int argc, char const* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X;
    cin >> N >> X;
    int min = 1000;
    for (int i=0; i<N; ++i) {
        int mi;
        cin >> mi;
        X -= mi;
        if (mi < min) {
            min = mi;
        }
    }
    cout << (N + X / min) << '\n';
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int N, H, W; cin >> N >> H >> W;
  int ans = 0;
  rep(i, N) {
    int A, B; cin >> A >> B;
    if (A >= H && B >= W) ans++;
  }
  cout << ans << '\n';
}


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

using namespace std;

const int MAXN = 1e2 + 10, K = 1e5 + 10;

bool dp[K];
int a[MAXN];

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

	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	sort(a, a + n);

	for (int j = 0; j <= k; ++j) {
	  dp[j] = 1;
		for (int i = 0; i < n; ++i) {
			if (j - a[i] < 0)
				break;
			if (dp[j - a[i]]) {
				dp[j] = 0;
				break;
			}
		}
	}

	cout << ((dp[k]) ? "Second\n" : "First");

	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int aa = a;
        int bb = b;

        while (b != 0) {
            int c = a % b;
            a = b;
            b = c;
        }
        System.out.print((long) aa/a*bb );
    }
}


Measured memory_bytes: 23636
import sys
from collections import defaultdict
bbn=1000000007
	
#+++++

		
def main():
	n, m = map(int, input().split())
	al = list(map(int, input().split()))
	bl= [0] * len(al)
	ruiseki=0
	ddi=defaultdict(lambda : 0)
	ddi[0]+=1
	for i,v in enumerate(al):
		ruiseki+=v
		bl[i] = ruiseki % m
		ddi[bl[i]] += 1
		
	ret=0
	for k in ddi:
		v=ddi[k]
		ret += v * (v - 1)//2
	
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 62576
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

import itertools

N = int(input())
S = [ input().rstrip() for _ in range(N)]

# MARCH
C = [0] * 5
for s in S:
    i = -1
    if s[0] == 'M': i = 0
    if s[0] == 'A': i = 1
    if s[0] == 'R': i = 2
    if s[0] == 'C': i = 3
    if s[0] == 'H': i = 4

    if i > -1:
        C[i] += 1

count = 0
for x in itertools.combinations("01234", 3):
    (a, b, c) = map(int, x)
    count += C[a]*C[b]*C[c]
#    print(x, count, C)

print(count)

Measured memory_bytes: 9780
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

  private static int INF = 1000000000;

  public static void main(final String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final var N = scanner.nextInt();
    final var M = scanner.nextInt();
    final Map<Integer, Set<Integer>> graph = new HashMap<>();
    for (int i = 1; i <= N; i++) {
      graph.put(i, new HashSet<>());
    }

    for (int i = 0; i < M; i++) {
      final var to = scanner.nextInt();
      final var from = scanner.nextInt();

      graph.get(to)
          .add(from);
      graph.get(from)
          .add(to);
    }

    final var route = dijkstra(N, graph);
    for (int i = 2; i <= N; i++) {
      if (route[i] == 0) {
        System.out.println("No");
        return;
      }
    }

    System.out.println("Yes");
    for (int i = 2; i <= N; i++) {
      System.out.println(route[i]);
    }
  }

  static int[] dijkstra(final int N, final Map<Integer, Set<Integer>> graph) {
    final int[] distance = new int[N + 1];
    for (int i = 2; i <= N; i++) {
      distance[i] = INF;
    }
    distance[1] = 0;

    final Queue<Pair> q = new PriorityQueue<>(Comparator.comparingInt(a -> a.d));
    q.add(new Pair(1, 0));
    final var route = new int[N + 1];

    while (!q.isEmpty()) {
      final Pair point = q.poll();
      final var v = point.p;

      if (distance[v] < point.d) {
        continue;
      }

      for (final int i : graph.get(v)) {
        if (distance[i] > distance[v] + 1) {
          distance[i] = distance[v] + 1;
          q.add(new Pair(i, distance[i]));
          route[i] = v;
        }
      }
    }

    return route;
  }

  private static class Pair {

    public final int p;
    public final int d;

    public Pair(final int p, final int d) {
      this.p = p;
      this.d = d;
    }
  }
}


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

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

	if(A != 1 && B != 1)
		cout << 1 << endl;
	else if(A != 2 && B != 2)
		cout << 2 << endl;
	else
		cout << 3 << endl;

	return 0;
}

Measured memory_bytes: 256