akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
x = []
for i in range(m):
    x.append(list(map(int, input().split())))

d = [-10**13 for i in range(n)]
d[0] = 0
flag = [0 for i in range(n)]
flag[0] = 1
d2 = [-10**13 for i in range(n)]
d2[0] = 0
flag2 = [0 for i in range(n)]
flag2[0] = 1

for i in range(n):
    for j in range(m):
        if flag[x[j][0] - 1]:
            d[x[j][1] - 1] = max(d[x[j][1] - 1], d[x[j][0] - 1] + x[j][2])
            flag[x[j][1]-1] = 1

for i in range(2*n+1):
    for j in range(m):
        if flag2[x[j][0] - 1]:
            d2[x[j][1] - 1] = max(d2[x[j][1] - 1], d2[x[j][0] - 1] + x[j][2])
            flag2[x[j][1] - 1] = 1

if d2[n-1] > d[n-1]:
    print("inf")
else:
    print(d[n-1])


Measured memory_bytes: 47320
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int n; cin >> n;
    map<int, int> m;
    vector<int> v;
    rep(i, n){
        int a; cin >> a;
        m[a]++;
        if(m[a]==1) v.push_back(a);
    }   
    sort(ALL(v));

    // pr
    ll ans = 0;
    rep(i, v.size()){
        int a = v[i];
        FOR(j, i+1, v.size()){
            int b = v[j];
            FOR(k, j+1, v.size()){
                int c = v[k];
                if(a+b > c && b+c > a && c+a > b){
                    ans += m[a]*m[b]*m[c];
                }
            }
        }
    }
    pr(ans);

    return 0;}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<stack>
#include<queue>
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long 
#define ull unsigned long long
#define MOD 998244353 
#define inf 2147483647

int a,b,c,k;

int main()
{
	read(a),read(b),read(c),read(k);
	if(k<=a) printf("%d\n",k);
	else if(k<=a+b) printf("%d\n",a);
	else printf("%d\n",a-(k-a-b));
	return 0; 	
}


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

int tarnsform(long long N,int k)
{
    string result;
    while(N)
    {
        result += N%k+'0';
        N/=k;
    }
    reverse(result.begin(),result.end());
    return result.size();
}
void solve(long long N, long long K){
    cout<<tarnsform(N,K)<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


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

int main(){
  int n;cin >> n;
  vector<int> b(n-1);
  int sum=0;
  rep(i,n-1){
    cin >> b.at(i);
    if(i>0)sum += min(b.at(i),b.at(i-1));
  }
  sum += b.at(0)+b.at(n-2);
  cout << sum;
}

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

bool kaibun(int n) {
    int a[5], b[5];
    for(int i = 0; i < 5; ++i) {
        a[i] = b[4-i] = n%10;
        n/=10;
    }
    bool f=true;
    for(int i = 0; i < 5; ++i) {
        if(a[i]!=b[i]) {
            f=false;
            break;
        }
    }
    return f;
}


int main() {
    int A,B;
    cin >> A >> B;
    int ans = 0;
    for(int i = A; i <= B; ++i) {
        if(kaibun(i)) ++ans;
    }
    cout << ans << endl;


}

Measured memory_bytes: 256
N = int(input())
li = []
for i in range(N):
    A = int(input())
    li.append([[int(j) for j in input().split()] for k in range(A)])

ans = 0

for i in range(1 << N):
    consistent = True  # 全ての証言と矛盾がなければTrue
    honests = 0  # 正直者の人数
    for j in range(N):  # j番目の人の証言をチェックする
        if not consistent:
            break
        claims = li[j]  # j番目の人の証言リスト
        if (i >> j) & 1 == 1:
            # i is honest
            honests += 1
            for claim in claims:
                if (i >> (claim[0] - 1)) & 1 != claim[1]:
                    # 正直者・嘘つきの仮定と証言が一致しない
                    consistent = False
                    break
    if consistent:
        ans = max(ans, honests)

print(ans)


Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))

res = [0 for _ in range(N)]

res[0] = sum(A)

for i in range(N-1):
    if i%2 == 1:
        res[0] -= 2 * A[i]

for i in range(N-1):
    res[i+1] = 2 * A[i] - res[i]

result = ''
for res in res:
    result += str(res) + ' '
    
print(result)

Measured memory_bytes: 14028
from math import sqrt
from itertools import permutations

n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]

dd = [[0]*n for _ in range(n)]
for i in range(n):
  for j in range(i,n):
    dd[i][j] = dd[j][i] = sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)

p = permutations(range(n),n)

ans = 0
count = 0
for v in p:
  count+=1
  add = 0  
  for i in range(n-1):
    add += dd[v[i]][v[i+1]]
  ans += add
  
print(ans/count)  

Measured memory_bytes: 3064
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long A[] = new long [N];
    
    for(int i=0; i<N; i++){
      A[i]=sc.nextInt();
    }
    int count = 0;
    boolean next = true;
    while (next) {
      for (int i = 0; i < A.length; i++) {
        if (A[i] % 2 == 0) {
          A[i] = A[i] / 2;
        } else {
          next = false;
        }
      }
      if (next) {
        count++;
      }
    }
    System.out.printf("%d\n", count);
  }
}

Measured memory_bytes: 36068
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define pll pair <ll,ll>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<=(ll)n;i++)
#define rep(i,x,y) for(ll i=(ll)x;i<=(ll)y;i++)
#define reprev(i,n) for(ll i=(ll)n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

// FOR DEBUGGING
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", ";
	else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

const int mod = 1e9+7;
const long double pi = acos(-1);
const ll INF = 1e15;

ll power(ll x, ll y){
	x %= mod;
	ll ans = 1;
	while(y){
		if(y&1) ans = (ans*x)%mod;
		y /= 2;
		x = (x*x)%mod;
	}
	return ans;
}

void solve(){

	int n,k;
	cin >> n >> k;
	vector <int> p(n);
	rep0(i,n) cin >> p[i];
	sort(all(p));
	int ans = 0;
	rep0(i,min(n,k)) ans += p[i];
	cout << ans;

	return;
}

int main(){

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

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 3844
from sys import stdin
n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))
A = sum(a);B = sum(b)
count_1 = 0
count_2 = 0
total = B-A
for i,j in zip(a,b):
    if i < j:
        count_1 += (j-i+1)//2
    else:
        count_2 += i-j
count = max(count_1,count_2)
if count <= total:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4596
// by syu
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var in = NewScanner(os.Stdin, 0)

func main() {
	s, k := in.String(), in.Int()
	for i, x := range s {
		if i >= k {
			break
		}
		if x != '1' {
			Rf("%c\n", x)
		}
	}
	Pln("1")
}

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader, max int) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(scanWords)
	if max <= 0 {
		max = 1048576
	}
	s.Buffer([]byte{}, max)
	return &Scanner{s}
}
func (s *Scanner) String() string {
	s.Scan()
	return s.Text()
}
func (s *Scanner) Int() int {
	s.Scan()
	i, e := strconv.ParseInt(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}
func isSpace(b byte) bool {
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}
func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	start := 0
	for start < len(data) && isSpace(data[start]) {
		start++
	}
	for i := start; i < len(data); i++ {
		if isSpace(data[i]) {
			return i + 1, data[start:i], nil
		}
	}
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	return start, nil, nil
}
func Pln(s ...interface{}) {
	fmt.Println(s...)
}
func Rf(f string, s ...interface{}) {
	fmt.Printf(f, s...)
	os.Exit(0)
}


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

int main(){
    ll X; cin >> X;
    
    for (ll i = 0; i <= 1000; i++)
    {
        for (ll j = -1000; j <= 1000; j++)
        {
            ll t = i*i*i*i*i - j*j*j*j*j;
            if(t==X){
                cout << i << " " << j << endl;
                return 0;
            }
        }
        
    }
    
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int s,w;cin >> s >> w;
    if(w>=s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>

long calc(long max, long count) {
  return (max - count + 1) * count + 1;
}

int main(void) {
  int n, k;
  
  scanf("%d %d", &n, &k);
  if(k > n) {
    printf("1\n");
    return 0;
  }
  long ret = 0;
  for(int i = k;i <= n + 1;i++) {
    ret += calc(n, i);
  }
  ret %= 1000000007;
  printf("%ld\n", ret);
  return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 6e5 + 5;
ll t[4 * N];
void update(ll v, ll tl, ll tr, ll idx, ll val){
    if(tl == tr){
        t[v] = 1 + val;
        return;
    }
    ll tm = (tl + tr) / 2;
    if(idx <= tm){
        update(2 * v, tl, tm, idx, val);

    }
    else{
        update(2 * v + 1, tm + 1, tr, idx, val);
    }
    t[v] = max(t[2 * v], t[2* v + 1]);
} 
ll query(ll v, ll tl, ll tr, ll l, ll r){
    if(l > r){
        return -INF;
    }
    if(tl == l && tr == r){
        return t[v];
    }
    ll tm = (tl + tr) / 2;
    ll lef = query(2 * v, tl, tm, l, min(r, tm));

    ll rig =  query(2 * v + 1, tm + 1, tr, max(tm + 1, l), r);
    
    return max(lef, rig);
} 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n, k;
        cin >> n >> k;
        vector<ll> v(n);
        for(i = 0; i < n; i++){
            cin >> v[i];
            v[i]++;
        }
        ll ans = 1;
        for(i = 0; i < n; i++){
            ll l, r;
            l = max(1LL, v[i] - k);
            r = min(600001LL, v[i] + k);
            ll val = query(1, 1, 600001, l, r);
            update(1, 1, 600001, v[i], val);
            ans = max(ans, 1 + val);
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 13948
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    vector <int> a(3);
    for (int i = 0; i < 3; ++i)
        cin >> a[i];


    for (int t = 0; t < 2007; ++t) {
        vector <int> b(3);
        for (int i = 0; i < 3; ++i) {
            if (a[i] & 1) {
                cout << t << endl;
                exit(0);
            }   
            for (int j = 0; j < 3; ++j)
                if (j != i)
                    b[j] += a[i] >> 1;
        }   
        a = b;
    }   
    cout << "-1" << endl;

}   

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

int main() {
    int N, K, S;
    cin >> N >> K >> S;
    for(int i = 0; i < N; ++i) {
        if(i < K){
            cout << S << " ";
        } else {
            int T = S + 1;
            if(T >=1000000000) T = S - 1;
            cout << T << " ";
        }
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 1280
/*
 * atcoder/abc130/a.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N, M;
int counter[31] = {0};

void input() {
  cin >> N >> M;
}

void solve() {
  int K, a;
  loop(n,0,N) {
    cin >> K;
    loop(k,0,K) {
      cin >> a;
      counter[a]++;
    }
  }

  int total = 0;
  loop(m,0,M+1) {
    total += counter[m] == N;
  }
  cout << total << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define ranger(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define repr(i, b) for (int i = (b)-1; i >= 0; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

signed main() {
	double h, w, n;
	cin >> h >> w >> n;

	cout << ceil(n / max(h, w)) << endl;
}


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

using namespace std;

long long cnt = 1;
int n;
bool v;
int b[100005];

void f(int p)
{
    for(int i = 0; i < p; i++)
    {
        cnt = 2 * cnt % (1000000007);
    }
}

int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        int t;
        scanf("%d", &t);
        b[t]++;
    }
    if(b[(n + 1) % 2] != (n + 1) % 2 + 1)
    {
        v = true;
    }
    for(int i = (n + 1) % 2 + 2; i < n; i+=2)
    {
        if(b[i] != 2)v = true;
    }
    if(v)
    {
        printf("0");
        return 0;
    }
    else
    {
        f(n / 2);
        printf("%lld", cnt);
    }
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
 
const int N = 2e6 + 6;
const int M = 1e9+7;
int A[N];
int n , m;

void solve()
{
	int n , k;
	cin >> n >> k;

	loop(i,0,n)cin >> A[i];

	int sum = 0;
	sort(A,A+n);

	loop(i,0,k)sum += A[i];

	cout << sum;

}			
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	
 
 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 3648
n = int(input())
strs = [input() for _ in range(n)]
chars = 'abcdefghijklmnopqrstuvwxyz'
char_dict = dict.fromkeys(chars, 51)

for s in strs:
    tmp = dict.fromkeys(chars, 0)
    for c in s:
        tmp[c] += 1
    for c in chars:
        char_dict[c] = min(char_dict[c], tmp[c])

print(''.join([c * char_dict[c] for c in chars]))


Measured memory_bytes: 3060
while True:
	H,W = list(map(int, input().split()))
	if (H == 0 and W == 0):
		break
	else:
		for n in range(0, H):
			s = ""
			for m in range(0, W):
				if (1 <= n and n <= (H-2)) and (1 <= m and m <= (W-2)):
					s += "."
				else:
					s += "#"
			print(s)
		print("")

Measured memory_bytes: 7628
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[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 COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
vector<vector<pair<int, int>>> s(100030);
long long int seen[100020] = {};
long long int value[100020] = {};
int main() {
	int n;
	int q, k;
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		s[a].push_back(make_pair(b, c));
		s[b].push_back(make_pair(a, c));
	}
	cin >> q >> k;
	queue<int> que;
	seen[k] = 1;
	que.push(k);
	while (que.size()) {
		int t = que.front();
		que.pop();
		for (auto i : s[t]) {		
			if (seen[i.first] == 0) {
				value[i.first] = value[t] + i.second;
				seen[i.first] = 1;
				que.push(i.first);
			}
		}
	}
	vector<pair<int, int>> l;
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		l.push_back(make_pair(x, y));
	}
	for (int i = 0; i < l.size(); i++) {
		cout << value[l[i].first] + value[l[i].second] << endl;
	}
}

Measured memory_bytes: 11124
N=int(input())
A=list(map(int,input().split()))

aA_n=[0]
for i in range (N):
    aA_n.append(A[i]+aA_n[-1])
aA_n=aA_n[1:]


rA=A[::-1]
aA_r=[0]
for i in range (N):
        aA_r.append(rA[i]+aA_r[-1])
aA_r=aA_r[1:]
aA_r=aA_r[::-1]

ans=aA_n[-1]
for i in range (N-1):
    _tempans=abs(aA_n[i]-aA_r[i+1])
    if _tempans<ans:
        ans=_tempans

print(ans)


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

using namespace std;

int main() {
	int N;
	cin >> N;
	int A[222];
	int ans = 100;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		int res = 0;
		while (A[i] % 2 == 0) {
			A[i] /= 2;
			res++;
		}
		ans = min(ans, res);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", _dmp_(#__VA_ARGS__, __VA_ARGS__);
void _dmp_(const char*) { cerr << endl; }
template <class T, class... U>
void _dmp_(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; _dmp_(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S> const& p) { return is >> p.first >> p.second; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
#define YesNo(c) ((c) ? "Yes" : "No")
////////////////////////////////

int32_t main() {
    int n; cin >> n;
    vector<int> a(n),b(n),c(n-1); cin >> a >> b >> c;
    for (int& x : a) x--;
    
    int s = 0;
    rep (i,n) s += b[a[i]];
    rep (i,n-1) if (a[i]+1 == a[i+1]) s += c[a[i]];
    cout << s << endl;    
}


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

int main() {
  string s,t;
  cin >> s >> t;
  
  int n = 0;
    
  for(int i=0;i<3;i++){
    if(s.at(i)==t.at(i)){
      n++;
    }
  }
  cout << n << endl;
}

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

int main()
{
    string s, t;
    cin >> s >> t;
    string u = t.substr(0, t.size() - 1);
    if (s == u) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll i,j,k;


int main(){
    ll n,m;cin>>n>>m;
    

    vector<ll> a(n);
    for(i=0;i<n;i++){
        cin>>a[i];
    }

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

    vector<ll> b(m),c(m);
    for(i=0;i<m;i++){
        cin>>b[i]>>c[i];
    }

    vector<pair<ll,ll>> P(m);
    for(i=0;i<m;i++){
        P[i]=make_pair(c[i],b[i]);
    }

    sort(P.begin(),P.end(),greater<pair<ll,ll>>());//cの大きい順にsort

    ll keymax,num=0,key=0,sum=0;
    for(i=0;i<m;i++){
        vector<long long int>::iterator position;
        position=lower_bound(a.begin()+num,a.end(),P[i].first);//置き換え済みのものの次から順に見ていく
        key=distance(a.begin(),position);
        if(key==num && P[i].first<a[num]){break;}
        
        key-=num;//num:置き換え済みのものの個数->keyは次に置き換え可能なものの個数
        if(key>=P[i].second){sum+=P[i].first*P[i].second;num+=P[i].second;}
        //a[num]以前のa[i]は置き換え済み
        //keyがcの個数(b)以上の時はb個を小さいものからcで置き換える方がよい
        else{sum+=P[i].first*key;num+=key;break;}
    }

    for(i=num;i<n;i++){
        sum+=a[i];
    }

    cout<<sum<<endl;
    return 0;
}

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

const int MAX_V = 1000;
const int MAX_E = 2000;
const long long INF = 9e18;
struct edge{ int from, to, cost; };
edge e[MAX_E + 10];
long long d[MAX_V + 10];
int V, E;

// 負の閉路が存在するかどうか
bool bellman_ford(){
    for (int i = 1; i <= V; ++i) d[i] = INF;
    d[1] = 0;

    // |V|回目のループで更新が発生していれば負の閉路が存在する
    for (int i = 1; i <= V; ++i){

        bool update = false;
        bool goal_update = false;
        // すべての辺に関して更新がないか調べる
        for (int j = 0; j < E; ++j){
            edge _e = e[j];
            if (d[_e.from] != INF && d[_e.to] > d[_e.from] + _e.cost){
                d[_e.to] = d[_e.from] + _e.cost;
                update = true;
                if (_e.to == V) goal_update = true;
            } 
        }
        // 更新がなければ負の閉路は存在しない
        if (!update) return false;
        if (i == V && goal_update) return true;
    }
    return false;
}




int main(){

    cin >> V >> E;
    for (int i = 0; i < E; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        e[i] = edge{a,b,-c};
    }

    if (bellman_ford()){
        cout << "inf" << endl;
    }else{
        cout << -d[V] << endl;
    }

    return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long X, Y;
    cin >> X >> Y;

    if (X % Y == 0) cout << -1 << '\n';
    else cout << X << '\n';

    return 0;
}

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

int main(){
  bool turnA = true;
  long long a, b;
  int k;
  cin >> a >> b >> k;
  for (int n = 0; n < k; n++) {
    if(turnA){
      if(a%2==0){

      }else{
        a--;
      }
      a/=2;
      b+=a;
      turnA = !turnA;
    }else{
      if(b%2==0){

      }else{
        b--;
      }
      b/=2;
      a+=b;
      turnA = !turnA;
    }
  }
  cout << a << " "<< b << endl;

  return 0;
}


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

int main(){
	int N;
	cin >> N;
	vector<long> a(N);
	for(int i=0; i<N; i++) cin >> a[i];


	int odd = 0,
		four = 0,
		even = 0;

	for(int i=0; i<N; i++){
		if(a[i]%2 == 1)
			odd++;
		if(a[i]%4 == 0) {
			four++;
			continue;
		}
		if(a[i]%2 == 0)
			even++;
	}

	
	if(odd <= four || (odd == four+1 && even == 0))
		cout << "Yes" << endl;
	else cout << "No" << endl;
}




Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
 int a[10001];
 for (int i = 0; i < 10001; i++)
 {
  int x;
  cin >> x;
  a[i] = x;
  if (x != 0) continue;
  for (int j = 1; j <= i; j++)
  cout << "Case " << j << ": " << a[j - 1] << endl;
 }
 return 0;
}

Measured memory_bytes: 3008
while True:

  n = int(raw_input())

  if n == 0:
   break

  A_score = B_score = 0

  for i in range(n):

    A, B = map(int, raw_input().split())

    if A > B:
      A_score += (A + B)

    elif A == B:
      A_score += A
      B_score += B

    else:
      B_score += (A + B)

  print A_score, B_score

Measured memory_bytes: 6560
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
LD t1, t2, n, d, ans = 0;

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

	cin >> n >> d;
	while(n--){
		cin >> t1 >> t2;
		if(sqrt(t1*t1 + t2*t2) <= d)ans++;
	} cout <<ans << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 3800
#include<iostream>
#include<algorithm>
#define v(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,m,q[2]={0},s=0,a[10];
	long long dp[2][10],c[10];
	char z;
	cin>>n;
	v(i,n){
		cin>>z;
		if(z=='*')q[1-((n-i)%2)]++;
		else{
			z-='0';
			if((n-i)%2==0)z=(z*2-1)%9+1;
			s+=z;
		}
	}
	cin>>m;
	v(i,m)cin>>a[i];
	v(i,2)v(j,10)dp[i][j]=0;
	v(i,2)dp[i][0]=1;
	v(i,2){
		v(j,q[i]){
			v(k,10)c[k]=0;
			v(k,m){
				v(r,10){
					c[(r+a[k])%10]+=dp[i][r];
				}
			}
			v(k,10)dp[i][k]=c[k];
		}
		v(i,m)a[i]=(a[i]*2-1)%9+1;
	}
	long long ans=0;
	v(i,10)v(j,10)if((s+i+j)%10==0)ans+=dp[0][i]*dp[1][j];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1156
import bisect

n = int(input())
a = [int(input()) for _ in range(n)]
# それぞれの色の最大値を入れる筒のリスト
t = [a[-1]]

for i in reversed(a[:-1]):
    # それぞれの色のどの値よりも小さかったとき
    idx = bisect.bisect_left(t, i+1)
    # print(i, idx)
    if idx == len(t):
        t.append(i)
    # 効率的な色の探索
    else:
        t[idx] = i
    # print(t)

print(len(t))

Measured memory_bytes: 8604
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#初期化
#根なら-size,子なら親の頂点
n, m = map(int, input().split())
par = [-1]*n

for i in range(m):
  a, b = map(int, input().split())
  unite(a - 1, b - 1)

ans = 0
for i in range(n):
  ans = max(ans, size(i))

print(ans)

Measured memory_bytes: 14288
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N, M;
  cin >> N >> M;
  vector<ll> x(N), y(N), z(N);
  REP(i, N)
  cin >> x[i] >> y[i] >> z[i];
  ll ans = 0;
  REP(i, 8)
  {
    vector<ll> vc;
    REP(j, N)
    {
      ll val = 0;
      val += (i & 1 ? x[j] : -x[j]);
      val += (i & 2 ? y[j] : -y[j]);
      val += (i & 4 ? z[j] : -z[j]);
      vc.push_back(val);
    }
    sort(ALL(vc));
    reverse(ALL(vc));
    ll tmp = 0;
    REP(j, M)
    tmp += vc[j];
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;
const long long mod = 1e9 + 7;

int main(){
     int n, m;
     cin >> n >> m;
     vector<int> oks(n+1, true);
     for(int i= 0; i < m; i++){
          int a;
           cin >> a;
          oks[a] = false;
     }
     vector<long long int> dp(n+1);
     dp[0] = 1;
     for(int i = 0; i < n; i++){
          for(int j = i+1; j<=min(n,i+2); j++){
               if(oks[j]){
                    dp[j]+=dp[i];
                    dp[j]%=mod;
               }
          }
     }
     cout << dp[n] << endl;
     return 0;

} 

Measured memory_bytes: 1408
/*
By Snickeen
*/
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VI vector<int>
#define VL vector<LL>
#define VII vector<PII >
#define VLL vector<PLL >
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define FF first
#define SS second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL MAXN=2e6+10;
LL t,n,m,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;

string a;

int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0,u,v;
	cin>>a;
	u=0;
	l=a.size();
	for(i=0;i<l;i++){
		if(a[i]=='C'){
			u=1;
		}
		else if(a[i]=='F'){
			if(u==1)return cout<<"Yes\n",0;
		}
	}
	cout<<"No\n";
	return 0;
}



Measured memory_bytes: 256
A,B = readline.chomp.split.map(&:to_i)

if(A % 2 == 0)
  case ((B-A) % 4)
  when 1 then
    p 1
  when 2 then
    p 1 ^ B
  when 3 then
    p 0
  when 0 then
    p B
  end
else
  case ((B-A) % 4)
  when 1 then
    p A ^ B
  when 2 then
    p A ^ 1
  when 3 then
    p A ^ 1 ^ B
  when 0 then
    p A
  end
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;
//階乗できるよ
ll kaizyo(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  int n;cin >> n;
  vector<char> ans(2*n);
  rep(i,n) {
    char s; cin >> s;
    ans.at(2*i) = s;
  }
  rep(i,n){
    char t;cin >> t;
    ans.at(2*i + 1) = t;
  }
rep(i,2*n){
  cout << ans.at(i);
}
cout << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

int N, M, K;
void solve() {
  for (int n = 0; n <= N; n++) {
    for (int m = 0; m <= M; m++) {
      if (K == M * n + N * m - 2 * n * m) {
        cout << "Yes" << endl;
        return;
      }
    }
  }
  cout << "No" << endl;
}

int main() {
  cin >> N >> M >> K;
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string S;
  int a=0;
  cin>>S;
  for(int i=0;i<S.size();i++){
    if(S[i]=='*'){
      cout<<a<<"\n";
      break;
    }
    else if(S[i]=='(')a++;
    else a--;
  }
}



Measured memory_bytes: 3204
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#define N 200005
#define inf 1000000000
#define pi acos(-1.0)
#define lowbit(o) o&(-o)
using namespace std;
int i,j,k,l,s,n,m,f[N],bb,x1,x2,y2,Ans,Y1;
double ans;
struct node {
	int x,y;
}a[N];
inline bool cmp(const node &x,const node &y) {
	return x.y<y.y;
}
inline int ask(int x) {
	int l=1,r=n,s=0;
	while (l<=r) {
		int mid=(l+r)>>1;
		if (f[mid]<x) s=mid,l=mid+1;
		else r=mid-1;
	}
	return s;
}
int main() {
	scanf("%d%d%d%d",&x1,&Y1,&x2,&y2);
	if (Y1>y2) swap(x1,x2),swap(Y1,y2);
	if (x1>x2) bb=1,x1=1e8-x1,x2=1e8-x2;
	scanf("%d",&n);
	ans=abs(x1-x2)+abs(Y1-y2);
	ans*=100;
	for (i=1;i<=n;i++) {
		scanf("%d%d",&a[i].x,&a[i].y);
		if (bb) a[i].x=1e8-a[i].x;
	}
	sort(a+1,a+1+n,cmp);
	for (i=1;i<=n;i++) f[i]=inf;
	f[0]=0;
	for (i=1;i<=n;i++) if (a[i].y>=Y1) break;
	for (;i<=n&&a[i].y<=y2;i++) if (a[i].x>=x1&&a[i].x<=x2) Ans=max(Ans,ask(a[i].x)+1),f[ask(a[i].x)+1]=min(f[ask(a[i].x)+1],a[i].x);
	if (Ans==min(x2-x1,y2-Y1)+1) ans+=5*pi;
	ans+=Ans*(5*pi-20);
	printf("%.13lf",ans);
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

// auto mod int
// depends on Template

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


//input
ll n;
vector<ll>c;


int main(){
    cin >> n;
    c.resize(n);
    rep(i,n)cin>>c[i];
    sort(c.begin(),c.end());
    mint ans = 0;
    rep(j,n){
        mint tmp = 1;
        tmp *= modpow(2,2*n-2-j);
        tmp *= n+1-j;
        tmp *= c[j];
        tmp *= modpow(2,j);
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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






int solve(int n,int k,int s){
    if(k==0){
        // cerr << "  "<<n<<" "<<k<<" "<<s<<endl;
        if(s==0)return 1;
        return 0;
    }

    // if(k==1){
    //      cerr << "  "<<n<<" "<<k<<" "<<s<<endl;
    //     if(n>=s)return 1;
    //     return 0;
    // }

    int r=0;
    for(int i=n;i>0;i--){
        if(s-i<0)continue;
        r += solve(i-1,k-1,s-i);
    }
    // cerr << "  "<<n<<" "<<k<<" "<<s<< " = "<<r<<endl;
    return r;
}


int main(){

    for(;;){
        int n,k,s;

        cin >> n >> k >> s;
        if((n|k|s)==0)return 0;

        cout << solve(n,k,s) << endl;
    }
}

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

long dp[50];

long fib(long n) {
    if (n == 0 || n == 1) {
        dp[n] = 1;
    }
    if (dp[n] != -1) {
        return dp[n];
    }
    return dp[n] = fib(n - 1) + fib(n - 2);
}

int main() {
    long n;
    cin >> n;

    for (long i = 0; i < 50; i++) {
        dp[i] = -1;
    }

    cout << fib(n) << endl;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B(M);
	vector<vector<int> >A(N, vector<int>(M));
	for (int i = 0; i < M; i++)cin >> B[i];
	for (int i = 0; i < N; i++)for (int j = 0; j < M; j++)cin >> A[i][j];
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int tmp = C;
		for (int j = 0; j < M; j++)tmp += A[i][j] * B[j];
		if (tmp > 0)ans += 1;
	}
	cout << ans << endl;
}

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

using namespace std;

int main()
{
    int N;
    cin>>N;
    
    int A[N+1];
    for(int i=1;i<N+1;i++)
    cin>>A[i];
    
    A[0]=A[1];
    int dp[N+1];
    dp[0]=0;dp[1]=0;
    
    for(int i=2;i<N+1;i++)
    {
        dp[i]=min(abs(A[i]-A[i-1])+dp[i-1],abs(A[i]-A[i-2])+dp[i-2]);
    }
    
    cout<<dp[N]<<endl;
    
    return 0;
}

Measured memory_bytes: 4340
from collections import defaultdict
def solve():
  H, W, M = map(int, input().split())
  bomb = defaultdict(lambda: 0)
  lis_h = [0]*H
  lis_w = [0]*W
  for _ in range(M):
    h,w = map(int, input().split())
    h -= 1
    w -= 1
    bomb[(h,w)] = 1
    lis_h[h] += 1
    lis_w[w] += 1
  m_h = max(lis_h)
  m_w = max(lis_w)
  m_h_lis = []
  m_w_lis = []
  for i in range(H):
    if lis_h[i]==m_h:
      m_h_lis.append(i)
  for i in range(W):
    if lis_w[i]==m_w:
      m_w_lis.append(i)
  ans = 0
  for h in m_h_lis:
    for w in m_w_lis:
      if bomb[(h,w)]==0:
        return m_h+m_w
  return m_h+m_w-1
print(solve())

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

int main() {
  int yy, mm, dd;
  scanf("%d/%d/%d", &yy, &mm, &dd);
  if (mm > 4) {
    printf("TBD\n");
  } else {
    printf("Heisei\n");
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
if a[0] == 1 and n == 0:
    print(1)
    exit()
su = sum(a)
# print(su)
l = [su]*(n+1)
for i in range(1,n+1):
    l[i]=l[i-1]-a[i-1]
# print(l)
count=0
x = 0
m=[1]*(n+1)
for j in range(1,n+1):
    m[j] = m[j-1]*2
    if m[j]>l[j]:
        m[j]=l[j]
    if (m[j]<a[j])or(m[j]==a[j] and j!=n):
        # print(m[j],a[j])
        x = 1
        break
    # print(m[j])
    count += m[j]
    m[j] -= a[j]
count+=1

if x==1 or a[0]!=0 :
    print(-1)
else:
    print(count)

Measured memory_bytes: 20840
#include<bits/stdc++.h>
using namespace std;
#define N 100000
int a[N+1];
int main(){
	int n,sum=0,po=0,i;scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",a+i),sum+=abs(a[i]),po+=a[i]>0;
	sort(a+1,a+n+1);
	if(po==n){
		printf("%d\n",sum-2*a[1]);
		for(i=2;i<n;i++)printf("%d %d\n",a[1],a[i]),a[1]-=a[i];
		printf("%d %d\n",a[n],a[1]);
	}
	else if(!po){
		printf("%d\n",sum+2*a[n]);
		for(i=n-1;i;i--)printf("%d %d\n",a[n],a[i]),a[n]-=a[i];
	}
	else{
		printf("%d\n",sum);
		for(i=n-po+1;i<n;i++)printf("%d %d\n",a[1],a[i]),a[1]-=a[i];
		printf("%d %d\n",a[n],a[1]);a[n]-=a[1];
		for(i=2;i<=n-po;i++)printf("%d %d\n",a[n],a[i]),a[n]-=a[i];
	}
	return 0;
}
/*1
3
1 -1 2
*/
/*2
3
1 1 1
*/

Measured memory_bytes: 2304
// https://atcoder.jp/contests/abc080/tasks/abc080_c
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int bcnt[100], profit[100][11];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t, ans = -INF;
    cin >> n;
    REP(i, n) REP(j, 10) {
        cin >> t;
        bcnt[i] = (bcnt[i] << 1) + t;
    }
    REP(i, n) REP(j, 11) cin >> profit[i][j];
    FOR(i, 1, BIT(10)) {
        int sum = 0;
        REP(j, n) {
            t = i & bcnt[j];
            int bcnt = __builtin_popcount(t);
            sum += profit[j][bcnt];
        }
        ans = max(ans, sum);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
typedef long long ll;

int main()
{
    int X, A;
    cin >> X >> A;
    
    if (X < A) cout << 0 << endl;
    else cout << 10 << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
x = int(input())
N = 500000
dp = [False] * N
dp[0] = True
for i in range(N - 110):
    dp[i + 100] |= dp[i]
    dp[i + 101] |= dp[i]
    dp[i + 102] |= dp[i]
    dp[i + 103] |= dp[i]
    dp[i + 104] |= dp[i]
    dp[i + 105] |= dp[i]
print(0 + dp[x])


Measured memory_bytes: 6900
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let s: String = read();
    let str2: &str = &s[5..7];
    let m: i64 = str2.parse().ok().unwrap();
    if m > 4 {
      println!("TBD");
    }
    else {
      println!("Heisei");
    }

}


Measured memory_bytes: 4352