akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.PrintWriter;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int h = sc.nextInt();
        int w = sc.nextInt();
        
        // 問題:
        // 1. (H+1)*Wのboardがある
        // 2. 最初(0,0)(0,1)...(0,W)に人がいる
        // 3. 右or下に進める
        // 4. i行目には区間[L,R]の壁があり下には行けない
        
        // ans[i]: i行目に到達する人のうち、最小の歩数
        
        // map(now, from): 最初from列にいて、今now列にいる人らの集合
        SortedMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
        for (int i = 0; i < w; i++) {
            map.put(i, i);
        }
        
        // gaps: mapの(now-from)の集合
        TreeMap<Integer, Integer> gaps = new TreeMap<Integer, Integer>();
        for (Integer key : map.keySet()) {
            int val = map.get(key);
            int gap = key-val;
            
            int cnt = gaps.getOrDefault(gap, 0);
            gaps.put(gap, ++cnt);
        }
        
        for (int i = 1; i <= h; i++) {
            int L = Integer.parseInt(sc.next())-1;
            int R = Integer.parseInt(sc.next())-1;
            
            // submap: 壁で下に行けない人の集合(R+1列目のまっすぐ行ける人も含む)
            // (submapは区間[l,r)なので、[L,R+1]は[l,r+2))
            SortedMap<Integer, Integer> submap = map.subMap(L, R+2);
            
            // (次の行,R+1)に最小で行ける人は、submapの一番右の人なので、
            // それ以外は削除する
            if (!submap.isEmpty()) {
                int val = 0;
                int now_r = submap.lastKey();
                int from_r = submap.get(now_r);
                
                // gapsの削除
                for (Integer key : submap.keySet()) {
                    val = map.get(key);
                    int gap = key-val;
                    
                    int cnt = gaps.get(gap);
                    if (cnt == 1) {
                        gaps.remove(gap);
                    } else {
                        gaps.put(gap, --cnt);
                    }
                }
                
                // mapの削除
                submap.clear();
                
                // map(now, from)のnowの更新
                now_r = R+1;
                if (now_r < w) {
                    map.put(now_r, from_r);
                }
                
                // gapsの追加
                if (now_r < w) {
                    val = gaps.getOrDefault(now_r - from_r, 0);
                    gaps.put(now_r - from_r, ++val);
                }
                // System.out.println(map.toString());
                // System.out.println(gaps.toString());
                // System.out.println(now-right);
            }
            
            // ans: 縦移動+横移動
            int ans = -1;
            if (!gaps.isEmpty()) {
                ans = i + gaps.firstKey();
            }
            out.println(ans);
        }
        out.flush(); 
    }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a % 2 == 0)
  {cout << "Even" << endl; }
  else if(b % 2 == 0)
  {cout << "Even" << endl;}
  else
  {cout << "Odd" << endl;}
}

Measured memory_bytes: 3500
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#include <iostream>
#include <iomanip>    
#include <cstring>
#include <cmath>

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define eprintf(...) fprintf(stderr,__VA_ARGS__)

using namespace std;

template<class T> inline void umax(T &a,T b){if(a < b) a = b;}
template<class T> inline void umin(T &a,T b){if(a > b) a = b;}
template<class T> inline T abs(T a){return a > 0 ? a : -a;}

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 1e9 + 143;
const ll longinf = 1e18 + 143;

inline int read(){int x;scanf(" %d",&x);return x;}

int main() {
  int n = read();
  int x = read();
  if (x == 1 || x == 2 * n - 1) {
    puts("No");
    return 0;
  }
  printf("Yes\n");
  if (x <= n) {
    int at =  2 * n - 1;
    for (int i = 1; i <= n - 2; i++) {
      while (at == x || at == x - 1) {
        at--;
      }
      printf("%d\n", at);
      at--;
    }
    printf("%d\n%d\n", x - 1, x);
    while (at > 0) {
      if (at != x && at != x - 1)
        printf("%d\n", at);
      --at;
    }
  } else {
    for (int i = 1; i <= n - 1; i++) {
      printf("%d\n", i);
    }
    printf("%d\n%d\n", x, x + 1);
    for (int i = n; i <= 2 * n - 1; i++) {
      if (i == x || i == x + 1)
        continue;
      printf("%d\n", i);
    }
  }
  return 0;    
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  bool ans = false;
  int co = 0;
  rep(i, n){
    int a, b;
    cin >> a >> b;
    if(a == b){
      co++;
      if(co == 3) ans = true;
    }else co = 0;
  }
  if(ans == true) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

int
main(void)
{
    int sec;
    int h, m, s;
    scanf("%d", &sec);
    h = sec / 3600;
    m = (sec - h * 3600) / 60;
    s = sec % 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


Measured memory_bytes: 2100
"use strict";

const main = (arg) => {
  const array = arg.trim().split(" ");
  const X = parseInt(array[0], 10);
  const Y = parseInt(array[1], 10);
  if (X * 4 < Y) {
    console.log("No");
    return;
  }
  for (let i = 0; i <= X; i++) {
    let kameLegs = i * 2;
    let toriLegs = (X - i) * 4;
    let tolalLrgs = kameLegs + toriLegs;
    if (tolalLrgs == Y) {
      console.log("Yes");
      return;
    }
  }
  console.log("No");
};
main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  cout << (N % 2 == 0 ? N / 2 - 1 : (N - 1) / 2) << '\n';
  return 0;
}


Measured memory_bytes: 256
/*
2020-05-03
atcoder ABC
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

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

    if(S == "ABC"){
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)
#define scin(a) scanf("%d",&a);
#define scdo(a) scanf("%lf",&a);
#define scch(a) scanf("%s",a);
#define anin(a) printf("%d\n",a);
#define ando(a) printf("%lf\n",a);
#define anch(a) printf("%s\n",a);

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(void){
	char mozi[4],ans[5];
	strcpy(ans,"Good\0");
	scch(mozi)
	rep(i,0,3){
		if(mozi[i] == mozi[i + 1]){
			strcpy(ans,"Bad\0");
			break;
		}
	}
	anch(ans)
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
const int N = 105;
int main()
{
    int a[N][N], b[N] = {0}, c[N] = {0}, n, m;

    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            a[i][j] = 0;
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }
    for (int i = 0; i < m; i++)
    {
        scanf("%d", &b[i]);
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            c[i] += a[i][j] * b[j];
        }
    }
    for (int i = 0; i < n; i++)
    {
        printf("%d\n", c[i]);
    }
    return 0;
}


Measured memory_bytes: 2736
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    int n, t;
    cin >> n >> t;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    // dp1[i][j]:[0,i)まで使用、時間j以内での最大値
    vector<vector<int>> dp1(n + 1, vector<int>(t, 0));
    // dp2[i][j]:[i,n)まで使用、時間j以内での最大値
    vector<vector<int>> dp2(n + 1, vector<int>(t, 0));
    // dp1
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < t; j++) {
            dp1[i + 1][j] = max(dp1[i][j], dp1[i + 1][j - 1]);
            if (j - a[i] >= 0) {
                dp1[i + 1][j] = max(dp1[i + 1][j], dp1[i][j - a[i]] + b[i]);
            }
        }
    }
    // dp2
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 1; j < t; j++) {
            dp2[i][j] = max(dp2[i + 1][j], dp2[i][j - 1]);
            if (j - a[i] >= 0) {
                dp2[i][j] = max(dp2[i][j], dp2[i + 1][j - a[i]] + b[i]);
            }
        }
    }
    int ans = 0;
    // iを最後に食べる
    for (int i = 0; i < n; i++) {
        //前半にj掛ける
        for (int j = 0; j < t; j++) {
            ans = max(ans, dp1[i][j] + dp2[i + 1][t - 1 - j] + b[i]);
        }
    }
    cout << ans << endl;
}

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

double p[3000];
double dp[3000][1505];
int n;

double solve(int x, int t){
    if (x == n && t <= n/2) return 1;
    if (t > n/2) return 0;
    if (dp[x][t] != -1) return dp[x][t];
    return dp[x][t] = p[x]*solve(x+1,t)+(1-p[x])*solve(x+1,t+1);
}

int main(int argc, char const *argv[]) {
    cin >> n;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n/2+1; j++){
            dp[i][j] = -1;
        }
        cin >> p[i];
    }
    cout << setprecision(10) << solve(0,0) << endl;
    return 0;
}


Measured memory_bytes: 35712
D = int(input())
C = list(map(int, input().split()))
S = []
for i in range(D):
    S.append(list(map(int, input().split())))

T = []
for i in range(D):
    T.append(int(input()))

distance_list = [0] * 26

sum_ = 0
for i in range(D):
    sum_ += S[i][T[i]-1]
    down = 0
    for j in range(26):
        if T[i] - 1 == j:
            distance_list[j] = 0
            continue
        distance_list[j] += 1
        down += distance_list[j] * C[j]
    sum_ -= down

    print(sum_)


Measured memory_bytes: 9284
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const int mod = 1e9 + 7;

int64 power(int64 x, int64 y){
    if(y == 0) return 1;
    int64 ret = 1;
    if(y & 1) {
        ret *= x;
        ret %= mod;
    }
    int64 temp = (power(x, y / 2) % mod);
    ret = (((ret * temp) % mod) * temp) % mod;
    return ret;
}
int main(){
    int64 n, k; cin >> n >> k;

    vector<int64> dp(k + 1, 0);
    for(int64 gcd = k; gcd >= 1; gcd--){
        int64 total_multiples = k / gcd;
        int64 temp = power(total_multiples, n);
        temp %= mod;
        for(int64 j = gcd * 2; j <= k; j += gcd){
            temp = (temp - dp[j]);
        }
        dp[gcd] = temp;
    }
    int64 ans = 0;
    for(int64 i = 1; i <= k; i++){
        ans = ans + ((dp[i] * i) % mod);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4016
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  ll sum=0;
  rep(i,n)sum+=a[i];
  ll MIN=INF;
  ll b=0;
  rep(i,n){
    b+=a[i];
    ll d=sum-b;
    ll k=abs(b-d);
    MIN=min(k,MIN);
  }
  cout<<MIN<<endl;
}

Measured memory_bytes: 1792
// failed to generate code

#include <bits/stdc++.h>
using namespace std;

int a[210][210];
int H,W;
int dp[210][210][210];

int dfs(int x,int y,int x2){
	//cout << x << " " << y << " " << x2 << endl;
	if( x >= W ) return 0;
	if( y >= H ) return 0;
	int y2 = (x + y) -x2;
	if( y2 >= H ) return 0;
	if( x2 >= W ) return 0;
	if( y2 < 0 ) return 0;
	if( dp[x][y][x2] != -1 ) return dp[x][y][x2];
	//cout << x2 << " " << y2 << endl;
	int ans = a[y][x];
	if( x != x2 or y != y2 )
		ans += a[y2][x2];
	int ans2 = 0;
	ans2 = max(dfs(x+1,y,x2+1),dfs(x,y+1,x2+1));
	ans2 = max(ans2,max(dfs(x+1,y,x2),dfs(x,y+1,x2)));
	
	return dp[x][y][x2] = ans + ans2;
}

int main(){	
	memset(dp,-1,sizeof(dp));
	ios::sync_with_stdio(false);
	
	cin >> H >> W;
	for(int i = 0 ; i < H ; i++)
		for(int j = 0 ; j < W ; j++)
			cin >> a[i][j];
	cout << dfs(0,0,0) << endl;
}



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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T>
T chmin(T &a, T b){
    if(a > b){ a=b; return true;}
    return false;
}

template<typename T>
T chmax(T &a, T b){
    if(a < b){ a=b; return true;}
    return false;
}

int main(){
    int H, N;
    cin >> H >> N;
    vi A(N), B(N);
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i];
    }

    vi dp(H+1, INF);
    dp[0]=0;
    for(int i=0; i<=H; i++){
        for(int j=0; j<N; j++){
            chmin(dp[min(i+A[j], H)], dp[i]+B[j]);
        }
    }
    cout << dp[H] << endl;
    return 0;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    string s;
    while(n>26){
        ll k1=n/26,k2=n%26;
        if(k2) s+=char('a'+k2-1);
        else{
            s+='z';
            k1--;
        }
        n=k1;
    }
    if(n) s+=char('a'+n-1);
    reverse(all(s));
    //forn(i,sz(s)-1) s[i]--;
    cout<<s;
    return 0;
}



Measured memory_bytes: 3640
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;
 
using namespace std;

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


int main()   {
    cout.precision(17);
    ll modd = 1000 * 1000 * 1000 + 7;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
    ll infinit = 10000000000000000;

//    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(x);

        cout << 360/gcd(360,x) << endl;

    }

//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;

    return 0;
}

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

using namespace std;
 
long long n, u ,v, memo[100010][2], num = 1, mod = 1e9 + 7, vis[100010]; //stasts 0 --> black, 1 --> white
vector<long long> adjlist[100010];
vector<long long> ejlist[100010];
 
void dfs(long long x) {
	vis[x] = 1;
	for(long long i = 0; i < adjlist[x].size(); i++) {
		if(vis[adjlist[x][i]] == -1) {
			ejlist[x].push_back(adjlist[x][i]);
			dfs(adjlist[x][i]);
		}
	}
}
 
long long dp(long long idx, long long stats) {
	if(idx == n + 1) {
		return 1;
	}
	if(memo[idx][stats] != -1) {
		return memo[idx][stats];
	}
	memo[idx][stats] = 1;
	for(long long i = 0; i < ejlist[idx].size(); i++) {
		long long next = ejlist[idx][i];
		if(stats == 0) {
			memo[idx][stats] *= dp(next, 1);
			memo[idx][stats] %= mod;
		}
		else {
			memo[idx][stats] *= ((dp(next, 0) + dp(next, 1)) % mod);
			memo[idx][stats] %= mod;
		}
	}
	return memo[idx][stats] % mod;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	memset(vis, -1, sizeof(vis));
	cin >> n;
	for(long long i = 0 ; i < n - 1; i++) {
		cin >> u >> v;
		adjlist[u].push_back(v);
		adjlist[v].push_back(u);
	}
	dfs(1);
	memset(memo, -1, sizeof(memo));
	long long ret = dp(1, 1);
	memset(memo, -1, sizeof(memo));
	ret += dp(1, 0);
	ret %= mod;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 21888
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
drink=[tuple(map(int,input().split())) for _ in range(N)]
drink.sort(key=lambda x:x[0],reverse=True)
cost=0
cnt=0
while True:
    A,B=drink.pop()
    if cnt+B>=M:
        cost+=A*(M-cnt)
        break
    else:
        cnt+=B
        cost+=A*B
print(cost)

Measured memory_bytes: 18176
N,H = list(map(int,input().split()))
Amax = 0
Bs = []
for i in range(N):
    A,B = list(map(int,input().split()))
    Amax = max(Amax,A)
    Bs.append(B)
Bs.sort(reverse=True)
cnt = 0
flag = 0
for i in range(N):
    if Bs[i]>=Amax:
        H += -1*Bs[i]
        cnt += 1
        if H<=0:
            print(cnt)
            flag=1
            break
    else:
        break
if flag==0:
    if H%Amax==0:
        print(cnt+H//Amax)
    else:
        print(cnt+H//Amax+1)

Measured memory_bytes: 80936
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
int h1,h2,m1,m2,k;
cin>>h1>>m1>>h2>>m2>>k;
int p=(h1*60)+m1;
int q=(h2*60)+m2;
int ans=q-p-k;
cout<<ans;
}


Measured memory_bytes: 3644
from collections import deque
n=int(input())
v=deque(list(map(int,input().split())))
c=deque(list(map(int,input().split())))
ans=deque([])
value=0
for i in range(n):
    ans.append(v[i]-c[i])
for j in range(n):
    if ans[j]>=0:
        value+=ans[j]
print(value)

Measured memory_bytes: 3316
n=int(input())
mod=10**9 + 7
import math
from collections import Counter
#試し割法
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

ans=[]
for i in range(1,n+1):
    arr=factorize(i)

    ans.append(arr)

ans=sum(ans,[])

c=list(Counter(ans).values())
cnt=1
for j in c:
    cnt*=(j+1)

print(cnt%mod)

Measured memory_bytes: 9512
#include<bits/stdc++.h>
using namespace std;
int p[200],n,x,res=0;
int main() {
    cin>>n>>x;
    for(int i=1;i<=n;i++)
        cin>>p[i];
    sort(p+1,p+n+1);
    for(int i=1;i<=n;i++)
        if(x>=p[i]) {
            if(i==n)
            {
                if(x==p[i])
                    res++;
                    break;
             }
                x-=p[i];
                res++;
        }
        cout<<res<<endl;
}

Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! p {
    ($($x:expr),*) => {
        $(println!("{:?}", $x);)*
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
#[allow(unused_imports)]
use std::cmp::*;
trait Each: Iterator{
    fn each<F>(self, mut f: F) where
        Self: Sized, F: FnMut(Self::Item),
    {
        self.fold((), move |(), item| f(item));
    }
}
impl<T:Iterator>Each for T{}
macro_rules! dp{
    ($e: expr ; $x: expr) => (vec![$e; $x]);
    ($e: expr ; $x: expr , $($t: expr),*) => (
        vec![dp![$e;$($t),*] ; $x]
    )
}
fn main(){
    input!{
        n:usize,m:usize,
         a:[i64;n]
    }
    let mut s = std::collections::BinaryHeap::new();
    for i in a{s.push(i)};
    for _ in 0..m{
        let a = s.pop().unwrap();
        s.push(a/2);
    }
    
    p!(s.into_iter().sum::<i64>())
}

Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){
	
	int N;
	cin>>N;
	
	vector<vector<pair<int,int>>> E(N,vector<pair<int,int>>());
	
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		
		E[a].emplace_back(b,i);
		E[b].emplace_back(a,i);
	}
	
	queue<int> Q;
	Q.push(0);
	
	vector<int> ans(N-1,-1);

	while(Q.size()!=0){
		int from = Q.front();
		Q.pop();
		set<int> S;
		for(int i=0;i<E[from].size();i++){
			int to = E[from][i].first;
			int ind = E[from][i].second;
			if(ans[ind]==-1){
				Q.push(to);
			}
			else{
				S.insert(ans[ind]);
			}
		}
		int now = 1;
		for(int i=0;i<E[from].size();i++){
			int to = E[from][i].first;
			int ind = E[from][i].second;
			if(ans[ind]==-1){
				while(S.count(now))now++;
				ans[ind] = now;
				S.insert(now);
			}
		}
	}
	
	int a = 0;
	for(int i=0;i<N-1;i++){
		a = max(a,ans[i]);
	}
	cout<<a<<endl;
	for(int i=0;i<N-1;i++){
		cout<<ans[i]<<endl;
	}
	
	return 0;
	
}


Measured memory_bytes: 6912
#include<iostream>
using namespace std;
int coin[6] = {500,100,50,10,5,1};

int main(){
	int money, price;
	while(cin >> price){
		if(price==0) break;
		money = 1000-price;
		int count=0;
		for(int i=0; i<6; i++)
			while(money>=coin[i]) {count++; money-=coin[i];}
		cout << count << endl;
	}
	return 0;
}

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

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

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

    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
        a[i] = abs(a[i] - x);
    }
    int ans = a[0];
    Rep(i, 1, n) ans = gcd(ans, a[i]);
    cout << ans << endl;
}

Measured memory_bytes: 640
str = gets
l = str[0..1].to_i
r = str[2..3].to_i

def valid_month?(i)
  i >= 1 && i <= 12
end

if valid_month?(l) && valid_month?(r)
  puts "AMBIGUOUS"
elsif valid_month?(r)
  puts "YYMM"
elsif valid_month?(l)
  puts "MMYY"
else
  puts "NA"
end

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

const int Max = 100;
const int white = 0;
const int black = 1;
int M[Max][Max];
int d[Max], nt[Max], color[Max];
int n;
queue<int> Q;

int next(int u){
    for(int v=nt[u]; v<n; v++){
        nt[u] = v + 1;
        if(M[u][v]) return v;
    }
    return -1;
}

void bfs_visit(int u){
    for(int i=0; i<n; i++){
        nt[i] = 0;
        d[i] = -1;
    }

    color[u] = black;
    d[u] = 0;
    Q.push(u);
    while(!Q.empty()){
        int u = Q.front();
        int v = next(u);
        if(v != -1){
            if(color[v] == white){
                color[v] = black;
                d[v] = d[u] + 1;
                Q.push(v);
            }
        } else {
            Q.pop();
        }
    }
}

int main(){
    int u, k, v;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        color[i] = white;
    }
    for(int i=0; i<n; i++){
        cin >> u >> k;
        u--;
        for(int i=0; i<k; i++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    bfs_visit(0);

    for(int i=0; i<n; i++){
        cout << i+1 << " " << d[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3292
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())

s = [list(input()) for _i in range(h)]

bord = [[float('inf') for _i in range(w)] for _j in range(h)]
bord[ch-1][cw-1] = 0

dh, dw = dh-1, dw-1
from collections import deque
q = deque([[ch-1, cw-1]])
while q:
    x, y = q.pop()
    for i, j in [[1,0], [0, 1], [-1, 0], [0, -1]]:
        if 0 <= x+i and 0 <= y+j and x+i < h and y+j < w:
            if s[x+i][y+j]=='.':
                if bord[x][y] < bord[x+i][y+j]:
                    bord[x+i][y+j] = bord[x][y]
                    q.append([x+i, y+j])
            else:
                for n in range(-2, 3):
                    for m in range(-2, 3):
                        if n==0 and m==0:
                            continue
                        if 0 <= x+n and 0 <= y+m and x+n < h and y+m < w:
                            if s[x+n][y+m] == '.':
                                if bord[x][y]+1 < bord[x+n][y+m]:
                                    bord[x+n][y+m] = bord[x][y] + 1
                                    q.appendleft([x+n, y+m])

if bord[dh][dw]==float('inf'):
    print(-1)
else:
    print(bord[dh][dw])

Measured memory_bytes: 169448
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

MOD = 924844033

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

# mod (2K) ごとに、「反例として決めうつ個数」 -> 「合法な決め打ち方」を求める。
# 項数・両端の選択肢の有無でdp

N,K = map(int,readline().split())

dp_0 = np.zeros((N+1,N+1),np.int64) # 両端がともに使えない
dp_1 = np.zeros((N+1,N+1),np.int64) # 両端が片方だけ使える → 右側だけ使えるとして
dp_2 = np.zeros((N+1,N+1),np.int64) # 両端がともに使える
dp_0[0,0] = 1
dp_1[0,0] = 1
dp_2[0,0] = 1
for n in range(1,N+1):
    # 最後の項を右側でとる
    dp_1[n,1:] += dp_1[n-1,:-1]
    dp_2[n,1:] += dp_2[n-1,:-1]
    # 最後の項を左側でとる
    if n >= 2:
        dp_0[n,1:] += dp_0[n-1,:-1]
        dp_1[n,1:] += dp_0[n-1,:-1]
    dp_2[n,1:] += dp_1[n-1,:-1]
    # 最後の項を放置する
    dp_0[n] += dp_1[n-1]
    dp_1[n] += dp_1[n-1]
    dp_2[n] += dp_2[n-1]
    dp_0[n] %= MOD
    dp_1[n] %= MOD
    dp_2[n] %= MOD

def F(N,K,n):
    # mod 2Kでnのものたち
    items = (N-n)//(2*K)+1
    last = n + (items-1)*(2*K)
    x = (n-K>0) + (last+K<=N)
    arr = dp_0 if x == 0 else (dp_1 if x == 1 else dp_2)
    return arr[items][:items+1]

def convolve(x,y):
    Lx = len(x)
    Ly = len(y)
    if Lx < Ly:
        x,y = y,x
        Lx,Ly = Ly,Lx
    arr = np.zeros(Lx+Ly-1,np.int64)
    for n in range(Ly):
        arr[n:n+Lx] += y[n] * x % MOD
    arr %= MOD
    return arr

x = np.array([1],np.int64)
for n in range(1,2*K+1):
    if n > N:
        break
    x = convolve(x,F(N,K,n))

fact, _ = make_fact(N+100,MOD)

L = len(x)
x[1::2] *= (-1)
answer = (x[::-1] * fact[N-L+1:N+1] % MOD).sum() % MOD
print(answer)

Measured memory_bytes: 106364
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

template<typename T>
using v = vector<T>;

int main() {
	int N;
	cin >> N;
	int maximum = -1, minimum = INF;
	rep(i, N) {
		int a;
		cin >> a;
		maximum = max(maximum, a);
		minimum = min(minimum, a);
	}
	cout << maximum - minimum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    int lis[10000];
    for(int i=0;i<N;i++)cin>>lis[i];
    sort(lis,lis+N);
    int ans=0;
    for(int i=0;i<K;i++)ans+=lis[i];
    cout<<ans<<endl;
    return 0;
}


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

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

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

  ll a, b; cin >> a >> b;
  if(a*b <= 0) {
    cout << "Zero" << '\n';
    return 0;
  }

  int cntMinus = 0;
  for(int i = a; i <= b; i++) {
    if(i < 0) cntMinus++;
  }

  cout << (cntMinus&1 ? "Negative" : "Positive") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	long long int a,l=0,x=0;
	cin>>a;
	string s="";
	while(1)
	{
		if(l>0)
			a/=26;
		x=a%26;
		if(x!=0)
			s+=char(x-1+'a');
		else
			s+='z', a-=26;
		a-=x;
		//cout<<a<<' '<<x<<"\n";
		l++;
		if(a<=0)
			break;
	}
	reverse(s.begin(),s.end());
	cout<<s;
		
	
	return 0; 	
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
	ll n,m;
	cin>>n>>m;
	priority_queue<ll> pq;
	rep(i,0,n){
		ll a;
		cin>>a;
		pq.push(a);
	}
	rep(i,0,m){
		ll a = pq.top();
		pq.pop();
		a/=2;
		pq.push(a);
	}
	ll ans = 0;
	rep(i,0,n){
		ll a = pq.top();
		pq.pop();
		ans += a;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	string s;
	cin >> s;
	map<char, int> m;
	for(char z: s){
		if(m.find(z) != m.end()){
			cout << "no";
			exit(0);
		}
		m[z] = 1;
	}
	cout << "yes";
	

}


Measured memory_bytes: 256
#include<stdio.h>
int main() {
    int n, i, j, flag;
    scanf("%d", &n);
    for(i = n; ; ++i) {
        flag = 1;
        for(j = 2; j < i; ++j) {
            if(i % j == 0) flag = 0;
        }
        if(flag) return printf("%d\n", i), 0;
    }
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace MyProgram
{
    public class Program
    {	
        public static void Main(string[] args)
        {
            string s = Console.ReadLine();
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            
            for(int i = 0 ; i < s.Length ; i++)
            {
                if((i+1) % 2 == 1)
                {
                    sb.Append(s[i]);
                }
            }
            Console.WriteLine(sb);
        }
    }
}

Measured memory_bytes: 11616
import java.util.Scanner;
public class Main{
    public static void  main(String[] args) {
        Scanner sc = new Scanner(System.in); 
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a*b;
        int length = 2*a+2*b;
        System.out.println(area + " " +length);
        sc.close();
    }
}


Measured memory_bytes: 26144
//In The Name of Beauty
//...So here I go is my shot
//Feet fail me not 'cause maybe the only opportunity that I got...
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 1e5 + 8;
ll const INF  = 1e12 + 8;
ll const delta = 1000000007;
ll a[MAXN];
ll par[MAXN];
ll sz[MAXN];
ll sum[MAXN];
ll q[MAXN];
ll getpar(ll v)
{
    if(par[v] == v)return v;
    return (par[v] = getpar(par[v]));
}
void mergee(ll v,ll u)
{
    v = getpar(v);
    u = getpar(u);
    if(v == u)return;
    if(sz[u] > sz[v])swap(v,u);
    sz[v] += sz[u];
    par[u] = v;
    sum[v] += sum[u];
    q[v] += q[u];
}
int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m;
    cin >> n >> m;
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
        sum[i] = a[i];
        par[i] = i;
        sz[i] = 1;
    }
    ll temp = 0;
    ll f , s , w;
    vector<pair<ll,pll> > edges;
    for(ll i = 0;i < m;i++)
    {
        cin >> f >> s >> w;
        edges.pb(mp(w,mp(f,s)));
    }
    sort(edges.begin(),edges.end());
    for(ll i = 0;i < m;i++)
    {
        ll v = edges[i].S.F;
        ll u = edges[i].S.S;
        w = edges[i].F;
        mergee(v,u);
        ll x = getpar(v);
        if(sum[x] >= w)
        {
            temp += (q[x] + 1);
            q[x] = 0;
        }
        else
        {
            q[x]++;
        }
    }
    cout << m - temp;
    return 0;
}
//Written by M_H_H_7


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

using namespace std;

int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    stack<char> a;
    a.push(s[0]);
    for(int i = 1; i < n; i++){
        if(a.top() != s[i]){
            a.push(s[i]);
        }
    }
    cout << a.size() << endl;
    return 0;
}

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

using namespace std;
#define inf 1e18
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<ll> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 402;

ll dp[maxn][maxn];

ll a[maxn];
ll pref[maxn];

ll price(int depan, int belakang) {
	if(depan > belakang){return 0;}
	return pref[belakang] - pref[depan-1];
}

ll solve(int depan, int belakang) {
	// printf("depan: %d belakang: %d\n",depan, belakang);
	if(depan >= belakang) {
		// printf("sekarang depan: %d belakang: %d\n",depan, belakang);	
		return 0;
	}
	if(dp[depan][belakang] != -1){return dp[depan][belakang];}
	int i,j;
	ll ans = inf;
	for(i=depan;i<belakang;i++){
		// ll ans1 = solve(depan, i-1) + solve(i+1, belakang) + price(depan, belakang);
		ll ans2 = solve(depan, i) + solve(i+1, belakang) + price(depan, i) + price(i+1, belakang);
		ans = min(ans, ans2);
	}
	for(i=depan+1;i<=belakang;i++){
		// ll ans1 = solve(depan, i-1) + solve(i+1, belakang) + price(depan, belakang);
		ll ans2 = solve(depan, i-1) + solve(i, belakang) + price(depan, i-1) + price(i, belakang);
		ans = min(ans, ans2);
	}
	return dp[depan][belakang] = ans;
}

void min_self(ll &a, ll b){
	a = min(a,b);
}

int main(){
	int n,i,j;
	
	scanf("%d",&n);
	
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		pref[i] = a[i];
		pref[i] += pref[i-1];
	}
	// memset(dp, -1, sizeof dp);
	for(i=1;i<=n;i++){
		for(j=1;j<=n-i;j++){
			int depan = j, belakang = j+i;
			dp[depan][belakang] = inf;
			for(int k=depan;k<belakang;k++){
				min_self(dp[depan][belakang], price(depan, k) + price(k+1, belakang) + dp[depan][k] + dp[k+1][belakang]);
				// printf("sekarang k: %d dp[%d][%d]: %lld, price: %lld %lld\n",k, depan, belakang, dp[depan][belakang], price(depan, k), price(k+1, belakang));	
			}
			// printf("dp[%d][%d]: %lld\n",depan, belakang, dp[depan][belakang]);
		}
	}
	printf("%lld\n",dp[1][n]);
	return 0;
};

Measured memory_bytes: 1536
#!/usr/bin/env python3
import sys
from random import randint

def main():
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())   
    
    class RollingHash:
        def __init__(self, s):
            self.s = s    # パターン探索を行われる側の文字列
            self.size = len(s)
            self.hashmod = 2 ** 64 - 1
            self.base = randint(2 ** 10, 2 ** 11)
            self.hash_list = self._make_rolling_hash_list()

        def _make_rolling_hash_list(self):
            hash_list = [0] * (self.size + 1)    # [h(s[0:0]), h(s[0:1]), h(s[0:2]), h(s[0:3]), ..., h(s[0:size])]
            prev = 0
            for i in range(1, self.size + 1):
                hash_num = (prev * self.base + ord(self.s[i-1])) % self.hashmod
                hash_list[i] = hash_num
                prev = hash_num
            return hash_list
        
        def calc_interval_hash(self, i, j):
            """
            s[i:j] のハッシュを計算
            """
            return (self.hash_list[j] - self.hash_list[i] * pow(self.base, (j - i), self.hashmod)) % self.hashmod

    
    def span_bisect(rolling):
        left = 1    # 絶対に発見成功するとわかっている
        right = (n // 2) + 1    # 絶対に発見失敗するとわかっている
        while right - left > 1:
            d = dict()
            mid_span = left + (right - left) // 2    # 二分探索で今回選ばれた span
            for i in range(n - mid_span + 1):
                j = i + mid_span
                h = rolling.calc_interval_hash(i, j)
                try:
                    first_j = d[h]
                    if first_j <= i:
                        left = mid_span
                        break
                except KeyError:
                    d[h] = j
            else:
                right = mid_span
        return left


    n = ii()
    s = input()
    if len(list(set(list(s)))) == n:
        print(0)
    else:
        # main
        rolling = RollingHash(s)
        print(span_bisect(rolling))


if __name__ == "__main__":
    main()

Measured memory_bytes: 48288
n,m=map(int,input().split())
X=[[int(i) for i in input().split()] for j in range(n)]
X.sort(key=lambda X:X[0])
ans_sum=0
for i in range(n):
        for j in range(X[i][1]):
                m-=1
                ans_sum+=X[i][0]
                if m==0:
                        break
        if m==0:
                break
print(ans_sum)


Measured memory_bytes: 22800
#include <stdio.h>

int main(void)
{
	int i;
	int s;
	int h1, m1, s1;
	int h2, m2, s2;
	
	for (i = 0; i < 3; i++){
		scanf("%d %d %d %d %d %d", &h1, &m1, &s1, &h2, &m2, &s2);
		
		s = (h2 - h1) * 3600 + (m2 - m1) * 60 + (s2 - s1);
		
		printf("%d %d %d\n", s / 3600, (s % 3600) / 60, (s % 3600) % 60);
	}
	
	return (0);
}

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

using namespace std;

#define LL long long
const int MAXN = (int)2e5+10;

int arr[MAXN];

int main() {
    string s;
    cin >> s;
    int k = 0, kk = 0;
    for(int i = 0; i < s.size(); ++i)
        if(s[i] == '-')
            k++;
        else
            kk++;
    cout << kk-k << endl;
    return 0;
}

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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) (in).begin(),(in).end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
  int m,d;
  cin >> m >> d;
  int ans=0;
  for(int i=1;i<=m;i++){
    for(int j=22;j<=d;j++){
      if(j%10<2)continue;
      if((j/10)*(j%10) == i)ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
bool vcom(pair<ll,pair<ll,ll>> a,pair<ll,pair<ll,ll>> b){
  if(a.second.first!=b.second.first) return a.second.first<b.second.first;
  else return a.second.second<b.second.second;
}

int main(){
  ll N,M;
  cin>>N>>M;
  vector<pair<ll,pair<ll,ll>>> v(M);
  for(ll i=0;i<M;i++){
    v[i].first=i;
    cin>>v[i].second.first>>v[i].second.second;
  }
  sort(v.begin(),v.end(),vcom);
  bool f=true;
  for(ll i=0;i<M;i++){
    if(f){
      v[i].second.second=1;
      f=false;
    }else v[i].second.second=v[i-1].second.second+1;
    if(v[i].second.first!=v[i+1].second.first) f=true;
  }
  sort(v.begin(),v.end());
  for(ll i=0;i<M;i++){
    printf("%06lld%06lld\n",v[i].second.first,v[i].second.second);
  }
}


Measured memory_bytes: 3840
import bisect
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)

n = int(input())
a = list(map(int, input().split()))
edges = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = map(int, input().split())
    edges[u-1].append(v-1)
    edges[v-1].append(u-1)

inf = 10 ** 10
d = [inf for _ in range(n)]
dp = [inf for _ in range(n)]

def dfs(cur, prev):
    memo = bisect.bisect_left(dp, a[cur])
    memo_v = dp[memo]
    dp[memo] = a[cur]
    d[cur] = bisect.bisect_left(dp, inf)

    for to in edges[cur]:
        if to != prev:
            dfs(to, cur)

    dp[memo] = memo_v

dfs(0, -1)
for i in range(n):
    print(d[i])


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

int main () {
  float a, b;
  cin >> a >> b;
  float x = (a + b) / 2;
  if (int(x * 10) % 10 != 0) cout << int(x+1) << endl;
  else cout << int(x) << endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
a = input()
box = []
for i in range(w):
    if a[i] == ".":
        box.append(i)

if "#" in a:
    pages = [a]
else:
    pages = []

for i in range(h-1):
    a = input()
    if "#" in a:
        pages.append(a)
    else:
        continue
    for j in box:
        if a[j] != ".":
            box.remove(j)

box.reverse()
for i in range(len(pages)):
    for j in box:
        pages[i] = pages[i][:j] + pages[i][j+1:]

    print(pages[i])


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

void dfs(vector<int> & as, vector<vector<int>> & edge, vector<bool> & iss, vector<int>& dp, vector<int> & ans, int n, int p, int cur)
{
	auto it = std::lower_bound(dp.begin(), dp.end(), as[p]);
	int v = (it - dp.begin());
	int pre = dp[v];
	if (as[p] < dp[v]) {
		dp[v] = as[p];
	}
	cur = max(cur, v);
	ans[p] = cur;
	iss[p] = true;

	for (auto b : edge[p]) {
		if (iss[b]) continue;
		dfs(as, edge, iss, dp, ans, n, b, cur);
	}

	dp[v] = pre;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);
	
	int n; cin >> n;
	vector<int> as(n + 1);
	FOR_LE(i, 1, n) {
		cin >> as[i];
	}
	vector<int> dp(n + 1);
	FOR_LE(i, 1, n) {
		dp[i] = INT_MAX / 2;
	}
	dp[0] = -1;

	vector<vector<int>> edge(n + 1);
	REP(n - 1) {
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	vector<bool> iss(n + 1);
	vector<int> ans(n + 1);
	dfs(as, edge, iss, dp, ans, n, 1, 0);

	FOR_LE(i, 1, n) {
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 39436
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

	Scanner sc = new Scanner(System.in);

	String c1 = sc.next();
	String c2 = sc.next();
	String c3 = sc.next();

	System.out.println(c1.substring(0,1) + c2.substring(1,2) + c3.substring(2,3));
	}
}

Measured memory_bytes: 19796
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	int x = stoi(s + t); // s+iでsとtを連結しそれをstoi関数で整数に変換

	for (int i = 1; i <= 1000; i++) {
		if (i * i == x) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}

Measured memory_bytes: 3616
<?php

while ($stdin = fgets(STDIN)) {
    $line[] = trim($stdin);
}
foreach ($line as $key => $value) {
    $data[] = explode(' ', $value);
}

//foreach ($data as &$line) {
//    $line = array_map(function($val) { return (int)$val; }, $line);
//}

$S = (string)$data[0][0];
$len = strlen($S);

$secure = true;
for ($i = 0;$i < $len - 1; $i++) {
   if (substr($S, $i, 1) === substr($S, $i + 1, 1)) {
        $secure = false;
   }
}

$ans = $secure ? 'Good' : 'Bad';

printf('%s', $ans);



Measured memory_bytes: 4984
N, W = map(int, input().split())
items = []
INF = 10**12
for _ in range(N):
    items.append(tuple(map(int, input().split())))
MAX_V = sum([v for _, v in items])
dp = [[INF for j in range(MAX_V+1)] for i in range(N+1)]
dp[0][0] = 0
for i in range(1, N+1):
    w, v = items[i-1]
    for j in range(MAX_V+1):
        if j - v >= 0:
            dp[i][j] = min(dp[i-1][j-v] + w, dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]
for v in range(MAX_V, -1, -1):
    if dp[N][v] <= W:
        break
print(v)

Measured memory_bytes: 171120