akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	int n, m;
	cin >> n >> m;

	string ans(n, '.');
	int s, c;
	for (int i = 0; i < m; ++i) {
		cin >> s >> c;
		--s;
		if (ans[s] != '.' && c != ans[s] - '0') {
			cout << "-1\n";
			return 0;
		}

		ans[s] = c + '0';
	}

	if (n == 1 && !m) {
		cout << "0\n";
		return 0;
	}

	int actual = 0;
	for (int i = 0; i < n; ++i) {
		if (ans[i] != '.') {
			++actual;
		}
	}

	if (actual < n) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 10; ++j) {
				if (ans[i] == '.') {
					if (j == 0 && i == 0) {
						continue;
					}

					ans[i] = j + '0';
				}
			}
		}
	}	

	if (ans[0] == '0' && n > 1) {
		cout << "-1\n";
	} else {
		cout << ans << "\n";		
	}


	return 0;

}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vll ans ;
	for(int i=11;i<=55555;i+=10){
		bool ok = true ;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				ok = false ;
				break ;
			}
		}
		if(ok){
			ans.emplace_back(i) ;
			if(ans.size()==n) break ;
		}
	}
	for(int i=0;i<n;i++) cout << ans.at(i) << (i==n-1?'\n':' ') ;
}


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

using namespace std;

int main(void){

    int n;
    cin >> n;
    
    int result = 0;
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            if(i*4+j*7==n) result++;
        }
    }

    if(result > 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
    
}


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

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n;
    cin >> n;
    vector<vector<int>> graph(n);
    for(int i = 0; i < n; ++i){
        int u, k;
        cin >> u >> k;
        --u;
        for(int j = 0; j < k; ++j){
            int v;
            cin >> v;
            --v;
            graph[u].emplace_back(v);
        }
    }
    
    vector<bool> visited(n, false);
    vector<int> in(n), out(n);
    int T = 0;
    auto dfs = [&](auto&& self, int from) -> void {
        in[from] = ++T;
        visited[from] = true;
        for(int to : graph[from]){
            if(visited[to]) continue;
            self(self, to);
        }
        out[from] = ++T;
        return;
    };

    for(int i = 0; i < n; ++i){
        if(!visited[i]) dfs(dfs, i);
    }
    for(int i = 0; i < n; ++i){
        cout << i + 1 << ' ' << in[i] << ' ' << out[i] << '\n';
    }
}


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

int a, b, c, d, e, f, answ = 0, anss = 0;

double calc(int w, int s) {
  if(w + s == 0) return 0;
  return (double)100 * s / (double)(s + w);
}
void solve();

int main() {
  cin >> a >> b >> c >> d >> e >> f;
  solve();
  cout << answ + anss << " " << anss << endl;
  return 0;
}

void solve() {
  for(int i = 0; i * 100 * a <= f; ++i)
    for(int j = 0; (i * a + j * b) * 100 <= f; ++j)
      for(int k = 0; k * c + (i * a + j * b) * 100 <= f;
          ++k) {
        int nw = (i * a + j * b) * 100, ns = k * c;
        if(e * (nw / 100) - k * c < 0) continue;
        ns +=
            (min(f - nw - ns, e * (nw / 100) - ns) / d) * d;
        if(calc(answ, anss) <= calc(nw, ns)) {
          answ = nw;
          anss = ns;
        }
      }
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
int n, a, b, c, d; 
map<int, int>M;
int dfs(int now) {
	if (M[now])return M[now];
	if (now == 0)return M[now] = 0;
	M[now] = 7e18;
	if (now < 7e9)M[now] = d * now;
	for (int i = -4; i <= 4; i++) {
		int nxt = now + i;
		if (nxt < 0)continue;
		if (abs(i)<2&&nxt % 2 == 0)M[now] = min(M[now], d*abs(i) + a + dfs(nxt / 2));
		if (abs(i)<3&&nxt % 3 == 0)M[now] = min(M[now], d*abs(i) + b + dfs(nxt / 3));
		if (nxt % 5 == 0)M[now] = min(M[now], d*abs(i) + c + dfs(nxt / 5));
	}
	return M[now];
}
signed main() {
	int t; cin >> t;
	rep(T, t) {
		cin >> n >> a >> b >> c >> d;
		M.clear();
		dfs(n);
		cout << M[n] << endl;
	}
}

Measured memory_bytes: 4436
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define PI 3.14159265358979323846264338327950L

int res;

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

    string S;
    cin >> S;
    int red = 0, blue = 0;
    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] == '0')
        {
            red++;
        }
        else
        {
            blue++;
        }
    }
    res = min(red, blue) * 2;
    cout << res << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  if (s == "000") {
    cout << 0 << endl;
  } else if (s == "100" || s == "010" || s == "001") {
    cout << 1 << endl;
  } else if (s == "110" || s == "011" || s == "101") {
    cout << 2 << endl;
  } else {
    cout << 3 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7

s = input()
dp = [0] * 13
dp[0] = 1
for i in range(len(s)):
    dp2 = [0] * 13
    for j in range(10):
        if (s[i] == '?') | (s[i] == str(j)):
            for k in range(13):
                dp2[(10 * k + j) % 13] += dp[k]
                dp2[(10 * k + j) % 13] %= mod
    dp = dp2
print(dp[5])

Measured memory_bytes: 74332
/*input
5
10 1
2 1
4 1
6 1
8 1



*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ll n;
	cin>>n;
	set<pll> v;
	ll x,l;
	rep(i,0,n){
		cin>>x>>l;
		v.insert({x,l});
	}
	ll ans=0;
	set<pll> :: iterator it,it1;
	for(it=v.begin();it!=v.end();){
		pll z=*it;
		it1=it;
		it1++;
		if(it1==v.end())
			break;
		pll z1=*it1;
		if(z.F+z.S>z1.F-z1.S){
			//cout<<z.F<<" "<<z.S<<" "<<z1.F<<" "<<z1.S<<endl;
			if(z.S+z.F>=z1.F+z1.S){
				v.erase(it);
				it=it1;
			}else{
				v.erase(it1);
			}
		}else
			it++;
	}
	cout<<v.size();
	return 0;
}




Measured memory_bytes: 6528
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main()
{
    int a,b,c,d,t;
    string s;
    cin>>t;
    a = b = c = d = 0;
    while(t--)
    {
        cin>>s;
        if(s[0]=='A') a++;
        else if(s[0]=='W') b++;
        else if(s[0]=='T') c++;
        else d++;
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",a,b,c,d);

}



Measured memory_bytes: 3724
from collections import defaultdict


def main():
    N = int(input())
    counter = defaultdict(int)
    for _ in range(N):
        s = ''.join(sorted(input()))
        counter[s] += 1
    answer = 0
    for c in counter.values():
        answer += c * (c - 1) // 2
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 18236
#include<bits/stdc++.h>
#define maxn 100000
using namespace std;
typedef long long LL;
int num[4*maxn+10],a[maxn+10],b[maxn+10],c[maxn+10];
int find(int x,int *a,int n){
	int l=1,r=n;
	for(;;){
		int m=l+r>>1;
		if(a[m]==x)return m;
		if(a[m]<x)l=m+1;
		else r=m-1;
	}
}
int sa[4*maxn+10],sc[4*maxn+10];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%d",a+i),num[i]=a[i];
	for(int i=1;i<=n;i++)scanf("%d",b+i),num[i+n]=b[i]-1,num[i+2*n]=b[i];
	for(int i=1;i<=n;i++)scanf("%d",c+i),num[i+3*n]=c[i];
	sort(num+1,num+4*n+1);
	int tot=1;
	for(int i=2;i<=4*n;i++)if(num[i]!=num[i-1])num[++tot]=num[i];
	for(int i=1;i<=n;i++)sa[find(a[i],num,tot)]++,sc[find(c[i],num,tot)]++;
	for(int i=2;i<=tot;i++)sa[i]+=sa[i-1],sc[i]+=sc[i-1];
	LL ans=0;
	for(int i=1;i<=n;i++)ans+=(LL)sa[find(b[i]-1,num,tot)]*(n-sc[find(b[i],num,tot)]);
	cout<<ans<<endl;
	return 0;
}

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

void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
int dp[100010][3];
int main(int argc, char const *argv[])
{
	// fastio();
	int n;
	cin >> n;

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < 3; ++j)
			cin >> dp[i][j];
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < 3; ++j) {
			int m = -1;
			for (int jj = 0; jj < 3; ++jj) {
				if (jj == j) continue;
				m = max(m, dp[i][j] + dp[i-1][jj]);
			}
			dp[i][j] = m;
		}
	}
	cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << endl;
	return 0;
}

Measured memory_bytes: 1408
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let k = read::<usize>();
    let q = read::<usize>();
    let mut cnts = vec![0; n];
    for _i in 0..q {
        let a = read::<usize>() - 1;
        cnts[a] += 1;
    }
    for i in 0..n {
        println!("{}", if k + cnts[i] > q { "Yes" } else { "No" });
    }
}


Measured memory_bytes: 2740
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>

std::vector<std::size_t> prime_table = {2};

void make_prime_table()
{
    std::set<std::size_t> undefined_table;
    for(std::size_t i = 3; i <= 999999; i += 2)
    {
        undefined_table.insert(i);
    }

    const std::size_t sn = 1000;
    for(std::size_t p = 0; !undefined_table.empty() && p < prime_table.size(); ++p)
    {
        for(auto u = undefined_table.begin(); u != undefined_table.end();)
        {
            if(0 == *u % prime_table[p])
            {
                u = undefined_table.erase(u);
            }
            else
            {
                ++u;
            }
        }

        if(!undefined_table.empty())
        {            
            prime_table.push_back(*undefined_table.begin());
            undefined_table.erase(undefined_table.begin());
            if(sn <= prime_table.back())
            {
                break;
            }
        }
    }
    prime_table.insert(prime_table.end(), undefined_table.begin(), undefined_table.end());
}

std::array<std::size_t, 1000000> prime_acc = {{0, 0}};

void make_prime_acc()
{
    std::size_t acc_found = 1;
    for(auto p = prime_table.begin(); p != prime_table.end(); ++p)
    {
        std::fill_n(prime_acc.begin() + acc_found + 1, *p - acc_found - 1, prime_acc[acc_found]);
        acc_found = *p;
        prime_acc[acc_found] = prime_acc[acc_found - 1] + 1;
    }
    std::fill(prime_acc.begin() + acc_found + 1, prime_acc.end(), prime_acc[acc_found]);
}

int main()
{
    make_prime_table();
    make_prime_acc();

    std::size_t n;

    while(std::cin >> n, !std::cin.eof())
    {
        std::cout << prime_acc[n] << std::endl;
    }
}

Measured memory_bytes: 32808
#include <iostream>

typedef long long ll;

const ll MAXN = 1000005;
int cnt[MAXN];

int main() {
  for (int i = 0; i < MAXN; ++i)
    cnt[i] = 0;

  for (ll i = 1; i < MAXN; ++i)
    for (ll j = i*i; j < MAXN; j += i)
      cnt[j] += (i*i == j ? 1 : 2);

  int N;  std::cin >> N;
  ll ans = 0;
  for (int i = 1; i < N; ++i)
    ans += cnt[i];
  std::cout << ans << "\n";

  return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s;
    cin>>s;
    if(s=="Sunny")
    {
        cout<<"Cloudy"<<endl;
    }
    else if(s=="Cloudy")
    {
        cout<<"Rainy"<<endl;
    }
    else
    {
        cout<<"Sunny"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;
#define int long long


struct Edge{
	int src;
	int dst;
	int cost;
	Edge(int src = -1, int dst = -1, int cost = 1)
	: src(src), dst(dst),cost(cost){};
	bool operator<(const Edge &e) const {
		return this -> cost < e.cost;
	}
	bool operator>(const Edge &e) const{
		return this -> cost > e.cost;
	}
};
using Graph = vector<vector<Edge>>;

int N,u,v;
Graph tree;
//here begins your code
int D[100010][2];
void dfs(int cur,int pre,int dist,int id){
	D[cur][id] = dist;
	for(auto e : tree[cur]){
		if(e.dst == pre)continue;
		dfs(e.dst,cur,dist+1,id);
	}
}

signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N >> u >> v;
  tree.resize(N);
  for(int i = 0; i < N - 1 ; i++){
  	int a,b;
  	cin >> a >> b;
  	a--;
  	b--;
  	tree[a].emplace_back(a,b);
  	tree[b].emplace_back(b,a);
  }
  u--;
  v--;
  dfs(u,-1,0,0);//takahashi
  dfs(v,-1,0,1);//aoki

  int ans = 0;
  for(int i = 0 ; i < N ; i++){
  	if(D[i][0] < D[i][1]){
  		ans = max(ans,D[i][1]);
  	}
  }
  cout << ans - 1 << endl;
  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

Measured memory_bytes: 16000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String line = in.readLine();

      char[] str = new char[line.length()];
      int i = 0;
      for (char ch : line.toCharArray()) {
        if(ch == '1')
          str[i++] = '9';
        else if (ch == '9')
          str[i++] = '1';
        else
          str[i++] = ch;
      }

      System.out.println(str);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 21204
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
    int n;
    int i;
    long long int power = 1;
    
    cin >> n;
    
    for(i = 1; i <= n; i++) {
        if(power * i > 1000000007) {
            power = (power * i) % 1000000007;
        } else {
            power = power * i;
        }
    }
    
    cout << power << "\n";
    
    return 0;
}

Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(v)";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
    var a = o.a();
    var b = o.a();
    if(a === b)return a+b;
    return Math.max(a,b)*2-1;
}

Measured memory_bytes: 21064
import sys
input = lambda: sys.stdin.readline().rstrip()
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
mod = 1000000007

a, b = input().split()

a = int(a)
b = list(b)
for i in range(len(b)):
    if b[i] == '.':
        pos = i

x = len(b) - pos - 1
b.pop(pos)
b = int(''.join(b))

ans = a * b
ans = str(ans)
if len(ans) < 2:
    ans = int(int(ans) * 10**(-2))
else:
    ans = int(ans[:-pos -1])

print(ans)




Measured memory_bytes: 77752
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[2] * 10 + a[1] + a[0] << endl;
	//getchar(); getchar(); getchar();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void func()
{
    int n,W;
    cin>>n>>W;
    ll w[n+1],v[n+1];
    for(int i=1;i<=n;i++)
    {
    	cin>>w[i]>>v[i];
	}
	ll dp[n+1][W+1]={};
	for(int i=1;i<=n;i++)
	dp[i][0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=W;j++)
		{
			if(j>=w[i])
			{
				dp[i][j]=max(v[i]+dp[i-1][j-w[i]],dp[i-1][j]);
			}
			else
			{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	cout<<dp[n][W];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    func();
	return 0;
}



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

int main()
{
    string S,T;
    cin>>S>>T;
    int A,B;
    cin>>A>>B;
    string U;
    cin>>U;
    if (U==S){
        A-=1;
    }
    else B-=1;
    cout<<A<<" "<<B;
    return 0;
}


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

typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;


int main()
{
    ll n ;
    cin >> n ;
    if (n % 2 == 0) cout << n / 2 ;
    else    cout << (n / 2) + 1 << endl ;
}


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

vector<int> v[100010];
bool vis[100010];
int ans,n,m,dist[100010];

int dfs(int u)
{
	vis[u]=1;
	int sum=1,maxv=0;
	for(int i=0;i<v[u].size();i++) {
		int val;
		if(dist[v[u][i]]==0) val=dfs(v[u][i]);
		else val=dist[v[u][i]];
		maxv=max(maxv,val);
	}
	sum+=maxv;
	dist[u]=sum;
	return sum;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
	}
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			ans=max(ans,dfs(i));
		}
	}
	cout<<ans-1<<endl;
	return 0;
}


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


int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c%b!=0 && a%d!=0)
    {
        if (a/d<c/b) cout << "No";
        else cout << "Yes";
    }
    else if (c%b!=0 && a%d==0)
    {
        if (a/d<c/b+1) cout << "No";
        else cout << "Yes";
    }
    else if (c%b==0 && a%d!=0)
    {
        if (a/d+1<c/b) cout << "No";
        else cout << "Yes";
    }
    else if (c%b==0 && a%d==0)
    {
        if (a/d<c/b) cout << "No";
        else cout << "Yes";
    }
}


Measured memory_bytes: 3580
#!/usr/bin/env python3
import heapq
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, a: "List[int]"):
    h = a[:N]
    heapq.heapify(h)
    l1 = [0] * (N + 1)
    l1[0] = sum(h)
    for i in range(N):
        m = heapq.heappushpop(h, a[N + i])
        l1[i + 1] = l1[i] + a[N + i] - m
    h = [-ai for ai in a[-N:]]
    heapq.heapify(h)
    l2 = [0] * (N + 1)
    l2[N] = sum(h)
    for i in reversed(range(N)):
        m = heapq.heappushpop(h, -a[N + i])
        l2[i] = l2[i + 1] + (-a[N + i]) - m
    print(max(l1[i] + l2[i] for i in range(N + 1)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(3 * N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 52416
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	vector<ll> p(n),pos(n+1,0);
	REP(i,n){
		cin>>p[i];
		pos[p[i]] = i+1;
	}
	ll ans = 0;

	multiset<ll> s;
	s.insert(0);
	s.insert(0);
	s.insert(n+1);
	s.insert(n+1);
	for (ll now = n; now >= 1; now--){
		auto it = s.lower_bound(pos[now]);
		ll pos_r = *it;

		it++;
		ll pos_rr = *it;

		it--;
		it--;
		ll pos_l = *it;

		it--;
		ll pos_ll = *it;

		ans += now*(pos_r-pos[now])*(pos_l-pos_ll);
		ans += now*(pos_rr-pos_r)*(pos[now]-pos_l);

		s.insert(pos[now]);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int n, m, l;
  long long A[100][100];
  long long B[100][100];
  long long C[100][100];
  cin >> n >> m >> l;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  for(int i = 0; i < m; i++) {
    for(int j = 0; j < l; j++) {
      cin >> B[i][j];
    }
  }
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < l; j++) {
      C[i][j] = 0;
      for(int k = 0; k < m; k++) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < l; j++) {
      cout << C[i][j];
      if (j < l-1) {
        cout << " ";
      }
    }
    cout << endl;
  }  
  return 0;
}


Measured memory_bytes: 3340
/*
    g++ -std=c++14 -O2 -Wall a.cpp -o a && a
    g++ -std=c++14 -O2 -Wall a.cpp -o a && a < in.txt > out.txt
    */

//  io
#include <iostream>
//#include <fstream> //http://www.cplusplus.com/reference/fstream/fstream/
//#include <cstdio>
//#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
//  util
#include <algorithm>
#include <cstring>
#include <string>
#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
//#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <queue>
#include <vector>
//#include <set>
#include <tuple>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
constexpr int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//int modadd(int a, int b) { return ((a += b) < mod) ? a : (a - mod); }
//int modmult(int a, int b) { return (int)((a * b) % mod); }

//file input routed to stdinout
/*
    std::ifstream inFile("input.txt");
    std::ofstream outFile("output.txt");
    std::cin.rdbuf(inFile.rdbuf());
    std::cout.rdbuf(outFile.rdbuf());
*/

long long dp[11][11];

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

    int n, m;

    cin >> n >> m;

    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            cin >> dp[i][j];
        }
    }

    for (int k = 0; k < 10; k++)
    {
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }

    long long sum = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            int u;
            cin >> u;
            if(u == -1) continue;

            sum += dp[u][1] ;
        }
    }

    cout << sum;
}

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

using namespace std;
typedef long long llint;
const int mod = 2019;

int n;
string s;
int cnt[mod + 10];

int main() {
    cin >> s;
    reverse(s.begin(), s.end());
    n = s.size();

    int suma = 0;
    int pot = 1;

    llint sol = 0;
    cnt[0] = 1;
    for (int i = 0; i < n; i++) {
        suma += (pot * (s[i] - '0')) % mod;
        suma %= mod;
        pot *= 10, pot %= mod;

        sol += cnt[suma]++;
    }

    cout << sol << endl;
    return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

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

int main(){
    int k;
    cin >> k;
    int ans=0;
    for(int i=1;i<=k;i+=2){
        for(int j=2;j<=k;j+=2) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
long long int pw(long long int x,long long int n,long long int MOD){
  long long int res=1;
  if(n>0){
    res=pw(x,n/2,MOD);
    if(n%2==0)res=(res*res)%MOD;
    else res=(((res*res)%MOD)*x)%MOD;
  }
  return res;
}
int main(){
  long long int m;
  long long int n;
  scanf("%lld %lld",&m,&n);
  printf("%lld\n", pw(m,n,1000000007));
  return 0;
}

Measured memory_bytes: 596
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  vector<int> d(m + 2), e(m + 2);
  d[m + 1] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) {
      int L = j, R = min(j + a[i], m) + 1;
      int cur = (d[R] + MOD - d[L]) % MOD;
      e[j + 1] = (e[j] + cur) % MOD;
    }
    swap(d, e);
  }
  printf("%d\n", d[1]);
  return 0;
}


Measured memory_bytes: 1024
/*                    */
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
lint gcd(lint a, lint b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
lint lcm(lint a, lint b) { return a * b / my::gcd(a, b); }
}  // namespace my
/*                    */

int main() {
  const lint hoge = 1e9 + 7;
  lint n, k;
  cin >> n >> k;
  lint ans = 0;
  for (lint i = k; i <= n + 1LL; i++) {
    ans += i * n - i * (i - 1LL) + 1LL;
    ans %= hoge;
  }
  cout << ans << endl;
}

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

int main() {
    //const int Inf = 1e9;
    int n;
    cin >> n;

    int dp[305][305];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin >> dp[i][j];
        }
    }
    long long ans =0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            bool flag=true;
            for(int k=0; k<n; k++){
                if(k==i | k ==j) continue;
                if(dp[i][j]>dp[i][k]+dp[k][j]){
                    cout << -1 << endl;
                    return 0;
                } else if (dp[i][j]==dp[i][k]+dp[k][j]){
                    flag = false;
                }
            }
            if(flag) ans += dp[i][j];
        }
    }

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

Measured memory_bytes: 640
import itertools

n, k = (int(x) for x in input().split())
okashi_count_list = []
okashi_snuke_list = []
l = [0] * n

for i in range(k * 2):

    if i % 2 == 0 :
        okashi_count_list.append(list(map(int,input().split())))
    else :
        okashi_snuke_list.append(list(map(int,input().split())))

# print(okashi_count_list)
# print(okashi_snuke_list)

# 1次元に変換
okashi_snuke_list = list(itertools.chain.from_iterable(okashi_snuke_list))
# 重複を削除
okashi_snuke_list = set(okashi_snuke_list)

l_n_str = [str(n) for n in okashi_snuke_list]

# print('lの長さ')
# print(len(l))

for e in l_n_str:
    # print(e)

    # print('l[e]')
    # print(l[int(e) - 1])

    l[int(e) - 1] = 1

count = 0

for e in l:
    if e == 0 :
        count = count + 1

print(count)

Measured memory_bytes: 9252
class SWAG():
    def __init__(self,unit,f):
        self.fold_r=[unit]
        self.fold_l=[unit]
        self.data_r=[]
        self.data_l=[]
        self.f=f
    def __refill_right(self):
        temp=[]
        n=len(self.data_l)
        *_,=map(temp.append,(self.popleft()for _ in range(n//2)))
        *_,=map(self.append,(self.popleft()for _ in range(n//2,n)))
        *_,=map(self.appendleft,temp[::-1])
    def __refill_left(self):
        temp=[]
        n=len(self.data_r)
        *_,=map(temp.append,(self.pop()for _ in range(n//2)))
        *_,=map(self.appendleft,(self.pop()for _ in range(n//2,n)))
        *_,=map(self.append,temp[::-1])
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.__refill_right()
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.__refill_left()
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=map(int,open(0).read().split())
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min)
s_max=SWAG(0,max)
*_,=map(s_min.append,p[:k-1])
*_,=map(s_max.append,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print(x+f)

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

using namespace std;

vector<int> v;
int dp[2][100100];

#define INF 1000000000
#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
bool init()
{
	v.clear();
	string s;
	cin >> s;
	if (s[0] == '#') return false;
	rep(i, s.length()) {
		v.push_back((s[i] - '0' + 2) % 3);
	}
	rep(i, 2) rep(j, 100100) dp[i][j] = INF;
	dp[0][0] = dp[1][0] = 0;
	return true;
}


int main()
{
    while (init()) {
		reps(i, 1, v.size()) {
			if (v[i] <= v[i-1]) {
				dp[0][i] = min(dp[0][i], dp[1][i-1]);
				dp[0][i] = min(dp[0][i], dp[0][i-1] + 1);
			}
			if (v[i] >= v[i-1]) {
				dp[1][i] = min(dp[1][i], dp[0][i-1]);
				dp[1][i] = min(dp[1][i], dp[1][i-1] + 1);
			}
		}
		cout << min(dp[0][v.size()-1], dp[1][v.size() - 1]) << endl;
    }
}



Measured memory_bytes: 4384
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wtr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	a := make([]uint, n)

	for i := 0; i < n; i++ {
		a[i] = uint(scanInt())
	}

	cnt := make([]uint, 61)
	for _,ai:=range a{
		for i:=uint(0);i<=60;i++{
			cnt[i] +=(uint(ai) >> i)&1
		}
	}
 
	ans :=uint(0)
	for i, v:=range cnt{
		ans = (ans + (v*(uint(n)-v)%mod) * ((1<<uint(i)) % mod)) %mod
	}

	fmt.Println(ans)
}

const mod = 1000000007


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

using namespace std;

int main(void){

    int N,cnt = 0,a[110],l;

    cin >> N;

    while(cin>>l){

        a[cnt] = l;
        cnt++;

        if(cnt > N-1){
            cnt = 1;
            break;
        }

    }

    sort(a,a+N,greater<int>());

    for(int i=0;i<N - 1;i++){
        if(a[i]>a[i+1]){
            cnt++;
        }
    }

    cout << cnt << endl;

}

Measured memory_bytes: 256
# Aizu Problem 0063: Palindrome
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


cnt = 0
while True:
    try:
        string = input().strip()
    except EOFError:
        break
    if string == string[::-1]:
        cnt += 1
print(cnt)

Measured memory_bytes: 7496
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 998244353;
const int INF = 1e9 + 7;
const int MAXN = 2e5 + 5;
const double eps = 1e-9;
char str[MAXN];
int dp[MAXN][3][3]; // ind, sm, last, two cons

void add(int& a, int b) {
	a = (a+b) % MOD;
}

int main() {
	scanf("%s", str);
	int n = strlen(str);
	if (n == 2) return !pri(str[0] == str[1] ? 1 : 2);
	if (n == 3) {
		if (str[0] == str[1] && str[1] == str[2])
			return !pri(1);
		if (str[0] != str[1] && str[1] != str[2]) {
			if (str[0] == str[2])
				return !pri(7);
			return !pri(3);
		}
		return !pri(6);
	}
	bool fl = 1, fl2 = 1;
	int sm = 0;
	ll p2 = 1;
	for (int i = 0; i < n; i++) {
		fl &= str[i] == str[0];
		sm = (sm+str[i]-'a')%3;
		if (i) {
			fl2 &= (str[i] != str[i-1]);
			p2 = (p2 * 3ll) % MOD;
		}
	}
	if (fl) return !pri(1);
	for (int i = 0; i < 3; i++)
		dp[1][i][i] = 1;
	for (int i = 1; i < n; i++)
		for (int nx = 0; nx < 3; nx++)
			for (int j = 0; j < 3; j++) // sm
				for (int k = 0; k < 3; k++) // last
					if (k != nx)
						add(dp[i+1][(j+nx)%3][nx], dp[i][j][k]);

	int ans = (dp[n][sm][0]+dp[n][sm][1]) % MOD;
	ans = (ans + dp[n][sm][2]) % MOD;
	ans = (p2 - ans + MOD) % MOD;
	if (fl2) ans = (ans+1) % MOD;
	pri(ans);
    return 0;
}


Measured memory_bytes: 7424
H, W = map(int, input().split())

maze = [[0 for j in range(W)] for i in range(H)]
dp = [[0 for j in range(W+1)] for i in range(H+1)]
dp[1][0] = 1

for i in range(H):
    maze[i] = list(str(input()))

for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            dp[i+1][j+1] = 0
        else:
            dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j]

print(dp[H][W] % 1000000007)


Measured memory_bytes: 166304
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
 vector< int> a(3);
  cin >> a[0];
  cin >> a[1];
  cin >> a[2];
  sort(a.begin(),a.end());
  
  cout << a[2]-a[0] <<endl;
  
   return 0;
}


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

using namespace std ;

int n , k ;
const int N = 1e5 + 10;
int a[N] , cost[N] ;




int main(){
    scanf("%d %d" , &n , &k) ;
    for(int i = 1 ; i < n ; i++)
        cost[i] = 2e9 ;



    for(int i = 0 ; i < n ; i++){

        scanf("%d" , &a[i]) ;

        int j = i - k  ;
        if(j < 0) j = 0 ;

        for(j ; j < i ; j++){

            if(cost[j] + abs(a[j] - a[i]) < cost[i])
                cost[i] = cost[j] + abs(a[j] - a[i]) ;

        }


        //printf("%d " , cost[i]) ;
    }




    printf("%d\n" , cost[n - 1]) ;
}


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

using namespace std;

using ll = long long;

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

    ll n;
    cin >> n;
    vector<ll> a(3 * n), score(n + 1);
    for (int i = 0; i < 3 * n; ++i) cin >> a[i];

    priority_queue<ll> que_l, que_r;
    for (ll i = 0, sum[4] = {0, 0, 0, 0}; i < 2 * n; ++i) {
        sum[0] += a[i]; que_l.push(-a[i]);
        sum[1] += a[3 * n - i - 1]; que_r.push(a[3 * n - i - 1]);

        if (n + 1 <= (int)que_l.size()) {
            sum[2] -= que_l.top(); que_l.pop();
            sum[3] += que_r.top(); que_r.pop();
        }
        if (n - 1 <= i) {
            score[i - n + 1] += sum[0] - sum[2];
            score[2 * n - i - 1] -= sum[1] - sum[3];
        }
    }

    cout << *max_element(score.begin(), score.end()) << endl;

    return 0;
}


Measured memory_bytes: 5228
s=input()
n=len(s)
if n==1:
  kouho1=[1]
  kouho2=[0]
else:
  kouho1=[0,1]*(n//2)
  kouho2=[1,0]*(n//2)
if n%2==1:
  kouho1.append(0)
  kouho2.append(1)

count1=0
count2=0
for i in range(0,n):
  ss=int(s[i])
  count1+=abs(kouho1[i]-ss)
  count2+=abs(kouho2[i]-ss)
  
print(min(count1,count2))

Measured memory_bytes: 4724
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main(){
    int64_t X;
    cin >> X;
    vector<int64_t> temp;

    temp.push_back(0);
    
    int64_t bufA=0,bufB=0;

    for(int64_t i=0;;i++){
        temp.push_back((i+1)*(i+1)*(i+1)*(i+1)*(i+1));
        for(int j =0;j<=i;j++){
            if(temp[i] - temp[j] == X){
                bufA = i;
                bufB = j;
                cout << bufA <<" "<<bufB<<endl;
                return 0;
            }
            else if(temp[i] + temp[j] == X){
                bufA = i;
                bufB = -1 *j;
                cout << bufA <<" "<<bufB<<endl;
                return 0;
            }
        }
    }
}



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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef vector<int> vi;
typedef long long ll;
#define all(c) begin(c),end(c)

auto solve() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, bool>> balls(N, make_pair(1, false));
    balls[0] = make_pair(1, true);

    REP(i, M) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        --balls[x].first, ++balls[y].first;
        if (balls[x].second) balls[y].second = true;
        if(balls[x].first == 0) balls[x].second = false;
    }

    int res = 0;
    for (auto &&e:balls) res += (e.first > 0 && e.second ? 1 : 0);
    return res;
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 1024
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    ans, cnt = N, 1
    for a in A:
        if a == cnt:
            ans -= 1
            cnt += 1
    if ans == N:
        print('-1')
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 82380
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

int main() {
    int n, m;

    for (;;) {
        cin >> n >> m; 
        if (n == 0 && m == 0) break;

        vector<int> s(n + m);
        int s1 = 0, s2 = 0;
        for (int i = 0; i < n + m; i++) {
            cin >> s[i];
            if (i < n) {
                s1 += s[i];
            } else {
                s2 += s[i];
            }
        }

        int ans1 = 100, ans2 = 100;
        for (int i = 0; i < n; i++) {
            for (int j = n; j < n + m; j++) {
                int a = s[i], b = s[j];
                if ((s1 + b - a) == (s2 + a - b) && (a + b) < (ans1 + ans2)) {
                    ans1 = a;
                    ans2 = b;
                }
            }
        }

        if (ans1 == 100 && ans2 == 100) {
            cout << -1 << endl;
        } else {
            cout << ans1 << " " << ans2 << endl;
        }
    }
}

Measured memory_bytes: 1196
//g++  5.4.0

#include <iostream>
#include <vector>
using namespace std;

int n, m, q;
int a[50],b[50],c[50],d[50];
long long int maxnum = 0;

long long int calc(std::vector<int>& v)
{
        long long int sum = 0;
        for(int j=0; j<q; j++){
            int aj = a[j]-1;
            int bj = b[j]-1;
            if(v[bj]-v[aj] == c[j]){
                sum += d[j];
            }
            //cout << a[j]-1 << "," << b[j]-1 << "," << c[j] << "," << d[j] << endl;
        }
        //cout << sum << endl;
        return sum;
}

void dfs(std::vector<int>& v)
{
    if(v.size() >= n){
        //for(int i=0; i<n; i++) cout << v[i];
        //cout << endl;
        long long int sum = calc(v);
        if(sum > maxnum) maxnum = sum;
        return;
    }
    
    int last = 1;
    if(v.size() > 0) last = v[v.size()-1];
    for(int i=last; i<=m; i++){
        v.push_back(i);
        dfs(v);
        v.pop_back();
    }
}

int main()
{
    cin >> n >> m >> q;
    for(int i=0; i<q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }   
    std::vector<int> v;
    dfs(v);
    cout << maxnum << endl;
}

Measured memory_bytes: 3604
N, K = map(int, input().split())

h = list(map(int, input().split()))
dp = [10 ** 9 + 1] * N
dp[0] = 0
for i in range(N):
    for j in range(i + 1, i + K + 1):
        if j < N:
            dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
        else:
            break
print(dp[N - 1])

Measured memory_bytes: 52448