akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1000000001;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    ll ans=1;
    unordered_map<ll,ll> mp;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            ll m=n;
            while(m%i==0)m/=i;
            if(m%i==1){
                ans++;
                mp[i]=1;
            }
            if(i*i<n){
                ll u=n/i;
                ll mm=n;
                while(mm%u==0)mm/=u;
                if(mm%u==1){
                    ans++;
                    mp[u]=1;
                }
            }
        }
    }
    n--;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            if(mp[i]==0)ans++;
            if(i*i<n&&mp[n/i]==0)ans++;
        }
    }
    if(n>=2)ans++;
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


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

	ll n;
	cin >> n;
	Array p(n,0), q(n,0);
	REP(i, n)cin >> p[i];
	REP(i, n)cin >> q[i];
	
	Array order;
	REP(i, n) order.push_back(i + 1);


	ll a = -1;
	ll b = -1;
	ll num = 1;
	do {
		if (p == order) a = num;
		if (q == order) b = num;
		num++;
	} while (next_permutation(all(order)));

	cout << abs(a - b) << endl;

	return 0;
}

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

int main() {
  int N;
  scanf("%d", &N);
  int x[N],y[N],h[N];
  tuple<int,int,int>G;
  for (int i = 0; i < N; ++i) {
    cin >> x[i] >> y[i] >> h[i];
    if (h[i] >= 1) G = make_tuple(x[i], y[i], h[i]);
  }

  int ansi,ansj,ansh;
  vector<tuple<int,int,int>>vec;

  for (int i = 0; i < 101; ++i){
    for (int j = 0; j < 101; ++j){
      int height = max(get<2>(G) + abs(get<0>(G)-i) + abs(get<1>(G)-j),0);
      bool flag = true;
      for (int k = 0; k < N; ++k){
        int test = max(height - abs(x[k]-i) - abs(y[k]-j),0);
        if(h[k] != test) flag = false;
      }
      if (flag) {
          ansi =i;
          ansj = j;
          ansh = height;
      }
    }
  }

  cout << ansi << " " << ansj << " " << ansh << endl;

}



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

using namespace std;

int main (){
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);

    int sum = 0;
    string s;

    cin >> s;

    for (int i = 0; i < (int) s.size() - 1; i++){
        if (s[i] != s[i + 1]){
            sum ++;
        }
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a, b, c;
cin >> a >> b >> c;
((b*10 + c)%4 == 0) ? cout << "YES\n" : cout << "NO\n";
return 0;
}


Measured memory_bytes: 256
/* ITP1_2_B: Range*/

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main(void){
	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if(a < b && b < c && a < c){
		puts("Yes");
	}else{
		puts("No");
	}

	return 0;
}


Measured memory_bytes: 1964
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mod 1000000007

vector<int> arr;

map<int, int> mp;

int dp(int pos, int n)
{
    if(mp.find(pos)!=mp.end())
        return mp[pos];
    if(pos==n)
        return mp[pos]=0;
    if(pos>n)
        return mp[pos]=100000000000;
    return mp[pos]=min(abs(arr[pos]-arr[pos+1])+dp(pos+1, n), abs(arr[pos]-arr[pos+2])+dp(pos+2, n));
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    arr.resize(n+5);
    for(int i=0; i<n; i++)
        cin>>arr[i];
    cout<<dp(0, n-1);
    return 0;
}

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

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  for(int i=1;i<n;i++){
    int x,y;
    cin>>x>>y;
    if(x>a){
      a=x; b=y;
    }
  }
  cout<<a+b<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = 0;
		int[] a = new int[n];
		for(int i = 0;i < n;i++)
		{
		a[i] = sc.nextInt();
		if(i > 0)
		{
		    if(a[i] == a[i - 1])
		    {
		    a[i] = -1;
		    l++;
		    }
		}
		}
		System.out.println(l);
	}
}

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

        int main() {
            int N;
            cin>>N;
            string S;
            cin>> S; 
            int C=0; 

          
          for(int i=1; i<N; i++){
                if(S.at(i-1)==S.at(i)) C++;  
          }

          cout<< N-C <<endl;

        }

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){

  int sum = 0, x, total, ans;
  vector<int> p1(0);
  vector<int> p2(0);
  int n;
  
    while(1){
      cin >> n;
      if(n==0)
      break;
      for(int i=0; i<n; i++){
        cin >> x;
        p1.push_back(x);
      }

      int max = *max_element(p1.begin(), p1.end());
      int min = *min_element(p1.begin(), p1.end());

      for(int i=0; i<n; i++){
        sum += p1[i];
      }
      total = sum - min - max;
      ans = total / (n-2);
      cout << ans << endl;
      p1 = p2;
      sum = 0;
      total = 0;
      ans = 0;
    }

  return 0;
}

Measured memory_bytes: 3156
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d, suma = 0, sumb = 0;
	cin >> a >> b >> c >> d;
	suma = a + b + c + d;
	cin >> a >> b >> c >> d;
	sumb = a + b + c + d;
	if (suma > sumb) cout << suma << endl;
	else cout << sumb << endl;
}

Measured memory_bytes: 3112
#ABC089C
import numpy as np
N=int(input())
M=['M','A','R','C','H']
C=[0,0,0,0,0]
for _ in range(N):
	x=input()
	for i in range(5):
		if x[0]==M[i]:
			C[i]+=1
ans=0
for a in range(3):
	for b in range(a+1,4):
		for c in range(b+1,5):
			ans+=C[a]*C[b]*C[c]
print(ans)

Measured memory_bytes: 12392
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;

void solve() {
	int n;
	cin >> n; 
	int arr[n];
	ll sum = 0;
	for(int i = 0; i < n; ++i) cin >> arr[i], sum += arr[i];
	int m; 
	cin >> m;
	for(int i = 0; i < m; ++i) {
		int pos, val;
		cin >> pos >> val;
		--pos;
		if(val > arr[pos]) cout << sum + (val - arr[pos]) << endl;
		else cout << sum - (arr[pos] - val) << endl;
		}
}

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	solve();
	return 0;
	}


Measured memory_bytes: 3652
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

signed main() {
	int H, N; cin >> H >> N;
	vector<pair<int, int>> ab(N);
	for (int i = 0; i < N; ++i)
		cin >> ab[i].first >> ab[i].second;
	ll* dp = new ll[H + 10000];
	dp[0] = 0;
	for (int i = 1; i < H + 10000; ++i)
		dp[i] = 10000000000LL; // inf
	for (int j = 1; j < H + 10000; ++j) {
		for (int i = 0; i < N; ++i) {
			if (ab[i].first > j) continue;
			dp[j] = min(dp[j], dp[j - ab[i].first] + ab[i].second);
		}
	}
	ll res = 10000000000LL;
	for (int j = H; j < H + 10000; ++j)
		res = min(res, dp[j]);
	cout << res << endl;
	return 0;
}

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

map<long long, int> prime_factor(long long n) {
    map<long long, int> ret;
    for (long long i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

int main() {
    long long N;
    cin >> N;
    auto P = prime_factor(N);
    long long res = 0;
    for (auto data : P) {
        //cout << data.first << " : " << data.second << " : ";
        int X = data.second;
        int plus = 0;
        int sub = 1;
        while (true) {
            if (X - sub == 0) {
                ++plus;
                X -= sub;
                ++sub;
                continue;
            }
            if (X - sub > 0) {
                if (X - sub < sub + 1) {
                    ++plus;
                    break;
                } else {
                    ++plus;
                    X -= sub;
                    ++sub;
                    continue;
                }
            }
            if (X - sub < 0) {
                break;
            }
        }
        //cout << plus << endl;
        res += plus;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<vector>

using namespace std;

const int MX = 100005;

int N;

int main()
{
	string A;
	cin >> A;
	string B = "AKIHABARA";

	int cnt = 0;
	for(char c : A){
		if( cnt >= B.size()) return !printf("NO\n");
		if( c == B[cnt]) cnt++;
		else if( B[cnt] == 'A' ){
			cnt++;
			if( c == B[cnt]) cnt++;
			else return !printf("NO\n");
		}
		else return !printf("NO\n");
	}
	while(cnt < B.size() && B[cnt] == 'A') cnt++;
	if( cnt == B.size() ) printf("YES\n");
	else printf("NO\n");
}


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

int main(void){
    int n, T;
    cin>>n>>T;
    int res = INF;
    rep(i,n){
        int c,t;
        cin>>c>>t;
        if(t<=T){
            res = min(res,c);
        }
    }
    if(res==INF){
        cout<<"TLE"<<endl;
    }else{
        cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
ans = 0
for n in range(1000):
    num = "0"*(3-len(str(n))) + str(n)
    index = 0
    can_set = False
    for i in range(N):
        if S[i] == num[index]:
            if index == 2:
                can_set = True
                break
            index += 1
    if can_set:
        ans += 1
print(ans)

Measured memory_bytes: 41180
n = gets.to_i
s = gets.chomp
cnt = 0
(?0..?9).each do |a|
  i = s.index a, 0
  next unless i
  (?0..?9).each do |b|
    j = s.index b, i+1
    next unless j
    (?0..?9).each do |c|
      k = s.index c, j+1
      cnt += 1 if k
    end
  end
end
p cnt

Measured memory_bytes: 14412
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, K, X, Y;
	int sum=0;
	cin >> N >> K >> X >> Y;
	for (int i = 1; i <= N; i++)
	{
		if (i <= K) {
			sum += X;
		}
		else
		{
			sum += Y;
		}
		
	}
	cout << sum << endl;


}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
   public static void main(String[] args){
     Scanner scanner = new Scanner(System.in);
     for(int i=1;i>0; i++){
          String c0 ="?";
          String c1 ="+";
          String c2 ="-";
          String c3 ="*";
          String c4 ="/";
          int a = scanner.nextInt();
          String op = scanner.next();
          int b = scanner.nextInt();
          if(op.equals(c0))break;
          if(op.equals(c1)){
              int e1=a+b;
              System.out.println(e1);
          }
          else if(op.equals(c2)){
              int e2=a-b;
              System.out.println(e2);
          }
          else if(op.equals(c3)){
              int e3=a*b;
              System.out.println(e3);
          }
          else if(op.equals(c4)){
              int e4=a/b;
              System.out.println(e4);
          }
     }     
}
}

Measured memory_bytes: 26380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010

/*
道路と鉄道、両方でつながっている街の数を求める
道路と鉄道のUnionFind木を二つ作ってあげて
そのグループの番号(根の番号)のペアの種類で場合分け
してあげる
*/

int par[MAX_N];//親の番号
int siz[MAX_N];//木のサイズ
int par1[MAX_N];//親の番号
int siz1[MAX_N];//木のサイズ
//int rnk[MAX_N];

void init(int n)
{
  //根の定義・・・par[i]=iの時iを根という
  //最初全てが根
  for (int i=0;i<=n;i++){
    par[i]=i;
    siz[i]=1;
  }
}

void init1(int n)
{
  for (int i=0;i<=n;i++){
    par1[i]=i;
    siz1[i]=1;
  }
}

//木の根を求める
int root(int x){
  if (par[x]==x){  //xが根の時
    return (x); 
  }else{
    par[x]=root(par[x]);//xを、xの親の根につなぎ直す
    return par[x]; //経路圧縮
  }
}

int root1(int x){
  if (par1[x]==x){  //xが根の時
    return (x); 
  }else{
    par1[x]=root1(par1[x]);//xを、xの親の根につなぎ直す
    return par1[x]; //経路圧縮
  }
}

//x,yが同じ集合に属しているか、つまり同じ根に繋がっているか
bool same(int x,int y){
  return ( root(x)==root(y) );
}
bool same1(int x,int y){
  return ( root1(x)==root1(y) );
}

//x,yの属する集合を合併する
bool merge(int x, int y) {
   x = root(x); y = root(y);
   if (x == y) return false;
   if (siz[x] < siz[y]) swap(x, y);
   siz[x]+=siz[y];
   par[y] = x; //ランクが大きい方に小さい方を繋げる
   return true;
}

bool merge1(int x, int y) {
   x = root1(x); y = root1(y);
   if (x == y) return false;
   if (siz1[x] < siz1[y]) swap(x, y);
   siz1[x]+=siz1[y];
   par1[y] = x; //ランクが大きい方に小さい方を繋げる
   return true;
}

int treesize(int x)
{
  return (siz[root(x)]); 
}

int main()
{
  int N,K,L;cin>>N>>K>>L;
  init(N);init1(N);
  for (int i=1;i<=K;i++)
  {
    int a,b;cin>>a>>b;
    merge(a,b);
  }
  for (int i=1;i<=L;i++)
  {
    int a,b;cin>>a>>b;
    merge1(a,b);
  }
  
  //ここでi,jでforを二回回してしまうとTLE
  //mapを使ってペアを数えてあげる？？？
  map<P,int> m;
  for (int i=1;i<=N;i++)
  {
    pair<int,int> p=make_pair(root(i),root1(i));
    m[p]++;
  }
  
  int count=0;
  for (int i=1;i<=N;i++)
  {
    pair<int,int> q=make_pair(root(i),root1(i));
    cout<<m[q]<<" "; 
  }
  
}


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


int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int a, b, c, k;
    cin>>a>>b>>c>>k;
    int ans = 0;
    if (k<a){
        ans = k;
    }
    else if (k>=a and k<=a+b){
        ans = a;
    }
    else if (k>a+b){
        ans = a-(k-(a+b));
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
	int n, y;
	cin >> n >> y;
	for (int i = 0; i <= n; i++){
		for (int j = 0; j <= n; j++){
			int tmp = y-10000*i-5000*j;
			if (tmp >= 0 and i+j+tmp/1000 == n){
				cout << i << " " << j << " " << n-i-j << endl;
				return 0;
			}
		}
	}

	cout << -1 << " " << -1 << " " << -1 << endl;
}


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

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

    int num_1 = stoi(S.substr(0, 2));
    int num_2 = stoi(S.substr(2, 2));

    if (num_1 <= 12 && num_1 > 0 && num_2 <= 12 && num_2 > 0)
        cout << "AMBIGUOUS" << endl;
    else if (num_1 <= 12 && num_1 > 0)
        cout << "MMYY" << endl;
    else if (num_2 <= 12 && num_2 > 0)
        cout << "YYMM" << endl;
    else
        cout << "NA" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define INF 1e9

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

    int H, W;
    scanf("%d%d", &H, &W);

    int x[510][510];
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            scanf("%d", &x[i][j]);
        }
    }

    int num = 0;
    int ans[300000][5];
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W-1; j++) {
            if (x[i][j] % 2 == 1) {
                x[i][j+1]++;
                num++;
                ans[num][1] = i;
                ans[num][2] = j;
                ans[num][3] = i;
                ans[num][4] = j+1;
            }
        }
    }

    for (int i = 1; i <= H-1; i++) {
        if (x[i][W]%2 == 1) {
            x[i+1][W]++;
            num++;
            ans[num][1] = i;
            ans[num][2] = W;
            ans[num][3] = i+1;
            ans[num][4] = W;
        }
    }

    cout << num << endl;
	for(int i=1;i<=num;i++) cout<<ans[i][1]<<" "<<ans[i][2]<<" "<<ans[i][3]<<" "<<ans[i][4]<<"\n";
	return 0;
}

Measured memory_bytes: 7424
#include <set>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 200100;
const int MOD = (int) 1e9 + 7;

int n;
char s[N];

long long fact(int n) {
	long long ret = 1;
	for (int i = 1; i <= n; i++) {
		ret = ret * i % MOD;
	}
	return ret;
}

int main() {

	scanf("%d %s", &n, s);

	int cnt = 0;
	long long res = 1;

	for (int i = 0; i < 2 * n; i++) {
		int k = cnt % 2;
		k ^= ((s[i] == 'B') ? 1 : 0);
		if (k == 1) {
			cnt++;
		} else if (cnt > 0) {
			res *= cnt;
			res %= MOD;
			cnt--;
		} else {
			puts("0");
			exit(0);
		}
	}

	if (cnt > 0) {
		puts("0");
		exit(0);
	}

	printf("%lld\n", res * fact(n) % MOD);

	return 0;

}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    val steps
            = readLine()!!.split(" ").map(String::toInt)
    val dp = listOf(0).toMutableList()
    for ((i, v) in steps.withIndex()) {
        if (i < 1) {
            continue
        }
        val costs = listOf<Int>().toMutableList()
        for (j in 1..k) {
            costs.add(
                if (i < j) Int.MAX_VALUE else (Math.abs(v - steps[i-j]) + dp[i-j])
            )
        }
        val bestMove = costs.min() ?: Int.MAX_VALUE
        dp.add(bestMove)
    }
    println(dp.last())
}

Measured memory_bytes: 120000
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	int n, t;
	cin >> n >> t;
	vector<pair<int, int>> c(n);
	rep(i, 0, n) cin >> c[i].first >> c[i].second;

	int ans = 1001;
	rep(i, 0, n) {
		if (c[i].second <= t) {
			ans = min(ans, c[i].first);
		}
	}

	if (ans == 1001) cout << "TLE" << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
c1,c2=a1-b1,a2-b2
if t1*c1+t2*c2==0:
  print('infinity')
else:
  # t1+t2でどれだけ二人が離れるか。
  d=t1*c1+t2*c2
  if c2*d<0:
    print(0)
  elif abs(t2*c2)<abs(d):
    print(0)
  else:
    tmp=((t2*c2)//d)
    if (t2*c2)%d==0:
      print(2*tmp-2)
    else:
      print(2*tmp-1)


Measured memory_bytes: 9116
/* 160 */

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

int main()
{
    int f=1;
    string s;
    cin>>s;
    if(s[2]==s[3])
    {
        if(s[4]==s[5]) 
        {
            cout<<"Yes"<<endl;
            f=0;
        }
    }
    if(f) cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int n,a,x=0,z=0;
    cin>>n;
    vector<int> A,B,ans;
    rep(i,n) cin>>a,A.push_back(a),B.push_back(a);
    rep(i,n) if(A[i]>i+1) x=1;
  if(x) cout<<-1;
  else{
    while(z<n){
        for(int i=A.size()-1;i>=0;i--){
            if(A[i]==1){
                z++;
                ans.push_back(i);
                for(int j=i;j<A.size();j++) A[j]--;
                break;
            }
        }
    }
    rep(i,n) cout<<B[ans[i]]<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
  //printf("%d %d %d",a,b,c);

    if(a==b && a!=c){
        puts("Yes");
        return 0;
    }
    if(a==c && a!=b){
        puts("Yes");
        return 0;
    }
    if(c==b && a!=c){
        puts("Yes");
        return 0;
    }

    puts("No");
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
s = sum(A)
from collections import defaultdict
d = defaultdict(int)
for a in A:
    d[a] += 1
for _ in range(Q):
    b, c = [int(x) for x in input().split()]
    delta = c * (d[b]) - b * d[b]
    s += delta
    print(s)
    d[c] += d[b]    
    d[b] = 0


Measured memory_bytes: 94040
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#define INF 100000000
using namespace std;
int main(void){
  long N;
  long trans1[5],trans2[5];
  cin>>N;
  for(int i=0;i<5;i++){
      cin>>trans1[i];
      if(N%trans1[i]!=0){trans2[i]=N/trans1[i]+1;}
      else trans2[i]=N/trans1[i];
  }
  sort(trans2,trans2+5);
  cout<<trans2[4]+4;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[102][100005];         // dp[x][y][a][b], using (x and y) to get b from a
int a[100005];
int N;
int mod=int(1e9)+7;
ll fun(int k){
    for(int i=0;i<=k;i++){
        if(i<=a[0]){
            dp[0][i]=(i-1>=0?dp[0][i-1]:0)+1;
           // cout<<"h1"<<i;
        }
        else dp[0][i]=dp[0][i-1];
        //cout<<dp[0][i]<<" ";
        //cout<<
    }
    //cout<<endl;
    for(int i=1;i<N;i++){
        for(int j=0;j<=k;j++){
            dp[i][j]=((j-1>=0?dp[i][j-1]:0)+dp[i-1][j]-(j-a[i]-1>=0?dp[i-1][j-a[i]-1]:0)+mod)%mod;
           // cout<<dp[i][j]<<" ";
        }
      //  cout<<endl;
    }
    if(N-2>=0) return (dp[N-2][k]-(k-a[N-1]-1>=0?dp[N-2][k-a[N-1]-1]:0)+mod)%mod;
    if(a[0]==k) return 1;
    
    return 0;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin>>N>>k;
    for(int i=0;i<N;i++) cin>>a[i];
    cout<<fun(k)<<"\n";
}

Measured memory_bytes: 79744
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, x, ans = 0, now = 0;
    cin >> n >> x;
    vector<int> l(n);
    rep(i, n){
        if(now <= x)ans++;
        cin >> l.at(i);
        now += l.at(i);
    }
    if(now <= x)ans++;
    cout << ans << endl;
}


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

int main(void) {
	int i;
	int a, b;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	a = atoi(ch);
	ch = strtok(NULL, " ");
	b = atoi(ch);

	printf("%d\n", (a + b) % 24);

	return 0;
}


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

int main(){
    int n, m;
    std::cin >> n >> m;

    int lPrev= 0, l, rPrev = 1000000, r;
    for(int i = 0; i < m; ++i){
        std::cin >> l >> r;
        l = std::max(lPrev, l);
        r = std::min(rPrev, r);
        lPrev = l;
        rPrev = r;
    }

    std::cout << std::max(0, r - l + 1) << std::endl;

    return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int N;
	cin >> N;
	
	for_(i,0,N) {
		int x, y, b, p;
		cin >> x >> y >> b >> p;
		
		int ans = int(1e9);
		
		for_(bi,b,100) {
			for_(pi,p,100) {
				if (bi >= 5 && pi >= 2) ans = min(ans, x * bi * 4 / 5 + y * pi * 4 / 5);
				else ans = min(ans, x * bi + y * pi);
			}
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

void printRectangle(int height, int width) {
    for (int row = 0; row < height; ++row) {
        bool isHash = (row % 2 == 0) ? true : false;

        string line;
        for (int column = 0; column < width; ++column) {
            line += (isHash) ? "#" : ".";
            isHash = !isHash;
        }

        cout << line << endl;
    }

    cout << endl;
}

int main() {
    while (true) {
        int height, width;
        cin >> height >> width;

        if (height == 0 && width == 0) break;

        printRectangle(height, width);
    }

    return 0;
}

Measured memory_bytes: 3136
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();

		int K = Integer.parseInt(sc.next());
		String S = sc.next();

		if(S.length() <= K) {
			System.out.print(S);
		} else {
			System.out.print(S.substring(0,K) + "...");
		}
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
}

Measured memory_bytes: 36088
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define prin(num) cout << num << endl;
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;
typedef map<ll, ll> Map;

int main(void) {
    ll N, W, i, j, k, l;
    ll w1=0, w, v;
    ll sum[4][110]={0};
    cin >> N >> W;
    vector<ll> vec[4];
    
    for(i=0; i<N; i++) {
        cin >> w >> v;
        if(i==0) w1=w;
        vec[w-w1].push_back(v);
    }
    
    for(i=0; i<4; i++) sort(vec[i].rbegin(), vec[i].rend());
    for(i=0; i<4; i++) {
        for(j=0; j<vec[i].size(); j++) {
            sum[i][j+1]=sum[i][j]+vec[i][j];
        }
    }
    
    ll max=0;
    for(i=0; i<vec[0].size()+1; i++) {
        for(j=0; j<vec[1].size()+1; j++) {
            for(k=0; k<vec[2].size()+1; k++) {
                for(l=0; l<vec[3].size()+1; l++) {
                    ll pos=i*w1+j*(w1+1)+k*(w1+2)+l*(w1+3);
                    ll v=sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l];
                    if(pos<=W) max=max(max, v);
                }
            }
        }
    }
    
    prin(max)
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
#define mod 998244353
#define N 200010
using namespace std;
int a[N],head[N],tot,n,d[N],mx[N],ans;
struct A
{
    int next;
    int to;
} s[N*2];
void add(int u,int v)
{
    tot++;
    s[tot].to=v;
    s[tot].next=head[u];
    head[u]=tot;
}
void dfs(int u,int fa)
{
    int b,v,save,flag,l,r,mid;
    for(b=head[u]; b; b=s[b].next)
    {
        v=s[b].to;
        if(v==fa)
            continue;
        save=ans,flag=0;
        if(d[ans]<a[v])
        {
            d[++ans]=a[v];
        }
        else
        {
            l=0,r=ans;
            while(l+1<r)
            {
                mid=(l+r)/2;
                if(d[mid]<a[v])
                    l=mid;
                else
                    r=mid;//a[st[mid]]>=a[v]

            }
            flag=d[r],d[r]=a[v];
        }
        mx[v]=ans;//记录最大值
        dfs(v,u);
        ans=save;//回溯
        if(flag)
            d[r]=flag;
    }

}
void init()
{
    int i,u,v;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
        scanf("%d",&a[i]);
    for(i=1; i<n; i++)
    {
        scanf("%d%d",&u,&v);
        add(u,v),add(v,u);//无向图
    }
}

int main()
{
    init();
    ans=1,d[1]=a[1],mx[1]=1;//记录根节点数据
    dfs(1,0);
    for(int i=1; i<=n; i++)
        printf("%d\n",mx[i]);

    return 0;
}


Measured memory_bytes: 23552
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (A1, A2, A3) = read!(i64, i64, i64);

    let status = if A1 + A2 + A3 >= 22 { "bust" } else { "win" };

    println!("{}", status)
}


Measured memory_bytes: 4352
if __name__ == '__main__':
    N, M = map(int, input().split())
    PY = []
    for i in range(1, M+1):
        p, y = map(int, input().split())
        PY.append((y, p, i))
    PY.sort()
    ANS = [""]*(M+1)
    P = [0]*(N+1)
    for y, p, i in PY:
        P[p] += 1
        ANS[i] = "{0:06d}".format(p) + "{0:06d}".format(P[p])
    
    for ans in ANS:
        if ans=="": continue
        print(ans)

Measured memory_bytes: 92164
#include<stdio.h>
#include<string.h>
int main()
{
    long long int a,b;
    scanf("%lld %lld",&a,&b);
    long long int k;
    scanf("%lld",&k);
    if(k<a)
        a=a-k;
    else
    {
        k=k-a;
        a=0;
    }
    if(a<=0)
    {if(k<b)
        b=b-k;
    else  b=0;}
    printf("%lld %lld",a,b);

}


Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
#define rep(k,nu)    for(int i=k; i<nu;  i++)
#define rep2(k,n)   for(int j=k; j<n;  j++)
#define INF 1000000000000 //1e+12
#define MOD 10000007 //1e9+7
#define ll long long
#define pb pop_back
template<typename T> inline void chMin(T* a, T* b) {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  divUp(T a, T b)   {return ((a+b-1)/b);}
const double PI = acos(-1);

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

    a.push_back(a[0]+k);
    int l=0;
    rep(0,n)    l = max(l, a[i+1]-a[i]);
    int ans = k-l;
    cout << ans << endl;
    return 0;
}
/*

*/


Measured memory_bytes: 2300
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>
#include <list>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;

const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, -1, 0, 1};


int main()
{
    ios_base::sync_with_stdio(0);    cin.tie(NULL);    cout.tie(NULL);

    int n; cin>>n;
    vi p(n*n);
    for (int & i : p) cin>>i;

    vector<vi> _mp(n, vi(n));

    for (int i=0; i<n*n; ++i){
        int c = p[i]-1;
        _mp[c/n][c%n] = i;
    }
    const vector<vi> mp = _mp;

    vector<vi> ans(n, vi(n, INT_MAX));

//    deque<pii> bfs;



    for (int i=0; i<= n-1; i++){
        for (int j=0; j<=n-1; j ++){
            int a = min(i, j);
            int na = min(n-1-i, n-1-j);
            ans[i][j] = min(a, na) +1;
        }
    }
    int res = 0;
//    vector<vi> dirs({{0,1}, {0,-1}, {-1,0}, {1,0}});

    vector<pii> bfs;
    for (int i=0; i<n*n; ++i){
        int c = p[i]-1;
        res += ans[c/n][c%n]-1;
        ans[c/n][c%n]--;

        bfs.clear();
        bfs.push_back({c/n, c%n});

        int cur = mp[c/n][c%n];

        for (int i=0; i<bfs.size(); ++i){
            pii pos = bfs[i];
            int len = ans[pos.first][pos.second];

            for (int did = 0; did<4; ++did){
                int nx = pos.first + di[did];
                int ny = pos.second + dj[did];
                if (nx >=0 && nx <n && ny>=0 && ny < n){
                    if (mp[nx][ny] < cur){
                        if (ans[nx][ny] > len){
                            ans[nx][ny] = len;
                            bfs.emplace_back(nx, ny);
                        }
                    } else {
                        if (ans[nx][ny] > len+1){
                            ans[nx][ny] = len+1;
                            bfs.emplace_back(nx, ny);
                        }
                    }
                }
            }
        }

    }


//    while(!bfs.empty()){
//        pii pos = bfs.front(); bfs.pop_front();
//        for (vi dir : dirs){
//            int nx = pos.first + dir[0];
//            int ny = pos.second + dir[1];
//            int len = ans[pos.first][pos.second];
//            if (nx >=0 && nx <n && ny>=0 && ny < n){
//                if (mp[nx][ny] < mp[pos.first][pos.second]){
//                    push({nx, ny}, len+1, 1);
//                } else {
//                    push({nx, ny}, len, 0);
//                }
//            }
//        }
//    }

//    int res = 0;
//    for (vi & va : ans){
//        for (int i : va) res += i;
//    }
    cout<<res;


}


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

int main()
{
    int A, B, used, reversed;
    int count = 0;
    cin >> A >> B;

    // ここにプログラムを追記
    // 入力される符号と値

    // A以上B以下の整数の繰り返し処理
    while (A <= B)
    {
        reversed = 0;
        used = A;
        //
        while (used > 0)
        {
            reversed = used % 10 + reversed * 10;
            used = used / 10;
        }

        // 回文数の場合
        if (A == reversed)
        {
            count++;
        }
        A++;
    }
    cout << count;
}


Measured memory_bytes: 3632
//E
//by Cydiater
//2017.6.3
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define up(i,j,n)	for(int i=j;i<=n;i++)
#define down(i,j,n)	for(int i=j;i>=n;i--)
#define cmax(a,b)	a=max(a,b)
#define cmin(a,b)	a=min(a,b)
#define pii		pair<int,int>
#define fi		first
#define se		second
#define FILE		"three"
 
const int MAXN=305;
const int oo=0x3f3f3f3f;
const int mod=1e9+7;
 
int f[MAXN][MAXN][MAXN],N,M,S[MAXN];
vector<pii>pre[MAXN];
bool ok[MAXN][MAXN][MAXN];
ll ans=0;

namespace solution{
	void col(int x,int y){
		int p=max(x,y),siz=pre[p].size();
		fill(S,S+N+1,0);
		up(i,0,siz-1){
			int l=pre[p][i].fi,r=p,c=pre[p][i].se;
			if(x>=l&&x<=r)c--;
			if(y>=l&&y<=r)c--;
			if(c>1||c<0)return;
			if(c==0){
				S[0]++;
				S[l]--;
				S[r+1]++;
				S[N+1]--;
			}else{
				S[l]++;
				S[r+1]--;
			}
		}
		up(i,1,p)S[i]+=S[i-1];
		up(i,0,p)if(S[i]==siz){
			if((x==y&&x)||(y==i&&i)||(x==i&&x))continue;
			ok[x][y][i]=ok[x][i][y]=ok[i][x][y]=1;
			ok[y][x][i]=ok[y][i][x]=ok[y][x][i]=1;
//			cout<<x<<' '<<y<<' '<<i<<endl;
		}
	}
	void Prepare(){
		scanf("%d%d",&N,&M);
		up(i,1,M){
			int l,r,c;
			scanf("%d%d%d",&l,&r,&c);
			pre[r].push_back(make_pair(l,c));
		}
		up(i,1,N)up(j,0,i-1)
			col(i,j);
	}
	void Solve(){
		f[1][0][0]=f[0][1][0]=f[0][0][1]=1;
		up(i,1,N){
			up(x,0,i)up(y,0,i){
				if(!ok[x][y][i])f[x][y][i]=0;
				(f[x][y][i+1]+=f[x][y][i])%=mod;
				(f[x][i+1][i]+=f[x][y][i])%=mod;
				(f[i+1][y][i]+=f[x][y][i])%=mod;
				if(!ok[x][i][y])f[x][i][y]=0;
				(f[x][i][i+1]+=f[x][i][y])%=mod;
				(f[x][i+1][y]+=f[x][i][y])%=mod;
				(f[i+1][i][y]+=f[x][i][y])%=mod;
				if(!ok[i][x][y])f[i][x][y]=0;
				(f[i][x][i+1]+=f[i][x][y])%=mod;
				(f[i][i+1][y]+=f[i][x][y])%=mod;
				(f[i+1][x][y]+=f[i][x][y])%=mod;
			}
		}
		up(i,0,N-1)up(j,0,N-1)(ans+=1LL*f[N][i][j]+f[i][N][j]+f[i][j][N])%=mod;
		cout<<ans<<endl;
	}
}
 
int main(){
	//freopen(FILE".in","r",stdin);
	//freopen(FILE".out","w",stdout);
	using namespace solution;
	Prepare();
	Solve();
	return 0;
}

Measured memory_bytes: 137728
import numpy as np

N, M, X = map(int, input().split())
ca_list = [list(map(int, input().split())) for _ in range(N)]
c = [ca_list[i][0] for i in range(N)]
a = [ca_list[i][1:] for i in range(N)]

a = np.array(a)
cost = 1000000000000000000

for i in range(1, 2 ** N):
    skill = np.zeros((1, M))
    money = 0
    for j in range(N):
        if (i >> j) & 1:
            skill += a[j]
            money += c[j]

    if np.all(skill >= X):
        cost = min(cost, money)

if cost == 1000000000000000000:
    cost = -1

print(cost)


Measured memory_bytes: 27224
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int M = sc.nextInt();
        int D = sc.nextInt();
int d1 = 0;
int d10 = 0;
int count = 0; 
        for(int i = 1; i <= M; i++){
            for(int j = 1; j <= D; j++){
                d1 = j%10;
                d10 = j/10;
                if(d1 != 1 && d10 != 1 && d1 * d10 == i){
                        count++;
                    }
                }
            }
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
import sys
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ab=[]
ans=0
tmp=0
if sum(b)>sum(a):
    print(-1)
    sys.exit()
for i in range(n):
    ab.append(a[i]-b[i])
    if a[i]-b[i]<0:
        ans+=1
        tmp+=a[i]-b[i]
ab.sort()
if ans ==0:
    print(ans)
while tmp<0:
    tmp+=ab.pop()
    ans+=1
    if tmp>=0:
        print(ans)
        sys.exit

Measured memory_bytes: 18492
using System;

namespace ConsoleApp3
{
    internal class Class2
    {
        private static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var count = 0;
            for (var j = 1; j < n; ++j)
            {
                for (int i = 1; i * i <= j; ++i)
                {
                    if (j % i == 0)
                    {
                        count++;
                        if (j / i != i) count++;
                    }
                }
            }


            Console.WriteLine(count);
        }
    }
}

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

typedef long double ld;
const ld pi=3.14159265358979;

int a,b,h,m;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>a>>b>>h>>m;
    pair<ld,ld> p1=make_pair(a,30*h+(ld)m/2);
    pair<ld,ld> p2=make_pair(b,m*6);
    cout<<fixed<<setprecision(10)<<sqrt(p1.first*p1.first+p2.first*p2.first-2*p1.first*p2.first*cos((p1.second-p2.second)*pi/180))<<endl;

    return 0;
}

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

#chr(ord('a')

ans = True
if s[0] != "A":
    print("WA")
elif s[2:-1].count("C") != 1:
    print("WA")
else:
    s.remove("A")
    s.remove("C")
    if not str(s).islower():
        print("WA")
    else:
        print("AC")

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

#define MAXN (100010)
#define ll long long

int n;
int a[MAXN * 3];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= 3 * n; ++ i){
		scanf("%d", a + i);
	}
	std::sort(a + 1, 3 * n + a + 1);
	ll ans = 0;
	for(int i = 3 * n - 1, j = 0; j < n; i -= 2, ++ j){
		ans += a[i];
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll calc(const vector<pair<int,int>>& v){
  ll ret = 0;

  priority_queue<int> que;
  int j = 0;
  for(int i=v.size()-1; i>=0; i--){
    while(j<v.size() && v[j].first >= i){
      que.push(v[j].second);
      j++;
    }

    if(!que.empty()){
      ret += que.top();
      que.pop();
    }
  }

  return ret;
}

void solve(){
  int N;
  cin >> N;
  vector<pair<int,int>> lhs, rhs;
  ll sum = 0;
  rep(i,N){
    int k, l, r;
    cin >> k >> l >> r;
    k--;
    int mn = min(l, r);
    sum += mn;
    l -= mn;
    r -= mn;

    if(l > 0){
      lhs.emplace_back(k,l);
    }else{
      rhs.emplace_back(N-1-(k+1),r);
    }
  }

  sort(ALLOF(lhs));
  reverse(ALLOF(lhs));
  sort(ALLOF(rhs));
  reverse(ALLOF(rhs));

  sum += calc(lhs);
  sum += calc(rhs);

  cout << sum << endl;
}


int main(){
  int T;
  cin >> T;
  rep(t,T){
    solve();
  }
  
  return 0;
}



Measured memory_bytes: 5608
/*
ID: tohoast1
TASK: gymnastics
LANG: C++
*/
#include <bits/stdc++.h>
#define speedup ios_base::sync_with_stdio(NULL)
#define fin freopen("gymnastics.in", "r", stdin)
#define fout freopen("gymnastics.out", "w", stdout)
#define FILENAME
#define PUBG push_back
#define p_b pop_back
#define mp make_pair
#define fi first
#define se second
#define cls clear
#define INF const int ci = 1e6 + 100
#define K_INF 1e9 + 7
#define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define MIN_INT -999999999
#define MOD 1000000007
#define d109 1000000000
#define basay break
#define bmbr exit(0)

using namespace std;
typedef long long LL;
typedef long L;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef string STR;
int a1, a2, a3;

int main() {
    #ifdef FILENAMEs
        fin;
        fout;
    #endif // FILENAME
    cin >> a1 >> a2 >> a3;
    if (a1 + a2 + a3 >= 22) cout << "bust";
    else cout << "win";
    ///time;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
int n,m;
int dist[200001];
int tree[200001];
ve gr[200001];
void bfstree(int start){
  queue<int>q;
  q.push(0);
  dist[0]=1;
  while(!q.empty()){
    auto u=q.front();
    q.pop();
    for(auto it:gr[u]){
      if(!dist[it]){
        dist[it]=1;
        q.push(it);
        tree[it]=u;
      }
    }
  }
  cout<<"Yes"<<'\n';
  for (int i = 1; i < n; ++i)
  {
    cout<<tree[i]+1<<'\n';
  }
}
int main()
{
  //flash;
  cin>>n>>m;
  for (int i = 0; i < m; ++i)
  {
    int x,y;
    cin>>x>>y;
    x--,y--;
    gr[x].pb(y);
    gr[y].pb(x);
  }
  bfstree(0);
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 15140