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

typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod


int n, m;
vector<vector<int>> g(1000000 + 6);

int ord[1000000 + 6], low[1000000 + 6];
bool visited[1000000 + 6];

vector<pair<int, int>> Bridges;
vector<int> Points;

void dfs(int now, int par, int &cnt) {
    visited[now] = true;
    ord[now] = cnt++;
    low[now] = ord[now];
    bool check = false;
    int outdeg = 0;
    for (auto nx : g[now]) {
        if (nx == par) continue;
        if (!visited[nx]) {
            outdeg++;
            dfs(nx, now, cnt);
            low[now] = min(low[now], low[nx]);
            //???????????????
            if (ord[now] < low[nx]) {
                Bridges.push_back({min(now, nx), max(now, nx)});
            }
            //??¢??????????????????
            if (par != -1 && !check && ord[now] <= low[nx]) {
                check = true;
                Points.push_back(now);
            }
        }
        else {
            low[now] = min(low[now], ord[nx]);
        }
    }
    //???????????????????????\?????¢????????¨???????????????
    if (par == -1 && outdeg >= 2) {
        Points.push_back(now);
    }
    return;
}

void lowlink (int n, vector<vector<int>>& g) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            dfs(i, -1, cnt);
        }
    }
    sort(all(Bridges));
    sort(all(Points));
    return;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    lowlink(n, g);
    rep(i, Bridges.size()) {
        cout << Bridges[i].fi << " " << Bridges[i].se << endl;
    }
    /*
    rep(i, Points.size()) {
        cout << Points[i] << endl;
    }
    */
}

Measured memory_bytes: 28844
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
ans=0
mon1=a[0]
mon2=a[0]+a[1]
for i in range(n):
   if b[i] <= mon1:
      ans+=b[i]
      mon1=a[i+1]
      if i<=n-2:
         mon2=a[i+1]+a[i+2]
   elif mon1<b[i]<=mon2:
      ans+=b[i]
      mon1=mon2-b[i] #ここmon2-b[i]のほうがきれい？
      if i<=n-2:
         mon2=mon1+a[i+2]
   else: 
      ans+=mon2 #ここmon2にしないと動かないぞ
      mon1=0
      if i<=n-2:
         mon2=a[i+2]
print(ans)

Measured memory_bytes: 19004
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int h,w;cin >> h >> w;
  vector<vector<char>> s(h+2,vector<char>(w+2));
  for(int i = 0; i < h; ++i){
    string t;cin >> t;
    for(int j = 0; j < w; ++j){
      s[i+1][j+1]=t[j];
    }
  }
  for(int i = 1; i <= h; ++i){
    for(int j = 1; j <= w; ++j){
      if(s[i][j]=='#'){
        cout << '#';
        continue;
      }
      int ans = 0;
      if(s[i-1][j-1]=='#')++ans;
      if(s[i-1][j]=='#')++ans;
      if(s[i-1][j+1]=='#')++ans;
      if(s[i][j-1]=='#')++ans;
      if(s[i][j+1]=='#')++ans;
      if(s[i+1][j-1]=='#')++ans;
      if(s[i+1][j]=='#')++ans;
      if(s[i+1][j+1]=='#')++ans;
      cout << ans;
    }
    cout <<  endl;
  }
}


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

const int N=100005;

int n,m,k,a[N],b[N];

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	int mn1=1e9,mn2=1e9;
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),mn1=std::min(mn1,a[i]);
	for (int i=1;i<=m;i++) scanf("%d",&b[i]),mn2=std::min(mn2,b[i]);
	int ans=mn1+mn2;
	while (k--)
	{
		int x,y,z;scanf("%d%d%d",&x,&y,&z);
		ans=std::min(ans,a[x]+b[y]-z);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int flag = 0;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]==s[i+1]){
            flag =1;
        }
    }
    if(flag==1){
        cout<<"Bad"<<endl;
    }
    else{
        cout<<"Good"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N,M,K=map(int,input().split())
table=[]
for i in range(N):
    a,b,c=map(int,input().split())
    table.append([a,b,c])

inf=10**9
#[N+1][400a][400b]
dp=[[[inf]*401 for i in range(401)]for i in range(N+1)]
dp[0][0][0]=0
for i in range(1,N+1):
    a,b,c = table[i-1]
    for j in range(401):
        for k in range(401):
            dp[i][j][k]=dp[i-1][j][k]
            if 400>=j-a>=0 and 400>=k-b>=0:
                dp[i][j][k] =min(dp[i-1][j][k],dp[i-1][j-a][k-b]+c)

ans =10**9
i=1
while max(M,K)*i <401:
    ans = min(ans,dp[N][M*i][K*i])
    i=i+1
if ans ==10**9:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 94300
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

pub fn pow(x: i64, n: i64) -> i64 {
    let (mut x, mut y, mut n) = (x % P, 1_i64, n);
    while n > 0 {
        if n % 2 != 0 {
            y = (y * x) % P;
            n -= 1;
        }

        x = (x * x) % P;
        n /= 2;
    }
    y
}

fn main() {
    let (N, K) = read!(usize, usize);

    let mut dp = vec![0; K + 1];
    let mut total = 0_i64;

    for g in (1..K + 1).rev() {
        let m = K / g;
        let mut count = pow(m as i64, N as i64);

        let mut d = g * 2;
        while d <= K {
            count += P - dp[d];
            count %= P;
            d += g;
        }

        count %= P;

        dp[g] = count;

        total += count * g as i64;
        total %= P;
    }

    println!("{}", total)
}


Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const int mod = 1e9 + 7;
#define int long long int

int32_t main() {
    IOS ;
    int n, k ; cin >> n >> k ;  int arr[n+1] ;
    for(int i=1; i<=n; i++) cin >> arr[i] ; 

    bool dp[k+1] ; dp[0] = false ; 
    for(int i=1; i<=k; i++) {
        bool flag = false ;
        for(int j=1; j<=n; j++) {
            if((i - arr[j] >= 0) and (!dp[i - arr[j]]))  
            { flag = true ; break ; } 
        }
        if(flag) dp[i] = true ; 
        else dp[i] = false ;
    }

    if(dp[k]) cout << "First" ; 
    else cout << "Second" ;

    return 0 ;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    std::string s;
    std::vector<int> a(4);
    std::cin >> s;
    a[0] = s[0]-'0';
    a[1] = s[1]-'0';
    a[2] = s[2]-'0';
    a[3] = s[3]-'0';

    for(int bits=0; bits<(1<<3); bits++){
        int sum = 7 - a[0];
        for(int i=0; i<3; i++){
            if(bits&(1<<i)) sum += a[i+1];
            else sum -= a[i+1];
        }
        if(sum==0){
            std::cout << a[0] << ((bits&(1<<0))?('-'):('+'))
                      << a[1] << ((bits&(1<<1))?('-'):('+'))
                      << a[2] << ((bits&(1<<2))?('-'):('+'))
                      << a[3] << "=7\n";
            return 0;
        }
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <bitset>
#include <fstream>
#include <unordered_set>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
  
          
using namespace std;
using namespace __gnu_pbds;
 
  
 
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")*/
      
#define int long long
#define eb emplace_back
#define pb push_back
#define ld long double
#define mp make_pair
#define f first
#define s second
#define deb(a) cerr << #a << " = " << a << '\n';
#define fast() { \
    ios_base::sync_with_stdio(0); \
    cin.tie(0); \
    cout << fixed << setprecision(5); \
    cerr << fixed << setprecision(11); \
}
 
template < typename firstType, typename secondType = null_type, class compare = less < firstType > >
struct sett {
    typedef tree <
        firstType,
        secondType,
        compare,
        rb_tree_tag,
        tree_order_statistics_node_update
    > _ ;
};
 
  
const int INF = 1e9 + 7;
const ld EPS = 1e-10;
const int MAXI = 200000;
const int P = 223; 
const int MOD = 998244353; 
const int MAXST = 2000000;
const ld PI = 3.14159265358979323;
        
ostream &operator<<(ostream &stream, const pair <int, int> &p) {
    stream << p.first << ' ' << p.second << ' ';
    return stream;
}

int p[21], q, d[100], c[100], b[100], a[100], ans = 0, n, m;

void rec(int x, int mx, int k){
	if (k == m){
		int ans1 = 0;
		for (int i = 0; i < q; i++){
			if (p[b[i]] - p[a[i]] == c[i])
				ans1 += d[i];
		}
		ans = max(ans, ans1);
		return;
	}
	else{
		p[k] = x;
		for (int i = mx; i <= n; i++)
			rec(i, i, k + 1);
	}
}

signed main(){  
    fast();
    srand(time(0));
    #ifdef _LOCAL               
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cin >> m >> n >> q;
    for (int i = 0; i < q; i++){
    	cin >> a[i] >> b[i] >> c[i] >> d[i];
    	a[i]--;
    	b[i]--;
    }
    for (int i = 1; i <= n; i++)
    	rec(i, i, 0);
    cout << ans << '\n';
    return 0;                   
   	
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    int n, m, k;
    cin >> n >> m >> k;
    
    int b = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            b = i * m + n * j - 2 * i * j;
            
            if (b == k) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

class Pos{
public:
	int tx,ty,kx,ky,n;
	bool operator<(const Pos &pos)const{return n>pos.n;}
};

int memo[50][50][50][50];
int m[50][50];

int main() {
	int X,Y;
	int tx,ty;
	int kx,ky;
	while(cin>>X>>Y,X){
		memset(memo,-1,sizeof(memo));
		priority_queue<Pos> que;
		cin>>tx>>ty>>kx>>ky;
		tx--;ty--;kx--;ky--;
		int i,j;
		for(i=0;i<Y;i++){
			for(j=0;j<X;j++){
				m[i][j]=in();
			}
		}
		Pos pos;
		pos.tx=tx;
		pos.ty=ty;
		pos.kx=kx;
		pos.ky=ky;
		pos.n=0;
		que.push(pos);
		while(!que.empty()){
			pos=que.top();
			que.pop();
			if(pos.tx==pos.kx&&pos.ty==pos.ky)break;
			if(memo[pos.tx][pos.ty][pos.kx][pos.ky]>=0)continue;
			memo[pos.tx][pos.ty][pos.kx][pos.ky]=pos.n;
			int xx[]={1,-1,0,0};
			int yy[]={0,0,1,-1};
			Pos next;
			for(i=0;i<4;i++){
				if(0<=pos.tx+xx[i]&&pos.tx+xx[i]<X&&0<=pos.ty+yy[i]&&pos.ty+yy[i]<Y&&m[pos.ty+yy[i]][pos.tx+xx[i]]==0){
					next.tx=pos.tx+xx[i];
					next.ty=pos.ty+yy[i];
				}else{
					next.tx=pos.tx;
					next.ty=pos.ty;
				}
				if(0<=pos.kx-xx[i]&&pos.kx-xx[i]<X&&0<=pos.ky-yy[i]&&pos.ky-yy[i]<Y&&m[pos.ky-yy[i]][pos.kx-xx[i]]==0){
					next.kx=pos.kx-xx[i];
					next.ky=pos.ky-yy[i];
				}else{
					next.kx=pos.kx;
					next.ky=pos.ky;
				}
				next.n=pos.n+1;
				que.push(next);
			}
		}
		if(!que.empty()){
			cout<<pos.n<<endl;
		}else{
			cout<<"NA"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 25000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int a,b;
  if(A%D == 0) a = A/D;
  else a = A/D + 1;
  
  if(C%B == 0) b = C/B;
  else b = C/B + 1;
  
  if(b > a) cout << "No" << endl;
  else cout << "Yes" << endl;
  
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(std::string b) {
  string ret = " ";
  if (b == "A") ret = "T";
  if (b == "G") ret = "C";
  if (b == "C") ret = "G";
  if (b == "T") ret = "A";

  cout << ret << endl;
}

int main() {
  cout << setprecision(10);
  std::string b;
  std::cin >> b;
  solve(b);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long min = Long.MAX_VALUE;
		long N = sc.nextLong();
		int max = (int) Math.sqrt(N);
		for (int i=1;i<=max;i++) {
			if (N%i==0) {
				long y = N/i;
				long temp = String.valueOf(y).length();
				if (temp <min) {
					min = temp;
				}
			}
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 22228
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long
LL n,a[100002],ans;
bool vis[100002];
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(a[i])vis[i]=1;
		ans+=a[i]/2;
		a[i]%=2;
	}
	for(int i=2;i<=n;i++)
	{
		if(a[i]+a[i-1]==2)a[i-1]=a[i]=0,ans++;
		if(a[i]==0&&a[i-1]&&vis[i])
			a[i]++,a[i-1]--;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] strlist = str.split(" ");
		int x = Integer.parseInt(strlist[0]);
		int y = Integer.parseInt(strlist[1]);
		int[] A = {1, 3, 5, 7, 8,10, 12};
		int[] B = {4, 6, 9, 11};
		ArrayList<Integer> listA = toList(A);
		ArrayList<Integer> listB = toList(B);

		String answer = "No";
		if(x == 2 && y == 2){
			answer = "Yes";
		}else if(listB.contains(x) && listB.contains(y)){
			answer = "Yes";
		}else if(listA.contains(x) && listA.contains(y)){
			answer = "Yes";
		}
		System.out.println(answer);
	}

	public static ArrayList<Integer> toList(int[] list){
		ArrayList<Integer> returnList = new ArrayList<Integer>();
		for(int i=0; i<list.length; i++){
			returnList.add(list[i]);
		}
		return returnList;
	}

}


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

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

  vector<int> A1(N);
  vector<int> A2(N);
  rep(i, N) cin >> A1[i];
  rep(i, N) cin >> A2[i];

  int calc = 0;
  int ans = 0;
  rep(i, N) {
    rep(j, i + 1) calc += A1[j];
    for (int j = i; j < N; j++) calc += A2[j];
    ans = max(ans, calc);
    calc = 0;
  }

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

Measured memory_bytes: 3616
#include <cstdio>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
int H, W, a[2009][2009], t[2009][2009], dp[2009][2009], pl[2009], pr[2009];
int main() {
	scanf("%d %d", &H, &W);
	int vl = inf, vr = -1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char c = getchar_unlocked();
			while (c < 48 || 57 < c) c = getchar_unlocked();
			while (48 <= c && c <= 57) a[i][j] = 10 * a[i][j] + c - 48, c = getchar_unlocked();
			vl = min(vl, a[i][j]);
			vr = max(vr, a[i][j]);
		}
	}
	int ret = inf;
	for (int i = 0; i < 4; i++) {
		pr[W] = 0;
		for (int j = 0; j < H; j++) {
			for (int k = 1; k <= W; k++) pl[k] = max(pl[k - 1], a[j][k - 1] - vl);
			for (int k = W - 1; k >= 0; k--) pr[k] = max(pr[k + 1], vr - a[j][k]);
			int curmin = inf;
			for (int k = 0; k <= W; k++) {
				curmin = min(curmin, dp[j][k]);
				dp[j + 1][k] = max({ curmin, pl[k], pr[k] });
			}
		}
		ret = min(ret, *min_element(dp[H], dp[H] + W + 1));
		for (int j = 0; j < H; j++) {
			for (int k = 0; k < W; k++) {
				t[k][H - j - 1] = a[j][k];
			}
		}
		swap(H, W);
		for (int j = 0; j < H; j++) {
			for (int k = 0; k < W; k++) {
				a[j][k] = t[j][k];
			}
		}
	}
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 49780
#include <bits/stdc++.h>
using namespace std;
#define INF 100005

double cosd(double angle)
{
	//if(angle==90.0)
    	//return 0;
    return cos((angle*M_PI)/180.0f);
}

void calc(int a,int b,double angle)
{
	angle=cosd(angle);
	double ans=sqrt((a*a)+(b*b)-(2*a*b*(angle)));
	cout << fixed << setprecision(18) << ans << endl;
}

double ang(double h,double m)  
{
    double ha=0.5*(h*60.0+m);  
    double ma=6.0*m;
    double angle=abs(ha-ma);
    angle=min(360.0-angle,angle);
    return angle;  
}

int main()
{
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
	int a,b,h,m;
	cin >> a >> b >> h >> m;
	double angle=ang(h,m);
	calc(a,b,angle);
}


Measured memory_bytes: 4212
import sys
from bisect import bisect_right, bisect_left
from itertools import accumulate

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def meguru_bisect(ok, ng):
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    def is_ok(x):
        cnt = 0
        for a in A:
            t = x - a
            idx = bisect_right(A, t)
            cnt += n - idx
        return cnt < m

    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    ng, ok = 0, 10 ** 15 + 1
    mth = meguru_bisect(ok, ng)
    R = [0] + list(accumulate(A))

    res = 0
    cnt = 0
    for a in A:
        s = mth - a
        left = bisect_left(A, s)
        res += (n - left) * a + R[-1] - R[left]
        cnt += n - left
    print(res - mth * (cnt - m))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 21064
n=int(input())
s = input().rstrip()
numw,nume=0,0
if 'W' in s:
  numw = s.count('W')
  nume = n - numw
else:
  print(0)
  exit()
donew,donee=0,0
result = pow(10,6)
for i in range(n):
  if s[i] == 'W':
    numw -= 1
  else:
    nume -= 1
  result = min(result,(nume+donew))
  if s[i] == 'W':
    donew += 1
  else:
    donee += 1
print(result)


Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=(1<<18)+5;
int v[N],w[N],a[N],b[N];
int x,y,n,Q,cnt,nA,nB;
vector<pii> AA[N];
pii A[N],B[N];

void dfs(int l,int r,int V,int W,pii A[],int &nA){
	if(l>r){
		A[++nA]=mp(W,V);
		return;
	}
	dfs(l+1,r,V,W,A,nA);
	dfs(l+1,r,V+a[l],W+b[l],A,nA);
}

int main(){
	read(n);
	rep(i,1,n){
		read(v[i]);
		read(w[i]);
	}
	REP(i,min(n+1,1024)){
		int x=i;
		cnt=0;
		for(;x;x>>=1){
			a[++cnt]=v[x];
			b[cnt]=w[x];
		}
		nA=0;
		dfs(1,cnt,0,0,A,nA);
		sort(A+1,A+nA+1);
		AA[i].resize(nA);
		rep(j,1,nA){
			AA[i][j-1]=A[j];
		}
	}
	read(Q);
	rep(i,1,Q){
		read(x);
		read(y);
		cnt=0;
		int z=x;
		for(;x;x>>=1){
			a[++cnt]=v[x];
			b[cnt]=w[x];
		}
		reverse(a+1,a+cnt+1);
		reverse(b+1,b+cnt+1);
		per(t,cnt,cnt/2+1){
			z=z>>1;
		}
		nA=AA[z].size();
		REP(i,nA){
			A[i+1]=AA[z][i];
		}
		nB=0;
		dfs(cnt/2+1,cnt,0,0,B,nB);
		sort(B+1,B+nB+1);
		rep(i,1,nA){
			A[i].se=max(A[i].se,A[i-1].se);
		}
		rep(i,1,nB){
			B[i].se=max(B[i].se,B[i-1].se);
		}
		int p=nA,ans=0;
		rep(i,1,nB){
			while(p&&A[p].fi+B[i].fi>y){
				p--;
			}
			if(A[p].fi+B[i].fi<=y){
				ans=max(ans,A[p].se+B[i].se);
			}
		}
		printf("%d\n",ans);
	}

	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

struct par {
	int a, b;
	bool operator< (const par& o) const {
		return b < o.b;
	}
};

par s[100005];
int p[100005];
int a[100005];
bool v[100005];
int n;

void ans(string s) {
	cout << s << '\n';
	exit(0);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> n;
	for (int i=0; i<n; i++)
		cin >> s[i].a;
	for (int i=0; i<n; i++)
		cin >> s[i].b;
	
	sort(s, s+n);
	for (int i=0; i<n; i++)
		a[i] = s[i].a;
	sort(a, a+n);

	// ne moze jer ne majorira
	for (int i=0; i<n; i++)
		if (a[i] > s[i].b)
			ans("No");

	// transponovano?
	for (int i=0; i<n-1; i++)
		if (a[i] <= s[i+1].b && a[i+1] <= s[i].b)
			ans("Yes");

	// tvrdo, proveri permutaciju
	for (int i=0; i<n; i++)
		p[i] = lower_bound(a, a+n, s[i].a) - a;

	for (int i=0, x=0; i<n; i++)
		v[x] = 1, x = p[x];

	if (count(v, v+n, true) == n)
		ans("No");
	else
		ans("Yes");
}

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

const int N = 1e5+2;
int n, q;
ll freq[N];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    ll sum = 0;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        sum += x;
        freq[x]++;
    }
    cin >> q;
    while (q--)
    {
        int a, b;
        cin >> a >> b;
        sum -= freq[a] * a;
        sum += freq[a] * b;
        freq[b] += freq[a];
        freq[a] = 0;
        cout << sum << '\n';
    }
    return 0;
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using namespace __gnu_pbds;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using pl = pair<ll, ll>;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll t, d, m;

ll a, b, c;

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> a >> b >> c;

  cout << c << ' ' << a << ' ' << b << endl;
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {

	int n;
	cin >> n;
	for (int i = 0; i < 100; i ++) {
		int t = i * 7;
		if (t > n) break;
		if ((n-t) % 4 == 0) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";

	return 0;
}

Measured memory_bytes: 256
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
queue = [[root, 0]]
counter = -1
while counter < N - 1:
    counter += 1
    node = queue[counter][0]
    depth = queue[counter][1]
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            queue.append([n, depth + graph[node][n]])

for a in answer:
   print('0' if a % 2 else '1')

Measured memory_bytes: 64556
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    int a,b,c,d,k;
    cin >> a >> b >> c >> d >> k;
    int s = a*60+b;
    int t = c*60+d;
    cout << max(0,t-k-s) << endl;
    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
#define ll long long
ll dp[405][405];
#define MAX 1e18+5;
int main()
{
  fin;
  int n,i;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  auto sum=[&](int l,int r)
  {
    ll s=0;
    for(int i=l;i<=r;i++)
      s+=a[i];
    return s;
  };
  for(int l=n-1;l>=0;l--)
  {
    for(int r=l;r<n;r++)
    {
      if(l==r)
        dp[l][r]=0;
      else
      {
        dp[l][r]=MAX;
        ll s=sum(l,r);
        for(i=l;i<=r;i++)
          dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+s);
      }
    }
  }
  cout<<dp[0][n-1];
}


Measured memory_bytes: 1536
///
// File:  d.cpp
// Author: ymiyamoto
//
// Created on Sat Apr 14 20:18:39 2018
//
#include <bits/stdc++.h>
using namespace std;

#define rep(_n, _init, _N) for (int32_t _n = _init; _n < (int32_t)(_N); _n++)
#define rrep(_n, _N, _end) for (int32_t _n = (int32_t)(_N); _n >= _end; _n--)
#define iceil(_x, _y) (((_x) + (_y)-1) / (_y))
#define ifloor(_x, _y) ((_x) / (_y))

static const double pi = 2 * asin(1);
static const double precision = 10e-9;

struct route_t {
  int32_t to, weight;
  route_t(int32_t t, int32_t w)
  {
    to = t;
    weight = w;
  }
};

vector<vector<route_t>> graph;

int32_t wfs()
{
  deque<int32_t> q;
  vector<int32_t> weights(graph.size(), 1 << 30);

  q.push_back(1);
  weights[1] = 0;
  while (!q.empty()) {
    auto from = q.front();
    q.pop_front();
    for (auto r : graph[from]) {
      auto to = r.to;
      auto weight = r.weight;
      if (weights[from] + weight < weights[to]) {
        weights[to] = weights[from] + weight;
        if (weight == 0) {
          q.push_front(to);
        } else {
          q.push_back(to);
        }
      }
    }
  }

  return weights[0];
}

int32_t main()
{
  int64_t K;
  cin >> K;

  graph = vector<vector<route_t>>(K + 1, vector<route_t>{});

  for (int32_t i = 1; i <= K; i++) {
    route_t route((i + 1) % K, 1);
    graph[i].push_back(route);
    route_t route1((10 * i) % K, 0);
    graph[i].push_back(route1);
  }

  cout << wfs() + 1 << endl;
  return 0;
}


Measured memory_bytes: 6272
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int a, b, c;
    cin >> a >> b >> c;
    int res = 0;
    int d = std::min(a, c);
    res += d;
    a -= d;
    c -= d;

    d = std::min(b, c);
    res += d + d;
    b -= d;
    c -= d;

    res += b;
    if (c > 0) res++;

    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            double[] v = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);

            if (n == 2)
            {
                Console.WriteLine((v[0] + v[1]) / 2.0);
                return;
            }
            //昇順に並べて価値の小さいものから消去するのが最も価値が高い

            sort(v, n);

            //2^(n-1)
            double ans = 0;
            for (int i = 0; i < n; i++)
            {
                if (i < 1)
                {
                    //最初の二つ
                    ans += v[i] / Math.Pow(2, n - 1);
                }else
                {
                    ans += v[i] / Math.Pow(2, n - i);
                }

            }
            Console.WriteLine(ans);

        }

        //ソート
        public static void sort(double[] a, int n)
        {
            for(int i = 0; i < n - 1; i++)
            {
                for(int j = i + 1; j < n; j++)
                {
                    if (a[i] > a[j])
                    {
                        double b = a[i];
                        a[i] = a[j];
                        a[j] = b;
                    }
                }
            }
        }

    }
}

Measured memory_bytes: 13140
{
  const resol = 10 ** 7

  const main = (input: string) => {
    const r = reader(input)
    const [a, b, x] = r.ns()
    const ih = x / a / a

    if (b / 2 > ih) {
      const t = (2 * x) / a / b

      const res = 90 - (Math.atan(t / b) * 180) / Math.PI

      console.log(res)
      return
    }
    const res = _binarySearch(0, 90 * resol, n => {
      const h = Math.tan(((n / resol) * Math.PI) / 180) * a

      return h / 2 < b - ih
    })

    console.log(res / resol)
  }

  const _binarySearch = (
    lo: number,
    hi: number,
    compare: (v: number) => boolean
  ) => {
    while (lo < hi) {
      const mid = lo + Math.floor((hi - lo) / 2)

      if (compare(mid)) {
        lo = mid + 1
      } else {
        hi = mid
      }
    }
    return hi
  }

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')

  main(getInput())
}


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

using namespace std;

int a[69], b[69], k;

int main() {
  cin >> a[0] >> a[1] >> a[2] >> k;
  for (int i = 0; i <= k; ++i) {
    for (int j = 0; i + j <= k; ++j) {
      for (int l = 0; i + j + l <= k; ++l) {
        // cout << i << " " << j << " " << l << endl;
        b[0] = a[0] << i, b[1] = a[1] << j, b[2] = a[2] << l;
        if (b[0] < b[1] and b[1] < b[2]) {
          cout << "Yes\n";
          return 0;
        }
      }
    }
  }
  cout << "No\n";
  return 0;
}



Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    cout<<(1000-n%1000)%1000<<endl;
    return 0;
}

Measured memory_bytes: 3616
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int mod = 1000000007;

//		fact[0] = 1;
//		factInv[0] = 1;
//		for(int i = 0; i < fact.length - 1; i++){
//			fact[i+1] = fact[i]*(i+1) % mod; // n!(mod M)
//	        factInv[i+1] = (int)(factInv[i]*repeatablePow(i+1, mod-2, mod) % mod);
//		}

		long a[] = new long[n];
		long b[] = new long[n];

		int zeros = 0;
		HashMap<String, Integer> map = new HashMap<>();
		for(int i = 0; i < n; i++){
			a[i] = sc.nextLong();
			b[i] = sc.nextLong();

//			System.out.println("i = " + i+ " " +a[i] + " " + b[i]);

			if(a[i] == 0 && b[i] == 0){
				zeros++;
				continue;
			}
			if(a[i] == 0 && b[i] != 0){
				b[i] = 1;
			}
			if(a[i] != 0 && b[i] == 0){
				a[i] = 1;
			}
			if(a[i] != 0 && b[i] != 0){
				long gcd = gcd(a[i], b[i]);
				a[i] /= gcd;
				b[i] /= gcd;
			}

			if(a[i] < 0){
				a[i] *= -1;
				b[i] *= -1;
			}

			String tmpStr = a[i] + "," +b[i];

			if(!map.containsKey(tmpStr)){
				map.put(tmpStr, 1);
			}
			else {
				map.put(tmpStr, map.get(tmpStr) + 1);
			}
		}

		Iterator<String> it = map.keySet().iterator();

		HashSet<String> used = new HashSet<String>();
		long result = 1;
		while(it.hasNext()){
			String tmpStr = it.next();
//			System.out.println(tmpStr);

			if(used.contains(tmpStr)){
				continue;
			}
			String tmpArray[] = tmpStr.split(",");

			long tmpA = Long.parseLong(tmpArray[0]);
			long tmpB = Long.parseLong(tmpArray[1]);

//			if(tmpB == 0){
//				continue;
//			}

			String counterStr = "";
			if(tmpA == 0 && tmpB == 1){
				counterStr = "1,0";
			}
			else if(tmpA == 1 && tmpB == 0){
				counterStr = "0,1";
			}
			else {
				if(tmpB > 0){
					counterStr = tmpB + "," + (-tmpA);
				}
				else {
					counterStr = -tmpB + "," + tmpA;
				}
			}

			if(map.containsKey(counterStr)){
				result *= (repeatablePow(2, map.get(tmpStr), mod) + repeatablePow(2, map.get(counterStr), mod) + mod - 1)%mod;
			}
			else {
				result *= repeatablePow(2, map.get(tmpStr), mod)%mod;
			}
			result %= mod;
			used.add(counterStr);
//			System.out.println("str "+tmpStr + " counter "+counterStr+" result" + result);
		}

		result += zeros ;
		result += mod - 1;
		result %= mod;

		System.out.println(result);
	}

	static long gcd(long a, long b){
        long tmp;

        while (a % b != 0)
        {
            tmp = b;
            b = a % b;
            a = tmp;
        }
        return b;
    }
	static long repeatablePow(int x, int n, int mod){
		if(n == 0){
			return 1;
		}
		long result = repeatablePow((int)((long)x*x%mod), n/2, mod);
		if(n % 2 == 1){
			result = result*x%mod;
		}
		return result;
	}

//	static long combination(int a, int b, int mod){ //aCbをmod計算
//	    if(a == 0 && b == 0)return 1;
//	    if(a < b || a < 0)return 0;
//
//	    long tmp = factInv[a - b]* factInv[b] % mod;
//	    return tmp * fact[a] % mod;
//	}

//	static long fact[] = new long[2000002];
//	static long factInv[] = new long[2000002];

}

Measured memory_bytes: 127240
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b) {
    cout << c << endl;
  } else if (b == c) {
    cout << a << endl;
  } else {
    cout << b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	long long n, k, s;
	cin >> n >> k >> s;
	for (int i = 0; i < k; i++)
		cout << s << " ";
	s %= 100000007;
	s++;
	for (int i = k; i < n; i++)
		cout << s << " ";
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include <climits>
#include <algorithm>
using namespace std;
using ll = long long ;
int main(){
	ll n,m,k;
	cin >> n >> m >> k;

	vector<ll> v(n+1);
	vector<ll> v1(m+1);
	// vector<ll> v(n+1);
	// vector<ll> v1(m+1);
	v[0] = 0;
	v1[0] = 0;
	for (ll i = 1; i <= n; ++i)
	{
		cin >> v[i];
		v[i] += v[i-1];
	}
	for (ll i = 1; i <= m; ++i)
	{
		cin >> v1[i];
		v1[i] += v1[i-1];
	}
	ll ans = 0;
	
	for(ll i = 0; i <= n; i++)
    {
        if(v[i] <= k)
        ans = max(ans,i);
        ll l=0,r=m,temp=-1;
        while(l<=r)
        {
            ll mid = l + (r - l)/2 ;
            if(v1[mid]+v[i]>k)
            {
                r=mid-1;
            }
            else
            {
                temp=max(temp,mid);
                l=mid+1;
            }
        }
        if(temp!=-1)
        	ans = max(ans,i+temp);
    }
    cout << ans << endl;
	// for (ll i = 0; i <= n; ++i)
	// {
	// 	if(v[i] > k){
	// 		break;
	// 	}
	// 	ll lb = upper_bound(v1.begin(),v1.end(),k - v[i]) - v1.begin();
	// 	x.push_back(lb+i-1);
	// 	cout << v[i] << " " << k - v[i] << " " << lb << " " << lb + i -1  << endl;
	// 	ans = max(ans,lb + i - 1);
	// }
	// sort(x.begin(),x.end());
	// reverse(x.begin(),x.end());
	// cout << x[0] << " ";
	// cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6368
from collections import defaultdict

MOD = 1000000007
iist = lambda: map(int,input().split())

N,M = iist()
Q = defaultdict(list)
for i in range(M):
  l,r,x = iist()
  Q[r].append((l,x-1))

if any(x != 0 for l,x in Q[1]):
  print(0)
  exit(0)

dp = {(0,0):3}
memo = [6]
s = 3

for pk in range(1,N):
  k = pk+1

  for i,c in enumerate(memo):
    c %= MOD
    dp[i,pk] = c
    memo[i] *= 2
    memo[i] %= MOD

  memo.append(2*s%MOD)
  s = 3*s%MOD
  subQ = Q[k]

  for i,j in list(dp.keys()):
    for l,x in subQ:
      if x != (l<=i)+(l<=j):
        c = dp[i,j]
        memo[i] -= c
        memo[j] -= c
        s -= c
        del dp[i,j]
        break

  s %= MOD

print(s)

Measured memory_bytes: 12524
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

priority_queue<long long, vector<long long>, less<long long>> Q;
long long N, M, A[1 << 18], B[1 << 18], ans;
vector<long long> T[1 << 18];

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
		if (A[i] <= M) T[M - A[i]].push_back(B[i]);
	}
	for (int i = M; i >= 0; i--) {
		for (int j = 0; j < T[i].size(); j++) Q.push(T[i][j]);
		if (!Q.empty()) {
			ans += Q.top(); Q.pop();
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod=1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

ll mpow(ll a, ll b) {
    if(b == 0) return 1 % mod;
    ll x = mpow(a,b/2);
    x = (x*x)%mod;
    if(b&1) {
        x = (x * a) % mod;
    }
    return x;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    vll m(k + 1,0);
    for(ll i = k; i >= 1; i--) {
        ll res = mpow(k / i, n);
        for(ll j = i * 2; j <= k; j += i) {
            res = (res - m[j]) % mod;
            if(res < 0) res += mod;
        }
        ans += (i*res)%mod;
        ans %= mod;
        m[i] = res;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3992
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll N;
    cin >> N;
    vel p(N);
    rep(i, N) {
        cin >> p[i];
        p[i]--;
    }
    ll cnt = 0;
    rep(i, N - 1) {
        if (p[i] == i) {
            swap(p[i], p[i + 1]);
            cnt++;
        }
    }
    if (p[N - 1] == N - 1) {
        cnt++;
    } 
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  ll s,mod=1000000000LL;
  cin>>s;
  if(s==mod*mod){
    cout<<0<<" "<<0<<" "<<mod<<" "<<0<<" "<<0<<" "<<mod;
  }else{
    ll y=s%mod;
    ll x=(s-y)/mod;
    cout<<0<<" "<<0<<" "<<mod<<" "<<1<<" "<<mod-y<<" "<<x+1;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main(){
	long long a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	long long k=gcd(c,d);
	long long num=c*d/k;
	long long ans=b-a+1-(b/c-(a-1)/c)-(b/d-(a-1)/d)+(b/num-(a-1)/num);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
//今日の成果*AOJ0027*AOJ0028


#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int main(){
	
	int h,ans=0;
	while(true){
	cin>>h;
	if(h==0)break;
	ans=0;
	int ta[200][5]={{0},{0}};
	for(int i=0;i<h;i++)for(int j=0;j<5;j++)cin>>ta[i][j];
	//盤面の存在しないところは0
	while(true){

	bool f=1;
	for(int i=0;i<h;i++){
	int cnt=0,fi=-1;
		for(int j=0;j<3;j++){
			if(ta[i][j]==ta[i][j+1]&&ta[i][j]==ta[i][j+2]&&ta[i][j]!=0){
			cnt++;
			if(fi==-1)fi=j;
			}
		}//endfor
		if(cnt!=0)ans+=ta[i][fi]*(2+cnt),f=0;
		if(cnt!=0)for(int j=0;j<2+cnt;j++)ta[i][fi+j]=0;
	}//endfor
	if(f)break;
	//落とす処理
	for(int i=h-2;i>=0;i--){
		for(int j=0;j<5;j++){
			int ti=i;
			while(true){
			if(ti==h-1||ta[ti+1][j]!=0)break;
			ta[ti+1][j]=ta[ti][j];
			ta[ti][j]=0;
			ti++;
			}//endwhile
		}//endfor
	}//endfor
	//for(int i=0;i<h;i++)printf("%d%d%d%d%d\n",ta[i][0],ta[i][1],ta[i][2],ta[i][3],ta[i][4]);
	//printf("\n");
	}//endwhile
	cout<<ans<<endl;
	}//endwhile
	return 0;
}

Measured memory_bytes: 1168