akhauriyash/Code-Regression huggingface dataset:
inputnumber = int(input())
numpage = 0
oddnumber = inputnumber % 2
if inputnumber >= 1 and inputnumber <= 100:
  if oddnumber == 0:
    numpage = inputnumber / 2
    print(int(numpage))
  else:
    inputnumber = inputnumber - 1
    numpage = inputnumber / 2
    numpage = numpage + 1
    print(int(numpage))
else:
  print()


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

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

ll dp[105][100005];

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }

    dp[0][k] = 1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= k; ++j){
            int pos = max(0, j - a[i]);
            dp[i+1][pos] = (dp[i+1][pos] + dp[i][j]) % mod;
            dp[i+1][j+1] = (dp[i+1][j+1] - dp[i][j]) % mod;
            while(dp[i+1][j+1] < 0) dp[i+1][j+1] += mod;
        }
        for(int j = 0; j <= k; ++j){
            dp[i+1][j+1] = (dp[i+1][j+1] + dp[i+1][j]) % mod;
        }
    }
    cout << dp[n][0] << endl;
}

Measured memory_bytes: 79360
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
lst = [a,b,c,d,e]
for i in lst:
    for j in lst:
        if i - j > k:
            print(":(")
            exit()
            
print("Yay!")

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

using namespace std;

int main(void)
{
	int n,index;
	int max=0;
	int sum=0;
	cin>>n;

	int li[n];

	for(int i=0;i<n;i++){
		cin>>li[i];
		if(li[i]>max) max=li[i];
		sum+=li[i];
	}

	index=sum-max;

	if(index>max) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)
 
n = int(input())
g = [[] for _ in range(n)]
for i in range(n-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  g[a].append([b, i])
  g[b].append([a, i])
  
ans = [0]*(n-1)
  
def dfs(v, c=-1, p=-1):
  k = 1
  for u, ei in g[v]:
    if u == p:
      continue
    if k == c:
      k += 1
    ans[ei] = k
    k += 1
    dfs(u, ans[ei], v)
 
dfs(0)
print(max(ans))
for i in range(n-1):
  print(ans[i])

Measured memory_bytes: 89332
using System;
using System.Linq;

namespace ABC091_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var s = new string[N];
            for (int i = 0; i < N; i++)
                s[i] = Console.ReadLine();
            var M = int.Parse(Console.ReadLine());
            var t = new string[M];
            for (int i = 0; i < M; i++)
                t[i] = Console.ReadLine();
            var X = 0;

            foreach (var cs in s.Distinct())
            {
                var tmp = 0;
                foreach (var ss in s)
                    if (cs == ss)
                        tmp++;

                foreach (var tt in t)
                    if (cs == tt)
                        tmp--;

                X = X < tmp ? tmp : X;
            }
            Console.WriteLine(X);

        }
    }
}


Measured memory_bytes: 11348
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
/*
using ll = long long;
using P = pair<int, int>;
*/
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dp[101][10001];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, W;
    cin >> n >> W;
    vector<int> v(n), w(n);
    rep(i,n) cin >> v[i] >> w[i];
    int ans = 0;
    rep(i,n){
        rep(j,W+1){
            if(j-w[i] < 0) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            chmax(ans, dp[i+1][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7092
#include <bits/stdc++.h>
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N,M;
int a[300][300];
bool can(int T){	// leq T?
	int cnt[300]={};
	int it[300]={};
	bool erased[300]={};
	rep(i,N){
		cnt[a[i][0]]++;
	}
	while(true){
		int mx = -1;
		int ag = -1;
		rep(j,M){
			if(mx<cnt[j]){
				mx = cnt[j];
				ag = j;
			}
		}
		if(mx>T){
			erased[ag] = 1;
			rep(i,N){
				cnt[a[i][it[i]]]--;
				while(it[i]<M && erased[a[i][it[i]]]){
					it[i]++;
					if(it[i] == M) return 0;
				}
				cnt[a[i][it[i]]]++;
			}
		}else{
			return 1;
		}
	}
}
int main(){
	cin>>N>>M;
	rep(i,N){
		rep(j,M) cin>>a[i][j],a[i][j]--;
	}
	int ub = N, lb = 0;
	while(ub-lb>1){
		int m = (ub+lb)/2;
		if(can(m)) ub = m;
		else lb = m;
	}
	cout<<ub<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
using namespace std;

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



#define rep(n) for(int i=0;i<n;i++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
const int MOD = 1000000007;
const int INF = 1 << 29;


int main() {
	
	int a, b, c,n;
	int cnt = 0;
	cin >> a >> b >> c >> n;
	for (int i = 0; a*i<=n; i++) {
		for (int j = 0; a*i + b * j <= n; j++) {
			if ((n - a * i - b * j) % c == 0) {
				cnt++;
				//cout << i << j ;
			}
		}
	}
	cout << cnt << endl;
	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;

using namespace std;

vector<ll> preparing_boxes(vector<ll> a) {
  ll n = (ll) a.size();
  vector<ll> ans(n);
  vector<ll> res;
  for(ll i=n-1;i>=0;i--) {
    //cout << "i: " << i << endl;
    ll offset = i+1;
    ll j = i + offset;
    ll acc = 0;
    while(j < n) {
      //cout << "check j: " << j << " ans[j] -> " << ans[j]  << endl;
      acc += ans[j];
      j += offset;
    }
    if(a[i] == 0) {
      if(acc % 2 == 0) {
	ans[i] = 0;
      } else {
	ans[i] = 1;
	res.push_back(i+1);
      }
    } else {
      if(acc % 2 == 0) {
	ans[i] = 1;
	res.push_back(i+1);
      } else {
	ans[i] = 0;
      }
    }
    //cout << "ans " << i << " -> "<< ans[i] << endl;
  }
  return res;
}

int main() {
 ll n;
 cin >> n;
 vector<ll> a(n);
 for(ll i=0;i<n;i++) {
   cin >> a[i];
 }
 vector<ll> ans = preparing_boxes(a);
 cout << ans.size() << endl;
 for(ll i=0;i< (ll) ans.size();i++) {
   cout << ans[i];
   if(i != (ll) ans.size() -1) {
     cout << " ";
   }
 }
}

Measured memory_bytes: 8836
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll N,maxx=0;
    ll maxs = 0;
    ll maxp = 0;
    cin >> N;
    vll A(N);
    REP(i,N){
        cin >> A[i];
    }
    maxx = *max_element(A.begin(), A.end());
    REP(i,N){
        if(A[i] == maxx){
            maxs++;
            maxp = i;
        }
    }
    REP(i,N){
        if(maxs<=0){
            cerr << "おかしい" << endl;
        }else if(maxs==1){
            if(i==maxp){ //2番目にデカイやつ
                A[i]=0;
                cout << *max_element(A.begin(), A.end()) << endl;
            }else{
                cout << maxx << endl;
            }
        }else{
            cout << maxx << endl;            
        }
        
    }
    
}

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

int main() {
  int n,c=0,d=0;
  string s;
  cin>>s;
  n=s.length();
  for(int i=0;i<n;i++)
  {
    if(s[i]=='1')
    {
            c++;
    }
  }
  d=n-c;
  int ans=min(c,d);

cout<<2*ans<<endl;
}

Measured memory_bytes: 512
#include <iostream>

int main()
{
    while(1) {
        int a1,a2,a3;

        int n = 0,x = 0;;
        int count = 0;

        std::cin >> n >> x;

        if (n == 0 && x == 0) {
            return 0;
        }


        for (int i = n; i > 2 ; i--) {
            a3 = i;
            for (int j = a3 - 1; j > 1; j--) {
                a2 = j;
                for (int k = a2 - 1; k > 0; k--) {
                    a1 = k;

                    if (a1 + a2 + a3 == x && a1 >= 1) {
                        count += 1;
                    }
                }
            }
        }


        std::cout << count << std::endl;
        }
}

Measured memory_bytes: 1160
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define INF 1e10
#define ull unsigned long long int
using namespace std;

/* TYPE DEFINITIONS */
typedef     long long int   ll;
typedef     vector<ll>      vi;
typedef     pair<ll,ll>     pi;


/* Prime Checker!!! */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

/* MACROS */
#define  all(A)         (A).begin() , (A).end()
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)  
void solve()
{    
    int n;
    cin>>n;
    long double sum=0;
    ll mul=1;
    forn(i,n)
    {
        int a;
        cin>>a;
        sum+=(long double)1/a;
    }
    cout<<fixed<<setprecision(10)<<(long double)1/sum;
}   


int main()
{
    FastIO;
    ll t=1;
    //cin>>t;
    //double start_time = clock();
    while(t--)
    {
        solve();
    }
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll A, B, V, W, T;
  cin >> A >> V >> B >> W >> T;
  if(V <= W) {
    cout << "NO" << endl;
  } else {
    if(abs(A - B) <= T * (V - W)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

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

//ライブラリ始まり

//定数
//円周率
const double pi = 3.1415926535897932384;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//関数
//ctoi
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}
//素数判定
bool PN(int x) {
  if (x <= 1) return false; // 1や0,-1は素数ではない
  if (x == 2) return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) return false; // 割れたら素数じゃない
  }
  return true;
}
// A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。
ll modpow(ll A, ll N, ll M) {
  long long ans = 1;
  while (N > 0) {
    if (N & 1) ans = ans * A % M;
      A = A * A % M;
      N >>= 1;
   }
  return ans;
}

//ライブラリ終わり
  
//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int N;
  cin >> N;
  int S = 0;
  int M = INF;
  for (int i = 0; i < N; i++) {
    int T;
    cin >> T;
    S += T;
    if (T % 10 != 0) {
      M = min(M, T);
    }
  }
  if (M == INF) {
    cout << 0 << endl;
  }
  else {
    if (S % 10 == 0) {
      cout << S - M << endl;
    }
    else {
      cout << S << endl;
    }
  }
}

Measured memory_bytes: 3676
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<numeric>

using namespace std;

int main()
{
    int N, M, t, x, y;   cin >> N >> M;
    long long ans;
    vector<int> a(N), c(31,0);
    for(int i=0; i<N; i++)  cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());
    for(int i=30; i>=0; i--){
        for(int j=0; j<N; j++){
            if(a[j] >= pow(2,i))    c[30-i]++;
        }
    }
    t = 0;
    ans = 0;
    for(int i=0; i<=30; i++){
        x = c[i];
        for(int j=0; j<x; j++){
            a[j] /= 2;
            if(t + j >= M-1){
                for(int k=0; k<N; k++)  ans += a[k];
                cout << ans;
                return 0;
            }
        }
        t += x;
        if(i < 30) sort(a.begin(),a.end(),greater<int>());
    }
    for(int i=0; i<N; i++)  ans += a[i];
    cout << ans;
}

Measured memory_bytes: 4124
n, m , c = map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
for _ in range(n):
  l = list(map(int,input().split()))
  if sum([lis[i]*l[i] for i in range(m)]) + c >= 1:
    ans += 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define fi first
#define se second
#define mod 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
ll a[100005]={};
bool safe(ll x,ll y)
{
	if(abs(x-y)>1)
		return false;
	else
		return true;
}
int main()
{
	ios;
	ll f,k,i,g,pos=1,max1=1,j;
	cin>>k;
	a[1]=1;f=1;
	while(f<k)
	{
		a[1]++;
		i=1;g=0;
		while((i<max1&&!safe(a[i],a[i+1]))||(i<=max1&&a[i]==10))
		{
			g=1;
			a[i+1]++;
			i++;
		}
		if(g==1)
		{
			max1=max(max1,i);
			for(j=i-1;j>=1;j--)
				a[j]=max(a[j+1]-1,0ll);
		}
		f++;
	}
	for(i=max1;i>=1;i--)
		cout<<a[i];
	cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int N; cin >> N;
  int ans = 0;
  int A = 0, B = 0, BA = 0;
  for (int i = 0; i < N; i++) {
    string s; cin >> s;
    for (int j = 0; j < s.size()-1; j++) {
      if (s[j] == 'A' && s[j+1] == 'B') ans++; 
    }
    if (s[0] == 'B' && s[s.size()-1] == 'A') {
      BA++;
    } else if (s[0] == 'B') {
      B++;
    } else if (s[s.size()-1] == 'A') {
      A++;
    }
  }

  if (BA == 0) {
    ans += min(A, B);
  } else {
    if (A + B > 0) {
      ans += BA + min(A,B);
    } else {
      ans += BA-1;
    }
  }

  cout << ans << endl;
}



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

static const int N=100;
static const int INF=100000;

int n;
int M[N][N];

//初期化
int prim(){
  int u,minv;
  int d[N],p[N],color[N];
  for(int i=0;i<n;i++){
    d[i]=INF;
    p[i]=-1;
    color[i]=0;
  }
  
  d[0]=0;
  
  while(1){
    minv=INF;
    u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i] != 2){
        u = i;
        minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = 2;
    
    for(int v=0;v<n;v++){
      if(color[v] !=2 && M[u][v] != INF){
        if(d[v]>M[u][v]){
          d[v]=M[u][v];
          p[v]=u;
          color[v]=1;
        }
      }
    }
  }
  int sum=0;
  for(int i=0;i<n;i++){
    if(p[i] !=-1 ) sum += M[i][p[i]];
  }
  return  sum;
}

int main(){
  int e; 
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>e;
      M[i][j]=(e== -1)? INF : e;
    }
  }
  
  cout<<prim()<<endl;
  return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b ? a:b;}
ll min(ll a, ll b) {return a<b ? a:b;}


int main(void) {
    ll N;
    cin >> N;
    ll i, j;
    ll a[N+5];
    ll max=-INF, min=INF;
    ll maxid=-1, minid=-1;
    
    for(i=0; i<N; i++) {
        cin >> a[i];
        
        if(max<a[i]) {
            max=a[i];
            maxid=i;
        }
        
        if(min>a[i]) {
            min=a[i];
            minid=i;
        }
        
    }
    
    if(abs(max)>abs(min)) {
        pt(N*2-1);
        
        for(i=0; i<N; i++)
            pt(maxid+1 << " " << i+1);
        
        for(i=1; i<N; i++)
            pt(i-1+1 << " " << i+1);
        
    }else {
        pt(N*2-1);
        
        for(i=0; i<N; i++)
            pt(minid+1 << " " << i+1);
        
        for(i=N-1; i>=1; i--)
            pt(i+1 << " " << i-1+1);
    }
    
}







Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

long P = 10^^9+7;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];

    auto SS = readln.split.to!(int[]);
    auto TS = readln.split.to!(int[]);

    auto DP = new long[][](N+1, M+1);
    foreach (i; 1..N+1) {
        foreach (j; 1..M+1) {
            DP[i][j] = (DP[i][j-1] + DP[i-1][j] - DP[i-1][j-1] + P) % P;
            if (SS[i-1] == TS[j-1]) {
                (DP[i][j] += DP[i-1][j-1] + 1) %= P;
            }
        }
    }
    writeln((DP[N][M] + 1) % P);
}

Measured memory_bytes: 34752
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
int main(){
    int D,G;
    cin >> D >> G;
    vector < int > p(D);
    vector <int> c(D);
    for(int i=0;i<D;i++){
        cin >> p[i] >> c[i]; 
    }
    int sum;
    int aop;//amount of problem;
    bool ans = true;
    int minp = 10000;
    for(int bit=0;bit<(1<<D);bit++){
        bitset<10> s(bit);
        sum = 0;
        aop = 0;
        ans = true;
        for(int i = 0;i<D;i++){
            if(s.test(i)==1){//解き切る
                sum += p[i]*(i+1)*100 + c[i];
                aop += p[i];
            }
        }
        if(sum < G){
            int j = D-1;
            while(sum < G){
                if(s.test(j)==1){
                    j--;
                }
                else{
                    int nokori = ceil( double(G-sum) / ((j+1)*100));
                    if(nokori <= p[j]){
                        aop += nokori;
                        break;
                    }
                    else{
                        ans = false;
                        break;
                    }
                }
            }
        }
        if(ans == true && aop < minp){
            minp = aop;
        }     
        //bitが000000から111111...までまわるから
        //bitの1立ってる部分を解き切る
        //他の点数高い奴から解く
        //最大値を更新してって出す

    }
    cout << minp << endl;
        
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define sz(v) (int)v.size()
#define pb push_back

using namespace std;
int a,b;

int main(){
    cin >> a >> b;
    cout << (a-1)*(b-1) << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  ll n,P;
  cin >> n >> P;
  if(n == 1){
    cout << P << endl;
    return 0;
  }
  int t = 1000001;
  vi p(t, 1);
  p[0] = p[1] = 0;
  for(int i = 2; i < t; i++) if(p[i]) for(int j = i + i; j < t; j += i) p[j] = 0;
  int g = 1;
  rep(i, t){
    if(!p[i] || P % i != 0) continue;
    ll num = pow(i, n);
    if(P % num == 0){
      g *= i;
      P /= num;
      i--;
    }
  }
  cout << g << endl;
}

Measured memory_bytes: 4352
#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 << 30) - 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, m;
    cin >> n >> m;
    vector<P> v;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        v.push_back(P(a, b));
    }
    sort(all(v));
    ll ans = 0;
    priority_queue<ll> q;
    int id = 0;
    for (int i = m; i >= 0; i--) {
        while (id < n && v[id].first <= m - i) {
            q.push(v[id].second);
            id++;
        }
        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3696
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
#ifdef VC
#define scanf scanf_s
#endif
#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const ll mod = 998244353;
int n;
int ans = 0;

int main() {
	cin >> n;
	int lef = -1;
	forn(i) {
		int c;
		cin >> c;
		if (lef == c) {
			ans++;
			lef = -1;
		}
		else {
			lef = c;
		}

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

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

const int INF = 1e+9 * 2;
double eps = 1e-10;

int main() {
	string s, t(""), ans_c(""), ans_s("");
	map<string, int> cnt;
	getline(cin, s);
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == ' '){
			cnt[t]++;
			if(ans_s.length() < t.length())
				ans_s = t;
			t = "";
		}
		else{
			t += s[i];
		}
	}
	if(ans_s.length() < t.length())
		ans_s = t;
	int maxim = 0;
	for(auto it = cnt.begin(); it != cnt.end(); ++it){
		if(maxim < (*it).second){
			maxim = (*it).second;
			ans_c = (*it).first;
		}
	}
	cout << ans_c << " " << ans_s << endl;
	return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int l,r;
    cin>>l>>r;
    if(r/2019-l/2019)
        cout<<0<<endl;
    else
    {
        l%=2019;
        r%=2019;
        long long int ans=1e9;
        for(long long int i=l;i<=r;++i)
        {
            for(long long int j=i+1;j<=r;++j)
            {
                /*if(l==2020&&r==2021)
                {
                    cout<<l*r%2019<<endl;
                }*/
                ans=min(ans,i*j%2019);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int v[100000];
int d[100000];
struct test{
  int operator () (int a, int b){
    return b - a;
  }
};

int main(){
  int t = getInt();
  while(t --> 0){
    int n = getInt();
    int k = getInt();

    REP(i,n)
      v[i] = getInt();

    if(n <= k){
      puts("0");
      continue;
    }

    //sort(v, v+n);
    transform(v, v+n-1, v+1, d, test());
    sort(d, d+n-1);

    ll all = (ll)v[n-1] - (ll)v[0];
    REP(i, k-1)
      all -= d[n-i-2];

    printf("%lld\n",all);
  }
  return 0;
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  int N,K,A,i;cin>>N>>K;
  cout<<(N+K-3)/(K-1)<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace kyoupuro
{
    class MainClass
    {
        public static void Main()
        {
            MainClass mainClass = new MainClass();
            mainClass.Start();
        }

        void Start() {
            int N = int.Parse(Console.ReadLine());
            //var array = new List<int>(Console.ReadLine().Split('/').Select(int.Parse));
            const double rate = 380000d;
            double sum = 0;

            for (int i = 0; i < N;i++) {
                var line = Console.ReadLine().Split(' ').ToArray();
                if(line[1] == "JPY") {
                    sum += double.Parse(line[0]);
                } else {
                    sum += rate * double.Parse(line[0]);
                }
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13268
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String str=br.readLine();
        if(str.charAt(0)==str.charAt(str.length()-1)){
            System.out.println((str.length()%2==0) ? "First":"Second");
        }else{
            System.out.println((str.length()%2==0) ? "Second":"First");
        }
    }
}


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

int main() {
	int a, b;
	cin >> a >> b;
	if(a+b > a-b && a+b > a*b){
		cout << a+b;
	}
	else if(a-b > a*b){
		cout << a-b;
	}
	else{
		cout << a*b;
	}
	return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

constexpr int MAX_N = 51;
constexpr int MAX_K = MAX_N*MAX_N;
int N, K;

int dp[MAX_N][MAX_N][MAX_K];

signed main()
{
  cin >> N >> K;
  if(K == 0) {
    cout << 1 << endl;
    return 0;
  }

  dp[0][0][0] = 1;

  FOR(i,1,N+1) {
    REP(j,N+1) {
      REP(k,MAX_K) {
        if(k-2*j>=0) {
          dp[i][j][k] = (2*j+1)*dp[i-1][j][k-2*j] 
          + (j+1)*(j+1)*dp[i-1][j+1][k-2*j];
          if(j-1>=0) {
            dp[i][j][k] += dp[i-1][j-1][k-2*j];
          }
          dp[i][j][k] %= MOD;
        }
      }
    }
  }

  cout << dp[N][0][K] << endl;

  return 0;
}


Measured memory_bytes: 52096
use std::io::stdin;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let m: i32 = buf.trim().parse().unwrap();
    //let _m = 21;
    let ans;
    ans = 24 + (24-m);
    println!("{}",ans);
}


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

using namespace std;

const int N=1e5+10;

typedef vector<int> vec;

class RUQ
{
public:
    vec data;
    vec lazy;
    int n;
    const int INF=(1LL<<31)-1;

    RUQ(int _n)
    {
        data.resize(4*_n);
        lazy.resize(4*_n);
        for(n=1;n<_n;n<<=1);
        fill(data.begin(),data.end(),(1LL<<31)-1);
        fill(lazy.begin(),lazy.end(),-1);
    }

    void Down(int p,int l,int r)
    {
        if(lazy[p]==-1) return;
        data[p]=lazy[p];
        if(l+1<r)
        {
            lazy[p*2+1]=lazy[p];
            lazy[p*2+2]=lazy[p];
        }
        lazy[p]=-1;
    }

    int update(int p,int l,int r,int x,int a,int b)
    {
        Down(p,l,r);
        if(a>=r||b<=l) return data[p];
        if(a<=l&&r<=b)
        {
            lazy[p]=x;
            return data[p]=lazy[p];
        }
        int mid=(l+r)/2;
        return data[p]=min(update(p*2+1,l,mid,x,a,b),update(p*2+2,mid,r,x,a,b));
    }

    int query(int p,int l,int r,int a,int b)
    {
        if(a>=r||b<=l) return INF;
        Down(p,l,r);
        if(a<=l&&r<=b)
        {
            return data[p];
        }
        int mid=(l+r)/2;
        return min(query(p*2+1,l,mid,a,b),query(p*2+2,mid,r,a,b));
    }
};

int main()
{
    int n,q;

    while(scanf("%d %d",&n,&q)!=EOF)
    {

        RUQ ruq(n);
        while(q--)
        {
            int op,a,b,c;
            scanf("%d",&op);
            if(op)
            {
                scanf("%d %d",&a,&b);
                printf("%d\n",ruq.query(0,0,ruq.n,a,b+1));
            }else
            {
                scanf("%d %d %d",&a,&b,&c);
                ruq.update(0,0,ruq.n,c,a,b+1);
            }
        }
    }

    return 0;
}



Measured memory_bytes: 6020
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int d[2]={2,8},ans=-1;
vector<ll> s;

void func(int x,ll k){
  if(x!=0) s.push_back(k);
  if(x==18) return ;
  for(int i=0;i<2;i++) func(x+1,k*10+d[i]);
}

void func2(int x,ll k,int sum){
  if(k==1&&sum) ans=max(ans,sum);
  if(s[x]>k) return ;
  if(k%s[x]==0) func2(x,k/s[x],sum+1);
  if(x+1!=s.size()) func2(x+1,k,sum);
}

int main(){
  ll n;
  cin>>n;
  func(0,0);
  sort(s.begin(),s.end());
  //  for(int i=0;i<s.size();i++) cout<<s[i]<<endl;
  func2(0,n,0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 7260
Q=[]
while True:
    A=list(map(int,input().split()))
    if A==[0,0,0,0]:
        break
    else:
        Q.append(A)

for k in range(len(Q)):
    for i in range(100000):
        P=(Q[k][0]+i*Q[k][3])/Q[k][2]-Q[k][1]
        if P>=0:
            print(i)
            break


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int H,W;
    cin >> H >> W;
    vector<vector<char>>a(H,vector<char>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> a.at(i).at(j);
        }
    }
    for(int i=0;i<W+2;i++){
        cout<<'#';
    }
    cout<<endl;
    for(int i=0;i<H;i++){
        cout<<'#';
        for(int j=0;j<W;j++){
            cout << a.at(i).at(j);
        }
        cout <<'#'<< endl;
    }
    for(int i=0;i<W+2;i++){
        cout<<'#';
    }
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.append(0)
from collections import Counter
ca=Counter(a)
if max(ca.values())>2 or ca[0]>1 or ca[12]>1:
  print(0)
  exit()
elif ca[12]>0 and ca[11]>0:
  print(1)
  exit()
a.sort()
ans=a[0]
for i in range(2**n):
  aa=[0]
  for j in range(n):
    if (i>>j)&1:
      aa.append((24-a[j+1])%24)
    else:
      aa.append(a[j+1]%24)
  tmp=float('inf')
  aa.sort()
  for j in range(n):
    tmp=min(tmp,aa[j+1]-aa[j])
  tmp=min(tmp,24-aa[-1])
  #print(tmp,aa)
  ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 9380
#coding:UTF-8
class Node:
    def __init__(self,point):
        self.n=point
        self.left=None
        self.right=None
        
def insert(t,z):
    y=None
    x=t
    while x!=None:
        y=x
        if z.n<x.n:
            x=x.left
        else:
            x=x.right
    if y==None:
        return z
    else:
        if z.n<y.n:
            y.left=z
        else:
            y.right=z
        return t

def Pre(t,l):
    l.append(str(t.n))
    if t.left!=None:
        Pre(t.left,l)
    if t.right!=None:
        Pre(t.right,l)

def In(t,l):
    if t.left!=None:
        In(t.left,l)
    l.append(str(t.n))
    if t.right!=None:
        In(t.right,l)

def BST1(A,n):
    tree=None
    for i in range(n):
        if A[i]=="print":
            PreAns=[]
            InAns=[]
            Pre(tree,PreAns)
            In(tree,InAns)
            print(" "+" ".join(InAns))
            print(" "+" ".join(PreAns))
        else:
            z=Node(int(A[i].split(" ")[1]))
            tree=insert(tree,z)
            
if __name__=="__main__":
    n=int(input())
    A=[]
    for i in range(n):
        A.append(input())
    BST1(A,n)

Measured memory_bytes: 215576
#include<bits/stdc++.h>
using namespace std;
char a[1000001],b[1000001],c[1000001],la,lb;
int main()
{
	cin>>a>>b;
	la=strlen(a);lb=strlen(b);
	for(int i=0;i<la;i++)
	{
		c[i*2]=a[i];
	}
	for(int i=0;i<lb;i++)
	{
		c[(i+1)*2-1]=b[i];
	}
	for(int i=0;i<la+lb;i++)
	{
		cout<<c[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pp push_back
#define fr first
#define sc second

using namespace std;

int cnt[200020];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0) ,cout.tie(0);

    int n ;cin >> n;
    for(int i = 0;i < n - 1;i++){
        int x; cin >> x;
        cnt[x]++;
    }
    for(int i = 1;i <= n;i++)
        cout << cnt[i] << '\n';


    return 0;
}


Measured memory_bytes: 4340
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>

typedef long long LL;

using namespace std;

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

int main(void) {
	int x;
	cin >> x;
	int ans = 0;
	if (x == 1) {
		cout << 1;
		return 0;
	}
	for (int b = 2; b <= x; b++) {
		for (int p = 2; pow(b, p) <= x; p++) {
			ans = max(ans, (int)pow(b, p));
		}
	}
	cout << ans;
	return 0;
}

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

#define ll long long

const ll mod = 998244353;
int N, S, A[3001];
ll dp[3001][3001][3];

void solve() {
	cin >> N >> S;
	for (int i=0; i<N; ++i)
		cin >> A[i+1];
	dp[0][0][0] = 1;
	for (int i=1; i<=N; ++i) {
		for (int j=0; j<=S; ++j) {
			dp[i][j][0] += dp[i-1][j][0];
			dp[i][j][1] += dp[i-1][j][1];
			if (j == 0)
				dp[i][j][1] += dp[i-1][j][0];
			if (j >= A[i]) {
				dp[i][j][0] += dp[i-1][j-A[i]][0];
				dp[i][j][1] += dp[i-1][j-A[i]][1];
				if (j == A[i])
					++dp[i][j][1];	
			}
			dp[i][j][0] %= mod;
			dp[i][j][1] %= mod;
			dp[i][j][2] = (dp[i][j][1] + dp[i-1][j][2])%mod;
		}
	}
	cout << dp[N][S][2] << endl;
}


int main() {
	ios::sync_with_stdio(false);
	solve();
	return 0;
}


Measured memory_bytes: 214576
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 19 20:52:57 2020

@author: over-
"""


N, A, B=input().split()
N=int(N)
A=int(A)
B=int(B)

S=N//(A+B)
M=N%(A+B)
if M>A:M=A
ans=S*A+M

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std; 
#define all(c) c.begin(),c.end()
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ; 
typedef vector<int> vi;
#define mod 1000000007 
//bool good(ll d){
   
   
//}
int main()
{
   ios::sync_with_stdio(0);
   // cin.tie(0);
   int n,k;
   cin>>n>>k;
   vi v(n+1);
   REP(i,1,n)
   cin>>v[i];
   vector<int>dp(n+1,1e9);
dp[1]=0;
dp[0]=0;
   for(int i=2;i<=n;++i){
      for(int j=1;j<=min(k,i);++j){
          if(i-j>=1)
          dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
      }

   }
   cout<<dp[n];
 
   



    return 0;
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    long long q,h,s,d,n; cin>>q>>h>>s>>d>>n;
    long long quat=4*q,half=2*h,single=s,doub=d;
    long long cost[4]={2*quat,2*half,2*single,doub};
    sort(cost,cost+4);
    long long ans;
    if(cost[0]==doub&&cost[1]!=doub){
        ans=n/2*d;
        if(n%2==1) ans+=cost[1]/2;
    }else if(cost[0]==2*quat){
        ans=n*quat;
    }else if(cost[0]==2*half){
        ans=n*half;
    }else if(cost[0]==2*single){
        ans=n*single;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top,S[105];

void push(int x){
	S[++top]=x;
}

int pop(){
	top--;
	return S[top+1];
}

int ToInt(char *s){
	int res=s[0]-'0';
	for(int i=1;s[i]!=0;i++){
		res = res*10+s[i]-'0';
	}
	
	return res;
}

int main(){
	int a,b;
	top=0;
	char s[105];
	while(scanf("%s",s)!=EOF){
		if(s[0]=='+'){
			a=pop();
			b=pop();
			push(a+b);
		}else if(s[0]=='-'){
			b=pop();
			a=pop();
			push(a-b);
		}else if(s[0]=='*'){
			a=pop();
			b=pop();
			push(a*b);
		}else{
			/*atoi()???stdlib.h???????????°????°?????¬??????¢????????°?????¬??¢?????°????±????*/ 
//			push(atoi(s));

			push(ToInt(s));
			
		}
	}
	
	printf("%d\n",pop());
	
	return 0;
}

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

int main() {
    long long N,h,v,p;
    int a=1,ans=1,b=0;
    cin >> N;
    vector<long long> A(N),B(N,0);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        if(A.at(i)%2==0){
            if(A.at(i)%3!=0 && A.at(i)%5!=0) B.at(i)++;
        }
    } 
    
    for (int i = 0; i < N; i++){
        if(B.at(i)==1){
            ans=0;
            break;
        }
    }
    if(ans==1) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
import sys
N, Y = map(int, input().split())
 
for x in range(N+1):
  for y in range(N+1-x):
    z = N-(x+y)
    if z < 0: break
    elif 10000*x + 5000*y + 1000*z == Y:
      print(x,y,z)
      sys.exit()
 
print(-1,-1,-1)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
#include <cstdlib>
using namespace std;

int main()
{
	std::priority_queue<int> que;
	int N,M;
	int v ;
	cin >> N >> M ;

	for( int i = 0 ; i < N ; i++ ){
		cin >> v ;
		que.push(v) ;
	}
	for( int m = 0 ; m < M ; m++ ){
		v = que.top();
		que.pop();
		if ( v == 0 )
			break ;
		v /= 2 ;
		que.push(v) ;
	}

	long long sum = (long long)0;
	for( int i = 0 ; i < N; i++ )
	{
		sum += (long long)que.top();
		que.pop();
	}
	cout << sum << endl ;
}


Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main() {
    int n, r;   cin >> n >> r;
    if (n >= 10) {
        cout << r << endl;
        return 0;
    }
    else {
        cout << r + 100 * (10-n) << endl;
        return 0;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

struct Edge { lli v, c; };

lli n, m, s, t;
vector<Edge> ea[100001], eb[100001];

template<class T>
vector<lli> djk(const T& e, lli s) {
  vector<lli> d(n+1, 1e18);
  vector<bool> fix(n+1);

  using P = pair<lli, lli>;
  priority_queue<P, vector<P>, greater<P>> pq;
  d[s] = 0;
  pq.emplace(0, s);
  while (!pq.empty()) {
    P p = pq.top(); pq.pop();
    lli u = p.second;
    if (fix[u]) continue;
    fix[u] = true;
    for (const Edge& f : e[u]) {
      lli cv = f.c, v = f.v;
      if (!fix[v] && d[u] + cv < d[v]) {
        pq.emplace(d[u] + cv, v);
        d[v] = d[u] + cv;
      }
    }
  }
  return d;
}

int main() {
  cin >> n >> m >> s >> t;
  for (lli i=0; i<m; ++i) {
    lli u, v, a, b;
    cin >> u >> v >> a >> b;
    ea[u].push_back({v, a});
    ea[v].push_back({u, a});
    eb[u].push_back({v, b});
    eb[v].push_back({u, b});
  }

  auto da = djk(ea, s),
       db = djk(eb, t);

  vector<lli> dd(n+1);
  for (lli i=1; i<=n; ++i) dd[i] = da[i] + db[i];

  for (lli i=n-1; i>0; --i) dd[i] = min(dd[i], dd[i+1]);

  for (lli i=1; i<=n; ++i) cout << lli(1e15) - dd[i] << '\n';
  return 0;
}


Measured memory_bytes: 19140
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long int lld;
const lld MAX=300020;
const lld MOD=1000000007;
char s[MAX];
lld n,dp[MAX][4][10],alt[MAX],fin;
int main(){
    scanf(" %s",s);
    n=strlen(s);
    dp[0][3][3]=1;
    alt[n]=1;
    for(lld x=n-1;x>=0;x--) {
        alt[x]=alt[x+1];
        if(s[x]=='?') alt[x]*=2,alt[x]%=MOD;
    }
    for(lld x=0;x<n;x++){
        for(lld a=-2;a<=0;a++){
            for(lld b=-3;b<=3;b++){
                lld p=(s[x]=='0'||s[x]=='?'),q=(s[x]=='1'||s[x]=='?');
                //if(a==-3&&b==-3) prlldf("%d %d\n",p,q);
                if(p){
                    if(b+1-a>=3) dp[x+1][min(a,b-1) +3][b-1 +3]+=dp[x][a +3][b +3],dp[x+1][min(a,b-1) +3][b-1 +3]%=MOD;
                    else dp[x+1][a +3][b+1 +3]+=dp[x][a +3][b +3],dp[x+1][a +3][b+1 +3]%=MOD;
                }
                if(q){
                    if(min(a,b-1)<=-3) fin+=(alt[x+1]*dp[x][a +3][b +3])%MOD,fin%=MOD;
                    else dp[x+1][min(a,b-1) +3][b-1 +3]+=dp[x][a +3][b +3],dp[x+1][min(a,b-1) +3][b-1 +3]%=MOD;
                }
            }
        }
    }
    for(lld a=-2;a<=0;a++){
        for(lld b=-3;b<=0;b++){
            fin+=dp[n][a +3][b +3],fin%=MOD;
        }
    }
    printf("%lld\n",fin);
}


Measured memory_bytes: 96640
while True:
    H, W = input().split()
    if H == "0" and W == "0":
        break
    H = int(H)
    W = int(W)
    for i in range(H):
        if i == 0 or i == H - 1:
            for j in range(W):
                print("#", end="")
        else:
            for j in range(W):
                if j == 0 or j == W - 1:
                    print("#", end="")
                else:
                    print(".", end="")
        print()
    print()


Measured memory_bytes: 7004