akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=100000;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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

ll W,H;
vector<vector<vector<ll>>> table;

ll dp(ll sep,ll x,ll y){
  if(x==0&&y==0) return 1;
  if(table.at(sep).at(y).at(x)>-1) return table.at(sep).at(y).at(x);
  
  if(sep==0){
    if(x<2) return 0;
    if(x==2&&y==0) return 1;
    
    table.at(0).at(y).at(x)=0;
    table.at(0).at(y).at(x)+=dp(0,x-1,y);
    table.at(0).at(y).at(x)+=dp(1,x-1,y);
    
    return table.at(0).at(y).at(x)%=MOD;
  }
  
  if(sep==1){
    if(x<1||y<1) return 0;
    if(x==1&&y==1) return 1;
    
    table.at(1).at(y).at(x)=0;
    table.at(1).at(y).at(x)+=dp(3,x-1,y);
    
    return table.at(1).at(y).at(x)%=MOD;
  }
  
  if(sep==2){
    if(x<1||y<1) return 0;
    if(x==1&&y==1) return 1;
    
    table.at(2).at(y).at(x)=0;
    table.at(2).at(y).at(x)+=dp(0,x,y-1);
    
    return table.at(2).at(y).at(x)%=MOD;
  }
  
  if(sep==3){
    if(y<2) return 0;
    if(x==0&&y==2) return 1;
    
    table.at(3).at(y).at(x)=0;
    table.at(3).at(y).at(x)+=dp(3,x,y-1);
    table.at(3).at(y).at(x)+=dp(2,x,y-1);
    
    return table.at(3).at(y).at(x)%=MOD;
  }
}

int main()
{
  while(true){
    cin>>W>>H; if(W==0&&H==0) break;
    if(W==2||H==2) {cout<<2<<endl; continue;}
    
    //dp
    table=vector<vector<vector<ll>>> (4,vector<vector<ll>>(H,vector<ll>(W,-1)));
    ll ans=0;
    rep(i,4) ans+=dp(i,W-1,H-1);
    
    cout<<ans%MOD<<endl;
  }
  return 0;
}


Measured memory_bytes: 3596
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
// 12
const int inf = 1e9 + 10;
void _main(int tc) {
  int n, k;
  cin >> n >> k;
  assert(n >= 2);
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<int> mem(n, inf);
  mem[n - 1] = 0;
  mem[n - 2] = abs(h[n - 2] - h[n - 1]);

  // function<int(int)> fcost = [&](int i) -> int {
  //   if (mem[i] != inf) return mem[i];
  //   mem[i] = (1 << 30);
  //   forn(j, i + 1, (i + 1) + min(k, n - 1 - i)) {
  //     mem[i] = min(mem[i], abs(h[i] - h[j]) + fcost(j));
  //   }
  //   return mem[i];
  // };
  // cout << fcost(0) << endl;

  rrep(i, n - 2) {
    forn(j, i + 1, (i + 1) + min(k, n - 1 - i)) {
      mem[i] = min(mem[i], abs(h[i] - h[j]) + mem[j]);
    }
  }
  cout << mem[0] << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0);
  return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
	int n,answer;
	int i,j,k,l;
	
	while(scanf("%d",&n) != EOF){
		answer = 0;
		for(i=0;i < 10;i++){
			for(j=0;j < 10;j++){
				for(k=0;k < 10;k++){
					for(l=0;l < 10;l++){
						if(i+j+k+l == n) answer++;
					}
				}
			}
		}
		printf("%d\n",answer);
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int& a : A) cin >> a;
  sort(A.begin(), A.end(), greater<int>());
  long i = 0, x = 0, y = 0;
  while (i < N-1) {
    if (A[i] == A[i+1]) {
      if (x == 0) x = A[i];
      else {
        y = A[i];
        break;
      }
      i += 2;
    } else {
      i++;
    }
  }
  cout << x * y << endl;
}

Measured memory_bytes: 640
public class How_Many_Divisors {

  static void Main(string[] args) {

    var line = System.Console.ReadLine().Trim().Split(' ');
    int a = int.Parse(line[0]);
    int b = int.Parse(line[1]);
    int c = int.Parse(line[2]);

    int counter = 0;

    for (int i = a; i <= b; i++) {
      if(c % i == 0) {
        counter += 1;
      }
    }

    System.Console.WriteLine(counter);
  }

}

Measured memory_bytes: 9196
import java.util.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long t = Long.parseLong(sc.next());
        long start = 0l;
        long now = 0l;
        long ans = 0l;
        for(int i=0;i<n;i++){
            long tw = Long.parseLong(sc.next());
            if(now+t<tw){
                ans += now+t-start;
                start = tw;
            }
            now = tw;
        }
        ans += now+t-start;
        System.out.println(ans);
    }
}

Measured memory_bytes: 46392
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  V<double> p(n); REP(i, n) cin >> p.at(i);
  V<V<double>> dp(n+1, V<double>(n+1, 0));
  dp.at(0).at(0) = 1;
  rep(i, 1, n+1) {
    REP(j, i+1) {
      if (j > 0) dp.at(i).at(j) = dp.at(i-1).at(j) * (1-p.at(i-1)) + dp.at(i-1).at(j-1) * p.at(i-1);
      else dp.at(i).at(j) = dp.at(i-1).at(j) * (1-p.at(i-1));
    }
  }
  double ans = 0;
  rep(i, n/2+1, n+1) ans += dp.at(n).at(i);
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}


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

#include <math.h>
#include <stdlib.h>


#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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N, K; cin >> N >> K;

    map<int, int> mp;
    for(int i = 0; i < N; i++){
        int a; cin >> a;
        mp[a]++;
    }

    priority_queue<int> pque;
    int ans = 0;

    for(auto i: mp) pque.push(-1*i.second);

    while(pque.size() > K){
        ans += -1 * pque.top();
        pque.pop();
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10744
#include <stdio.h>
int main(void) {
  int X;
  int Y;

  scanf("%d", &X);
  scanf("%d", &Y);

  int kame = Y - 2 * X;
  int turu = 4 * X - Y;
  if (kame % 2 == 0 && turu % 2 == 0 && kame >= 0 && turu >= 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1640
#include <math.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>

#define nl                std::cout << "\n"
#define in(x)             std::cin  >> (x)
#define out(x)            std::cout << (x) << " "
#define err(x)            std::cerr << "DBG: " << #x << " " << (x) << "\n"

#define inn(x)            int x; in(x);
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)
#define rrep(i, n)        for (int i = (n) - 1; i > -1; --i)

#define no                puts("NO")
#define yes               puts("YES")

using ll  = long long int;
using vi  = std::vector<int>;
using ii  = std::pair<int, int>;
using iii = std::pair<ii, int>;
using vii = std::vector<ii>;

const int N = 1010101;
const int MD = 1e9 + 7;

void solve() {
    inn(n); inn(x);
    int d = 0;
    rep(i, n) {
        inn(l);
        d += l;
        if (d > x) {
            out(i + 1);
            return;
        }
    }
    out(n + 1);
}

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

    //int t; in(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>

using namespace std;
using ll=long long;
#define PRI(n) cout << n << endl;
#define PRI2(n, m) cout << n << " " << m << endl;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define REP1(i, n)  for(int i = 1; i <= (int)n; ++i)
#define REPT(i, t, n)  for(int i = t; i <= (int)n; ++i)
#define REPll1(i, n)  for(ll i = 1; i*i < (int)n; ++i)
const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;
typedef pair<int, int> Pi;

int mx[4] = {0, -1, 0, 1};
int my[4] = {-1, 0, 1, 0};
int X = 100000;
int tc[26];
int sc[26];

int main() {
    ll N, K, t;
    int cnt = 0;
    cin >> N >> K;
    t = N;
    while (t <= K) {
        cnt++;
        t *= 2;
    }

    cout << cnt << endl;
    return 0;
}







Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let mut s=read::<String>().chars().collect::<Vec<char>>();
    let mut t=read::<String>().chars().collect::<Vec<char>>();
    s.sort();
    t.sort();
    t.reverse();
    println!("{}",if s<t{"Yes"}else{"No"})
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int H, W, N;
typedef pair<int, int> coord;

struct data {
  int y, x, cost, dist;

  bool operator >(const data &e) const{
    return cost > e.cost;
  }
};

bool isInside( int y, int x ){
  return ( 0 <= y && y < H && 0 <= x && x < W );
}

int main(){

  cin >> H >> W >> N;

  vector< vector<char> > field(H, vector<char>(W));
  vector<coord> coord_list(N+1);
  int sy, sx, gy, gx;

  for(int y = 0; y < H; y++){
    for(int x = 0; x < W; x++){
      cin >> field[y][x];

      if( field[y][x] != 'S' && field[y][x] != '.' ){
        coord_list[field[y][x] - '0'] = coord(y,x);
      }else if( field[y][x] == 'S' ){
        sy = y;
        sx = x;
      }
    }
  }

  int answer = 0;
  int x, y;

  for(int i = 1; i <= N; i++){
    gy = coord_list[i].first;
    gx = coord_list[i].second;

    priority_queue<data, vector<data>, greater<data> > que;
    vector< vector<bool> > check_field(H, vector<bool>(W));

    data d;
    d.dist = 0;
    d.cost = 0;
    d.y = sy;
    d.x = sx;

    que.push(d);

    while( !que.empty() ){
      d = que.top(); que.pop();
      y = d.y;
      x = d.x;
      check_field[y][x] = true;

      if( d.y == gy && d.x == gx ){
        sy = gy;
        sx = gx;
        answer += d.dist;
        break;
      }
      if( isInside( y, x+1 ) && !check_field[y][x+1] && field[y][x+1] != 'X'){
        data nd;
        nd.y = y;
        nd.x = x+1;
        nd.dist = d.dist + 1;
        nd.cost = nd.dist + abs( gy - nd.y ) + abs( gx - nd.x );
        que.push(nd);
      }
      if( isInside( y+1, x ) && !check_field[y+1][x] && field[y+1][x] != 'X'){
        data nd;
        nd.y = y+1;
        nd.x = x;
        nd.dist = d.dist + 1;
        nd.cost = nd.dist + abs( gy - nd.y ) + abs( gx - nd.x );
        que.push(nd);
      }
      if( isInside( y, x-1 ) && !check_field[y][x-1] && field[y][x-1] != 'X'){
        data nd;
        nd.y = y;
        nd.x = x-1;
        nd.dist = d.dist + 1;
        nd.cost = nd.dist + abs( gy - nd.y ) + abs( gx - nd.x );
        que.push(nd);
      }
      if( isInside( y-1, x ) && !check_field[y-1][x] && field[y-1][x] != 'X'){
        data nd;
        nd.y = y-1;
        nd.x = x;
        nd.dist = d.dist + 1;
        nd.cost = nd.dist + abs( gy - nd.y ) + abs( gx - nd.x );
        que.push(nd);
      }
    }
  }

  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define pii pair<int, int>
#define X first
#define Y second
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}
const int N = 1e5 + 10;
int n, a[N], k, ans;
int dep[N], vis[N];
vector<int> G[N];

int dfs(int x, int dep)
{
	int ret = dep;
	int nn = G[x].size();
	rep(i, 0, nn - 1)
	{
		int to = G[x][i];
		ret = max(ret, dfs(to, dep + 1));
	}
	if(a[x] != 1 && ret - dep == k - 1)
	{
		ans ++;
		return 0;
	}
	return ret;
}

int main()
{
	n = read();
	k = read();
	rep(i, 1, n)
	{
		a[i] = read();
		if(i != 1) G[a[i]].pb(i);
	}
	if(a[1] != 1) a[1] = 1, ans ++;
	dfs(1, 0);
	cout << ans;
	return 0;
}


Measured memory_bytes: 13952
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N = Integer.parseInt(scanner.next());
	    long[] A  = new long[N+1];
	    long[] B  = new long[N];
	    
	    for (int i=0; i<N+1; i++) {
	    	A[i]=Long.parseLong(scanner.next());
	    }
	    for (int i=0; i<N; i++) {
	    	B[i]=Long.parseLong(scanner.next());
	    }
	    
	    long max=0;
	    for (int i=0; i<N; i++) {
	        long b = B[N-i-1];
	        long a1 = A[N-i];
	        long a2 = A[N-i-1];
	        if (a1 >= b) {
	        	max+=b;
	        } else {
	        	max += a1;
	        	b-=a1;
	        	if (a2>=b) {
	        		max+=b;
	        		A[N-i-1] -=b;
	        	} else {
	        		max+=a2;
	        		A[N-i-1] =0;
	        	}
	        }
	    }
        System.out.print(max);
	}

}

Measured memory_bytes: 61112
from collections import deque

q = int(input())

que = deque()
for i in range(q):
    query = input().split()

    if query[0] == "0":
        que.append(query[1])
    elif query[0] == "1":
        print(que[int(query[1])])
    else:##popBack
        que.pop()



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

using namespace std;

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;
   cin >> n;
   vector<double> a(n);
   for(int i = 0; i < n; i++) {
       cin >> a[i];
   }
   sort(a.begin(), a.end());
   double ans = a[0];
   for(int i = 1; i < n; i++) {
       ans = (ans + (double) a[i]) / 2.0;
   }
   cout << fixed << setprecision(20) << ans << endl;
}

Measured memory_bytes: 3760
N = int(input())
array = []
for i in range(N):
    a = list(map(int,input().split()))
    array.append(a)
array = sorted(array, key = lambda x:x[1])

suma = 0
c = 0
for i in range(N):
    suma += array[i][0]
    if suma > array[i][1]:
        c = 1
        break
if c == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 55252
#include <iostream>
using namespace std;
int main() {
  int n, k, i, j;
  cin>>n>>k;
  if(k>1 && k<2*n-1){
    cout<<"Yes\n";
    j=2;
    for(i=1; i<=2*n-1; i++){
      if(i==n-1)
        cout<<"1\n";
      else if(i==n)
        cout<<k<<"\n";
      else if(i==n+1)
        cout<<2*n-1<<"\n";
      else{
        if(j==k)
          j++;
        cout<<j<<"\n";
        j++;
      }
    }
  }else
    cout<<"No";
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

int n;
int a[200010];
int dp[200010];
int ans=0;

void solve(){
    rep(i,n){
        dp[a[i]]=dp[a[i]-1]+1;
        ans=max(ans,dp[a[i]]);
    }
    cout << n-ans << endl;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

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

Measured memory_bytes: 3328
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace AtCoder
{
    class Program2
    {

        static void Main(string[] args)
        {
            //lee un numero
            var n = Convert.ToInt64(Console.ReadLine());
            int premio = 0;

            while (n >= 500)
            {
                n = n - 500;
                premio = premio + 1000;
            } 
            while (n >= 5)
            {
                n = n - 5;
                premio = premio + 5;
            }

            //sacar
            Console.WriteLine(premio);
        }


    }
}

Measured memory_bytes: 13140
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<math.h>
#include<stdlib.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, pii > piii;
typedef pair<double, double> pdd;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N;
int a[10100];
stack<int> s;
bool in[10100];

signed main(){
    cin >> N;
    int flag = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(a[i] > 0){
            s.push(a[i]);
            if(in[a[i]]){
                flag = i + 1;
                break;
            }
            in[a[i]] = true;
        }
        else {
            a[i] *= -1;
            int top = 0;
            if(!s.empty()){
                top = s.top();
                s.pop();
            }
            if(!in[a[i]]){
                flag = i + 1;
                break;
            }
            in[a[i]] = false;
            if(top != a[i]){
                flag = i + 1;
                break;
            }
        }
    }
    if(flag == 0){
        cout << "OK" << endl;
    }
    else {
        cout << flag << endl;
    }
    

    return 0;
}

/*

*/


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n-1);0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<< " (L"<<__LINE__<<")"<<endl;
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;

int main() {
    ll x; cin >> x;
    ll n = x / 11 * 2;
    ll a;
    if(x % 11 != 0) {
        if(x % 11 <= 6) a = 1;
        else a = 2;
    } else a = 0;
    cout << n + a << endl;
    return 0;
}


Measured memory_bytes: 256
def solution():
    return 1

def main():
    N , M = list(map(int , input().split()))
    assignments = list(map(int , input().split()))
    for a in assignments:
        N -= a 
    if N < -1:
        N = -1
    print(N)       
   
if __name__ == "__main__":
    main()


Measured memory_bytes: 10188
import numpy as np

N,M = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]

AB.sort()

cnt = 0
yen = 0

for a,b in AB:
  if cnt + b <= M:
    cnt += b
    yen += a * b
    continue
  yen += a * (M - cnt)
  break

answer = yen
print(answer)

Measured memory_bytes: 30636
import java.util.*;

public class Main {

	public static void main(String[] args) {
		//入力受付
		Scanner scanner = new Scanner(System.in);
		int kari = Integer.parseInt(scanner.nextLine());
		String text = scanner.nextLine();

		//リスト作成
		String tempList[] = text.split(" ");
		int intList[] = new int[tempList.length];

		for(int i = 0; i < tempList.length; i++ ) {
			intList[i] = Integer.parseInt(tempList[i]);
		}

		//dpの初期化
		int dp[] = new int[intList.length];
		for(int i = 0; i < dp.length; i++) {
			dp[i] = 0;
		}
		//動的計画法の実施
		dp[1] = Math.abs(intList[1] - intList[0]);
		for(int i = 2; i < intList.length; i++) {
			int f1 = dp[i-1] + Math.abs(intList[i-1] - intList[i]);
			int f2 = dp[i-2] + Math.abs(intList[i-2] - intList[i]);
			if(f1 >= f2) {
				dp[i] = f2;
			}else {
				dp[i] = f1;
			}
		}

		System.out.println(dp[intList.length-1]);
	}
}


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

int main(){
    int x, y;
    while(true){
        cin >> x >> y;
        if(x == 0 && y == 0) break;
        if(x < y) cout << x << " " << y << endl;
        else cout << y << " " << x << endl;
    }
    return 0;
}


Measured memory_bytes: 3036
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
#define MOD 1000000007
using namespace std;

int main() {
	ll a, b, x;
	ll count = 0, counta = 0, countb = 0;
	cin >> a >> b >> x;
	countb = b / x + 1;
	counta = (a - 1) / x + 1;
	if (a == 0) {
		counta = 0;
	}
	count = countb - counta;
	cout << count << endl;
	return 0;
}

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

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());
    ll ans = 1e18;
    rep(i, n - k + 1) {
        ans = min(ans, h[i+k-1] - h[i]);
    }
    cout << ans << endl;
    return 0;
}


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

#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define inf INT_MAX
#define MOD 1000000007
#define fori(i,n) for(int i=0;i<(int)n;++i)
#define forri(i,n) for(int i=n-1;i>=0;--i)
#define forii(i,start,end) for(int i=start;i<end;++i)
#define MEM(a,b) memset(a,(b),sizeof(a))
#define sizearr(arr) sizeof(arr)/sizeof(arr[0])
#define LEN(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>

#define print(var) cout << var << endl;
#define ENDL cout << endl;
#define coutarr(arr) for(auto a:arr)print(a); ENDL;
#define coutpii(arr) for(pii a:arr)cout << '(' << a.fi << ',' << a.se << ") "; ENDL;
#define cinarr(arr, n) fori(i, n) {int tmp; cin >> tmp; arr.pb(tmp);}

const int MAX = 1e5 + 5;
int parent[MAX];
vector<int> childs[MAX];
int depth[MAX];
int vis[MAX];
int tipe[MAX];

void DFS(int n, int d){
	vis[n] = true;
	depth[n] = d;
	for(int a: childs[n]){
		if(!vis[a]){
			DFS(a, d+1);
		}
	}
}

int findRoot(int n){
	fori(i, n) {
        if(parent[i] == -1) return i;
    }
}

void deftipe(int n){
	fori(i, n){
		if (parent[i] == -1){
			tipe[i] = -1;
		} else if (childs[i].size() == 0) {
			tipe[i] = 1;
		} else {
			tipe[i] = 0;
		}
	}
}

int main(){
	int n; cin >> n;
	fori(i, n) parent[i] = -1;
	fori(i, n) depth[i] = 0;
	fori(i, n) vis[i] = false;
	
	fori(i, n){
		int id, x; cin >> id >> x;
		fori(j, x){
			int tmp; cin >> tmp;
			childs[id].pb(tmp);
			parent[tmp] = id;
		}
	}

    
	int root = findRoot(n);
	deftipe(n);
	DFS(root, 0);

	fori(i, n){
		cout << "node " << i << ": ";
		cout << "parent = " << parent[i];
		cout << ", depth = " << depth[i];
		cout << ", ";
		if (tipe[i] == -1) cout << "root";
		else if (tipe[i] == 0) cout << "internal node";
		else cout << "leaf";
		cout << ", [";
        int m = childs[i].size();
		fori(j, m) {
			cout << childs[i][j];
			if (j < m-1) cout << ", ";
		}
		cout << "]" << endl;
	}
	
	return 0;	
}


Measured memory_bytes: 7804
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ans = min(c,b/a);
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 29);

int main()
{
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> A(M);
  for (int i = 0; i < M; i++)
  {
    int a, b;
    cin >> a >> b;
    A.at(i) = make_pair(b, a);
  }
  sort(A.begin(), A.end());
  int ans = 0;
  int last = -INF;
  for (int i = 0; i < M; i++)
  {
    if (last <= A.at(i).second)
    {
      ans++;
      last = A.at(i).first;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
using priority_queue_small = priority_queue<int, vector<int>, greater<int> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int n;
int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n;
  vii p(n);
  rep(i, 0, n) cin >> p[i];
  ll ans = 0;
  rep(i, 0, n+1) {
    if (i+1 == p[i]) {
      ans++;
      swap(p[i], p[i+1]);
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<set>
#include<map>
using namespace std;
int main(){
	int n,m,flag=0;
	string str;
	set<string>	st;
	map<string,int>	mp;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> str;
		mp[str]++;
	}
	cin >> m;
	for(int i=0;i<m;i++){
		cin >> str;
		if(mp[str]!=0){
			if(flag){
				cout << "Closed by " << str << endl;
				flag=0;
			}
			else{
				cout << "Opened by " << str << endl;
				flag=1;
			}
		}
		else	cout << "Unknown " << str << endl;
	}
}


Measured memory_bytes: 3224
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int sum = 0;
		int max = 0,p;
		for(int i = 0; i < n; i++) {
			p = sc.nextInt();
			sum += p;
			max = Math.max(max, p);
		}
		sum = sum - max/2;
		System.out.println(sum);
	}
}


Measured memory_bytes: 21716
#include <algorithm>
#include <climits>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

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

typedef struct {
  int u, v, cost;
} Edge;

void solve(vector<Edge> es){
  VI d(10, INF);
  bool update = true;
  VI ans(10, 0);
  int lim = 10;

  REP(i, 0, lim){

    bool reach[10] = {false};
    REP(j, 0, 10){
      d[j] = INF;
    }
    d[i] = 0;
    reach[i] = true;
    update = true;

    while(update){
      update = false;
      REP(j, 0, es.size()){
        Edge e = es[j];
        if(d[e.u] != INF && d[e.v] > d[e.u] + e.cost){
          d[e.v] = d[e.u] + e.cost;
          update = true;
          reach[e.v] = true;
        }
      }
    }
    REP(j, 0, lim){
      if(reach[j]){
        ans[i] += d[j];
      } else {
        lim = j;
      }
    }
  }

  int f = INF;
  int v = -1;
  REP(i, 0, lim){
    if(f > ans[i]){
      f = ans[i];
      v = i;
    }
  }
  cout << v << " " << f << endl;

  return;
}

int main(){
  int N;

  while(1){
    cin >> N;
    if(N == 0){
      break;
    }
    vector<Edge> es(2*N);
    REP(i, 0, N){
      int a, b, c;
      cin >> a >> b >> c;
      es[i].u = a; es[i].v = b; es[i].cost = c;
      es[i+N].v = a; es[i+N].u = b; es[i+N].cost = c;
    }
    solve(es);
  }

  return 0;
}

Measured memory_bytes: 3160
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;

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

    sort(ALL(A), greater<ll>());

    ll ans = A[0];

    reps(i, 2, N) { ans += A[i / 2]; }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4752
import java.util.Scanner;

public class Main{//Merge Sort
	static int N;
	static int[] A;
	static int[] W;
	static long merge_and_count(int l, int r) {
		if(l+1 >= r) return 0;
		if(l+2==r) {//要素2つだけ
			if(A[l]<=A[l+1]) return 0;
			int a=A[l];
			A[l]=A[l+1];
			A[l+1]=a;
			return 1;//逆転1つ
		}
		int m=(l+r)/2;
		long cl=merge_and_count(l, m);
		long cr=merge_and_count(m, r);
		long c=0;
		int i=l, j=m;
		int k=l;
		while(i<m && j<r) {//左グループ右グループ中身比較
			if(A[i]<=A[j]) {
				W[k++]=A[i++];
			}
			else {
				W[k++]=A[j++];
				c+=m-i;//左半分で未処理の要素とびこえる
				//System.out.println("j="+j+"m="+m+"c="+c);
			}
		}
		while(i<m) {
			W[k++]=A[i++];
		}
		while(j<r) {
			W[k++]=A[j++];
		}
		//System.out.println("W["+2+"]="+W[2]+"W["+3+"]="+W[3]+"W["+4+"]="+W[4]);
		assert(k==r);
		for(int x=l; x<r; x++) {
			A[x]=W[x];
		}
		return cl+cr+c;
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			N=sc.nextInt();
			A=new int[N];
			W=new int[N];
			for(int i=0; i<N; i++) {
				A[i]=sc.nextInt();
			}
			System.out.println(merge_and_count(0, N));

		}
	}
}


Measured memory_bytes: 104732
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

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

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define f(i, l, r) for (int i = l; i <= r; i++)
#define rf(i, r, l) for (int i = r; i >= l; i--)
#define all(x) (x).begin(), (x).end()
#define sf(a) scanf("%d",&a)
#define llsf(a) scanf("%lld", &a)
#define l l
#define r r
#define lch (o << 1)
#define rch (o << 1 | 1)
#define mid ((l + r) >> 1)
#define mem(x, y) memset(x, y, sizeof(x))

const int inf = 2e9 + 7;
const ll INF = INT64_MAX;
double eps = 1e-6;
int mod = 1e9 + 7;
const int N = 25100;
const double pi = acos(-1.0);

int n, k, m;
int a[N];
int pos,rlen,llen;
bool ok[500];
int last[500];
void work() {
	if(m>=k){
		mem(ok, 0); mem(last, 0);
		int l = 1, r = 1;
		while (r <= m) {
			if (!ok[a[r]])ok[a[r]] = 1;
			else {
				for (; l < last[a[r]]; l++) {
					ok[a[l]] = 0;
				}
				l++;
			}
			if (r - l + 1 == k) { pos = 1; return; }
			last[a[r]] = r;
			r++;
		}
	}
	mem(ok, 0);
	f(i, 1, m)if (!ok[a[i]])ok[a[i]] = 1; else { 
		pos = 3;
		llen = i - 1;
		mem(ok, 0);
		rf(j, m, 1)if (!ok[a[j]])ok[a[j]] = 1; else {
			rlen = m - j; break;
		}
		return; 
	}
	pos = 2;
}
ll dp[N][410],g[N][410]; ll sum[410],sumg[410];
void M(ll& a) {
	a %= mod;
	if (a < 0)a += mod;
}
void init() {
	dp[1][1] = k;
	if (m == 1)g[1][1] += k;
	f(i, 2, n) {
		f(j, 1, k-1)M(sum[j] = sum[j - 1] + dp[i - 1][j]), M(sumg[j] = sumg[j - 1] + g[i - 1][j]);
		f(j, 1, k-1) {
			M(dp[i][j] = dp[i - 1][j - 1]*(k-j+1)%mod + sum[k-1] - sum[j - 1]);
		}
		f(j, 1, k - 1) {
			M(g[i][j] = g[i - 1][j - 1] * (k - j + 1) % mod + sumg[k - 1] - sumg[j - 1]+(j>=m?dp[i][j]:0));
		}
	}
}

ll power(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)M(res *= a);
		a = a * a % mod;
		b >>= 1;
	}return res;
}
ll powk[N];
ll jiechen[500];
ll L[N][500], R[N][500];
ll Lsum[N], Rsum[N];
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	jiechen[0] = 1;
	f(i, 1, 400)jiechen[i] = i * jiechen[i - 1]%mod;
	sf(n); sf(k); sf(m);
	powk[0] = 1;
	f(i, 1, 25000)powk[i] = powk[i - 1] * k % mod;
	f(i, 1, m)sf(a[i]);
	work();
	init();
	ll res = (n - m + 1) * power(k, n - m); M(res);
	if (pos == 1);
	else if (pos == 2) {
		ll tmp = 0;
		f(i, 1, n)M(tmp += g[n][i]);
		ll chu = jiechen[k] * power(jiechen[k - m], mod - 2); M(chu);
		M(tmp *= power(chu,mod-2)); M(res -= tmp);
	}
	else {
		R[0][rlen] = 1;
		f(i, 1, n) {
			f(j, 1, k-1)M(sum[j] = sum[j - 1] + R[i - 1][j]);
			f(j, 1, k-1) {
				M(R[i][j] = R[i - 1][j - 1] * (k - j + 1)%mod + sum[k-1] - sum[j - 1]);
			}
		}
		L[0][llen] = 1;
		f(i, 1, n) {
			f(j, 1, k-1)M(sum[j] = sum[j - 1] + L[i - 1][j]);
			f(j, 1, k-1) {
				M(L[i][j] = L[i - 1][j - 1] * (k - j + 1)%mod + sum[k-1] - sum[j - 1]);
			}
		}
		Lsum[0] = Rsum[0] = 1;
		f(i, 1, n)f(j, 1, k)M(Lsum[i] += L[i][j]), M(Rsum[i] += R[i][j]);
		ll tmp = 0;
		f(i, 0, n - m) {
			M(tmp += Lsum[i] * Rsum[n - m - i]);
		}
		res -= tmp;
	}
	M(res);
	cout << res;
}

Measured memory_bytes: 357504
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var c1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var c2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var c3 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int i = 0; i <= c1[0]; i++)
            {
                var b1 = c1[0] - i;
                var b2 = c1[1] - i;
                var b3 = c1[2] - i;

                if (c2[0] - b1 == c2[1] - b2  && 
                    c2[0] - b1 == c2[2] - b3  &&
                    c3[0] - b1 == c3[1] - b2 &&
                    c3[0] - b1 == c3[2] - b3)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13396
//#include <iostream>
//#include <string>
//#include <stdlib.h>
#include <stdio.h>

int main() {
    int X;
    int Y;
    scanf("%d%d", &X, &Y);
    if (X % Y == 0) {
        printf("%d\n", -1);
        return 0;
    }
    int ans = 1;
    for (int i = 1; ans <= 1000000000000000000; i++) {
        ans = X*i;
        if (ans % Y != 0) {
            printf("%d\n", ans);
            return 0;
        }
    }
    printf("%d\n", -1);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
int n, i;

scanf("%d", &n);

for(i = 1; i <= n; i++){


if(i % 3 == 0 || i % 10 == 3){
printf(" %d", i);
}
else if((i / 10) % 10 == 3){
 printf(" %d", i); 
}
else if((i / 100) % 10 == 3){
 printf(" %d", i);
}
else if((i / 1000) % 10 == 3){
 printf(" %d", i);
}

}
printf("\n");

return 0;

}




Measured memory_bytes: 2000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int a,b,c,x;
cin>>a>>b>>c>>x;
ll cnt= 0;
for(int i =0;i<=a;i++)
{
    for(int j =0;j<=b;j++)
    {
        for(int k =0;k<=c;k++)
        {
            if(500*i+100*j+50*k==x)
            {
                cnt++;
            }
        }
    }
}
cout<<cnt;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

long long int C(int p, int q) {
	long long int temp = 1;
	int s = min(p - q, q);
	for (int i = p; i > (p - s); i--) {
		temp *= i;
	}

	for (int i = 2; i <= s; i++) {
		temp /= i;
	}

	return temp;
}

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

	vector<int> odd;
	vector<int> even;

	int temp;
	for (int i = 0; i < N; i++) {
		cin >> temp;
		if (temp % 2 == 0) {
			even.push_back(temp);
		} else {
			odd.push_back(temp);
		}
	}

	long long unsigned int count = 0;
	if (P == 0) {
		count += pow(2, even.size());

		int odd_size = odd.size();
		long long int t = 0;
		for (int i = 0; i <= odd_size; i += 2) {
			t += C(odd_size, i);
		}
		count *= t;
	} else {
		int odd_size = odd.size();
		for (int i = 1; i <= odd_size; i += 2) {
			count += C(odd_size, i);
		}
		count *= pow(2, even.size());
	}


	cout << count << endl;
	return 0;
}

Measured memory_bytes: 512
import numpy as np

a,b,h,m = map(int,input().split())

ang1 = ((30*h+m/2)*np.pi)/180
ang2 = (6*m*np.pi)/180


# print(30*h+m/20)
# print(6*m)
# print(ang1)
# print(ang2)

x_dis = a*np.cos(ang1)-b*np.cos(ang2)
y_dis = a*np.sin(ang1)-b*np.sin(ang2)

dist = np.sqrt(x_dis*x_dis+y_dis*y_dis)
print(dist)


Measured memory_bytes: 27208
# 初期化
dp = []
for i in range(100001):
    dp.append(float('inf'))

# 入力 添え字のN-1が足場Nに相当する
N = int(input())
h = list(map(int, input().split()))

dp[0] = 0
dp[1] = abs(h[1] - h[0])

# 添え字N-1=足場Nまで計算している
for i in range(N - 2):
    dp[i + 2] = min(dp[i + 1] + abs(h[i + 2] - h[i + 1]), dp[i] + abs(h[i + 2] - h[i]))

print(dp[N-1])


Measured memory_bytes: 17464
n = int(input())
s = input()
r = 0
lr = 0
li = 0
for i in range(n):
    if s[i] == '(':
        li = i
        break
    if i==n-1:
        li = i
for i in range(li, n):
    if s[i] == '(':
        lr += 1
    else:
        if lr > 0:
            lr -= 1
        else:
            r += 1

res = '('*r
res += '('*li
res = res + s + ')' * max(0, lr)
print(res)


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

long long infinity = 1e18;

int v[100];
int w[100];
long long dp[100][100001];

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

    for(int i=0;i<n;i++){
        for(int j=0;j<=100000;j++){
            dp[i][j] = infinity;
        }
    }
    for(int i=0;i<n;i++){
        cin >> w[i] >> v[i];
    }

    dp[0][0] = 0;
    dp[0][v[0]] = w[0];

    for(int i=1;i<n;i++){
        dp[i][0] = 0;
        for(int j=0;j<=100000;j++){
            dp[i][j] = dp[i-1][j];

            if(j>=v[i]){
                dp[i][j] = min(dp[i][j] , w[i] + dp[i-1][j-v[i]]);
            }
        }
    }
    long long ans;
    for(int i=100000;i>=0;i--){
        if(dp[n-1][i] <= C){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

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

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

	if (n % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}

	string s2 = s.substr(n / 2);

	if (s == (s2 + s2)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n,W=map(int,input().split())
dp=[[0]*(W+1) for _ in range(n+1)]
for i in range(1,n+1):
    w,v=map(int,input().split())
    for j in range(w):
        dp[i][j]=dp[i-1][j]
    for j in range(W-w+1):
        dp[i][j+w]=max(dp[i-1][j+w],dp[i-1][j]+v)
print(max(dp[-1]))


Measured memory_bytes: 148936
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
    
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

if __name__ == '__main__':

    n = int(input())
    A = list(map(int,input().split()))

    ans = lcm(*A) - 1

    tmp = 0
    for i in A:
        tmp += ans % i
    print(tmp)


Measured memory_bytes: 9724
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n;
string str;

int main(){
	cin >> str;
	n = str.size();
	
	int ans = 100;
	for(int ab = 0; ab < 26; ab++){
		int ans_buf = 0;
		char c = 'a'+ab;
		//cout << c << endl;
		
		int cnt = 0;
		for(int i = 0; i < n; i++){
			if(str[i] == c){ans_buf = max(cnt, ans_buf); cnt = 0;}
			else{cnt++;}
		}
		ans_buf = max(cnt, ans_buf);
		ans = min(ans_buf, ans);
	}
	
	cout << ans << endl;
	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);
        int[][][] kan = new int[4][3][10];
        int num=sc.nextInt();
        for(int i=0;i<num;i++){
            int b=sc.nextInt(),f=sc.nextInt(),r=sc.nextInt(),v=sc.nextInt();
            kan[b-1][f-1][r-1] += v;
        }
        
        for(int i=0;i<4;i++){
            for(int k=0;k<3;k++){
                for(int l=0;l<10;l++){
                    System.out.print(" "+kan[i][k][l]);
                }
                System.out.print("\n");
            }
            if(i!=3){
                System.out.println("####################");
            }
        }
        sc.close();
    }
}



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

int Sum_each(int A){
  	int sum = 0, tmp = A;
  	while(1){
      	sum += tmp%10;
      	if(tmp/10 == 0) break;
      	else tmp = tmp/10;
    }
  	return sum;
}

int main(){
  	int N;
  	cin >> N;
  	int min = N;
  	for (int i = 1; i < N; i++){
      	int sum = Sum_each(i)+Sum_each(N-i);
      	if(sum < min) min = sum;
    }
  	cout << min << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


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

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(void){
	int N,max[26]={};
	string S;

	REP(i,26) max[i]=INF;

	cin>>N;
	REP(i,N){
		cin>>S;
		int counter[26]={};
		REP(j,(int)S.length()) counter[((int)S[j]-97)]++;

		REP(j,26) chmin(max[j],counter[j]);
	}
	
	REP(i,26){
		REP(j,max[i]) printf("%c",97+i);
	}
	cout<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    ll ans = 1;
    for(int i = 1; i <= n; ++i){
        ans *= i;
        ans = ans % 1000000007LL;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256