akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> H >> W;
	vector<vector<int>>v(10, vector<int>(10, 10000));
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> v[i][j];
		}
	}
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
			}
		}
	}
	vector<int>num(10);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> M;
			if (M != -1) {
				num[M]++;
			}
		}
	}
	for (int i = 0; i < 10; i++) {
		K += v[i][1] * num[i];
		//cout << K << endl;
	}
	cout << K << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif

//改造
typedef long long int ll;
using namespace std;

#define MOD 1000000007

ll kaijou(int n){
    if( n == 1) return 1;
    return n * kaijou(n - 1) % MOD;
}

int main() {
    int n,m;
    cin >> n >> m;
    int a = max(n,m);
    int b = min(n,m);
    ll ans;
    if(a == b){
        ans = kaijou(a) * kaijou(b) * 2 % MOD;
    }else if( a - 2 >= b){
        ans = 0;
    }else{
        ans = kaijou(a) * kaijou(b) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

ll dp[100005];
ll weight[105];
ll value[105];

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

    ll tot_value = 0;
    for(int i=0;i<n;i++)
    {
        cin >> weight[i] >> value[i];
        tot_value += value[i];
    }

    for(int i=0;i<100005;i++)
        dp[i] = 1e18L;

    dp[0] = 0;

    for(int i=0;i<n;i++)
    {
        for(ll cur_val = tot_value-value[i]; cur_val >= 0; cur_val--)
        {
            dp[cur_val + value[i]] = min(dp[cur_val + value[i]], dp[cur_val] + weight[i] );
        }
    }

    ll ans = 0;
    for(ll i=0; i<= tot_value ;i++)
    {
        if(W >= dp[i])
        {
            ans = max(ans, i);
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 1024
import java.util.*;

class Main{
	public static void main(String args[]){
		Solve s = new Solve();
		s.solve();
	}
}

class Solve{
	Scanner in = new Scanner(System.in);

	void solve(){
		while(in.hasNext()){
			int n = in.nextInt();
			int ans = 0, t = 1;
			for(int i = 0; i < n /2; i++){
				ans += t;
				t *= 3;
			} 
			ans *= 2;
			if(n % 2 ==1) ans += t;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 25852
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <list>
#include <string>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

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

    int ret = 1;
    int Hi;
    cin >> Hi;
    REP(i, N - 1)
    {
        int Hi2;
        cin >> Hi2;
        if (Hi <= Hi2)
        {
            ret++;
            Hi = Hi2;
        }
    }

    cout << ret << endl;
}

void cheatsheet()
{
    // loop
    // vector<int> vec(10);
    vector<int> vecloop;
    REP(i, 10)
    {
        vecloop.push_back(i);
    }

    // swap
    int a = 1;
    int b = 5;
    swap(a, b); // -> a = 5, b = 1

    // sort
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9, greater<int>()); // 9 8 7 6 5 4 3 2 1

    // lower
    vector<int> vec(arr, end(arr));
    sort(vec.begin(), vec.end());
    cout << lower_bound(vec.begin(), vec.end(), 2)[0]; // 2

    // map
    map<Pll, ll> m;
    m[Pll(10, 100)] = 100;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize, m: usize};

    let mut r_ac = vec![0; n];
    let mut r_wa = vec![0; n];

    let mut ac_count = 0;
    let mut wa_count = 0;

    for _ in 0..m {
        input! {p: usize, s: String};

        let index = p - 1;

        if r_ac[index] == 0 {
            if s == "AC" {
                r_ac[index] = 1;
                ac_count += 1;
                wa_count += r_wa[index];
            } else {
                r_wa[index] += 1;
            }
        }
    }

    print!("{} {}", ac_count, wa_count)
}


Measured memory_bytes: 3656
# ライブラリ高速化実験テスト
import sys


class Combi():
    def __init__(self, N, mod):
        self.power = [1 for _ in range(N+1)]
        self.rev = [1 for _ in range(N+1)]
        self.mod = mod
        for i in range(2, N+1):
            self.power[i] = (self.power[i-1]*i) % self.mod
        self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
        for j in range(N, 0, -1):
            self.rev[j-1] = (self.rev[j]*j) % self.mod

    def com(self, K, R):
        if K < R:
            return 0
        else:
            return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod

    def pom(self, K, R):
        if K < R:
            return 0
        else:
            return (self.power[K])*(self.rev[K-R]) % self.mod



def input(): return sys.stdin.readline().rstrip()


K = int(input())
S = input()
M = len(S)
N = K+M
mod = 10**9+7
ans = pow(26, N, mod)

c = Combi(2*10**6, mod)
for i in range(M):
    ans -= c.com(N, i)*pow(25, N-i, mod)
    ans %= mod
print(ans)

Measured memory_bytes: 187260
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    vector<int> v;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        v.push_back(temp);
    }
    
    int ans = 1;
    int max = v[0];
    for(int i = 1; i < n; i++)
    {
        if(v[i] >= max) {
            ans++;
            max = v[i];
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
// Last Change: 09/10/2019 14:17:46.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int N, M;
  cin >> N >> M;
  vector<set<int>> edge(N, set<int>());

  {
    int a, b;
    for (int i = 0; i < M; ++i) {
      cin >> a >> b;
      --a, --b;
      edge[a].insert(b);
      edge[b].insert(a);
    }
  }

  vector<int> perm(N - 1);
  for (int i = 0; i < N - 1; ++i) {
    perm[i] = i + 1;
  }

  ll ans = 0;
  do {
    bool flag = true;

    if (edge[0].count(perm[0]) == 0) {
      flag = false;
    }

    for (int i = 0; i < N - 2; ++i) {
      if (edge[perm[i]].count(perm[i + 1]) == 0) {
        flag = false;
      }
    }

    if (flag) {
      ++ans;
    }
  } while (next_permutation(perm.begin(), perm.end()));

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	long long int  a[26] = {};
	for (int i = 0; i < s.size(); i++) {
		a[25 - 'z' + s[i]] = 1;
	}
	char b;
	for (int i = 0; i < 26; i++) {
		if (a[i] == 0) {
			b = 'a' + i;
			cout << b << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 512
n, k = map(int, input().split())
p = list(map(int, input().split()))

e_max = 0
e_prev = 0

for i in range(n - k + 1):
    e = 0
    if i == 0:
        for j in range(k):
            e += p[i + j]
    else:
        e = e_prev - p[i-1] + p[i+k-1]
    if e > e_max:
        e_max = e
    e_prev = e

r = e_max/2 + (0.5 * k)
print(str(r))


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

int main() {
  int arr[5], k;
  bool can = true;

  for (int i = 0; i < 5; i++) {
    cin >> arr[i];
  }

  cin >> k;

  for (int i = 0; i < 5; i++) {
    for (int x = 0; x < 5; x++) {
      if (arr[x] - arr[i] > k) {
        can = false;
        break;
      }
    }
  }

  if (can == false) {
    cout << ":(";
  }

  else {
    cout << "Yay!";
  }
}

Measured memory_bytes: 256
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

setrecursionlimit(10**7)

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
A = input()
B = input()
C = input()

c = 0

for i in range(N):
  s = {A[i], B[i], C[i]}
  if len(s) == 2:
    c += 1
  elif len(s) == 3:
    c += 2

print(c)


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

int main (){
 int n,k; cin >> n >> k;
 vector<int> p(n);
 rep(i,n) cin >> p[i];
 sort(p.begin(),p.end());
 int ans=0;
 rep(i,k) ans+=p[i];
 cout << ans << endl;

}


Measured memory_bytes: 3628
#include <stdio.h>

int 
main(int argc, char *argv[])
{
  int a[5];
  for(int i = 0; i < 5; i++){
    scanf("%d", &a[i]);
  }
  
  int b[5];
  int sum = 0;
  
  for(int j = 0; j < 5; j++){
    b[j] = a[j] % 10;
    if(b[j] == 0){
      sum += a[j];
    }
    else{
      sum += (a[j] / 10 + 1) * 10;
    }
    
  }
  
  int m = 10;
  for(int i = 0; i < 5; i++){
    if(m > b[i] && b[i] != 0){
      m = b[i];
    }
  }
  
  printf("%d\n", sum - 10 + m);
}
      

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int n;
    cin >> n;

    vector<ll> a(n);

    rep(i, n){
        cin >> a[i];
    }

    ll ans = 0;
    ll left = a[0];

    for(int i = 1; i < n; i++){
        if(a[i] < left){
            ans += left - a[i];
        }else{
            left = a[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4784
#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 ll long long
#define hii cout << "hii" << endl
#define int ll
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
 
const int N = 5e5 + 5;
const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e15;
const int LG = 21;
const long double PI = acos(-1);

int arr[N];

void solve() 
{
	int n, m;
	cin >> n >> m;
	int tot = 0;
	for(int i = 0; i < m; i++)
	{
		cin >> arr[i];
		tot += arr[i];
	}
	n -= tot;
	cout << max(-1LL, n) << endl;
}

 
 
int32_t main() 
{	
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

Measured memory_bytes: 3716
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    //  String[] nyu=sc.nextLine().split(" ");
     String nyu=sc.nextLine();

//int[] num=new int[6];

//int num=Integer.parseInt(nyu);

switch(nyu){
case "A":
System.out.println("T");

break;
case "T":
System.out.println("A");

break;
case "G":
System.out.println("C");

break;
case "C":
System.out.println("G");

break;


default:
break;
}



//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);



	}
}

Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#define mop 1000000007

using namespace std;

static const int MAX = 51;
deque<int> G[MAX];
int n,m;
int color[MAX] = {};
int ans = 0;

void bfs(int u){
    for (int i=0;i<MAX;i++){
        color[i] = 0;
    }
    queue<int> Q;
    Q.push(u);
    while (!Q.empty()){
        int v = Q.front();
        Q.pop();
        for (auto itr=G[v].begin();itr!=G[v].end();itr++){
            if(color[(*itr)] != 0){
                continue;
            }
            color[(*itr)] = 1;
            Q.push((*itr));
        }

    }
}

void assignColor(){
    bfs(1);
    for (int u=1;u<=n;u++){
        if(color[u] == 0){
            ans += 1;
            break;
        }
    }
}
int main() {
   
    deque <int> p,q;
    cin >> n >> m;
    for (int i=0;i<m;i++){
        int x,y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
        p.push_back(x);
        q.push_back(y);
    }

    for (int i=0;i<p.size();i++){
        G[p[i]].pop_front();
        G[q[i]].pop_front();
        assignColor();
        G[p[i]].push_back(q[i]);
        G[q[i]].push_back(p[i]);
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */
/*
 *
 *
 *
 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int N;
	cin>>N;
	vector<int> h(N);
	for(int i=0; i<N; i++) {
		cin>>h[i];	
	}
	vector<int> dp(N);
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	for(int i=2;i<N;i++) {
		dp[i] += min(abs(h[i-1] - h[i]) + dp[i-1], abs(h[i-2] - h[i]) + dp[i-2]);
	}
	cout<<dp[N-1];
	return 0;
}





Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define rep(i, a, N) for(int i = a; i < N; i++)
#define rrep(i, a, N) for(int i = a; i >= N; i--)

int N, Y;

int main() {
    int N;
    scanf("%d", &N);

    vector<int> c(N), s(N), f(N);
    rep(i, 0, N - 1) {
        scanf("%d %d %d", &c[i], &s[i], &f[i]);
    }

    rep(i, 0, N) {
        int t = 0;
        rep(j, i, N -1) {
            if (t < s[j]) t = s[j];
            else if (t % f[j] == 0);
            else t += f[j] - t % f[j];
            t += c[j];
        }
        printf("%d\n", t);
    }
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll=long long;

unsigned TIgcd(ll a, ll b){
    if(a<b) return TIgcd(b,a);
    ll r;
    while((r=a%b)){
        a=b;
        b=r;
    }
    return b;
}

int main(){
    ll n,i,j,k,ans=0;
    cin>>n;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                ans+=TIgcd(TIgcd(i,j),k);
            }
        }
    }

    cout<<ans; 
    return 0;
}




Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int arr[3][3], n, b[10];
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
			cin >> arr[i][j];
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> b[i];
	bool t[3][3];
	memset(t,0,sizeof(t));
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
			for(int k = 0; k < n; k++)
				if(b[k] == arr[i][j]){
					//cout << i << " " << j << " " << arr[i][j] << " " << b[k] << endl;
					t[i][j] = 1;
					continue;
				}
//	cout << "****************" << endl;
//	for(int i = 0; i < 3; i++){
//		for(int j = 0; j < 3; j++)
//			cout << t[i][j] << " ";
//		cout << endl;
//	}
//	cout << "****************" << endl;
	for(int i = 0; i < 3; i++)
		if(t[i][0] && t[i][1] && t[i][2] && t[i][0]){
			cout << "Yes" << endl;
			return 0;
		}
		else if(t[0][i] && t[1][i] && t[2][i]){
			cout << "Yes" << endl;
			return 0;
		}
	if(t[0][0] && t[1][1] && t[2][2] || t[2][0] && t[1][1] && t[0][2]){
		cout << "Yes" << endl;
			return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())

w = []
for i in range(n):
    w.append(str(input()))

if len(w) != len(set(w)):
    print("No")
    exit()

for i in range(n - 1):
    if w[i][-1] != w[i + 1][0]:
        print("No")
        exit()

print("Yes")


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

using namespace std;

int main(){
    int n1;
    cin >> n1;
    vector<int>a1(n1);
    for(int i = 0;i < n1;++i){
        cin >> a1[i];
    }
    
    sort(a1.begin(),a1.end());
    std::vector<int>:: iterator it = unique(a1.begin(), a1.end());
    a1.resize(distance(a1.begin(), it));
    
    for(it = a1.begin();it != a1.end();++it){
        if(it != a1.begin()){
            cout << " ";
        }
        cout << *it;
    }
    cout << endl;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1e9+7;
int main(){
  int H, W, K;
  cin >> H >> W >> K;
  K--;//0-indexedにする
  
  ll dp[H+1][W];
  fill(dp[0],dp[H+1],0);
  dp[0][0] = 1; //dp[h][k] h列目で0からスタートした阿弥陀がkにくる数
  
  rep(h,H){//H段だけ繰り返す
    for(int b = 0; b < (1 << (W-1)); b++){ //各H段でW-1本まで線が引ける。（ただし、連続はできない）
      bool judge = true; //横線が隣り合っているかどうか判定
      for(int i = 0; i < W - 2;i++){
        if((b >> i) % 4 == 3) judge = false; //bをiだけ右に動かして、末尾がXXXX11となっていたら横線が隣り合っている
      }
      
      if(!judge) continue;
      
      int perm[W]; //各始点が何処に移動するか。W本に合わせて用意
      rep(i,W) perm[i] = i; //初期化。
      for(int i=0; i<W-1;i++){
        if((b>>i) & 1) swap(perm[i], perm[i+1]); //i桁目が1だったら、そこに線あるので位置をスワップ
      }
      
      //配るDP
      rep(i,W){
        dp[h+1][perm[i]] += dp[h][i];
        dp[h+1][perm[i]] %= MOD;
      }
    }
  }
  
  cout << dp[H][K] << endl;
  return 0;
}

Measured memory_bytes: 256
from itertools import accumulate


def get_sec(s):
    return sum(t * c for t, c in zip(map(int, s.split(':')), (3600, 60, 1)))

while True:
    n = int(input())
    if n == 0:
        break
    cnt = [0] * 86400
    for _ in range(n):
        dep, arr = map(get_sec, input().split())
        cnt[dep] += 1
        cnt[arr] -= 1
    print(max(accumulate(cnt)))

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

using edge=struct {int to,cap,cost,rev;};
using G=vector<vector<edge>>;
const int inf=1<<29;

void add_edge(G &graph,int a,int b,int c,int d){
	graph[a].push_back({b,c,d,int(graph[b].size())});
	graph[b].push_back({a,0,-d,int(graph[a].size()-1)});
}

int min_cost_flow(G &graph,int s,int t,int f){
	int res=0;
	while(f){
		int n=graph.size(),update;
		vector<int> dist(n,inf),pv(n,0),pe(n,0);
		dist[s]=0;

		rep(loop,n){
			update=false;
			rep(v,n)rep(i,graph[v].size()){
				edge &e=graph[v][i];
				if(e.cap>0 && chmin(dist[e.to],dist[v]+e.cost)){
					pv[e.to]=v,pe[e.to]=i;
					update=true;
				}
			}
			if(!update) break;
		}

		if(dist[t]==inf) return -1;

		int d=f;
		for(int v=t;v!=s;v=pv[v]) chmin(d,graph[pv[v]][pe[v]].cap);
		f-=d,res+=d*dist[t];

		for(int v=t;v!=s;v=pv[v]){
			edge &e=graph[pv[v]][pe[v]];
			e.cap-=d;
			graph[v][e.rev].cap+=d;
		}
	}
	return res;
}

int main(void){
	int n,m,f;
	cin >> n >> m >> f;
	G graph(n);
	rep(i,m){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		add_edge(graph,a,b,c,d);
	}
	cout << min_cost_flow(graph,0,n-1,f) << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    int sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;

    // 1回目
    if(sy-ty > 0) {
        rep(i, sy-ty) {
            cout << "D";
        }
    } else {
        rep(i, abs(sy-ty)) {
            cout << "U";
        }
    }
    if(sx-tx > 0) {
        rep(i, sx-tx) {
            cout << "L";
        }
    } else {
        rep(i, abs(sx-tx)) {
            cout << "R";
        }
    }
    // 帰り
    if(sy-ty > 0) {
        rep(i, sy-ty) {
            cout << "U";
        }
    } else {
        rep(i, abs(sy-ty)) {
            cout << "D";
        }
    }
    if(sx-tx > 0) {
        rep(i, sx-tx) {
            cout << "R";
        }
    } else {
        rep(i, abs(sx-tx)) {
            cout << "L";
        }
    }

    // 2回目
    if(sx > tx) cout << "R";
    else cout << "L";

    if(sy-ty > 0) {
        erep(i, sy-ty) {
            cout << "D";
        }
    } else {
        erep(i, abs(sy-ty)) {
            cout << "U";
        }
    }
    if(sx-tx > 0) {
        erep(i, sx-tx) {
            cout << "L";
        }
    } else {
        erep(i, abs(sx-tx)) {
            cout << "R";
        }
    }

    if(sy > ty) cout << "U";
    else cout << "D";

    // 帰り
    if(sx > tx) cout << "L";
    else cout << "R";

    if(sy-ty > 0) {
        erep(i, sy-ty) {
            cout << "U";
        }
    } else {
        erep(i, abs(sy-ty)) {
            cout << "D";
        }
    }
    if(sx-tx > 0) {
        erep(i, sx-tx) {
            cout << "R";
        }
    } else {
        erep(i, abs(sx-tx)) {
            cout << "L";
        }
    }

    if(sy > ty) cout << "D";
    else cout << "U";



    cout << endl;
    return 0;

}
// RRRUUULLLDDDURRRRUUUULDLLLLDDDDR
// UURRURRDDDLLDLLULUUURRURRDDDLLDL


Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string str;
	cin>>str;
	int ans=0;
	for(int i=0;i<3;++i){
		ans += str[i]-'0';
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 256
import itertools
n,k=map(int,input().split())
#4317
p=list(map(int,input().split()))
def keisan(x):
  return (k+x)/2
ans=0
zzz=list(itertools.accumulate(p))
zzz.insert(0,0)
han=0
for i in range(k,len(zzz)):
  if han<zzz[i]-zzz[i-k]:
    han=zzz[i]-zzz[i-k]
print(keisan(han))

Measured memory_bytes: 25152
import math as ms
N = int(input())

plow = ms.floor(N / 1.08)
# print(plow)
flag = 0

# print(plow * 1.08)
# print( (plow + 1) * 1.08)

if ms.floor(plow * 1.08) == N:
    flag = 1
elif ms.floor((plow + 1) * 1.08) == N:
    flag = 1
    plow += 1
    
if flag == 1:
    print(plow)
else:
    print(":(")





Measured memory_bytes: 3064
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int n;
    cin >> n;
    n /= 2;
    int V = 100001;
    vector<int> odd(V), even(V);
    int o, e;
    for (int i = 0; i < n; i++) {
        cin >> o >> e;
        odd[o]++;
        even[e]++;
    }

    pair<int, int> omax, emax;
    auto itr = max_element(odd.begin(), odd.end());
    omax = {distance(odd.begin(), itr) + 1, *itr};
    auto itr2 = max_element(even.begin(), even.end());
    emax = {distance(even.begin(), itr2) + 1, *itr2};

    int ans = 0;
    if (omax.first == emax.first && omax.second == emax.second) {
        if (omax.second == n && emax.second == n) {
            ans = n;
        } else {
            int om2 = 0, em2 = 0;
            for (int i = 0; i < V; i++) {
                if (om2 < odd[i] && i + 1 != omax.first) {
                    om2 = odd[i];
                }
                if (em2 < even[i] && i + 1 != emax.first) {
                    em2 = even[i];
                }
            }

            ans = min(2 * n - omax.second - em2, 2 * n - om2 - emax.second);
        }
    } else {
        ans = 2 * n - omax.second - emax.second;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define Set set<int>
#define int long long
#define P pair<int,int>
const int maxn = 3e3+5;
const int INF = 1e17 +6;
using namespace std;
//int n,m,a[maxn],b[maxn],d[maxn],c[maxn],ans;
int32_t main()
{
    IOS;
    int x,y;
    double n,m;
    cin>>n>>m>>x>>y;
    double t=n*m/2.0;
    cout<<setprecision(6)<<fixed<<t<<" ";
    if(2*x==n && 2*y==m)cout<<1;
    else cout<<0;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<vector>
#include<sstream>
#include<deque>
#include<algorithm>
#include<queue>

using namespace std;

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

int ini[100001];
int main(){
	while(1){
		int n,m;
		scanf("%d%d",&n,&m);
		if(n==0)break;
		rep(i,n){
			scanf("%d",&ini[i]);
		}
		
		int sum=0;
		rep(i,m){
			sum+=ini[i];
		}
		
		int maxi=sum;
		for(int i=m;i<n;i++){
			sum-=ini[i-m];
			sum+=ini[i];
			maxi=max(maxi,sum);
		}
		
		printf("%d\n",maxi);
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
int main()
{
    ///"In the name of Allah,most gracious and most merciful"///

    ll i,j,x,y,z,count=100000000000,sum=0,n,ans=0;
    cin>>n;
    ll a[n];
    rep(i,n)
    {
        cin>>a[i];
    }
    sort(a,a+n);

    for(j=a[n-1]; j>=a[0]; j--)
    {

        ll mid=j;
        rep(i,n)
        {
            ans=ans+((a[i]-mid)*(a[i]-mid));
        }

        count=min(count,ans);
        ans=0;

    }

    cout<<count<<endl;

    return 0;
}






Measured memory_bytes: 3644
import sys
sys.setrecursionlimit(1000000)

# 二部グラフ判定
def dfs(u, c):
    color[u] = c  # 訪問したら指定の色で塗る
    for v in G[u]:  # uからつながっている頂点を順に取り出す
        if color[v] != -1:  # すでに訪問していた場合
            if color[v] == c:
                return False  # 隣接する頂点が同じ色のときはFalse
            else:
                continue
        else:  # 未訪問の時は色は違う色にしてDFSで再帰的に探索
            if not dfs(v, 1 - c):  # FalseだったらFalseを返す
                return False
    return True


# 頂点数と辺数を入力
N, M = map(int, input().split())
# グラフの入力
G = [[] for _ in range(N)]  # 頂点数Nだけ準備
color = [-1] * N  # 未訪問は-1とする
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
# 探索
flag = True
for i in range(N):
    if color[i] == -1:
        if not dfs(i, 0):
            flag = False
            break
if flag:
    ans = color.count(1) * color.count(0) - M
else:
    ans = N * (N - 1) // 2 - M
print(ans)


Measured memory_bytes: 31164
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,in;
	cin>>n;
	vl a(n),b(n);
	ll ans=0;
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	rep(i,31){
		vl bmd(n);
		rep(j,n)bmd[j]=b[j]%(1ll<<(i+1));
		sort(all(bmd));
		ll num=0;
		rep(j,n){
			ll amd=a[j]%(1ll<<(i+1));
			num+=lower_bound(all(bmd),(1ll<<(i+1))-amd)-lower_bound(all(bmd),(1ll<<i)-amd);
			num+=lower_bound(all(bmd),(1ll<<(i+2))-amd)-lower_bound(all(bmd),((1ll<<(i+1))+(1ll<<i)-amd));
		}
		if(num%2==1)ans+=(1ll<<i);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4992
import numpy as np 
n,W=map(int,input().split())
dp=np.zeros(W+1,dtype=int)
for i in range(n):
    w,c= map(int,input().split())
    dp[w:] = np.maximum(dp[w:], dp[:W+1-w] + c)     
print(dp[W])

Measured memory_bytes: 15460
// D - Decrease (Contestant ver.)
#include <bits/stdc++.h>
using namespace std;

int main(){
	long long K; cin>>K;
	int N = 50;
	cout<< N <<endl;
	vector<long long> A(N, K/N-K%N);
	for(int i=0; i<K%N; ++i) A[i] += N + 1;
	for(int i=0; i<N; ++i) cout<< A[i] + i <<" ";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 501010;
int n , m , u , v , c;
vector<pii> V;
int l[N] , r[N] , Co[N] , vis[N];
ll dis[N];
vector<pii> g[N];

int main(){
    scanf("%d%d",&n,&m);
    rep(i,0,m){
        scanf("%d%d%d",&u,&v,&c);
        --u;--v;
        l[i] = u , r[i] = v , Co[i] = c;
        V.pb(mp(u , c));
        V.pb(mp(v , c));
    }
    sort(all(V));V.erase(unique(all(V)) , V.end());
    rep(i,0,m){
        u = lower_bound(all(V) , mp(l[i] , Co[i])) - V.begin();
        v = lower_bound(all(V) , mp(r[i] , Co[i])) - V.begin();
        g[n + u].pb(mp(n + v , 0));
        g[n + v].pb(mp(n + u , 0));
    }
    rep(i,0,sz(V)) g[V[i].fi].pb(mp(n + i , 1)) , g[n + i].pb(mp(V[i].fi , 1)) , dis[i + n] = 1ll<<62;
    rep(i,0,n) dis[i] = 1ll<<62;
    priority_queue<pair<ll,int> > PQ;
    dis[0] = 0;
    PQ.push(mp(0 , 0));
    while(sz(PQ)){
        int c = PQ.top().se;PQ.pop();
        if(!vis[c]){
            for(auto e : g[c]){
                ll ndis = dis[c] + e.se;
                if(ndis < dis[e.fi]){
                    dis[e.fi] = ndis;
                    PQ.push(mp(-e.fi , e.fi));
                }
            }
        }
    }
    if(dis[n-1] == 1ll<<62) puts("-1");
    else printf("%lld\n",dis[n-1] / 2);
    return 0;
}


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

using namespace std;
#define sd(x) scanf("%d",&x);
#define sdl(x) scanf("%lld",&x);
#define pr(x) printf("%d\n",x);
#define prl(x) printf("%lld\n",x);


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

long long fast_exp(long long a,long long n,long long mod1)
    {

    if (n==0)return 1;
    else if (n==1)return a;
    if (n%2==0)return fast_exp((a*a)%mod1,n/2,mod1);
    else return (a*fast_exp((a*a)%mod1,n/2,mod1))%mod1;
    }
bool is_square(long long  a)
{
    long long int b=sqrt(a);
    if (b*b==a)return true;
    else return false;
}


void solve()
{
  int n,m;
  cin >> n >> m;
  vector<int>arr(n);
  for (int c=0;c<n;c++)
    cin >> arr[c];
    vector<vector<int>>adj(n+1);
    for (int c=0;c<m;c++)
        {
            int a,b;
            cin >> a >> b;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }    
        int total=0;
        for (int c=1;c<=n;c++)
            {
                int flag=1;
                for (int c1=0;c1<adj[c].size();c1++)
                    if (arr[adj[c][c1]-1]>=arr[c-1])
                        {flag=-1;break;}
                if (flag==1)
                    total++;
            }
            cout << total << endl;

    
    
}



int main ()
{
      
     int t;
     //cin >> t;
     t=1;
     for (int tt=1;tt<=t;tt++)
     {
         solve();

     }

    return 0;
     
     
     
     
 }


Measured memory_bytes: 8844
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	long long int n;
	long long int t, a[200005], sum = 0;
	scanf("%lld %lld", &n, &t);
	for(int i = 0; i < n; i++)
	{
		scanf("%lld", &a[i]);
	}
	if(n > 1)
	{
		for(int i = 0; i < n - 1; i++)
		{
			if(a[i + 1] - a[i] >= t)
			{
				sum = sum + t;
			}
			if(a[i + 1] - a[i] < t)
			{
				sum = sum + (a[i + 1] - a[i]);
			}
		}
	}
	sum = sum + t;
	printf("%lld\n", sum);
	return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

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); }

// ------------------------------------------------------------------------------------------

int n;
string s;
vector<int> v;
int dp[222222][5]; // dp[i][j]: i番目の要素まで見た時、

int dfs(int idx, int old) {
  if (idx >= v.size()) {
    return 0;
  }

  if (dp[idx][old] != -1) {
    return dp[idx][old];
  }

  int ret = 0;

  int a = dfs(idx+1, 1) + (v[idx] == 0);
  int b = (old == 1 ? 1e18 : dfs(idx+1, 0) + (v[idx] == 1));
  ret += min(a, b);

  return dp[idx][old] = ret;
}

signed main() {
  cin >> n >> s;
  v.push_back(-1);
  for (int i = 0; i < n; i++) {
    int val = s[i] == '#' ? 1 : 0;
    v.push_back(val);
  }

  for (int i = 0; i < 222222; i++) { for (int j = 0; j < 5; j++) { dp[i][j] = -1; } }

  int ans = dfs(0, 3);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 20212
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list()
if sum(a) < sum(b):
    exit(print(-1))
for i in range(n):
    c.append(a[i]-b[i])
c.sort()
i = 0
ans = 0
flag = True
for p in c:
    if p >= 0:
        exit(print(ans))
    if flag:
        ans += 1
        flag = False
    while True:
        if c[n-1-i] + p < 0:
            p += c[n-i-1]
            i += 1
            ans += 1
        else:
            c[n-i-1] += p
            ans += 1
            break


Measured memory_bytes: 18612
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private final static String NEGATIVE = "NO\n";
	private final static String AFFIRMATIVE = "YES\n";

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in),1024);
		int number = Integer.parseInt(br.readLine());
		int sides[] = new int[3];
		StringTokenizer tknz;
		StringBuilder builder = new StringBuilder();

		for (; 0 < number; number--) {
			tknz = new StringTokenizer(br.readLine());
			for (int i = 0; i < 3; i++) {
				sides[i] = Integer.parseInt(tknz.nextToken());
			}
			Arrays.sort(sides);
			if (sides[0] * sides[1] * sides[2] % 60 != 0) {
				builder.append(NEGATIVE);
			} else if (Math.pow(sides[0], 2) + Math.pow(sides[1], 2) != Math.pow(sides[2], 2)) {
				builder.append(NEGATIVE);
			} else {
				builder.append(AFFIRMATIVE);
			}
		}
		System.out.print(builder);
	}
}

Measured memory_bytes: 18556
from collections import deque

S = "abcdefghij"
N = int(input())
d = deque([("a", 1, 1)])
while(len(d)>0):
    tmp = d.pop()
    if tmp[1] < N:
        for i in range(tmp[2] + 1):
            tmp2 = (tmp[0] + S[i], tmp[1] + 1, max(tmp[2], i + 1))
            d.appendleft(tmp2)
    else:
        print(tmp[0])

Measured memory_bytes: 20084
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second

using namespace std;
int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   
   long long int a;
   cin>>a;
   
   long double b;
   cin>>b;
   
   
  // cout<<b<<endl;
   
   // ans = a*(int b) + a*(fraction b)
   
   
   long long int x = a*(int)b;
   
   //cout<<"x = "<<x<<endl;
   
   long double p = (b - (int )b)*100.00;
   
   cout<<(long long int)(x + (a*p)/100)<<endl;
   
  
   
   
   
   
   
   return 0;
}


Measured memory_bytes: 3724
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
		int sec = sc.nextInt();
		int h =sec/3600;
		int m =sec%3600/60;
		int s =sec%3600%60;
		System.out.println(String.format("%d:%d:%d",h,m,s));
	}
}



Measured memory_bytes: 26260
#include <iostream>
using namespace std;
int main() {
  int n, k; cin >> n >> k;
  string s; cin >> s;
  int cnt = 0;
  for (int i = 0; i < n - 1; ++i) if (s[i] == s[i + 1]) ++cnt;
  cout << min(cnt + 2 * k, n - 1) << '\n';
  return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int base = 80*160;
    int H, W; cin >> H >> W;
    pair<int, int> nums[H][W];
    rep(i, H) rep(j, W) cin >> nums[i][j].first;
    rep(i, H) rep(j, W) cin >> nums[i][j].second;
    vector<bool> dp[H][W];
    rep(i, H) rep(j, W) dp[i][j].resize(base*2 + 1, false);

    dp[0][0][base + nums[0][0].first-nums[0][0].second] = true;
    dp[0][0][base + nums[0][0].second-nums[0][0].first] = true;
    int sz = base*2;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(i+1 < H){
                int fst = nums[i+1][j].first, snd = nums[i+1][j].second;
                for(int k = 0; k <= sz; k++){
                    if(dp[i][j][k]){
                        dp[i+1][j][k + (fst-snd)] = true;
                        dp[i+1][j][k + (snd-fst)] = true;
                    }
                }
            }
            if(j+1 < W){
                int fst = nums[i][j+1].first, snd = nums[i][j+1].second;
                for(int k = 0; k <= sz; k++){
                    if(dp[i][j][k]){
                        dp[i][j+1][k + (fst-snd)] = true;
                        dp[i][j+1][k + (snd-fst)] = true;
                    }
                }
            }
        }
    }
    int ans = mod;
    for(int i = 0; i <= sz; i++){
        if(dp[H-1][W-1][i]) ans = min(ans, abs(i-base));
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N,X,j=1,k=0;
  cin>>N>>X;
  for(int i=0;i<N;i++){
    int L;
    cin>>L;
    k+=L;
    if(k<=X)
      j++;
  }
  cout<<j<<endl;
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n),b(n),c(n);

    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++) cin >> b[i];
    for(int i=0;i<n;i++) cin >> c[i];

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

    vector<long long> bv(n+1);
    bv[0] = 0;
    for(int i=1;i<n+1;i++){
        auto itr = lower_bound(a.begin(), a.end(), b[i-1]);
        bv[i] = (long long)(itr - a.begin());
    }
    //for(int i=0;i<n+1;i++) cout << bv[i] << " ";
    //cout << endl;
    for(int i=0;i<n;i++){
        bv[i+1] = bv[i] + bv[i+1];
    }
    long long ans = 0;
    for(int i=0;i<n;i++){
        auto itr = lower_bound(b.begin(), b.end(), c[i]);
        ans = ans + bv[ (int) (itr - b.begin())];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&b!=a))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#include <map>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<int,int>;
const ll M = 1e9+7, mx = 301;
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; void chmax(ll& x, ll y) {if (x<y) x=y;}; void chmin(ll& x, ll y) {if (x>y) x=y;};

int main() {
  int n; cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  ll p[100001]={};
  for(int i=0;i<n;i++) p[a[i]]++;
  ll an=0;
  for(ll i=0;i<=100000;i++) {
    an+=i*p[i];
  }
  int q; cin>>q;
  for(int i=0;i<q;i++) {
    int b,c; cin>>b>>c;
    an-=b*p[b]; an+=c*p[b];
    p[c]+=p[b]; p[b]=0;
    cout<<an<<endl;
  }
}

Measured memory_bytes: 4768