akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

struct edge {
    int from;
    int to;
    int64_t cost;
    edge(int f = 0, int x=0, int64_t y=0):to(x), cost(y), from(f) {}
};

vector<vector<edge> > G; // resizeの必要あり


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vvi dist(n, vi(n, INF));
    edge G[m];
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        dist[a][b] = c;
        dist[b][a] = c;
        G[i] = edge(a, b, c);
    }

    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                if(i == j) dist[i][j] = 0;
                else {
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
    }

    vector<bool> check(m, false);
    rep(i, m) {
        edge &e = G[i];
        if(dist[e.from][e.to] < e.cost) check[i] = true;
    }

    int ans = 0;
    rep(i, m) {
        ans += check[i];
    }

    cout << ans << endl;
}

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

int a[20],n;

bool f(int i,int m){
	if(m==0)
		return true;
	if(i==n)
		return false;
	bool ret=f(i+1,m)||f(i+1,m-a[i]);
	return ret;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int m;
		cin>>m;
		if(f(0,m))
			cout<<"yes"<<endl;
		else
			cout<<"no"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

// ABC122 A

char c;

int main(){
	cin>>c;
	if(c=='A') cout<<'T'<<endl;
	if(c=='T') cout<<'A'<<endl;
	if(c=='G') cout<<'C'<<endl;
	if(c=='C') cout<<'G'<<endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val h = (0 until n).map { sc.next().toLong() }
    println(problem115c(n, k, h))
}

fun problem115c(n: Int, k: Int, h: List<Long>): Long {
    val h = h.sorted()
    val dp = (0 until n).map { Long.MAX_VALUE }.toMutableList()
    for (i in 0 until n) {
        if (i + k - 1 >= n) break
        if (i == 0) {
            dp[i] = h[i + k - 1] - h[i]
        } else {
            dp[i] = Math.min(dp[i - 1], h[i + k - 1] - h[i])
        }
    }
    return dp.min()!!
}

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

int h, w;
char m[30][30];

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

int bfs(int sx, int sy)
{
  int vs[30][30];
  queue<pair<int,int>> que;

  que.emplace(sx, sy);
  memset(vs, 0, sizeof(vs));
  vs[sx][sy] = 1;

  while (!que.empty()) {
    auto p = que.front(); que.pop();
    int x = p.first, y = p.second;

    for (int i = 0; i < 4; ++i) {
      int nx = x + dx[i], ny = y + dy[i], cnt = vs[x][y];

      if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
      if (m[nx][ny] == '#' || vs[nx][ny]) continue;

      vs[nx][ny] = cnt + 1;
      que.emplace(nx, ny);
    }
  }

  int res = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      res = max(res, vs[i][j]);
    }
  }

  return res;
}

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

  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> m[i][j];
    }
  }

  int ans = 0;

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (m[i][j] == '#') continue;
      ans = max(ans, bfs(i, j));
    }
  }

  cout << ans-1 << '\n';

  return (0);
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

const double pi = 3.14159265358979;

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double x, y;
    x = pow(a, 2);
    y = pow(b, 2);
    double deg = 2 * pi - abs(pi / 30 * m - pi * h / 6 - pi * m / 360);
    double c = x + y - 2 * a * b * cos(deg);
    
    c = sqrt(c);
    cout << fixed << setprecision(10) << c << endl;


    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


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

    printf("%.8f\n",n/m);

    return 0;
}


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

int main(){

    int n,k;
    cin >> n >> k;

    vector<int> h(n);

    rep(i,n) cin >> h[i];

    vector<int> c(n,1e+9);

    c[0]=0;
    c[1]=abs(h[0]-h[1]);

    for(int i=2;i<n;i++){
        for(int j=i-1;j>=i-k&&j>=0;j--){
            c[i]=min(c[i],c[j]+abs(h[i]-h[j]));
        }
    }
    cout << c[n-1] <<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,s,f;
    scanf("%d",&n);
    if(n % 1000 == 0){
        f = n / 1000;
    }
    else{
        f = (n / 1000) + 1;
    }
    s = (1000 * f) - n;
    printf("%d",s);
    return 0;
}


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

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

fn main(){
    let n: u64 = read();

    match n % 10 {
        0 | 1 | 6 | 8 => println!("pon"),
        3 => println!("bon"),
        _ => println!("hon"),
    }
}


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

using namespace std;
#define int long long
const int INF = 200000000007;


  
signed main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    s[k-1]=(s[k-1]-('A'-'a'));
    cout<<s;

   
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define FOR(i,a,b) for (int i = (a) ; i <= (b); ++i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
//#define print(x) printf("%d\n", x)

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい



void Main(){
	string S;
	cin >> S;

	if(S[0] - 'a' >= 0) cout << "a" << endl;
	else cout << "A" << endl;


}

int main()
{
	cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();

  return 0;
}


Measured memory_bytes: 3652
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>x>>n;
    vector<ll> v(n);
    set<ll> s;
    rep(i,n) cin>>v[i];

    if(accumulate(all(v),0)>=x) Yes;
    else No;
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  double a_min = 12.5 * a;
  double a_max = 12.5 * (a + 1);
  int b_min = 10 * b;
  int b_max = 10 * (b + 1);
  int ans = -1;
  while (b_min < b_max) {
    if (a_min <= b_min && b_min < a_max) {
      ans = b_min;
      break;
    }
    b_min++;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/s8pc-3/tasks/s8pc_3_b

import sys
input=sys.stdin.readline
from collections import deque
from copy import deepcopy

def main():
    H,W,K=map(int,input().split())
    mas=[[-1]*W for i in range(H)]
    for i in range(H):
        t=input()
        for j in range(W):
            mas[H-1-i][j]=int(t[j])
    maso=deepcopy(mas)
    maxans=0       
    for h in range(H):
        for w in range(W):
            mas=deepcopy(maso)
            mas[h][w]=-1
            for hh in range(h,H-1):
                t=mas[hh][w]
                mas[hh][w]=mas[hh+1][w]
                mas[hh+1][w]=t
            
            ans=0
            nankaime=0
            while(1):
                kiesum=0
                mast=deepcopy(mas)
                for i in range(H):
                    for j in range(W):
                        cnt=1
                        for k in range(j+1,W):
                            if mas[i][j]!=-1 and mas[i][k]!=-1 and mas[i][j]==mas[i][k]:
                                cnt+=1
                            else:
                                break
                        if cnt>=K:
                            for k in range(cnt):
                                kiesum+=mas[i][j+k]
                                mas[i][j+k]=-1
                f=[deque() for i in range(W)]
                for j in range(W):
                    for i in range(H):
                        if mas[i][j]!=-1:
                            f[j].append(mas[i][j])
                    for i in range(H-len(f[j])):
                        f[j].append(-1)
                for i in range(H):
                    for j in range(W):
                        mas[i][j]=f[j].popleft()
                ans+=pow(2,nankaime)*kiesum
                nankaime+=1
                if mas==mast:
                    break
            maxans=max(maxans,ans)
    print(maxans)
                    
                    
                
    
if __name__=="__main__":
    main()

Measured memory_bytes: 85820
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>

using namespace std;

bool possible(int x, vector<int> &v) {
	set<int> s;
	s.insert(0);
	for (int i : v) {
		set<int> n;
		for (int j : s) {
			n.insert(j + i);
			n.insert(j - i);
		}
		s = n;
	}
	return s.find(x) != s.end();
}

int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	int x, y, dist = 0;
	cin >> x >> y;
	bool dir = true, first = true;
	vector<int> v;
	for (char c : s) {
		if (c == 'F') {
			if (first) {
				--x;
			} else if (dir) {
				++dist;
			}
		} else {
			first = false;
			dir = !dir;
			if (dist) {
				v.push_back(dist);
				dist = 0;
			}
		}
	}
	if (dist) {
		v.push_back(dist);
		dist = 0;
	}
	bool ans = possible(x, v);
	if (ans) {
		v.clear();
		dist = 0;
		dir = false;
		for (char c : s) {
			if (c == 'F') {
				if (dir) {
					++dist;
				}
			} else {
				dir = !dir;
				if (dist) {
					v.push_back(dist);
					dist = 0;
				}
			}
		}
		if (dist) {
			v.push_back(dist);
			dist = 0;
		}
		ans = possible(y, v);
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


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

int main() {
  string S;
  cin >> S;

  vector<char> V(S.size());
  rep(i, 0, S.size()) {
    V.at(i) = S[i];
  }

  while(true) {
    V.pop_back();
    if (V.size()%2) continue;
    else {
      int count = 0;
      rep(i, 0, V.size()/2) {
        if (V.at(i) == V.at((V.size()/2)+i)) count++;
      }
      if (count == (int)(V.size())/2) {
        cout << V.size() << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long dp[3005][3005];
long solve(int i,int j,int a[]){
  if(i==j)
    return a[i];
  if(i>j)
    return 0;
  if(dp[i][j]!=-1)
    return dp[i][j];
  dp[i][j]=max(a[i]-solve(i+1,j,a),a[j]-solve(i,j-1,a));
  return dp[i][j];
}
int main() {
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  memset(dp,-1,sizeof(dp));
  cout<<solve(0,n-1,a)<<endl;
}

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

//x以下で最大の冪乗数(b^p)を求めたい
int main(){
    int x; cin >> x;
    //iがb^p(求めたい数)にあたる
    for(int i=x; i>=1; i--){
        int n=i;
        //iが1に到達してしまったら冪乗数はなかったということ
        if(i==1){
            cout << i << endl;
        }
        //jがbにあたる　jは最大でもnの平方根以下
        //冪乗数では次数は2でも3でも関係ないので割り続ければ良い
        for(int j=2;j*j<=n;j++){
            while(n%j==0){
                n /= j;
            }
            //1つの数で割り続けた結果が1になるならその数の冪乗と言える
            if(n==1){
                cout << i << endl;
                i=1;
            }
            n=i;
        }
    }


}

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

int main(){
  int count=0, ma=0;
  char c;
  while(cin>>c){
    if(c=='A'||c=='C'||c=='G'||c=='T'){
      count++;
      ma=max(ma,count);
    }
    else count=0;
  }
  cout << ma << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
#include<type_traits>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b == 15)cout << "+" << endl;
	else if (a*b == 15)cout << "*" << endl;
	else cout << "x" << endl;
	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int R; cin >> R;
  const double PI = 3.1415926535897932;
  cout << fixed << setprecision(10) << 2*PI*R << endl;
}


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

using namespace std;

int main()
{
    vector<int> ans_length(3);
    int n;
    cin >> n >> ans_length[0] >> ans_length[1] >> ans_length[2];
    vector<int> ls(n);
    for (auto& l : ls)
    {
        cin >> l;
    }

    vector<int> tag(n, 0);
    vector<int> length(3, 0);
    int min_mp = 10000000;
    for (int e = 0; e < (1 << (2 * n)); e++)
    {
        for (int i = 0; i < n; i++)
        {
            tag[i] = (e >> (2 * i)) % 4;
        }
        fill(length.begin(), length.end(), 0);
        int mp = 0;
        for (int i = 0; i < n; i++)
        {
            if (tag[i] <= 2)
            {
                if (length[tag[i]] == 0)
                {
                    length[tag[i]] = ls[i];
                }
                else
                {
                    length[tag[i]] += ls[i];
                    mp += 10;
                }
            }
        }
        if (length[0] > 0 && length[1] > 0 && length[2] > 0)
        {
            for (int i = 0; i < 3; i++)
            {
                mp += abs(ans_length[i] - length[i]);
            }
            min_mp = min(min_mp, mp);
        }
    }
    cout << min_mp << endl;
}

Measured memory_bytes: 256
n=int(input())
s=input()
r=0
g=0
b=0

for i in range(n):
    if s[i]=='R':
        r+=1
    if s[i]=='G':
        g+=1
    if s[i]=='B':
        b+=1

ans=r*g*b

for i in range(n):
    for j in range(i+1,(n+i-1)//2+1):
        if not(s[i]==s[j] or s[j]==s[2*j-i] or s[i]==s[2*j-i]):
            ans-=1
            
print(ans)

Measured memory_bytes: 9148
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;
#define mfor(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  mfor(i,0,n)
#define all(x) (x).begin(),(x).end()

bool comp(const vector<int> &x, const vector<int> &y){
    return x[2] > y[2];
}

int main(void){

	string s;
	cin >> s;

	for(int i=0; i<(int)s.size(); i++) {
		if (s[i] == '1'){
			s[i] = '9';
		}else if (s[i] == '9') {
			s[i] = '1';
		}
	}

	cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
(defun answer (lst)
  (cond
    ((null lst) 0)
    ((char= (car lst) #\+)
     (1+ (answer (cdr lst))))
    (t
     (1- (answer (cdr lst))))))

(princ (answer `(,(read-char)
                  ,(read-char)
                  ,(read-char)
                  ,(read-char))))
      


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int A,B,X; cin >>A>>B>>X;
    YES(A<=X&&X<=A+B);
}


Measured memory_bytes: 256
import copy
H,W,K=map(int,input().split())
S=[]
for _ in range(H):
    S.append([int(x) for x in list(input())])

ans=(H-1)+(W-1)

for i in range(2**(H-1)):
    check=[0]*H
    for j in range(H-1):
        if ((i>>j)&1):
            check[j+1]=check[j]+1
        else:
            check[j+1]=check[j]
    
    g=check[H-1]+1
    A=[0]*g
    c=0
    f=0
    for j in range(W):
        B=[0]*g
        for k in range(H):
            if S[k][j]==1:
                B[check[k]]+=1
            if B[check[k]]>K:
                c=10**4
                f=1
                break
        if f:
            break
        #print("AB",A,B)
        for l in range(g):
            if A[l]+B[l]>K:
                c+=1
                A=copy.copy(B)
                break
            else:
                A[l]+=B[l]
    ans=min(ans,c+g-1)

print(ans)




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

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

using namespace std;
typedef long long ll;

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


    int bef = 0;
    int acc = 0;
    int point = 0;

    vector<pair<int, int>> v;
    rep(i, n) {
        int a, b;
        cin >> a >> b;

        v.emplace_back(a, b);

    }

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

    for (auto[a, b] :v) {
        acc += a - bef;
        bef = a;
        point = b;
    }

    acc += point ;
    cout << acc << endl;
}

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

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

	ll ret = 0;
	for (int i = 0; i < N; i++) {
		ret += a[i] - 1;
	}

	cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 40) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    --a;
    --b;
    --c;
    --d;
    string s;
    cin >> s;
    bool f1 = false, f2 = false, f3 = false;
    for(int i = a; i < c; i++) {
        if(s[i] == '#' && s[i + 1] == '#') {
            f1 = true;
        }
    }
    for(int i = b; i < d; i++) {
        if(s[i] == '#' && s[i + 1] == '#') {
            f2 = true;
        }
    }
    for(int i = b; i <= d; i++) {
        if(i > 0 && i < n) {
            if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
                f3 = true;
            }
        }
    }
    if(c < d) {
        if(f1 == false && f2 == false) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if(f3 && f1 == false) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n,m;
bool mat[707][707];
vector<int> g[707];
vector<P> ps;
int cnt[2];
int col[707];
bool dp[707][707];

bool dfs(int v,int c){
  col[v]=c;
  cnt[c]++;
  for(int nv : g[v]){
    if(col[nv]==c)return false;
    if(col[nv]!=-1)continue;
    if(!dfs(nv,1-c))return false;
  }
  return true;
}

int main(){
  scanf("%d%d",&n,&m);
  rep(i,m){
    int a,b;
    scanf("%d%d",&a,&b);
    a--;b--;
    mat[a][b]=mat[b][a]=true;
  }
  rep(i,n)rep(j,i){
    if(mat[i][j])continue;
    g[i].push_back(j);
    g[j].push_back(i);
  }
  memset(col,-1,sizeof(col));
  rep(i,n){
    if(col[i]!=-1)continue;
    cnt[0]=cnt[1]=0;
    if(!dfs(i,0)){
      cout<<-1<<endl;
      return 0;
    }
    ps.push_back(P(cnt[0],cnt[1]));
  }
  dp[0][0]=true;
  rep(i,ps.size()){
    rep(j,n+1){
      if(dp[i][j]){
        if(j+ps[i].fi<=700)dp[i+1][j+ps[i].fi]=true;
        if(j+ps[i].se<=700)dp[i+1][j+ps[i].se]=true;
      }
    }
  }

  ll res=INF;
  rep(j,n+1){
    if(dp[ps.size()][j])minch(res,j*(j-1)/2+(n-j)*(n-j-1)/2);
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main( void )
{
	vector <string> kotae;
	string in;
	getline(cin,in);

	replace( in.begin(), in.end(), ',', ' ' );
	replace( in.begin(), in.end(), '.', ' ' );

	string w;
	istringstream is(in);
	while ( is >> w )
	{
		if ( w.size() > 2 && w.size() < 7 )
			kotae.push_back( w );
	}

	for ( int i = 0; i < kotae.size(); i++ )
	{
		cout << kotae[i];
		if ( i < kotae.size() - 1 )
			cout << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 0
n = int(input())
a = [0]*(n+1)
for i in range(1, n+1):
    a[i] = int(input())

ans = 0
now = 1
nex = a[1]
for i in range(n):
    ans += 1
    now = nex
    nex = a[now]
    if now == 2:
        break
if ans == n:
    ans = -1
print(ans)


Measured memory_bytes: 12836
def main():
    # 解説AC
    N, K = (int(i) for i in input().split())
    S = input()
    from itertools import groupby
    g = len(list(groupby(S)))
    ans = N - g
    print(min(ans + 2*K, N-1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 56412
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{    
    string s;
    cin >> s;

    int cnt[3] = {0};
    vector<string> abc({"a","b","c"});
    rep(i,3)
        rep(j,3)
            if(s.substr(i,1)==abc[j]) cnt[j]++;

    string ret = (cnt[0] && cnt[1] && cnt[2]) ? "Yes" : "No";
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
from math import floor, sqrt

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n // b) + n % b

def solve(n, s):
    if s > n:
        return -1
    elif s == n:
        return n + 1

    for b in range(2, floor(sqrt(n)) + 1):
        if f(b, n) == s:
            return b

    for p in reversed(range(1, floor(sqrt(n)) + 1)):
        if (n - s) % p == 0:
            b = (n - s) // p + 1
            q = n - p * b
            if 1 <= p < b and 0 <= q < b:
                return b

    return -1


n = int(input())
s = int(input())

print(solve(n, s))


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

const int MAXN = 100000 + 100;

vector<pair<long long, int> > data;
long long a[MAXN], b[MAXN];
int n, m;

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i ++) {
		cin >> a[i];
		data.push_back(make_pair(a[i], 0));
	}
	for (int j = 0; j < m; j ++) {
		cin >> b[j];
		data.push_back(make_pair(b[j], 1));
	}

	sort(data.begin(), data.end());
	long long ans = 0;
	for (int i = 0; i < data.size(); i ++) {
		if (data[i].second == 0) {
			ans += data[i].first * (m + 1);
			n --;
		} else {
			ans += data[i].first * (n + 1);
			m --;
		}
		// cout << i << ' ' << ans << endl;
	}

	cout << ans << endl;
}


Measured memory_bytes: 5616
n, m = map(int,input().split())
abl = [[int(i) for i in input().split()] for i in range(n)]
cdl = [[int(i) for i in input().split()] for i in range(m)]
ans = []
for i in range(n):
    tmp = abs(abl[i][0]-cdl[0][0])+abs(abl[i][1]-cdl[0][1])
    c_i = 1
    for j in range(1,m):
        if tmp > abs(abl[i][0]-cdl[j][0])+abs(abl[i][1]-cdl[j][1]):
            tmp = abs(abl[i][0]-cdl[j][0])+abs(abl[i][1]-cdl[j][1])
            c_i = j+1
    ans.append(c_i)
for i in range(n):
    print(ans[i])


Measured memory_bytes: 39280
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(H: int, W: int, N: int):
    m = max(H, W)
    from math import ceil
    print(ceil(N/m))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(H, W, N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using pi = pair<int, int>;
using crash = pair<double, pi>;

struct star
{
    double x,y,z,vx,vy,vz,r,vr,time;
};

double fa(star a, star b)
{
    double dvx, dvy, dvz, svr;
    dvx = a.vx - b.vx;
    dvy = a.vy - b.vy;
    dvz = a.vz - b.vz;
    svr = a.vr + b.vr;
    return dvx * dvx + dvy * dvy + dvz * dvz - svr * svr;
}
double fb(star a, star b)
{
    double dvx, dvy, dvz, svr, dx, dy, dz, sr;
    dvx = a.vx - b.vx;
    dvy = a.vy - b.vy;
    dvz = a.vz - b.vz;
    svr = a.vr + b.vr;
    dx = a.x - b.x;
    dy = a.y - b.y;
    dz = a.z - b.z;
    sr = a.r + b.r;
    return dvx * dx + dvy * dy + dvz * dz + svr * sr;
}
double fc(star a, star b)
{
    double dx, dy, dz, sr;
    dx = a.x - b.x;
    dy = a.y - b.y;
    dz = a.z - b.z;
    sr = a.r + b.r;
    return dx * dx + dy * dy + dz * dz - sr * sr;
}
int main()
{
    while (true)
    {
        int N; cin >> N;
        if(N == 0) return 0;
        vector<star> S(N);
        rep(i, N)
        {
            double x, y, z, vx, vy, vz, r, vr, time;
            cin >> x >> y >> z >> vx >> vy >> vz >> r >> vr;
            time = r / vr;
            S[i] = {x,y,z,vx,vy,vz,r,vr,time};
        }
        vector<crash> P;
        rep(i, N)repi(j, i + 1, N)
        {
            double A = fa(S[i], S[j]);
            double B = fb(S[i], S[j]);
            double C = fc(S[i], S[j]);
            double D = B * B - A * C;
            if(D < 0)continue;
            
            double crash_time = (-B - sqrt(D)) / A;
            if(crash_time <= 0)
            {
                crash_time = (-B + sqrt(D)) / A;
            }

            if(crash_time > 0 && crash_time < S[i].time && crash_time < S[j].time)
            {
                P.emplace_back(crash(crash_time, pi(i, j)));
            }
        }

        sort(P.begin(), P.end());
        vector<bool> used(N);
        vector<double> ans(N);
        for(auto p : P)
        {
            int a = p.second.first;
            int b = p.second.second;
            if(used[a] || used[b])
            {
                continue;
            }
            ans[a] = p.first;
            ans[b] = p.first;
            used[a] = true;
            used[b] = true;
        }

        cout << std::fixed << std::setprecision(9);
        rep(i, N)
        {
            if(used[i])
            {
                cout << ans[i] << endl;
            }
            else
            {
                cout << S[i].time << endl;
            }
            
        }
    }
}



Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define INS(x) x.begin(),x.end()
    

    
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,k;
    cin>>n>>k;

    int ans=0;
    while (n)
    {
        ans++;
        n/=k;
    }
    
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
#define MAX_N 1000000
#define MAX_P 190
typedef unsigned int uint;
int p[MAX_P];
int op[MAX_P];
int pn[MAX_N];
int opn[MAX_N];
#define INF 1000000
int main()
{
//	REP(i,MAX_P) p[i]=i*(i+1)*(i+2)/6;
	int c=0;
	REP(i,MAX_P)
	{

		p[i]=i*(i+1)*(i+2)/6;
		if((p[i]%2) ==1)
		{
			c++;
			op[c]= p[i];
		}
	}
	memset(pn,INF,MAX_N*sizeof(int));
	memset(opn,INF,MAX_N*sizeof(int));
	pn[0]=opn[0]=0;
	for(int i=0;i<MAX_N;i++)
	{
		for(int j=0;j<MAX_P;j++)
		{
			if(i+p[j] > MAX_N) break;
			pn[i+p[j] ]=min(pn[i+p[j]] ,pn[i]+1);
			
		}
	}
	for(int i=0;i<MAX_N;i++)
	{
		for(int j=0;j<MAX_P;j++)
		{
			if(i+op[j] > MAX_N) break;
			opn[i+op[j] ]=min(opn[i+op[j]] ,opn[i]+1);

		}
	}
	int n;
	while(cin >> n &&n)
	{
		cout << pn[n]  <<" " << opn[n] << endl;
	}
	return 0;
}

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

#define MATHPI acos(-1)

template<class T> void chmax(T &a, T b) {
    if (a < b) a = b;
}
template<class T> void chmin(T &a, T b) {
    if (b < a) a = b;
}

using Mat = vector<vector<ll>>;
using Column = vector<ll>;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll a,b,c;cin>>a>>b>>c;
    ll temp = c-a-b;
    if (temp >0 && 4*a*b<temp*temp) {
        cout << "Yes"<<"\n";
    } else {
        cout << "No"<<"\n";
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

template <typename T> lint gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> lint lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b) a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b) a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  cout << 180 * (n - 2) << '\n';
}


Measured memory_bytes: 256
def f(m, arr)
  result = 0
  arr.each do |n|
    result+=m % n
  end
  result
end
z = $stdin.read.split("\n")
b = z[1].split(" ").map{|c| c.to_i}
result = 1
b.each do |a|
  result*=a
end
puts f(result - 1, b)

Measured memory_bytes: 19324
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

bool cmp(pair<ll, ll>& a, pair<ll, ll>& b) {
	return a.ff + a.ss < b.ss + b.ff;
}

bool comp(pair<ll, ll>& a, pair<ll, ll>& b) {
	return a.ff - a.ss < b.ff - b.ss;
}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vector <pair<ll, ll> > v(n);
	for (ll i = 0; i < n; i++)
		cin >> v[i].ff >> v[i].ss;
	sort(all(v), cmp);
	vector <pair<ll, ll> > vv(all(v));
	sort(all(vv), comp);
	ll ans = abs(v[0].ff - v[n - 1].ff) + abs(v[0].ss - v[n - 1].ss);
	ans = max(ans, abs(vv[0].ff - vv[n - 1].ff) + abs(vv[0].ss - vv[n - 1].ss));
	cout << ans << "\n";
}


Measured memory_bytes: 9516
#include <stdio.h>

int main(void) {
	int R;
	int N;
	scanf("%d %d", &N, &R);
	if (N < 10) {
	printf("%d\n", R + 100 * (10 - N));
	}
	else {
	printf("%d\n", R);
	}

	return 0;
}

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

using namespace std;

typedef long long ll;


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

        string s; cin>>s;
        if(s.size()>=6 and s[2]==s[3] and s[4]==s[5]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;


}


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

#define pb push_back
#define ll long long

using namespace std;

int origa[10][1000];
int h, w, k;

int getMinCuts(vector< vector<int> >& chl) {
    int curr = 0, rows = chl.size();
    int cuts = rows-1;
    while(curr < w) {
        int minw = 2000;
        for (int i=0;i<rows;i++) {
            int currsum = 0;
            if (curr) currsum = chl[i][curr-1];
            auto nextit = lower_bound(chl[i].begin(), chl[i].end(), currsum+k+1);
            if ((int)(nextit-chl[i].begin()) == curr) return 1000000;
            minw = min(minw, (int)(nextit - chl[i].begin()));
        }
        curr = minw;
        if (curr != w) cuts++;
    }
    return cuts;
}

int createNewPartition(vector< vector<int> >& currPartition, int row) {
    if (row == h) {
        return getMinCuts(currPartition);
    }
    vector<int> roww(w, 0);
    currPartition.pb(roww);
    int mincuts = 40000;
    while(row < h) {
        for (int i=0;i<w;i++) currPartition.back()[i] += origa[row][i];
        mincuts = min(mincuts, createNewPartition(currPartition, ++row));
    }
    currPartition.pop_back();
    return mincuts;
}

int main() {
    cin >> h >> w >> k;
    for (int i=0;i<h;i++) {
        string s;
        cin >> s;
        for (int j=0;j<w;j++) origa[i][j] = s.at(j) - '0';
    }
    for(int i=0;i<h;i++) {
        for(int j=1;j<w;j++) origa[i][j] += origa[i][j-1];
    }

    vector< vector<int> > currP;
    cout << createNewPartition(currP, 0) << "\n";

    return 0;
}


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


namespace ConsoleApp6
{
	class Program
	{
		static void Main(string[] args)
		{
			var nm = Console.ReadLine().Split(' ');
			var n = int.Parse(nm[0]); //Aの列
			var m = int.Parse(nm[1]); //Aの行
			int[,] A = new int[n, m];
			int[] b = new int[m];
			int[] c = new int[n];

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

				var aij = Console.ReadLine().Split(' '); 

				for(int m_i = 0; m_i < m; m_i++)
				{
					
					var aj = int.Parse(aij[m_i]);
					A[n_i, m_i] = aj;
					//Console.WriteLine(A[n_i, m_i]);
				}
			}
			
			for(int b_i = 0; b_i < m; b_i++)
			{
				int bj = int.Parse(Console.ReadLine());
				b[b_i] = bj;
				//Console.WriteLine(b[b_i]);
			}
			
			for(int n_i = 0; n_i < n; n_i++)
			{
				for(int m_i = 0; m_i < m; m_i++)
				{
					int ans = A[n_i, m_i] * b[m_i];

						c[n_i] =  c[n_i] + ans;										
				}

				Console.WriteLine(c[n_i]);
			}
			
		}
	}
}



Measured memory_bytes: 17968
lis = list(map(int, input().split()))
n = lis[0]
m = lis[1]
count = 0

if n > 2 and m > 2:
	count += (n-2) * (m-2)
	print(count)
elif (n >2 or m > 2) and min(n,m) == 2:
	print(0)
elif (n >2 or m > 2) and min(n,m) == 1:
	count += max(n,m) - 2
	print(count)
elif n == 2 or m == 2:
	print(0)
else:
	print(1)

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

int main(){
    int n,k;
    cin >> n >> k;
    int r = 0;
    vector<int> cnt(n+1);
    rep(i,n){
        int a;
        cin >> a;
        cnt[a]++;
        if(cnt[a] == 1)r++;
    }
    int ans = 0;
    if(r <= k){
        cout << ans << endl;
        return 0;
    }
    r -= k;
    sort(cnt.begin(),cnt.end());
    rep(i,n-k+1){
        ans += cnt[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
N = int(input())
A = [int(i) for i in input().split()]
S = 0
P = 10**9 + 7
for i in range(N):
  S = (S + A[i])%P
ans = 0
for i in range(N):
  S = (S-A[i]+P)%P
  a = (A[i]*S)%P
  ans = (ans + a)%P
print(ans)

Measured memory_bytes: 105304
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    // k++;
    long[][] dp = new long[n][k+1];
    for(int i=0;i<n;i++){
      int a =sc.nextInt();
      int b = sc.nextInt();
      for(int j=0;j<k+1;j++){
        if(i==0){
          if(j>=a){
            dp[i][j]=b;
          }
        }
        else{
          if(j<a){
            dp[i][j]=dp[i-1][j];
          }
          else{
            dp[i][j]=Math.max(dp[i-1][j],b+dp[i-1][j-a]);
          }
        }
      }
    }
    // new helper().print(dp);
    System.out.println(dp[n-1][k]);
  }
}
class helper{
  public void print(long[][] ar){
    for(int i=0;i<ar.length;i++){
      for(int j=0;j<ar[0].length;j++){
        System.out.print(ar[i][j]+" ");
      }
      System.out.println();
    }
  }
}

Measured memory_bytes: 126420
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <algorithm>

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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

const ll INF = 10e17;

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

  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  ll dp[45][2];
  rep(i, 45)rep(j, 2) dp[i][j] = -INF;

  dp[41][0] = 0;

  for(int i = 40; i >= 0; i--){
    ll mask = 1LL<<i;

    int num1 = 0;
    for(int j = 0; j < N; j++){
      if(A[j]&mask) num1++;
    }
    int num0 = N - num1;

    // dp[i][0]からの遷移はKのi桁目の値によって変化
    if(mask&K){  //Kのi桁目が1のとき
      dp[i][0] = max(dp[i][0], dp[i+1][0] + mask * num0); //1にした
      dp[i][1] = max(dp[i][1], dp[i+1][0] + mask * num1); //0にした
    } else {  //Kのi桁目が0のとき
      dp[i][0] = max(dp[i][0], dp[i+1][0] + mask * num1); //0にするしかない
    }
    // dp[i][1] からはなんでもいい
    dp[i][1] = max(dp[i][1], dp[i+1][1] + mask * max(num0, num1));
  }

  ll ans = max(dp[0][0],dp[0][1]);
  cout << ans << endl;

  return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    string A[N], B[M];
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < M; i++) cin >> B[i];

    for (int i = 0; i <= N-M; i++) {
        for (int j = 0; j <= N-M; j++) {
            bool flag = true;
            for (int k = 0; k < M; k++) {
                for (int l = 0; l < M; l++) {
                    if (A[i+k][j+l] != B[k][l]) {
                        flag = false;
                    }
                }
            }
            if (flag) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3584
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int K = sc.nextInt();
   int X = sc.nextInt();
   int Y = sc.nextInt(); 
   if(N<=K)System.out.println(N*X);
   else System.out.println(K*X+(N-K)*Y);
 }
}

Measured memory_bytes: 23252
MOD=1e9+7

from collections import defaultdict
def check_even(c):
	ans=1
	d=defaultdict(int)
	for i in range(len(c)):
		d[c[i]]+=1
	
		if c[i]>=len(c) or c[i]%2==0 or d[c[i]]>2:
			return 0
		
		if d[c[i]]==1:
			ans=ans*2 % MOD
	return int(ans)
		
def check_odd(c):
	ans=1
	d=defaultdict(int)
	for i in range(len(c)):
		d[c[i]]+=1
		if c[i]>=len(c) or c[i]%2==1 or d[0]>1 or d[c[i]]>2:
			return 0
		
		if c[i]!=0 and d[c[i]]==1:
			ans=ans*2%MOD
			
	return int(ans)
		
n=int(input())
c=list(map(int,input().split()))
if n%2==0:
	print(check_even(c))
else:
	print(check_odd(c))
	


Measured memory_bytes: 83580
var
	N,i:Longint;
	A,L,R:Array[1..200000]of Longint;
begin
	read(N);
	for i:=1 to N do read(A[i]);
	for i:=2 to N do begin
		L[i]:=L[i-1];
		if A[i-1]>L[i] then L[i]:=A[i-1];
	end;
	for i:=N-1 downto 1 do begin
		R[i]:=R[i+1];
		if A[i+1]>R[i] then R[i]:=A[i+1];
	end;
	for i:=1 to N do if L[i]>R[i] then writeln(L[i]) else writeln(R[i]);
end.


Measured memory_bytes: 3840
(function(input) {
    var p = input.replace(/\n$/, '').split('\n');
    for (var i = 0; i < p.length; i++) {
        var args = p[i].split(' ').map(Number);
        var a = args[0];
        var b = args[1];
        var c = args[2];
        var d = args[3];
        var e = args[4];
        var f = args[5];
        var x = (c * e - b * f) / (a * e - b * d);
        var y = (c * d - a * f) / (b * d - a * e);
        x = x.toFixed(3);
        y = y.toFixed(3);
        console.log('%s %s', x, y);
    }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7644
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

long long const MOD = 1000000007LL;

int main() {
    string s;
    cin >> s;

    int n = s.size();

    int res[n];
    fill(res, res + n, 0);

    int dpR[n];
    fill(dpR, dpR + n, 0);
    dpR[0] = 1;
    if (s[1] == 'R') dpR[1] = 1;
    else {
        dpR[1] = 0;
        dpR[0] = 0;
        res[0]++;
    }
    for (int i = 2; i < n; i++) {
        if (s[i] == 'L') {
            res[i] += dpR[i - 2];
            res[i - 1] += dpR[i - 1];
            dpR[i - 1] = 0;
            dpR[i - 2] = 0;
        } else {
            dpR[i] = dpR[i - 2] + 1;
        }
    }

    int dpL[n];
    fill(dpL, dpL + n, 0);
    dpL[n - 1] = 1;
    if (s[n - 2] == 'L') dpL[n - 2] = 1;
    else {
        dpL[n - 2] = 0;
        dpL[n - 1] = 0;
        res[n - 1]++;
    }
    for (int i = n - 3; i >= 0; i--) {
        if (s[i] == 'R') {
            res[i] += dpL[i + 2];
            res[i + 1] += dpL[i + 1];
            dpL[i + 1] = 0;
            dpL[i + 2] = 0;
        } else {
            dpL[i] = dpL[i + 2] + 1;
        }
    }

    for (int i = 0; i < n; i++) cout << res[i] << endl;
}


Measured memory_bytes: 1792
//BISMILLAHIR RAHMANIR RAHIM
                                               //BY THE NAME OF ALLAH
                                               //FAISAL AHAMMED SHAWON
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<set>
#include<map>
#include<iterator>
#include<numeric>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define SQ(a) (a)*(a)
#define pi acos(-1.0)
const int MAX=100001;
const int MOD=1e9+7;
int ara[MAX];
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    else
    gcd(b,a%b);
}
ll lcd(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}

bool f(ll a,ll b)
{
    return a>b;
}
ll max_sum_subarrays(ll ara[],ll n)
{
    ll ans=0,sum=0;
    for(ll k=0;k<n;k++){
        sum=max(ara[k],sum+ara[k]);
        ans=max(ans,sum);
    }
    return ans;
}
ll num_divisors(ll n)
{
    long long cnt=0;
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0 && i*i==n)
            cnt+=1;
        if(n%i==0 && i*i!=n)
                cnt+=2;
    }
    return cnt;
}
ll comb(ll m, ll n)
{
    ll x = max(m-n,n),ans = 1,i=1;
    for(ll k=m;k>=x+1;k--){
        ans*=k;
        ans/=i;
        i++;
    }
    return ans;
}
ll binsearch(ll low,ll high,ll target)
{
    while(low<=high)
    {
        ll mid=(low+high)/2;
        if(ara[mid]>target)
            high=mid-1;
        else if(ara[mid]<target)
            low=mid+1;
        else return mid;
    }
    return -1;
}
bool visited[10];
bool check(int x)
{
    while(1)
    {
        int rem=x%10;
        if(visited[rem])
            return false;
        x/=10;
        if(x==0)
            break;
    }
    return true;
}
int main()
{
    fast();
    int n,k;
    cin>>n>>k;
    memset(visited,0,sizeof(visited));
    for(int i=0;i<k;i++)
    {
        int a;
        cin>>a;
        visited[a]=1;
    }
    for(int i=n; ;i++)
    {
        if(check(i))
        {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3612