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

const int INF = 1 << 30;

int w[100010];

bool check(int mid, const int &n, const int &k){
	int num = 0;
	for(int i = 0; i < k; i++) {
		int weight = 0;
		while(num != n && weight + w[num] <= mid) {
			weight += w[num];
			num++;
		}
	}
	return num == n;
}

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++)
		scanf("%d", &w[i]);
	int lb = INF, ub = 0;
	while(abs(lb - ub) > 1) {
		int mid = (lb + ub) / 2;
		if(check(mid, n, k)) lb = mid;
		else ub = mid;
	}
	printf("%d\n", lb);
}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e16+7;

//-------------------------<MATH>-------------------------------------------------------//
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;
ll c = (a * b)%mod;
//cout << a << " " << b << endl;
return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(5e5 + 5)] , inv_fac[(int)(5e5 + 5)];
void precomp_factorial(int M){fac[0] = 1;for(int i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(int i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int lo[(int)(1e3 + 6)];
void sieve(int M){for(int i = 2 ; i < M ; i++){ if(lo[i]) continue; for(int j = i ; j < M ; j += i)lo[j] = i;}}
int max_expo_prime_n_fac(ll N , int prime){int ress = 0;while(N){ress += (N/prime);N /= prime;}return ress;}
//-------------------------</MATH>-------------------------------------------------------//

//-------------------------<STRING>-------------------------------------------------------//
string get_prefix(string x , int MAX){return x.substr(0 , min((int)x.size() , MAX));}
string get_suffix(string x,int MAX){int dn=1;for(int i=x.size()-1;i>=0;i--){if(dn==MAX)return x.substr(i);dn++;}return x;}
string convert_to_binary(int x,int len) {string ans=""; while(x){if(x&1){ans='1'+ans;}
    else{ans ='0'+ans;}x/=2;}int k = ans.size();while(k < len){ans = '0' + ans;k++;}return ans;}
//-------------------------</STRING>-------------------------------------------------------//

ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};



ll getNex(ll n1){
   ll ans = 0;

   while((expo(26LL, ans)-1LL)/25LL <= n1) ans++;
   ans--;
   return ans;
}



int main(){
    
    int n;
    cin >> n;
    vector <ll> vec(n);
    ll sum = 0;
    map <ll,ll> mp;
    for(int i = 0; i < n; i++){
       cin >> vec[i];
       mp[vec[i]]++;
       sum += vec[i];
    }
    int q;
    cin >> q;
    while(q--){
          ll a, b;
          cin >> a >> b;
          ll cnt = mp[a];
          mp[a] = 0;
          sum += (b-a)*cnt;
          cout << sum << endl;
          mp[b] += cnt;
    }

}


Measured memory_bytes: 10052
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
int a[105];

int main() {
//	freopen("/Users/liyingyan/Documents/ACM/in.txt", "r", stdin);
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++) {
		int v = a[i];
		int j = i - 1;
		while(j>=0 && a[j] > v) {
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
		for(int k = 0; k<n; k++) {
			cout << a[k];
			if(k == n-1) cout << endl;
			else cout << " ";
		}
	}
	return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll n,k,s; cin >> n >> k >> s;
	vl ans;
	if(s==1e9){
		rep(i,k) ans.push_back(1e9);
		rep(i,n-k) ans.push_back(1);
	}else{
		rep(i,k) ans.push_back(s);
		rep(i,n-k) ans.push_back(1e9);
	}
	rep(i,n) cout << ans[i] << " ";
	cout << endl;
}

Measured memory_bytes: 2292
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
import copy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=[50 for i in range(50)]
lists=[]
for i in range(50):
    mx=-inf
    for j in range(50):
        if lis[j]>=mx:
            mx=lis[j]
            ind=j
    for j in range(50):
        lis[j]+=1
    lis[ind]-=51
    lists.append(copy.deepcopy(lis))
    #print(lis)
#print(lists)
#print(lists[0])
u=n%50
x=n//50
base=lists[50-u-1]
for i in range(50):
    base[i]+=x
print(50)
print(*base)




        

    
    
    
    
    

    


Measured memory_bytes: 9628
import numpy as np

a = []
for _ in range(3):
    a.append([int(i) for i in input().split()])
a = [e for row in a for e in row]
for i in range(int(input())):
    b = int(input())
    if b in a:
        a[a.index(b)] = 0
bingo = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
flg = 0
for i in range(len(bingo)):
    c = 0
    for j in bingo[i]:
        c += a[j]
    if c==0:
        flg = 1
        break
print('Yes' if flg==1 else 'No')

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

int N,M;
bool G[10][10];
int res=0;
bool used[10];

void dfs(int v,int cnt){
    if(cnt==N){
        res++;
        return;
    }
    used[v]=true;
    for(int i=0;i<N;i++){
        if(!used[i]&&G[v][i])dfs(i,cnt+1);
    }
    used[v]=false;
}
 
signed main(){
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a][b]=G[b][a]=true;
    }
    dfs(0,1);
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
				
int32_t main() {
	fast_cin();  
	int n, d;
	cin >> n >> d;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int x, y; cin >> x >> y;
		if (x * x + y * y <= d * d) ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

int N[1010] = {};

bool is_prime(int i){
    if(i < 2) return false;
    if(i == 2 or i == 3) return true;
    int j = sqrt(i);
    int c = 0;
    rfor(k, 2, j){
        if(i % k == 0) c++;
    }
    if(c >= 2) return false;
    return true;
}

int main(int argc, char *argv[]){
    int n; cin >> n;
    ll res = 1;
    v P(1010);
    rfor(i, 2, n + 1){
        int j = i;
        for(int k = 2; k * k <= i; k++){
            while(j % k == 0){
                j /= k;
                P[k]++;
            }
            if(k == 1) break;
        }
        if(j != 1) P[j]++;
    }
    rfor(i, 2, n + 1){
        res *= (P[i] + 1);
        res %= MOD;
    }
    


    // if(n >= 2){
    //     v P(n);
    //     rfor(i, 2, n + 1) { if(is_prime(i)) P.push_back(i); }
    //     rfor(i, 2, n + 1){
    //         for(auto j : P){
    //             while(i % j == 0){
    //                 i /= j;
    //                 N[j - 1]++;
    //             }
    //         }
    //     }
    //     for(auto i : P){
    //         res *= (1 + N[i - 1]) % MOD;
    //     }
    // }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

public class hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var sL = s.Length;
        var res = 0;
        for (int i = 0; i < sL; i++)
        {
            if (s[i] == '*') break;
            else if (s[i] == '(') res++;
            else res--;
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 17888
N = int(input())
A = list(map(int,input().split()))
flag = 1
for i in range(N):
    a = A[i]
    if a%2==1 or (a%3==0 or a%5==0):
        continue
    else:
        flag = 0
        break
if flag==1:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
constexpr int MOD = 1e9 + 7;

constexpr int MAX = 1001;
long long fac[MAX], inv[MAX], finv[MAX];
void CombInit(){
    fac[0] = inv[0] = finv[0] = 1;
    fac[1] = inv[1] = finv[1] = 1;
    for(int i=2; i<MAX; ++i){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long Comb(int n,int k){
    if(n < 0 || k < 0 || n < k) return 0;
    return (fac[n] * finv[n-k] % MOD) * finv[k] % MOD;
}

ll mod_pow(ll x, int e) {
    ll y = 1;
    while(e) {
        if(e&1) y = y*x%MOD;
        x = x*x%MOD;
        e >>= 1;
    }
    return y;
}

ll S(int n,int k) {
    ll res = 0;
    for(int i=0; i < k; ++i) {
        ll add = Comb(k, i) * mod_pow((k-i), n) % MOD;
        if(i&1) res = (res - add + MOD) % MOD;
        else res = (res + add) % MOD;
    }
    return res * finv[k] % MOD;
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    CombInit();
    ll ans = 0;
    for(int i=1; i <= k; ++i) {
        ans = (ans + S(n, i)) % MOD;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3228
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if((a%3 == 0)||(b%3==0)||((a+b)%3==0)){
	        System.out.println("Possible");
		}else{
		    System.out.println("Impossible");
		}
    }
}


Measured memory_bytes: 21716
i,r=999;main(n){
	char s[20];
	for(gets(s);i<9;){
		char t[]={s[i],s[i+1],s[i+++2]};
		n=abs(753-atoi(t));
		r=n<r?n:r;
	}
	printf("%d\n", r);
}

Measured memory_bytes: 128
N = input()
if N[0] == "9":
    if N[1:] == "9" * len(N[1:]):
        print(9 * len(N))
    else:
        print(9 * len(N) - 1)
else:
    if N[1:] == "9" * len(N[1:]):
        print(int(N[0]) + 9 * len(N[1:]))
    else:
        print(int(N[0]) + 9 * len(N[1:]) - 1)


Measured memory_bytes: 9136
n = int(input())
*h, = map(int, input().split())

ans = 0
g = [0]*n
while h != g:
    t = []
    for _h, _g in zip(h, g):
        if _h != _g:
            t.append(1)
        else:
            t.append(0)

    g = list(map(lambda x: x[0]+x[1], zip(g, t)))

    t.append(0)
    c = t[0]
    for i in range(len(t)):
        if c != t[i] and t[i] == 0:
            ans += 1

        c = t[i]

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

using ps = pair<string, string>;

constexpr int MINI = 60;
constexpr int SEC = 60;
constexpr int HOUR = 24;

int timeToInt (string time) {
  int t1 = stoi(time.substr(0,2));
  int t2 = stoi(time.substr(3,5));
  int t3 = stoi(time.substr(6));
  return t1 * 3600 + t2 * 60 + t3;
}

int overlap_trains(int n, vector<ps> const& trains) {
  int ans = 0;
  vector<int> overlap(MINI * SEC * HOUR + 1000, 0);
  for (int i = 0; i < n; ++i) {
    int begin = timeToInt(trains[i].first); 
    int end = timeToInt(trains[i].second);

    rep_r(i, end, begin) overlap[i] += 1;
  }

  for (auto itr : overlap) chmax(ans, itr);
  return ans;
}

int main() {
  int n;
  while (cin >> n and n != 0) {
    string s1, s2;
    vector<ps> trains(n);
    rep(i, n) {
      cin >> s1 >> s2;
      trains[i] = ps(s1, s2);
    }
    cout << overlap_trains(n, trains) << endl;
  }
}



Measured memory_bytes: 4184
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
int count(int n) {
    int res = 0;
    while(n > 0) {
        res += n / 2;
        n /= 2;
    }
    return res;
}
int solve(int n, int m) {
    if(m == 0 || m == n) return 1;
    if(count(n) > (count(n - m) + count(m))) return 0;
    return 1;
}
signed main(void) {
    int N;
    cin >> N;
    string s;
    cin >> s;
    int V[N];
    rep(i, N) V[i] = s[i] - '1';
    bool judge = true;
    rep(i, N) {
        if(V[i] % 2 == 1) judge = false;
    }
    if(judge) {
        int ans = 0;
        rep(i, N) {
            if(V[i] == 2) {
                //n-1Ciの偶奇
                ans += solve(N - 1, i);
            }
        }
        if(ans % 2 == 1)
            cout << 2 << endl;
        else
            cout << 0 << endl;
    } else {
        int ans = 0;
        rep(i, N) {
            if(V[i] == 1) {
                ans += solve(N - 1, i);
            }
        }
        if(ans % 2 == 1)
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }
}


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

int main(){
  int n,y,x;
  cin >> n >> y;
  y /= 1000;
  for(x=0;x<=n;x++){
    if((y-n-x*9)%4==0&&y-n-x*9>=0&&5*n-y+5*x>=0){
      cout << x << ' ' << (y-n-x*9)/4 << ' ' << (5*n-y+5*x)/4 << endl;
      return 0;
    }
  }
  
  cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 9 * 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    vector<int> cnt(100010);
    for(int i = 0;i < N;i++) {
        int A;
        cin >> A;
        A++;
        cnt.at(A - 1)++;
        cnt.at(A)++;
        cnt.at(A + 1)++;
    }
    int ret = 0;
    for(int i = 0;i < 100010;i++) {
        ret = max(ret,cnt.at(i));
    }
    cout << ret << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<ctype.h>


int main()
{

	int a,b;
	scanf("%d%d",&a,&b);
	if(a*b==15){
		printf("*\n");
	}
	else if(a+b==15){
		printf("+\n");
	}
	else{
		printf("x\n");
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int d2(int n){
    int ans = 0;
    while(n%2 == 0){ans++; n /= 2;}
    return ans;
}

int main(){
    int n; cin>>n;
    int ans = inf;
    rep(i,n){
        int t; cin>>t;
        ans = min(ans, d2(t));
    }
    cout<<ans<<endl; return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define  vi vector<int>
#define pb push_back
//#define int long long
#define boost ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0)
#define pi pair<int,int>
#define F first
#define S second
using namespace std;

//int mod=(int)(1e9+7);

void solve()
{
 
 int a,b;
 cin>>a>>b;
 if(a>b)
 cout<<"safe";
 else cout<<"unsafe";

}

signed main()
{ boost;
 //cout<<fixed<<setprecision(14 );
 // int t;cin>>t;
  //for(int i=1;i<=t;i++)
  solve();
 // cout<<"Case #"<<i<<": "<<solve()<<endl;

return 0;
}

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

using namespace std;

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

    char S[5];
    cin >> S;
    int ans = 0;
    for (int i = 0; i < 4; ++i) {
        if (S[i] == '+') {
            ans++;
        } else {
            ans--;
        }
    }
    cout << ans << endl;
}


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

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

  int min;
  std::cin >> min;

  int x;
  std::cin >> x;
  int max_profit = x - min;
  min = std::min(min, x);

  for(int i = 0; i < n - 2; ++i) {
    std::cin >> x;
    max_profit = std::max(max_profit, x - min);
    min = std::min(min, x);
  }

  std::cout << max_profit << std::endl;

  return 0;
}

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int a,b,q;cin>>a>>b>>q;
  set<ll> st1,st2;
  for(int i=0;i<a;i++){ll t;cin>>t;st1.insert(t);}
  for(int i=0;i<b;i++){ll t;cin>>t;st2.insert(t);}

  for(int i=0;i<q;i++){
    ll x;cin>>x;
    ll ans=pow(10,15);
    vector<ll> u,v;
    auto it1 = st1.lower_bound(x);
    auto it2 = st2.lower_bound(x);
    if(it1!=st1.end())u.push_back(*it1);
    if(it2!=st2.end())v.push_back(*it2);
    if(it1!=st1.begin()){it1--;u.push_back(*it1);}
    if(it2!=st2.begin()){it2--;v.push_back(*it2);}
    for(int i=0;i<u.size();i++){
      for(int j=0;j<v.size();j++){
        for(int k=0;k<2;k++){
          ll t=0;
          if(k){//u->v
            t = abs(x-u[i])+abs(u[i]-v[j]);
          }else{
            //v->u
            t = abs(x-v[j])+abs(v[j]-u[i]);
          }
          ans=min(t,ans);
        }
      }
    }
    cout<<ans<<endl;
  }
 
  return 0;
}


Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  int ans =0;
  cin >> S;
  int N = S.size();
  for(int i=0;i < N/2;i++){
    if(S.at(i) != S.at(N - i - 1)){
      ans = 1;
      break;
    }
  }
  for(int i=0;i < (N-1)/4;i++){
    if(S.at(i) != S.at((N-1)/2 - i - 1)){
      ans = 1;
      break;
    }
    if(S.at(i + (N+3)/2 - 1) != S.at(N - i - 1)){
      ans = 1;
      break;
    }
  }
  if(ans==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App  {
  val sc   = new Scanner(System.in)

  val n = sc.nextInt
  val k = sc.nextInt

  val res = (1 to n).foldLeft(0.0){ (sum, i) =>
    val cnt = log2_x(0, k, i)
    sum + 1 / Math.pow(2,cnt)
  } / n

  println(res)

  def log2_x(cnt: Long, bound: Long, tmp: Long): Long ={
    if(tmp >= bound) cnt
    else log2_x(cnt + 1, bound, tmp * 2)
  }
}


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

int main(){
  int r,a,b;
  cin >> r >> a >> b;
  if((r*100+a*10+b)%4 == 0){
    puts("YES");
    return 0;
  }
  puts("NO");
  return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
before = sum(A)

for i in range(n):
    if A[i] > B[i]:
        A[i] -= B[i]
    else:
        B[i] -= A[i]
        A[i] = 0
        A[i + 1] = max(0, A[i + 1] - B[i])
after = sum(A)

answer = before - after
print(answer)


Measured memory_bytes: 19116
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(v) (v).begin(),(v).end()

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    while(1){
        int n,m;
        cin >> n >> m;
        if(n == 0){
            break;
        }
        vector<int> v1(n),v2(m);
        set<int> s1,s2;
        int sm = 0;
    	rep(i,n){
    		cin >> v1[i];
            sm += v1[i];
            s1.insert(v1[i]);
    	}
        rep(i,m){
            cin >> v2[i];
            sm += v2[i];
            s2.insert(v2[i]);
        }
        int ans;
        if(sm % 2 == 0){
            int sm1 = accumulate(v1.begin(),v1.end(),0);
            int sm2 = sm - sm1;
            if(sm1 == sm2){
                bool flag = false;
                rep(i,n){
                    if(s2.find(v1[i]) != s2.end()){
                        flag = true;
                        ans = v1[i];
                        break;
                    }
                }
                if(flag){
                    cout << ans << " " << ans <<  "\n";
                }else{
                    cout << "-1\n";
                }
            }else{
                bool flag = false;
                if(sm1 > sm2){
                    int sub = (sm1 - sm2) / 2;
                    rep(i,n){
                        if(s2.find(v1[i]-sub) != s2.end()){
                            flag = true;
                            ans = v1[i];
                            break;
                        }
                    }
                    if(flag){
                        cout << ans << " " << ans-sub << "\n";
                    }else{
                        cout << "-1\n";
                    }
                }else{
                    int sub = (sm2 - sm1) / 2;
                    rep(i,n){
                        if(s2.find(v1[i]+sub) != s2.end()){
                            flag = true;
                            ans = v1[i];
                            break;
                        }
                    }
                    if(flag){
                        cout << ans << " " << ans+sub << "\n";
                    }else{
                        cout << "-1\n";
                    }
                }
            }
        }else{
            cout << "-1\n";
        }
    }
	return 0;
}

Measured memory_bytes: 3024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long unsigned int llui_t;
typedef long long int lli_t;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

struct city {
    llui_t index;
    llui_t p;
    llui_t y;
    string id;
};

/* inputs */
llui_t N, M;
vector<city> X;

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

	for(llui_t i=0; i<M; i++) {
		llui_t p, y;
		cin >> p >> y;
        city x = {i, p, y, ""};
		X.push_back(x);
	}

    sort(X.begin(), X.end(), [](city c1, city c2){return c1.y < c2.y;});

    vector<llui_t> pn(N, 1);

    for(city& c:X) {
        ostringstream sout;
        sout << setfill('0') << setw(6) << c.p;
        sout << setfill('0') << setw(6) << pn[c.p-1]++;
        c.id = sout.str();
	}

    sort(X.begin(), X.end(), [](city c1, city c2){return c1.index < c2.index;});

    for(city c:X) {
        cout << c.id << endl;
	}

}


Measured memory_bytes: 8808
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll h,w;cin>>h>>w;
    vector<vector<char>> s(52,vector<char>(52));
    //読み込み
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cin>>s[i][j];
        }
    }
    ll count=0;
    for(int i=1;i<=h;i++){
        for(int j=1; j<=w; j++){
            if(s[i][j]=='#'&&s[i][j-1]=='.'&&s[i-1][j]=='.'&&s[i+1][j]=='.'&&s[i][j+1]=='.'){
                count++;
            }
        }
    }
    if(count>0){
        cout<<"No";
    }else{
        cout<<"Yes";
    }
    
    return 0;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;

int main(){
  int h,n,a,i,s=0;
  cin >> h >> n;
  for(i=0;i<n;i++){
    cin >> a;
    s += a;
  }
  if(s<h) cout << "No" << endl;
  else cout << "Yes" << 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++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int X,A; cin >> X >> A;
    cout << (X<A?0:10) << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <map> 
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int n;
struct node
{
	int id;
	int score;
}a[100005];
inline bool cmp(node x,node y)
{
	return x.score<y.score;
}
int main()
{
	fast;
	cin>>n;
	for (int i=1;i<=n;i++)
	   cin>>a[i].id>>a[i].score;
	sort(a+1,a+n+1,cmp);
	cout<<a[1].id+a[1].score<<endl;
	return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
A = [int(c) -1 for c in input().split()]

is_used = [False for _ in range(N)]
cycle_head, cycle_tail = -1, -1
cur, k = 0, 0
while True:
    if k == K:
        print(cur+1)
        exit()

    next_cur = A[cur]
    if is_used[next_cur]:
        head = next_cur
        tail = cur
        break

    else:
        is_used[cur] = True
        cur = next_cur
        k += 1


before_cycle = 0
len_cycle = 1
cur = 0
while cur != head:
    before_cycle += 1
    cur = A[cur]

while cur != tail:
    len_cycle += 1
    cur = A[cur]


k = (K - before_cycle) % len_cycle
cur = head
while k != 0:
    k -= 1
    cur = A[cur]
print(cur+1)


Measured memory_bytes: 99352
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()

base = 753
ans = 1000

for i in range(len(s)-2):
    if abs(base - int(s[i:i+3])) < ans:
        ans = abs(base - int(s[i:i+3]))

print(ans)


Measured memory_bytes: 61952
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long int64;
typedef pair<int64, int64> pll;

const int MAX_N = 100000;

int ops[MAX_N];

bool dp[MAX_N+1][3][3][3];
int prv[MAX_N+1][3][3][3];
int inc[MAX_N];

int stra(int64 &A,int64 &B,int64 &C,int op){
	if(op == 2){
		if(A >= B){
			--A, ++B;
			return 1;
		}else{
			++A, --B;
			return 0;
		}
	}
	if(op == 1){
		if(A >= C){
			--A, ++C;
			return 2;
		}else{
			++A, --C;
			return 0;
		}
	}
	if(op == 0){
		if(B >= C){
			--B, ++C;
			return 2;
		}else{
			++B, --C;
			return 1;
		}
	}
	assert(false);
	return -1;
}

bool solve(int N,int64 A,int64 B,int64 C){
	if(A+B+C >= 3){
		//A is rich
		if(B == 0 && C == 0) if(ops[0] == 0)	return false;
		//B is rich
		if(A == 0 && C == 0) if(ops[0] == 1)	return false;
		//C is rich
		if(A == 0 && B == 0) if(ops[0] == 2)	return false;

		for (int i = 0; i < N; ++i)
				inc[i] = stra(A,B,C,ops[i]);
		return true;
	}

	if(A+B+C <= 2){
		dp[0][A][B][C] = 1;
		for (int i = 0; i < N; ++i){
			for (int nA = 0; nA <= 2; ++nA)
			for (int nB = 0; nB <= 2; ++nB)
			for (int nC = 0; nC <= 2; ++nC){
				if(dp[i][nA][nB][nC] == false)	continue;

				if(ops[i] == 0){
					if(nB-1 >= 0){
						dp[i+1][nA][nB-1][nC+1] = true;
						prv[i+1][nA][nB-1][nC+1] = 2;
					}
					if(nC-1 >= 0){
						dp[i+1][nA][nB+1][nC-1] = true;
						prv[i+1][nA][nB+1][nC-1] = 1;
					}
				}
				if(ops[i] == 1){
					if(nA-1 >= 0){
						dp[i+1][nA-1][nB][nC+1] = true;
						prv[i+1][nA-1][nB][nC+1] = 2;
					}
					if(nC-1 >= 0){
						dp[i+1][nA+1][nB][nC-1] = true;
						prv[i+1][nA+1][nB][nC-1] = 0;
					}
				}
				if(ops[i] == 2){
					if(nA-1 >= 0){
						dp[i+1][nA-1][nB+1][nC] = true;
						prv[i+1][nA-1][nB+1][nC] = 1;
					}
					if(nB-1 >= 0){
						dp[i+1][nA+1][nB-1][nC] = true;
						prv[i+1][nA+1][nB-1][nC] = 0;
					}
				}
			}
		}
		bool ret = false;
		int i,j,k;
		for (int nA = 0; nA <= 2; ++nA)
		for (int nB = 0; nB <= 2; ++nB)
		for (int nC = 0; nC <= 2; ++nC){
			if(dp[N][nA][nB][nC]){
				i = nA, j = nB, k = nC;
				ret = true;
			}
		}

		if(ret == false)	return false;

		for (int t = N; t > 0; --t){
			int m = prv[t][i][j][k];
			inc[t-1] = m;
			if(m == 0){
				--i;
				if(ops[t-1] == 1)	++k;
				if(ops[t-1] == 2)	++j;
			}
			if(m == 1){
				--j;
				if(ops[t-1] == 0)	++k;
				if(ops[t-1] == 2)	++i;
			}

			if(m == 2){
				--k;
				if(ops[t-1] == 0)	++j;
				if(ops[t-1] == 1)	++i;
			}
		}
		return true;
	}
	assert(false);
	return 0;
}
char buffer[100];
int main(){
	int N,A,B,C;	scanf("%d%d%d%d",&N,&A,&B,&C);
	for (int i = 0; i < N; ++i){
		scanf(" %s",buffer);
		if(buffer[0] != 'A' && buffer[1] != 'A')	ops[i] = 0;
		if(buffer[0] != 'B' && buffer[1] != 'B')	ops[i] = 1;
		if(buffer[0] != 'C' && buffer[1] != 'C')	ops[i] = 2;
	}
	if(solve(N,A,B,C)){
		puts("Yes");
		for (int i = 0; i < N; ++i)
			printf("%c\n","ABC"[inc[i]]);
	}else{
		puts("No");
	}
}

Measured memory_bytes: 15696
#include <stdio.h>

int main()
{
int S;
int h,m,s;

  scanf("%d",&S);

  h=S/3600;
  S%=3600;

  m=S/60;
  S%=60;

  s=S;

  printf("%d:%d:%d\n",h,m,s);

  return 0;
}


Measured memory_bytes: 592
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>

using namespace std;
typedef long long int ll;

ll n,a[2][200],mx=0,ca=0,ci=0;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[0][i]);
    for(int i=0;i<n;i++){
        scanf("%d",&a[1][i]);
        ci+=a[1][i];
    }
    ca=a[0][0];
    for(int i=0;i<n;i++){
        mx=max(mx,ca+ci);
        ci-=a[1][i];
        ca+=a[0][i+1];
    }
    printf("%lld\n",mx);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(r) do{cout<<#r": ";for(const auto &i:r){cout<<i<<" ";}cout<<endl;}while(0)
int main()
{
    int N; cin >> N;
    int m = 1000, M = 0;
    REP(i, N) {
        int a; cin >> a;
        m = min(m, a);
        M = max(M, a);
    }
    cout << (M - m) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 300001
using namespace std;
int n,mxx,mxy,sx[N],sy[N];
vector<int>gx,gy;
map<pair<int,int>,char>mp;
int main(void){
	int i,x,y;scanf("%d%d%d",&x,&y,&n);
	while(n--)scanf("%d%d",&x,&y),mxx=max(mxx,++sx[x]),mxy=max(mxy,++sy[y]),mp[make_pair(x,y)]=1;
	for(i=1;i<=300000;++i)if(sx[i]==mxx)gx.push_back(i);
	for(i=1;i<=300000;++i)if(sy[i]==mxy)gy.push_back(i);
	for(int x:gx)for(int y:gy)if(!mp.count(make_pair(x,y)))return printf("%d\n",mxx+mxy),0;//至少一对不重合 
	printf("%d\n",mxx+mxy-1);//都必定重叠 
	return 0;
}

Measured memory_bytes: 28568
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in range(m)]
abc=[[t[0],t[1],-t[2]] for t in abc]
def BF(edges,num_v,source):
    #グラフの初期化
    inf=float("inf")
    dist=[inf for i in range(num_v)]
    dist[source-1]=0
  
    #辺の緩和
    neg=[False for _ in range(num_v)]
    for i in range(num_v-1):
        for edge in edges:
            if edge[0] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
                dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
    for i in range(num_v):
        for edge in edges:
            if edge[0] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
                dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
                neg[edge[1]-1]=True
            if neg[edge[0]-1]==True:
                neg[edge[1]-1]=True
    return dist,neg
dis,neg=BF(abc,n,1)
#print(dis,neg)
if neg[-1]:
    print("inf")
else:
    print(-dis[-1])

Measured memory_bytes: 46680
N = int(input())
mod = 10**9+7
dp = [[[[0 for k in range(4)] for j in range(4)] for i in range(4)] for length in range(N+1)]
dp[0][3][3][3] = 1
#文字列の長さ
for length in range(N):
    #後ろから1文字目
    for c1 in range(4):
        #後ろから2文字目
        for c2 in range(4):
            #後ろから3文字目
            for c3 in range(4):
                if dp[length][c1][c2][c3]==0:
                    continue
                #追加する文字
                for a in range(4):
                    #ダメな条件
                    if a == 2 and c1 == 1 and c2 == 0:
                        continue
                    elif a == 2 and c1 == 0 and c2 ==1:
                        continue
                    elif a == 1 and c1 == 2 and c2 ==0:
                        continue
                    elif a == 2 and c1 == 1 and c3 == 0:
                        continue
                    elif a == 2 and c2 == 1 and c3 == 0:
                        continue
                    else:
                        dp[length+1][a][c1][c2] += dp[length][c1][c2][c3]
                        dp[length][c2][c3][a] %= mod
ans = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += dp[N][i][j][k]
print(ans%mod)

Measured memory_bytes: 3316
#include<stdio.h>
#include <string.h>


int main(void){
    int a,b;
    char c[100];
    int u,w,x,y,z;
    while(1){
        scanf("%d %s %d",&a,&c,&b);
        u = strcmp("?",c);
        w = strcmp("+",c);
        x = strcmp("-",c);
        y = strcmp("*",c);
        z = strcmp("/",c);
        
        if(u==0)
            break;
        if(w==0)
            printf("%d\n",a+b);
        if(x==0)
            printf("%d\n",a-b);
        if(y==0)
            printf("%d\n",a*b);
        if(z==0)
            printf("%d\n",a/b);
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define pq priority_queue
using namespace std; typedef pair<int, int> P; typedef pair<int, P> P2;
typedef pair<int, P2> P3; typedef long long ll; typedef long double ld;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<10> fact; constexpr Prime<10> prime;
constexpr int comb(int a, int b){long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b];return pos * pot % MOD * por % MOD;}
template<int n> struct Bernoulli{long long arr[n+1];constexpr Bernoulli():arr(){arr[0]=1;for(int i=1;i<=n;i++){long long sum=0;for(int j=0;j<i;j++){(sum+=comb(i+1,j)*arr[j]%MOD)%=MOD;}arr[i]=(MOD-mod_pow(i+1,MOD-2,MOD))%MOD*sum%MOD;}}};
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr int sqrtN = 512, logN = 32;
constexpr ld PI = abs(acos(-1));
constexpr ll LINF=1e18;

int main(){
	ll n, k; cin >> n >> k;
	if(!k){
		cout << n * n << endl;
		return 0;
	}
	
	ll s = 0;
	for(int i = k + 1; i <= n; i++){
		s += n / i * max(0LL, (i - k)) + max(0LL, (n % i - k + 1));
	}
	
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

 long long modpow(long long n, long long k,long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}
const int N = 1e6 + 10;
//const int mod = 1e9 + 7;

ll fac[N];

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i < N; i++)
        fac[i] = fac[i - 1] * i % mod;
}

ll inv(ll a) {
	return binpow(a, mod - 2);
}

ll A(ll n, ll m) {
	return fac[n] * inv(fac[n - m]) % mod;
}

ll C(ll n, ll m) {
    return fac[n] * inv(fac[m]) % mod * inv(fac[n - m]) % mod;
}

void solve(){
     init();
     int n;cin >>n;
     ll ans = 0;
     for(ll i = 2;i<=n;i++){
        ans += (C(n,i)%mod*modpow(8,n-i,mod)%mod*(modpow(2,i,mod)-2)%mod)%mod;
        ans %= mod;
     }
     ans = (ans+mod)%mod;
     cout << ans;
}

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

Measured memory_bytes: 11468
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int N;
    int score[101]={0};
    cin>>N;
    for(int i=0;i<N*(N-1)/2;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        if(c>d)score[a]+=3;
        else if(c<d)score[b]+=3;
        else score[a]++,score[b]++;;
    }
    for(int i=1;i<=N;i++){
        int cou=0;
        for(int j=1;j<=N;j++){
            if(score[i]<score[j])cou++;
        }
        cout<<cou+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import java.lang.Long.parseLong
import java.util.*

fun main(args:Array<String>) {
    val reader = System.`in`.bufferedReader()
    val (N, Q) = reader.readLine()!!.split(" ").map(Integer::parseInt)

    val list = mutableListOf<Triple<Long, Long, Boolean>>()
    for (i in 0 until N) {
        val (S, T, X) = reader.readLine()!!.split(" ").map(java.lang.Long::parseLong)
        list.add(Triple(S-X, X, true))
        list.add(Triple(T-X, X, false))
    }
    list.sortBy { it.first }

    val D = LongArray(Q){parseLong(reader.readLine()!!)}
    D.sort()
    val ans = mutableListOf<Long>()

    var l = 0
    val set = TreeSet<Long>()
    for (d in D) {
        while (l != list.size) {
            var q = list[l]
            if (q.first > d)
                break
            when(q.third){
                true->set.add(q.second)
                false->set.remove(q.second)
            }
            l++
        }
        ans.add(if (set.isEmpty()) -1 else set.first())
    }
    println(ans.joinToString("\n"))
}

Measured memory_bytes: 163476
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if ((i < b && j < a) || (i >= b && j >= a)) {
                    // System.out.print("1");
                    sb.append("1");
                } else {
                    // System.out.print("0");
                    sb.append("0");
                }
            }
            // System.out.println();
            sb.append("\n");
        }
        System.out.println(sb.toString());

        sc.close();
    }

}


Measured memory_bytes: 29364
/*
                  ,     \    /      ,
                 / \    )\__/(     / \
                /   \  (_\  /_)   /   \
           ____/_____\__\@  @/___/_____\____
          |             |\../|              |
          |              \VV/               |
          |        ------___-------         |
          |__________Chuta Dragon___________|
           |    /\ /      \\       \ /\    |
           |  /   V        ))       V   \  |
           |/     `       //        '     \|
           `              V                '
        */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

int main()
{
    fastread();


    ll a,b,c,d;

    cin>>a>>b>>c>>d;

    ll ara[5];

    ara[0]=a*c;
    ara[1]=a*d;
    ara[2]=b*c;
    ara[3]=b*d;

    sort(ara,ara+4);

    cout<<ara[3]<<endl;




}


Measured memory_bytes: 3652
#include<stdio.h>
#include<string.h>
int main(void) {
	char a[200], b[100], c[200] = {0};
	scanf("%s", a);
	scanf("%s", b);
	strcpy(c, a);
	strcat(a, c);
	printf("%s\n", (strstr(a, b) != NULL) ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 2092
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
 
struct era{
  era(){name="";s=0;e=0;};
  era(string str,int a,int b){
    name=str;
    s=a;
    e=b;
  }
  string name;
  int s,e;
};
 
bool operator<(era a,era b){
  return a.s<b.s;
}
 
int n,q;
vector<era> eras;
void init(){
  n=q=0;
  eras.resize(0);
}
bool input(){
  cin>>n>>q;
  return n!=0||q!=0;
}
 
bool input_era(){
  string str;
  int a,b;
  for(int i=0;i<n;i++){
    cin>>str>>a>>b;
    eras.push_back(era(str,b-a+1,b));
  }
  sort(eras.begin(),eras.end());
}
 
era serch(int n){
  for(int i=0;i<eras.size();i++){
    if(eras[i].s<=n&&n<=eras[i].e){
      return eras[i];
    }
  }
  return era("Unknown",-100,-100);
}
 
 
void solve(){
  for(int i=0;i<q;i++){
    int qu;
    cin>>qu;
    era ans=serch(qu);
    if(ans.s==-100&&ans.e==-100){
      cout<<ans.name<<endl;
    }else{
      cout<<ans.name<<" "<<qu-ans.s+1<<endl;
    }
  }
}
 
int main(){
  while(init(),input()){
    input_era();
    solve();
  }
}

Measured memory_bytes: 1292
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll A, B;
	cin >> A >> B;
	if (A>8||B>8) { cout << ":(" << endl; }
	else { cout << "Yay!" << endl; }

}


Measured memory_bytes: 3572
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main()
{
    std::unordered_set<char> s;
    char c;
    for (int i = 0; i < 4; ++i) {
        std::cin >>c;
        s.insert(c);
    }

    if (s.count('1') == 1 && s.count('9') == 1 && s.count('7') == 1 && s.count('4') == 1) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
from operator import itemgetter

N = int(input())
L = [[int(x) for x in input().split()] for _ in range(N)]


for i in range(N):
    L[i].append(L[i][1]-L[i][0])
    
L.sort()
#L.sort(key=itemgetter(1))
#L.sort(key=itemgetter(2))
    

la = L[0][0]
ra = L[0][1]
lb = L[1][0]
rb = L[1][1]
ans = L[-1][2]+1
for i in range(2, N):
    ta = max(0, min(ra, L[i][1])-max(la, L[i][0])+1) + rb-lb+1
    tb = max(0, min(rb, L[i][1])-max(lb, L[i][0])+1) + ra-la+1
    tc = max(0, min(ra, rb)-max(la,lb)+1) + L[i][1]-L[i][0]+1
    if max(ta, tb, tc) == ta:
        la = max(la, L[i][0])
        ra = min(ra, L[i][1])
    elif max(ta, tb, tc) == tb:
        lb = max(lb, L[i][0])
        rb = min(rb, L[i][1])
    else:
        la = max(la, lb)
        ra = min(ra, rb)
        lb = L[i][0]
        rb = L[i][1]
        
ans = max(ans, max(0, ra-la+1) + max(0, rb-lb+1))


print(ans)

Measured memory_bytes: 67160