akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,s;
    cin >> n >> s;
    vector<ll> a(n);
    cins(all(a));
    vector<vector<ll>> dp(n+1,vector<ll>(s+2,0));
    dp[0][0] = 1;
    rep(i,n){
        rep(j,s+2){
            (dp[i+1][min(j+a[i],s+1)] += dp[i][j])%=MOD2;
            (dp[i+1][j] += dp[i][j]*2)%=MOD2;
        }
    }
    PRINT(dp[n][s]);
}


Measured memory_bytes: 73648
#include <bits/stdc++.h>
//#include "atcoder/all"
typedef long long int ll;
using namespace std;
// using namespace atcoder;
multiset<pair<ll, ll>, greater<> > ms;
#define MAXN 200001
ll a[MAXN];
ll b[MAXN];
bool finish[MAXN];
int main() {
    int n;
    cin >> n;
    ll ret = 0;
    int fin_count = 0;
    memset(finish, false, sizeof(finish));
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        if (a[i] == b[i]) {
            finish[i] = true;
            fin_count++;
        }
        if (!finish[i]) ms.insert(make_pair(b[i], i));
    }
    while (fin_count < n) {
        int id = (*ms.begin()).second;
        //cout << id << endl;
        int id_b, id_n;
        if (id == 0) {
            id_b = n - 1;
            id_n = 1;
        }
        else if (id == n - 1) {
            id_b = n - 2;
            id_n = 0;
        }
        else {
            id_b = id - 1;
            id_n = id + 1;
        }
        if (b[id] <= b[id_b] + b[id_n]) {
            break;
        }
        ll q = (b[id] - a[id]) / (b[id_b] + b[id_n]);
        b[id] -= q * (b[id_b] + b[id_n]);
        if (q == 0) {
            break;
        }
        else if (a[id] == b[id]) {
            fin_count++;
            ms.erase(ms.begin());
            ret+=q;
            //cout << "JJJ" << endl;
        }
        else {
            ms.erase(ms.begin());
            ms.insert(make_pair(b[id], id));
            ret+=q;
        }
    }
    if (fin_count < n) {
        cout << -1 << endl;
    }
    else {
        cout << ret << endl;
    }
    return 0;
}

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

#define int long long

const int N = 1e5 + 10;
const int mod = 1e9 + 7;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) {
        if (i == 0 || a[i] - 1 >= a[i - 1]) --a[i];
    }
    bool res = true;
    for (int i = 1; i < n; ++i) {
        if (a[i - 1] > a[i]) res = false;
    }

    cout << (res ? "Yes" : "No") << '\n';
}

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

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

    map<int, int> mp1, mp2;
    rep(i, n) {
        if (i%2) mp1[v[i]]++;
        else mp2[v[i]]++;
    }

    int ma1 = 0, ma2 = 0;
    int v1 = 0, v2 = 0;
    for (auto t : mp1) {
        if (ma1 < t.second) {
            v1 = t.first;
            ma1 = t.second;
        }
    }
    for (auto t : mp2) {
        if (ma2 < t.second) {
            v2 = t.first;
            ma2 = t.second;
        }
    }

    int ans = 0;
    if (v1 != v2) {
        ans = n/2 - ma1 + n/2 - ma2;
    }
    else {
        if (mp1.size() == 1 and mp2.size() == 1 and v[0] == v[1]) {
            ans += n/2;
        }
        else {
            //
            map<int, int> tmp;
            if (ma1 > ma2) {
                ans = n/2 - ma1;
                tmp = mp2;
            }
            else if (ma1 > ma2) {
                ans = n/2 - ma2;
                tmp = mp1;

            }
            if (ma1 != ma2) {
                int ma = 0;
                for (auto t : tmp) {
                    if (ma < t.second and t.first != v1) {
                        ma = t.second;
                    }
                }
                ans += n/2 - ma;
            }
            else {

                vector<int> a1, a2;
                for (auto t : mp1) {
                    if (t.first != v1) a1.push_back(t.second);
                }
                for (auto t : mp2) {
                    if (t.first != v1) a2.push_back(t.second);
                }

                sort(a1.rbegin(), a1.rend());
                sort(a2.rbegin(), a2.rend());

                if (a1[0] >= a2[0]) {
                    ans = n/2 - a1[0] + n/2 - ma2;
                }
                else {
                    ans = n/2 - ma1 + n/2 - a2[0];
                }

            }

        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i,j;
    string s;
    cin>>a>>s;
    if(s.size()<=a)
        cout<<s<<endl;
    else{
    {
        for(i=0;i<a;i++)
            cout<<s[i];
    }
    cout<<"..."<<endl;}
    return 0;
}


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

int main(){
  int n;
   cin >> n;
  if(n>81){cout << "No" << endl;
          return 0;}
  for(int i=1;i<10;i++){
  if(n%i ==0 && n/i <=9){cout << "Yes" << endl;
                        return 0;}
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<int, int> P;
int main() {
  ll N;
  cin >> N;
  REP(a, 3600) REP(b, 3600) {
    if (a == 0 || b == 0) continue;
    if (4 * a * b  - N * a - N * b <= 0) continue;
    //cout << a << " " << b << endl;
    if ((N * a * b) % (4 * a * b - N * a - N * b) == 0) {
      cout << a << " " << b << " ";
      cout << (N * a * b) / (4 * a * b - N * a - N * b) << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3468
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    s=[chomp(readline()) for i in 1:n]
    m=parseInt(readline())
    t=[chomp(readline()) for i in 1:m]
    ans=0
    for i in 1:n
        res=0
        for j in 1:n
            if s[i]==s[j]
                res+=1
            end
        end
        for j in 1:m
            if s[i]==t[j]
                res-=1
            end
        end
        ans=max(res,ans)
    end
    println(ans)
end
main()

Measured memory_bytes: 112592
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    // for(int i = 0; i < n; ++i)  cerr << bitset<20>(a[i]) << "\n";

    int XorSum = 0;
    ll Sum = 0;
    ll ans = 0;
    int left = 0, right = 0;
    for(int i = 0; i < n; ++i){
        int NextXorSum = XorSum ^ a[i];
        ll NextSum = Sum + a[i];
        // cerr << NextXorSum << " " << NextSum << " ";
        if(NextXorSum != NextSum){
            int cnt = right - left + 1;
            while(NextXorSum != NextSum){
                NextXorSum ^= a[left];
                NextSum -= a[left];
                ans += right - left + 1;
                ++left;
            }
        }
        XorSum = NextXorSum;
        Sum = NextSum;
        right = i;
        // cerr << left << " " << right << " " << ans << "\n";
    }
    int cnt = right - left + 1;
    ans += (ll)cnt * (cnt + 1) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct t{int i,s,p;}t;
int T,P,R,i,tI,pI,time,w[51][11];
t s[51];
char M[9];
int c(const void* a,const void *b)
{
	t x=*(t*)a,y=*(t*)b;
	if(x.p==y.p&&x.s==y.s)return x.i-y.i;
	if(x.s==y.s)return x.p-y.p;
	return y.s-x.s;
}
int main()
{
	for(;scanf("%d%d%d",&T,&P,&R),T;)
	{
		for(i=0;i<T;i++)
		{
			s[i].i=i+1;
			s[i].p=s[i].s=0;
		}
		memset(w,0,sizeof(w));
		for(i=0;i<R;i++)
		{
			scanf("%d%d%d%s",&tI,&pI,&time,M);
			tI--;
			if(M[0]=='C')
			{
				s[tI].s++;
				s[tI].p+=w[tI][pI]*1200+time;
			}
			else
				w[tI][pI]++;
		}
		qsort(s,T,sizeof(t),c);
		for(i=0;i<T;i++)
			printf("%d %d %d\n",s[i].i,s[i].s,s[i].p);
	}
	return 0;
}

Measured memory_bytes: 612
#include<stdio.h>
int min(int a, int b ){
    if (a<b) return a; else return b;
}
int main( ){
    int a,b,c,d,e;
    scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
    int ans=0;
    c*=2;
    if (c<(a+b)) {
        ans=min(d,e)*c;
    }else{
        ans=a*(min(d,e))+b*min(d,e);
    }
    if (c<a) ans+=c*(d-min(d,e));else ans+=a*(d-min(d,e));
    if (c<b) ans+=c*(e-min(d,e));else ans+=b*(e-min(d,e));
    printf("%d",ans);
}


Measured memory_bytes: 128
N, X, M = map(int, input().split())

a = X
S = [0, a]
lasts = [None] * (10 ** 5)
for i in range(1, N):
    a = (a * a) % M
    if a == 0:
        break
    if lasts[a] is not None:
        LA = lasts[a]
        T = i - LA
        print(S[-1] + (S[-1]-S[-T-1])*((N-i)//T) + S[-T-1+(N-i)%T] - S[-T-1])
        exit()
    S.append(S[-1] + a)
    lasts[a] = i

print(S[-1])


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

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


int main() {
  long A,V,B,W,T;cin>>A>>V>>B>>W>>T;
  if(V<=W){
  	cout<<"NO"<<endl;
  }else{
    
    if(abs(V-W)*T>=abs(A-B))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 3640
N = int(input())
# N, K = [int(i) for i in input().split()]

red_points = []
for i in range(N):
    a, b = [int(i) for i in input().split()]
    red_points.append([a, b])
red_points_x_asc = sorted(red_points)
blue_points = []
for i in range(N):
    c, d = [int(i) for i in input().split()]
    blue_points.append([c, d])
blue_points_x_asc = sorted(blue_points)

paired_r = []
for b in blue_points_x_asc:
    b_x = b[0]
    b_y = b[1]
    r_cands = []
    for r in red_points:
        r_x = r[0]
        r_y = r[1]
        if r_x < b_x and r not in paired_r:
            r_cands.append(r)
    r_cands_y_desc = sorted(r_cands, key=lambda x: x[1], reverse=True)
    for r in r_cands_y_desc:
        r_x = r[0]
        r_y = r[1]
        if b_y > r_y:
            paired_r.append(r)
            break

print(len(paired_r))





Measured memory_bytes: 40300
import java.util.Scanner;

public class Main {
    static final int MAX_LENGTH = 150; // 幅と高さの上限

    public static void main(String[] args) {
	final int MAX_LENGTH = 150;
	Scanner sc = new Scanner(System.in);
	while (true) {
	    int h = sc.nextInt();
	    int w = sc.nextInt();
	    if (h == 0) {
		break;
	    }
	    
	    int diagonal = diagSquare(h, w); // 入力した長方形の対角線の長さの2乗
	    
	    // 方法1. 素直に総当たりする
	    all(h, w, diagonal);
	}
    }
    
    public static int diagSquare(int h, int w) {
	return h * h + w * w;
    }
    
    public static void all(int h, int w, int diagonal) {
	// iは高さ、jは幅
	int resultH = 0;
	int resultW = 0;
	int resultD = Integer.MAX_VALUE;
	
	// iは高さ、jは幅
	for (int i = 1; i <= MAX_LENGTH; i++) {
	    for (int j = i + 1; j <= MAX_LENGTH; j++) {
		int diagonalT = diagSquare(i, j);
		// データセットより大きい長方形のみ対象
		if (diagonal < diagonalT || diagonal == diagonalT && h < i) {
		    if (diagonalT < resultD || diagonalT == resultD && i < resultH) {
			resultH = i;
			resultW = j;
			resultD = diagonalT;
		    }
		}
	    }
	}
	System.out.println(resultH + " " + resultW);
    }
}

Measured memory_bytes: 18548
n = int(input())
d,x = map(int,input().split())
a = []
for i in range(n):
    a.append(int(int(input())))

num = []
for i in range(n):
    num.append((d - 1) // a[i] + 1)
#print(num)

ans = x
for i in range(n):
    ans += num[i]
print(ans)

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

using namespace std;

#define N 300000

int n,a[N],pos[N],f[N],ans;

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		pos[a[i]]=i;
	}
	ans=f[1]=1;
	for (int i=2;i<=n;++i){
		f[i]=pos[i]>pos[i-1]?f[i-1]+1:1;
		ans=max(ans,f[i]);
	}
	printf("%d\n",n-ans);
	
	return 0;
}
			

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

int n;
string s;
map<string, int> m;

int main() {
  cin >> n;
  while(n--) {
    cin >> s;
    m[s]++;
  }
  for(auto str : {"AC", "WA", "TLE", "RE"})
    cout << str << " x " << m[str] << endl;
  return 0;
}

Measured memory_bytes: 3592
from sys import exit

N = int(input())
A = list(map(int, input().split()))


def gcd(a, b):
    if a == 0:
        return b

    if b == 0:
        return a

    temp = a % b
    while temp != 0:
        a = b
        b = temp
        temp = a % b

    return b


left = [0 for i in range(N)]
right = left[:]

for i in range(1, N):
    left[i] = gcd(A[i - 1], left[i - 1])
    right[-i - 1] = gcd(A[-i], right[-i])

ans = [gcd(left[i], right[i]) for i in range(N)]

print(max(ans))


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

ll i,j,k,l,m;
ll mod=1000000007;

int main(){
    int n,sum=0,ans=0;cin>>n;
    vector<int> a(n),b(n);
    vector<pair<int,int>> P(n); 

    for(i=0;i<n;i++){
        cin>>a[i];
        cin>>b[i];
        P[i]=make_pair(b[i],a[i]);
    }

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

    bool can_do=true;
    for(i=0;i<n;i++){
        sum+=P[i].second;
        if(sum>P[i].first){
            can_do=false;
        }
    }
    
    if(can_do){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
    return 0;
}

Measured memory_bytes: 3328
while True:
  n = int(input())
  if n == 0:
    break
  c = list(input().split())
  count = [0 for i in range(26)]
  alphab = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
  for i in range(n):
    if c[i] == "A":
      count[0] += 1
    elif c[i] == "B":
      count[1] += 1
    elif c[i] == "C":
      count[2] += 1
    elif c[i] == "D":
      count[3] += 1
    elif c[i] == "E":
      count[4] += 1
    elif c[i] == "F":
      count[5] += 1
    elif c[i] == "G":
      count[6] += 1
    elif c[i] == "H":
      count[7] += 1
    elif c[i] == "I":
      count[8] += 1
    elif c[i] == "J":
      count[9] += 1
    elif c[i] == "K":
      count[10] += 1
    elif c[i] == "L":
      count[11] += 1
    elif c[i] == "M":
      count[12] += 1
    elif c[i] == "N":
      count[13] += 1
    elif c[i] == "O":
      count[14] += 1
    elif c[i] == "P":
      count[15] += 1
    elif c[i] == "Q":
      count[16] += 1
    elif c[i] == "R":
      count[17] += 1
    elif c[i] == "S":
      count[18] += 1
    elif c[i] == "T":
      count[19] += 1
    elif c[i] == "U":
      count[20] += 1
    elif c[i] == "V":
      count[21] += 1
    elif c[i] == "W":
      count[22] += 1
    elif c[i] == "X":
      count[23] += 1
    elif c[i] == "Y":
      count[24] += 1
    elif c[i] == "Z":
      count[25] += 1
    # 当選が決まればbreak
    count_sorted = sorted(count)
    if count_sorted[-1]-count_sorted[-2] > n-1-i:
      a = i+1
      break
  count_sorted = sorted(count)
  if count_sorted[-1] == count_sorted[-2]:
    print("TIE")
  else:
    for i in range(len(count)):
      if count_sorted[-1] == count[i]:
        print(alphab[i]+ " " + str(a))


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

int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int count = 0;

    int r = N / R + 1;
    int g = N / G + 1;
    int b = N / B + 1;
    for(int i = 0; i < r; i++){
        int sum = i * R;
        for(int j = 0; j < g; j++){
            int sum_sub = sum;
            sum_sub += j*G;
            if((N -sum_sub) >= 0 && (N -sum_sub) % B == 0){
                count += 1;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
typedef long long LL;
const int N=100005,M=200005;
struct node { int y,next; } a[M<<1];
LL an;
int s1,s2,s3,head[N],i,j,k,n,m;
bool p[N],P[N],F;
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

void jb(int x,int y)
{
	a[++k]=(node){y,head[x]},head[x]=k,
	a[++k]=(node){x,head[y]},head[y]=k;
}

void dfs(int w)
{
	p[w]=1;
	for (register int j=head[w];j;j=a[j].next)
	{
		int c=a[j].y;
		if (!p[c])
			P[c]=P[w]^1,dfs(c);
		else
			if (P[w]==P[c])
				F=0;
	}
}

int main()
{
	n=read(),m=read();
	while (m--) jb(read(),read());
	for (i=1;i<=n;++i)
		if (!p[i])
			if (head[i])
				F=1,dfs(i),++(F?s2:s3);
			else
				++s1;
	printf("%lld\n",(LL)s1*((n<<1)-s1)+((LL)s2*(s2+s3)<<1)+(LL)s3*s3);
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define int long long
    



signed main(){
    int n,m;
    cin >> n >>m;
    int score[n+1+m];
    int oya[n+1+m]={};
    vector<int> kodomo[n+1+m];
    int x;
    for(int i=1;i<=n;i++){
        cin >> score[i];
       
    }
    if(m==0){
        cout <<0;
    }else{
    pair<int,pair<int,int>> hen[m];
    int a,b,y;
    for(int i=0;i<m;i++){
        cin >> a >> b>>y;
        hen[i]=make_pair(y,make_pair(a,b));
    }
    sort(hen,hen+m);
    //cerr << hen[0].first<<hen[0].second.first;
    queue<int> que1,que2;
    
    for(int i=0;i<m;i++){
        a = hen[i].second.first;
        b= hen[i].second.second;
        que1.push(a);
        que2.push(b);
        while(oya[a]!=0){
            a=oya[a];
            que1.push(a);
        }
         while(oya[b]!=0){
            b=oya[b];
            que2.push(b);
        }
        if(a!=b){
            score[n+i+1]=score[a]+score[b];
            kodomo[n+i+1].push_back(a);
            kodomo[n+i+1].push_back(b);
        }else{
             score[n+i+1]=score[a];
            kodomo[n+i+1].push_back(a);
        }
        while(!que1.empty()){
            a =que1.front();
            que1.pop();
            oya[a]=n+i+1;
        }
        while(!que2.empty()){
            b =que2.front();
            que2.pop();
            oya[b]=n+i+1;
        }
    }
    int ans=0,k;
    que1.push(n+m);
    while(!que1.empty()){
        k=que1.front();
        que1.pop();
        if(score[k]<hen[k-n-1].first){
            ans++;
            for(int i=0;i<kodomo[k].size();i++){
               if(kodomo[k][i]>n) que1.push(kodomo[k][i]);
            }
        }
    }
    cout << ans;

    }

    return 0;
}

Measured memory_bytes: 13568
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int k = -1;
    for (int i = 2; i * (i - 1) <= 2 * N; i++) {
      if (i * (i - 1) == 2 * N) {
        k = i;
        break;
      }
    }
    if (k < 0) {
      System.out.println("No");
      return;
    }

    System.out.println("Yes");
    System.out.println(k);
    List<Integer>[] edges = new List[k];
    for (int i = 0; i < k; i++) edges[i] = new ArrayList<>();

    int e = 1;
    for (int offset = 1; offset <= (k - 1) / 2; offset++) {
      for (int i = 0; i < k; i++) {
        edges[i].add(e);
        edges[(i + offset) % k].add(e);
        e++;
      }
    }

    if (k % 2 == 0) {
      for (int i = 0; i < k / 2; i++) {
        edges[i].add(e);
        edges[i + k / 2].add(e);
        e++;
      }
    }

    StringBuilder sb = new StringBuilder();
    for(List<Integer> ed : edges) {
      sb.append(ed.size()).append(" ");
      for(int i : ed) sb.append(i).append(" ");
      sb.append("\n");
    }
    System.out.println(sb.toString());
  }
}


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

int a[55],b[55],c[55],d[55];
int e[11];
int ans;
int n,m,q;

void solve(int number,int tmp){
    if(number==n){
        int answer=0;
        for(int i=0;i<q;i++){
            if(e[b[i]-1]-e[a[i]-1]==c[i])answer+=d[i];
        }
        ans=max(ans,answer);        
    }
    else{
        for(int i=tmp;i<m+1;i++){
            e[number]=i;
            solve(number+1,i);
        }
    }
}

int main(){
    cin >> n >> m >> q;
    for(int i=0;i<q;i++)cin >> a[i] >> b[i] >> c[i] >> d[i];
    ans=0;
    solve(0,1);
    cout << ans << endl;
}

Measured memory_bytes: 3600
H, W, N = map(int, input().split())
A = []
L = 0
ans = [0] * 10

for i in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in range(max(0, a - 2), min(a + 1,H-2)):
        for j in range(max(0, b - 2), min(b + 1,W-2)):
            A.append((i, j))
            L += 1

A.sort()
count = 1
for i in range(L - 1):
    if A[i] == A[i + 1]:
        count += 1
    else:
        ans[count] += 1
        count = 1
if L >= 1:
    ans[count] += 1

ans[0] = (H - 2) * (W - 2) - sum(ans)

for i in range(10):
    print(ans[i])

Measured memory_bytes: 109000
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(h)]
ans = []
for i in range(h):
  for j in range(w):
    if i==h-1 and j==w-1:
      pass
    elif j==w-1 and a[i][j]%2==1:
      a[i+1][j] += 1
      ans.append((i+1, j+1, i+2, j+1))
    elif a[i][j]%2==1:
      a[i][j+1] += 1
      ans.append((i+1, j+1, i+1, j+2))
print(len(ans))
for e in ans:
  print(*e)

Measured memory_bytes: 26688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using vi = vector<int>;

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  vi z(n + 1);
  bool zero = false;
  z[0] = 0;
  rep2(i, 1, n + 1) {
    z[i] = z[i - 1];
    if(s[i - 1] == '1') zero = false;
    if(s[i - 1] == '0' && !zero) {
      z[i]++;
      zero = true;
    }
  }
  int ans = 0;
  rep(i, n) {
    if(i > 0 && s[i - 1] == '0' && s[i] == '0') continue;
    int r = upper_bound(all(z), k + z[i]) - z.begin() - 1;
    ans = max(ans, r - i);
  }
  cout << ans << endl;
}

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

  int s1,e1,t[1001]={},q,s[1000],e[1000];
  cin>>s1>>e1>>q;
  for(int i=s1;i<e1;i++) t[i]=1;
  for(int i=0;i<q;i++) cin>>s[i]>>e[i];
  for(int i=0;i<q;i++){
    for(int j=s[i];j<e[i];j++) if(t[j]==1){
        cout<<1<<endl;
        return 0;
      }
  }
  cout<<0<<endl;
  return 0;

}

Measured memory_bytes: 3124
package main

import (
	"fmt"
)

const mod = 1e9 + 7

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if (a+b)%2 == 1 {
		fmt.Println("IMPOSSIBLE")
	} else {
		fmt.Println((a + b) / 2)
	}
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main(){
    char s[101],p[101],t[201];
    scanf("%s",&s);
    scanf("%s",&p);
    strcpy(t,s);
    strcat(t,s);
    if (strstr(t,p)!=NULL){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}


Measured memory_bytes: 2100
al = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
N = int(input())
S = list(input())

for i in range(len(S)):
  x = al.index(S[i])
  c = x+N
  if c <= 25:
      S[i] = al[c]
  else:
      S[i] = al[c-26]
      
print("".join(S))

Measured memory_bytes: 39152
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
	int N;
	cin >> N;
	int c1=0;
	int c2=0;
	int c3=0;
	int c4=0;
	for(int i=0; i<N;i++){
		char s[256];
		cin >> s;
		if(!strcmp(s,"AC")){
			c1++;
		}else if(!strcmp(s,"WA")){
			c2++;
		}else if(!strcmp(s,"TLE")){
			c3++;
		}else if(!strcmp(s,"RE")){
			c4++;
		}
		
	}
	
	cout << "AC x " << c1 <<endl;
	cout << "WA x " << c2 <<endl;
	cout << "TLE x " << c3 <<endl;
	cout << "RE x " << c4 <<endl;
	
	return 0;

}

Measured memory_bytes: 3624
#include <stdio.h>

int main(){
    int l;
    scanf("%d",&l);
    int v[l];
    int c[l];
    for(int i = 0;i < l;i++){
        scanf("%d", &v[i]);
    }
    for(int i = 0;i < l;i++){
        scanf("%d", &c[i]);
    }
    int r;
    for(int i = 0;i < l;i++){
        if(v[i] - c[i] > 0){
            r += (v[i] - c[i]);
        }
    }
    printf("%d\n", r);
}


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

vector<ll> c;
void dfs(string s) {
	if (s.size() == 11) {		
		return;
	}
	if (3 <= s.size() && s.size() <= 10) {
		bool isExist3 = false;
		bool isExist5 = false;
		bool isExist7 = false;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '3') isExist3 = true;
			if (s[i] == '5') isExist5 = true;
			if (s[i] == '7') isExist7 = true;
		}
		if(isExist3 && isExist5 && isExist7) c.push_back(stoll(s));
	}
	for (int i = 0; i < 3; i++) {
		if (i == 0) {
			s += '3';
			dfs(s);
			s.pop_back();
		}
		else if (i == 1) {
			s += '5';
			dfs(s);
			s.pop_back();
		}
		else if (i == 2) {
			s += '7';
			dfs(s);
			s.pop_back();
		}
	}
}

int main() {

	ll n; cin >> n;
	string s = "";
	dfs(s);
	sort(c.begin(), c.end());
	ll ans = 0;
	for (ll i = 0; i <= c.size(); i++) {
		if (c[i] <= n) ans++;
		else break;
	}
	cout << ans << endl;
	return 0;
}

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

using ll= long long;
const ll INF=1LL<<60;
const ll MOD=1000000007;

struct Edge {
    long long from;
    long long to;
    long long cost;
};
using Edges = vector<Edge>;


bool bellman_ford(Edges &Es, int V, int r, vector<ll> &dist){
    dist[r]=0;
    int cnt=0;
    while(cnt < V){
        bool end=true;
        for(auto x: Es){
            if(dist[x.from] != INF && dist[x.to] > dist[x.from]+x.cost){
                dist[x.to]=dist[x.from]+x.cost;
                end=false;
            }
        }
        if(end) break;
        cnt++;
    }
    return (cnt == V);
}

int main(){
    int V, E, r;
    Edges Es;
    vector<ll> dist;
    cin >> V >> E >> r;
    Es.resize(E);
    dist.assign(V, INF);
    for(int i=0; i<E; i++){
        int s, t, d;
        cin >> s >> t >> d;
        Es[i].from=s;
        Es[i].to=t;
        Es[i].cost=d;
    }
    if(bellman_ford(Es, V, r, dist)) cout << "NEGATIVE CYCLE" << endl;
    else{
        for(auto x: dist){
            if(x == INF) cout << "INF" << endl;
            else cout << x << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define ones(n) __builtin_popcount(n)
#define ONES(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef pair<int, int> ii;
typedef pair<long long, pair<int, int>> iii;
typedef pair<ii, ii> iiii;

const double PI = acos(-1.0), EPS = 1e-6;
const int N = 100005, M = 102, mod = 998244353, mxLog = 20;
int n;
int W[N];
int memo[N];
int solve(int i) {
    if (i == n - 1)
        return 0;
    int &ret = memo[i];
    if (~ret)
        return ret;
    ret = abs(W[i + 1] - W[i]) + solve(i + 1);
    if (i + 2 < n) {
        ret = min(ret, solve(i + 2) + abs(W[i + 2] - W[i]));
    }
    return ret;
}


int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(7), cout << fixed;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> W[i];
    }
    memset(memo, -1, sizeof memo);
    cout << solve(0) << '\n';


    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

struct flow_network {
	struct edge { ll to, cap, cost; };

	ll n, s, t;
	vvl adj;
	vector<edge> e;
	
	flow_network(ll n, ll s, ll t): n(n), s(s), t(t), adj(n) { }

	void add_edge(ll a, ll b, ll cap, ll cost) {
		adj[a].pb(sz(e));
		e.pb({b,cap,cost});
		adj[b].pb(sz(e));
		e.pb({a,0,-cost});
	}

	pll mcmf() {
		vl pot(n);
		FOR(t,0,n) FOR(i,0,n) for (ll k: adj[i]) if (e[k].cap) {
			pot[e[k].to] = min(pot[e[k].to],pot[i] + e[k].cost);
		}
		ll flow = 0, cost = 0;
		while (true) {
			vl dist(n,oo), pred(n);
			set<pll> q;
			dist[s] = 0, q.insert({0,s});
			while (sz(q)) {
				ll i = begin(q)->yy;
				q.erase(begin(q));
				for (ll k: adj[i]) if (e[k].cap) {
					ll j = e[k].to, ndist = dist[i] + e[k].cost + pot[i] - pot[j];
					if (ndist >= dist[j]) continue;
					q.erase({dist[j],j});
					dist[j] = ndist, pred[j] = k;
					q.insert({dist[j],j});
				}
			}
			if (dist[t] == oo) break;

			ll cap = oo, cost1 = 0;
			for (ll i = t; i != s; i = e[pred[i]^1].to) {
				cap = min(cap,e[pred[i]].cap), cost1 += e[pred[i]].cost;
			}
			flow += cap, cost += cap*cost1;
			for (ll i = t; i != s; i = e[pred[i]^1].to) {
				e[pred[i]].cap -= cap, e[pred[i]^1].cap += cap;
			}
			FOR(i,0,n) pot[i] += dist[i];
		}
		return {flow,cost};
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	ll N = 2*n+6, s = N-2, t = N-1;
	flow_network F(N,s,t);
	
	FOR(i,0,n) {
		ll x, y, c;
		cin >> x >> y >> c;
		
		F.add_edge(s,i,c,0);
		F.add_edge(i,2*n+0,oo, x+y);
		F.add_edge(i,2*n+1,oo,-x+y);
		F.add_edge(i,2*n+2,oo, x-y);
		F.add_edge(i,2*n+3,oo,-x-y);
	}
	
	FOR(i,0,n) {
		ll x, y, c;
		cin >> x >> y >> c;

		F.add_edge(n+i,t,c,0);
		F.add_edge(2*n+0,n+i,oo,-x-y);
		F.add_edge(2*n+1,n+i,oo, x-y);
		F.add_edge(2*n+2,n+i,oo,-x+y);
		F.add_edge(2*n+3,n+i,oo, x+y);
	}

	pll res = F.mcmf();
	cerr << res.xx << endl;
	cout << -res.yy << endl;
	
}



Measured memory_bytes: 1328
#inport
import sys
import numpy as np

#input
N,M = [int(x) for x in sys.stdin.readline().split()]
A = [list(map(int, sys.stdin.readline().split()))]

A = np.array(A)
d = np.sum(A)        

#shori
##初期化
if N-d < 0:
    print(-1)
else:
    print(N-d)

Measured memory_bytes: 27748
k = int(input())
lst = [i for i in range(1, 10)]

left = 0
right = 9

while len(lst) < k:
  for i in range(left, right + 1):
    if lst[i] % 10 > 0:
      lst.append(lst[i] * 10 + lst[i] % 10 - 1)
    lst.append(lst[i] * 10 + lst[i] % 10)
    if lst[i] % 10 < 9:
      lst.append(lst[i] * 10 + lst[i] % 10 + 1)
  left = right + 1
  right = len(lst) - 1

print(lst[k - 1])

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using Graph = vector<vector<int>>;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int sum = A + B + C;
    if(sum >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		solve(sc, out);
		
		out.flush();
	}
	
	public static void solve(FastScanner sc, PrintWriter out){
		int[] a = new int[3];
		
		for(int i = 0; i < 3; i++) a[i] = sc.nextInt();
		
		int k = sc.nextInt();
		
		int max = Arrays.stream(a).max().getAsInt();
		
		int res = 0;
		
		for(int i = 0; i < 3; i++) {
			res+=a[i];
		}
		
		res+=max*(Math.pow(2, k)-1);
		
		out.println(res);
		

	}

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

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 25556
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int n , m;
    cin>>n;
    int counter[n] = {0};
    vector <int> arr(n-1);
    for(int i = 0;i<n-1;i++)
    {
        cin>>arr[i];
        counter[arr[i]-1]++;
    }
    for(int i = 0;i<n;i++)
    {
        
        cout<<counter[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 4788
s=input()
slist=[i for i in s]
K=int(input())
cost = []
for i in s:
    if i=="a":
        cost.append(0)
    else:
        cost.append(ord("z")-ord(i)+1)

for i,c in enumerate(cost):
    if c<=K:
        K = K-c
        slist[i]="a"

lastord = (ord(slist[-1])-ord("a")+K)%26+ord("a")
slist[-1]=chr(lastord)

print("".join(slist))

Measured memory_bytes: 5108
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define Pl pair<ll, ll>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;


int main()
{
  string S; cin >> S;
  reverse(S.begin(), S.end());
  int sz = S.size(); --sz;
  int index = 0;

  while(index < sz){
    if(S[index] == 'm'){
      if(S.substr(index, 5) == "maerd") index += 5;
      else { cout << "NO" << endl; return 0;};
    } else if(S[index] == 'r'){
      if(S[index + 2] == 'm'){
        if(S.substr(index, 7) == "remaerd") index += 7;
        else {cout << "NO" << endl;return 0;}
      } else if(S[index + 2] == 's'){
        if(S.substr(index, 6) == "resare") index += 6;
        else {cout << "NO" << endl;return 0;}
      } else {cout << "NO" << endl;return 0;}
    } else if(S[index] == 'e'){
        if(S.substr(index, 5) == "esare") index += 5;
        else {cout << "NO" << endl;return 0;}
    } else { cout << "NO" << endl;return 0;}
  }

  cout << "YES" << endl;
}

Measured memory_bytes: 3780
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;
 
inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
 
int a[20], b[20];
int n;
 
inline void chkmin(int& x, int y) {
    if (x == -1 || (y != -1 && y < x)) {
        x = y;
    }
}
 
inline int get(int x, int y) {
    return (x - y) & 1 ? b[x] : a[x];
}
 
inline void work() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
 
    vector<vector<int>> f(1 << n, vector<int>(n, -1));
    for (int i = 0; i < (1 << n); ++i) {
        int c = __builtin_popcount(i);
        if (c == 1) {
            f[i][__builtin_ctz(i)] = 0;
        }
        else {
            int mov = c;
            for (int j = 0; j < n; ++j) {
                if (i & (1 << j)) {
                    --mov;
                    for (int k = 0; k < n; ++k) {
                        if ((i & (1 << k)) && j != k && f[i ^ (1 << j)][k] != -1) {
                            if (get(j, c - 1) >= get(k, c - 2)) {
                                chkmin(f[i][j], f[i ^ (1 << j)][k] + mov);
                            }
                        }
                    }
                }
            }
        }
    }
 
    int ans = -1;
    for (int i = 0; i < n; ++i) {
        chkmin(ans, f[(1 << n) - 1][i]);
    }
    cout << ans << "\n";
}
 
int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 26880
import sys
input=sys.stdin.readline

n=int(input())
a=list(map(int,input().split()))

m=a[0]
mi=0
for i in range(n):
    if abs(a[i])>abs(m):
        m=a[i]
        mi=i

print(2*n-1)
for i in range(n):
    print(mi+1,i+1)

if m>=0:
    for i in range(n-1):
        print(i+1,i+2)
else:
    for i in range(n-1):
        print(n-i,n-1-i)



Measured memory_bytes: 62400
import sys
input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  LR = [list(map(int, input().split())) for _ in range(n)]
  
  BIT = [0]*(m+2)
  def add(i, a):
    while i <= m+1:
      BIT[i] += a
      i += i&(-i)
  def bit_sum(i):
    res = 0
    while i > 0:
      res += BIT[i]
      i -= i&(-i)
    return res
  
  S = sorted([(r-l+1, l, r) for l, r in LR], reverse=True)
  cnt = n
  L = []
  for i in range(1, m+1):
    while S and S[-1][0] == i:
      c, l, r = S.pop()
      cnt -= 1
      add(l, 1)
      add(r+1, -1)
    res = cnt
    for j in range(0, m+1, i):
      res += bit_sum(j)
    L.append(res)
  print(*L, sep="\n")

if __name__ == "__main__":
  main()

Measured memory_bytes: 127784
import java.util.*;
import java.io.*;

public class Main {
	static FastReader f = new FastReader();
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		int n = f.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++) arr[i] = f.nextInt();
		int max = arr[0];
		long ans = 0;
		for(int i=1;i<n;i++) {
			max = Math.max(max, arr[i]);
			ans += max - arr[i];
		}
		out.println(ans);
		out.close();
	}
		

	static class FastReader {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		String next() {
			while(st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch(IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		String nextLine() {
			String str = "";

			try {
				str = br.readLine();
			} catch(IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}
}

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 400054;
//#define int long long
const int INF = 1e9;

int ci(char c){
  return (int)(c - 'a');
}

struct Node {
  int isEnd = 0;
  int cnt = 0;
  int to[26];
  int jump[26];
  
  int& operator[] (const int ind){
    return to[ind];
  }
} trie[MAXN];

int newvert(){
  static int vertamount = 1;
  return vertamount++;
}

void add(const string& s){
  int cur = 0;
  int n = s.size();
  for (int i = 0; i < n; i++){
    trie[cur].cnt++;
    int c = ci(s[i]);
    if (!trie[cur][c]) trie[cur][c] = newvert();
    trie[cur].jump[c] = 1;
    cur = trie[cur][c];
  }
  trie[cur].isEnd = 1;
  trie[cur].cnt++;
}

pair<int, int> dfs(int v){
  pair<int, int> res;
  int cnt = 0;
  for (int i = 0; i < 26; i++){
    if (!trie[v][i]) continue;
    cnt++;
    res = dfs(trie[v][i]);
    trie[v][i] = res.ff;
    trie[v].jump[i] = res.ss;
  }
  
  if (cnt > 1 || trie[v].isEnd) return mp(v, 1);
  return mp(res.ff, res.ss + 1);
}

int get(const string& s, const string& cmp){
  int cur = 0;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i < n;){
    for (int j = 0; j < 26; j++){
      if (s[i] == cmp[j]) break;
      int c = ci(cmp[j]);
      if (!trie[cur][c]) continue;
      int to = trie[cur][c];
      ans += trie[to].cnt;
    }
    if (trie[cur].isEnd) ans++;

    //cerr << i << '\n';

    int c = ci(s[i]);
    i += trie[cur].jump[c];
    //ans += trie[cur].sz[c];
    //cerr << i << ' ' << trie[cur].sz[c] << " to -> " << trie[cur][c] << '\n';
    cur = trie[cur][c];
  }
  return ans;
}

void solve(){
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    add(s[i]);
  }
  dfs(0);
  int Q;
  cin >> Q;
  for (int i =0 ; i < Q; i++){
    int k;
    string cmp;
    cin >> k >> cmp;
    cout << get(s[k-1], cmp) + 1 << '\n';
  }
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 113152
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int V, E;
bool used[10000];
int d[105][105];

int prim()
{
	memset(used, false, sizeof(used));
	int sum = 0;

	priority_queue<edge, vector<edge>, greater<edge>> que;
	que.push(edge{ -1, 0, 0 });

	while (!que.empty())
	{
		edge e = que.top(); que.pop();
		if (used[e.to]) continue;
		sum += e.cost;
		used[e.to] = true;
		REP(i, V)
		{
			if (!used[i]) que.push(edge{ e.to, i, d[e.to][i] });
		}
	}
	return sum;
}

int main()
{
	cin >> V;
	REP(i, V)REP(j, V)
	{
		int t;
		cin >> t;
		d[i][j] = (t == -1 ? INF : t);
	}
	cout << prim() << endl;
}

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

int main()
{
  int K;
  string S;
  cin >> K >> S;
  if (S.size() <= K)
    cout << S << endl;
  else
  {
    for(int i=0;i<K;i++){cout << S.at(i);}
    cout<< "..." <<endl;
  }
    
}

Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        powVerify solver = new powVerify();
        solver.solve(1, in, out);
        out.close();
    }

    static class powVerify {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int m = in.nextInt();
            int n = in.nextInt();
            out.println(Arith.pow(m, n, (int) (1e9 + 7)));

        }

    }

    static class Arith {
        public static long pow(long a, long n, long MOD) {
            return n == 0 ? 1 : (pow(a * a % MOD, n / 2, MOD) * (n % 2 == 1 ? a : 1)) % MOD;
        }

    }
}




Measured memory_bytes: 26468