akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define REP2(i,n) for(int i=0;i<(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP4(i,m,n,s) for(int i=m;(s>0 and i<(int)(n)) or (s<0 and i>(int)(n));i+=s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define PIS(x) printf("%d ",x)
#define PN() putchar('\n')
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define MT make_tuple

using PII = pair<int, int>;
using TI3 = tuple<int, int, int>;
using LL = long long;
using ULL =  unsigned long long;
using MAT = array<array<LL, 2>, 2>;

template<class T> void _R( T &x ) { cin>>x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U>
void R( T& head, U&... tail ) {
    _R(head);
    R(tail...);
}

template<class T> void _print( const T &x ) { cout << x; }
void _print( const int &x ) { printf("%d", x); }
void _print( const LL &x ) { printf("%lld", x); }
void _print( const double &x ) { printf("%.16f\n",x); }
void _print( const char &x ) { putchar(x); }
void _print( const char *x ) { printf("%s",x); }
template<class T> void _print( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _print(*i++)) if (i != x.cbegin()) putchar(' '); }
void print() {}
template<class T, class... U> void print( const T& head, const U&... tail ) {
    _print(head);
    putchar(sizeof...(tail) ? ' ' : '\n');
    print(tail...);
}

const int MOD = 1000000007;
#define MAX_N 10005

int a[2][MAX_N];

int main()
{
    int n;
    R(n);
    REP(i, 2) {
        REP(j, n) {
            R(a[i][j]);
        }
    }
    REP(i, 1, n) {
        a[0][i] += a[0][i-1];
    }
    REP(i, n-2, -1, -1) {
        a[1][i] += a[1][i+1];
    }
    int ans = 0;
    REP(i, n) {
        ans = max(ans, a[0][i] + a[1][i]);
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  ll res = 0, mx = 0;
  for (int i = 0; i < N; i++) {
    ll A;
    cin >> A;
    if (i == 0) {
      res += A - 1;
      mx = 1;
      continue;
    }
    if (A <= mx + 1) {
      mx = max(mx, A);
    } else {
      res += (A - 1) / (mx + 1);
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXA 100000
#define MAXB 100000
#define MAXW 100000
int main(int argc,char const* argv[])
{
  int n,C;
  cin >> n >> C;
  int s[100000],t[100000],c[100000];
  int sm[200002],tt[200002];
  for(int i=0;i<n;i++)
    {
      cin >> s[i] >> t[i] >> c[i];	
    }
  for(int i=1;i<=C;i++)
    {
      for(int j=0;j<200002;j++)tt[j]=0;
      for(int j=0;j<n;j++)
	{
	  if(c[j]==i) tt[s[j]*2-1]++,tt[t[j]*2]--;
	}
      for(int j=1;j<200002;j++)tt[j]+=tt[j-1];
      for(int j=0;j<200002;j++) if(tt[j]>0)sm[j]++;
    }
  int mx=0;
  for(int j=0;j<200002;j++)
    {
      if(mx<sm[j])mx=sm[j];
    }
  cout << mx;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  string s;cin>>s;
  if(s[2]==s[3]&&s[4]==s[5])out("Yes");
  else out("No");

  return 0;
}


Measured memory_bytes: 256
'use strict'
const lines = require('fs').readFileSync(0, 'utf8').split('\n')
const N = parseInt(lines[0], 10)
const dp = {a:[],b:[],c:[]}
for (let i=1;i <= N;i++) {
  const abc = lines[i].split(' ')
  dp.a[i-1] = parseInt(abc[0], 10) + (i>1 ? Math.max(dp.b[i-2], dp.c[i-2]) : 0)
  dp.b[i-1] = parseInt(abc[1], 10) + (i>1 ? Math.max(dp.a[i-2], dp.c[i-2]) : 0)
  dp.c[i-1] = parseInt(abc[2], 10) + (i>1 ? Math.max(dp.b[i-2], dp.a[i-2]) : 0)
}
console.log(Math.max(dp.a[N-1], dp.b[N-1], dp.c[N-1]))

Measured memory_bytes: 31960
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-4-28 21:09:25
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
string S[310];
string T[310];

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    cin >> S[i];
  }
  int ans = 0;
  for (auto i = 0; i < N; i++)
  {
    T[i] = "";
    for (auto j = 0; j < N; j++)
    {
      T[i] += S[j][i];
    }
  }
  for (auto k = 0; k < N; k++)
  {
    bool ok = true;
    for (auto i = 0; i < N; i++)
    {
      if (T[i] != S[(i + k) % N])
      {
        ok = false;
        break;
      }
    }
    if (ok)
    {
      ans++;
    }
    for (auto i = 0; i < N; i++)
    {
      T[i] = T[i].substr(1, N - 1) + T[i].substr(0, 1);
    }
  }
  cout << ans * N << endl;
}

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

using namespace std;
typedef long long ll;

int main() {
    int A, B; cin >> A >> B;
    int res = 0;
    for (int i = 1; i <= max(A,B); i++){
        if (abs(A-i) == abs(B-i)) {
            res = i;
        }
    }
    if ( res == 0) cout << "IMPOSSIBLE" << endl;
    else
        cout << res << endl;
}


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

int main() {
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if ( (x<0) || (y<0)) {
        cout << "No" << endl;
        return 0;
    }
    if ( (W<x+r) || (0>x-r) ) {
        cout << "No" << endl;
        return 0;
    }
    if ( (H<y+r) || (0>y-r) ) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3096
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int N = stdIn.nextInt();
			int M = stdIn.nextInt();
			if(N == 0 && M == 0) {
				break;
			}
			int[] P = new int[N+1];
			for(int i = 0; i < N; i++) {
				P[i] = stdIn.nextInt();
			}
			P[N] = 0;
			int[] k = new int[(N+1)*(N+1)];
			//--- N^2 ---//
			for(int i = 0; i < N+1; i++) {
				for(int j = 0; j < N+1; j++) {
					k[i * N + j] = P[i] + P[j];
				}
			}
			
			Arrays.sort(k);
			int S = 0;
			IN:for(int j = 0; j < M; j++) {
				for(int i = 0; i < (N+1)*(N+1); i++) {
					if(Arrays.binarySearch(k, M-j-k[i]) >= 0) {
						System.out.println(M-j);
						break IN;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 49632
#include <bits/stdc++.h>
using namespace std;
string a;
int ans = 1 << 30; 
int main()
{
    cin >> a;
    for(int i = 1; i <= a.size() - 1;i++)
        if(a[i] != a[i-1])
            ans = min(ans, max(i, int(a.size())-i)); 
    cout << min(ans, int(a.size())) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n,m;
    cin >> n >> m;
    vi h(n);
    rp(i,n) cin >> h.at(i);
    matrix graph(n);
    rp(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    int ans=0;
    vector<int> seen(n,0);
    rp(i,n){
        if(seen[i]==0){
            bool ok=true;
            for(auto j:graph[i]){
                if(h.at(i)<=h.at(j)){
                    ok=false;
                    break;
                }
                seen[j]=1;
            }
            if(ok) ans++;
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 9856
n, k = map(int, input().split())
dp = {}

dp[(0, 0, 0)] = 1

def perm(i, j, k):
  if (i, j, k) in dp:
    return dp[(i, j, k)]
  
  if i < 0 or j < 0 or k < 0 or i < j:
    return 0
  
  dp[(i, j, k)] = ((j+j+1)*perm(i-1, j, k-2*j)\
                + (j+1)*(j+1)*perm(i-1, j+1, k-2*j)\
                +  1*perm(i-1, j-1, k-2*j))%(10**9+7)
  return dp[(i, j, k)]

print(perm(n, 0, k))

Measured memory_bytes: 23864
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

int main() {
    ll n,m;
    cin>>n>>m;
    vector<P> ans;
    if(n%2){
        for(ll l=1,r=n-1;l<r;l++,r--){
            ans.push_back(P(l,r));
        }
    }else{
        for(ll l=1,r=n-1;l<r;l++,r--){
            if(r-l>n/2)ans.push_back(P(l,r));
            else ans.push_back(P(l,r-1));
        }
    }
    rep(i,m)cout<<ans[i].first<<" "<<ans[i].second<<endl;
}


Measured memory_bytes: 5292
def main():
    cost_list = input().split()
    for i in range(len(cost_list)):
        cost_list[i] = int(cost_list[i])
    cost_list.sort()
    counter = 0
    for i in range(len(cost_list) - 1):
        counter += cost_list[i+1] - cost_list[i]
    print(counter)

main()

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
long long extgcd(long long a, long long b, long long &x, long long &y) {
  if(b == 0){
    x = 1; y = 0;
    return a;
  }
  long long d = extgcd(b, a%b, y, x);
  y -= (a / b) * x;
  return d;
}
//-----------------------------------------

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  ll a, b, x, y;
  cin >> a >> b;
  extgcd(a,b,x,y);
  cout << x << " " << y <<endl;




  return 0;
}



Measured memory_bytes: 3232
#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef long long int ll;
using namespace std;
const int M=1e9+7;
const int N=2e5+7;
#define F first
#define S second
#define pb push_back
int main()
{
    ll t=1;
    //cin>>t;
    while(t--)
    { 
   ll a,b;cin>>a>>b;
   cout<<a*b;
    }
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int a[3][103];
int main()
{
	int sum=-1;
	
	int n;
	 cin>>n;
	for(int i=1;i<=n;i++)
	  cin>>a[1][i];
	for(int i=1;i<=n;i++)
	  cin>>a[2][i];
	
	
		for(int i=1;i<=n;i++)
		{
			int ans1=0;
			int ans2=0;//记得清零 
			for(int j=1;j<=i;j++)
			{
				ans1=ans1+a[1][j];
			}
			for(int m=i;m<=n;m++)
			{
				ans2=ans2+a[2][m];
			}
			if(sum<(ans1+ans2)) sum=ans1+ans2;
		}
	cout<<sum<<endl;
	return 0;
} 

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	
	string s, t; cin >> s >> t;
	int n = s.size(), m = t.size();
	
	vector<vector<int>> dp(n + 1, vector<int>(m + 1));
	
	for (int i = n-1; i >= 0; --i) {
		for (int j = m-1; j >= 0; --j) {
			if (s[i] == t[j]) {
				dp[i][j] = 1 + dp[i+1][j+1];
			} else {
				dp[i][j] = max(dp[i+1][j], dp[i][j+1]);
			}
		}
	}

	string ans;
	
	int i = 0, j = 0;
	while (i < n && j < m) {
		if (s[i]==t[j]) {
			ans += s[i];
			i++;
			j++;
		} else {
			if (dp[i][j+1] > dp[i+1][j]) {
				++j;
			} else {
				++i;
			}
		}
	}
	
	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 35584
a,b = [int(i) for i in input().split()]

l = [int(i) for i in input().split()]

l2 = [i for i in l if i %2 == 1]

if not l2 :
    print(2**a if b % 2 == 0 else 0)
else:
    print(2**(a-1))

Measured memory_bytes: 3060
LL = input().split(" ")

LX = list(map(int,input().split()))
LY = list(map(int,input().split()))
	
LX.sort(reverse = True)
LY.sort()

CO = 0

for R in range(int(LL[2])+1,int(LL[3])):
	if LX[0]  >= LY[0]:
		break
	elif LX[0] <= R  <= LY[0] :
		print("No War")
		CO = 1
		break
		
if CO == 0:
	print("War")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <cassert>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
int main(){
	int A, B;
	cin >> A >> B;
	int ans;
	if(A >= 13){
		ans = B;
	}
	else if(A >= 6){
		ans = B / 2;
	}
	else{
		ans = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		System.out.println(Main.calc(s.nextInt(), s.nextInt()));
	}

	public static long calc(int a, int b) {
		return IntStream.rangeClosed(a, b).filter(Main::isPalindromic).count();
	}

	public static boolean isPalindromic(long num) {
		String str = String.valueOf(num);
		for (int i = 0; i <= str.length() - i; i++) {
			if (str.charAt(i) != str.charAt(str.length() - i - 1)) {
				return false;
			}
		}
		return true;
	}
}

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

int main(){
  long a,b,c;
  cin >> a >> b;
  c=0;
  if(a<b)
    cout << 0 << endl;
  else{
  vector<int> teki(a,0);
  for(int i=0;i<a;i++){
    cin >> teki[i];
  }
  sort(teki.begin(),teki.end(),greater<int>());
  for(int i=0;i<b;i++){
    teki[i]=0;
  }
    for(int i=0;i<a;i++){
      c=c+teki[i];
    }
    cout << c << endl;
  }
}
    


Measured memory_bytes: 1024
#include<iostream>
#include<string>

using namespace std;

int main(){

  int n;
  string s;
  int judge=0;
  bool flag=true;
  
  cin>>n;

  for(int i=0;i<n;++i){
    cin>>s;
    if(s=="A"){
      judge++;
    }
    else if(s=="Un"){
      judge--;
      if(judge<0)
	flag=false;
    }
  }
  if(flag==true && judge==0)
    cout<<"YES"<<endl;
  else if(flag==false || judge>0)
    cout<<"NO"<<endl;
}

Measured memory_bytes: 3080
n = int(input())
a = list(map(int, input().split()))
d = {}
for x in a:
    d[x] = d.get(x, 0) + 1
d = sorted(d.items(), key=lambda x: x[0], reverse=True)

l = []
ans = 0
for num, cnt in d:
    if cnt > 1:
        l.append(num)
        if len(l) == 2:
            ans = l[0] * l[1]
            print(ans)
            exit()
    if cnt > 3:
        ans = num ** 2
        print(ans)
        exit()

print(ans)

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

int Query(const std::string &a) {
	std::cout << "? " << a << std::endl;
	int x;
	std::cin >> x;
	return x;
}

const char C[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

int L, cnt[62];

std::string solve(int l, int r) {
	if (l + 1 == r) {
		return std::string(cnt[l], C[l]);
	}
	int md = (l + r + 1) >> 1;
	std::string s1(solve(l, md)), s2(solve(md, r));
	std::string s;
	int p1 = 0, p2 = 0;
	while (p1 < (int)s1.size() && p2 < (int)s2.size()) {
		std::string t = s + s1[p1] + std::string(s2.begin() + p2, s2.end());
		if (Query(t) == L - (int)t.size()) {
			s += s1[p1++];
		} else {
			s += s2[p2++];
		}
	}
	while (p1 < (int)s1.size()) {
		s += s1[p1++];
	}
	while (p2 < (int)s2.size()) {
		s += s2[p2++];
	}
	return s;
}

int main() {
	for (int i = 0; i < 62; ++i) {
		cnt[i] = 128 - Query(std::string(128, C[i]));
	}
	for (int i = 0; i < 62; ++i) {
		L += cnt[i];
	}
	std::string ans = solve(0, 62);
	std::cout << "! " << ans << std::endl;
}


Measured memory_bytes: 3756
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n; cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    int ma = -1, j = -1;
    rep(i, n) {
        if(chmax(ma, abs(a[i]))) {
            j = i;
        }
    }
    vector<P> ans;
    if(a[j] >= 0) {
        rep(i, n) {
            if(i == j) continue;
            if(a[i] < 0) {
                ans.pb(P{j, i});
            }
        }
    } else {
        rep(i, n) {
            if(i == j) continue;
            if(a[i] > 0) {
                ans.pb(P{j, i});
            }
        }
    }
    if(a[j] >= 0) {
        for(int i = 1; i < n; ++ i) {
            ans.pb(P{i - 1, i});
        }
    } else {
        for(int i = n - 1; i >= 1; -- i) {
            ans.pb(P{i, i - 1});
        }
    }
    cout << (int)ans.size() << endl;
    rep(i, (int)ans.size()) {
        cout << ans[i].fr + 1 << " " << ans[i].sc + 1 << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3676
/*
 * atcoder/abc127_2nd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
#include <map>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 */
int N, M;
vector<ll> A, C;
map<ll, ll> B;
void solve() {
  cin >> N >> M;
  A.resize(N);
  loop(n,0,N) cin >> A[n];
  sort(A.begin(), A.end());
  ll b, c;
  loop(m,0,M) {
    cin >> b >> c;
    B[c] += b;
  }
  for (auto&& b: B) C.push_back(b.first);
  sort(C.rbegin(), C.rend());

  // 1 4 5 5 7 8 13 33 52 100
  // 30 30 30 30 10 10 10 4
  int n = 0; c = 0;
  while (n < A.size() and c < C.size()) {
    ll &a = A[n];
    ll val = C[c]; ll &count = B[val];

    if (a >= val) break;
    a = val; count--;
    if (count==0) c++;
    n++;
  }
  ll total = 0;
  for (auto&&a: A) total += a;
  cout << total << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 8444
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int x1 = sc.nextInt();

		int y1 = sc.nextInt();

		int x2 = sc.nextInt();

		int y2 = sc.nextInt();


		int dx = x2 - x1;

		int dy  = y2 - y1;

		int x3 = x2 - dy;

		int y3 = y2 + dx;

		int x4 = x3 - dx;

		int y4 = y3 - dy;

		System.out.println(x3+" "+y3+" "+x4+" "+y4);

	}

}


Measured memory_bytes: 21716
N,M = map(int, input().split())
A = []
for _ in range(M):
    B = list(map(int, input().split()))
    A.append(B)
P = list(map(int, input().split()))
answer = 0

for i in range(2**N):
    p = [0]*N
    tmp = i
    for j in range(N):
        if tmp%2 == 1:
            p[j] = 1
        tmp //= 2
    flag = 0
    for j in range(M):
        count = 0
        for k in range(len(A[j])-1):
            if p[A[j][k+1]-1] == 1:
                count += 1
        if not count%2 == P[j]:
            flag = 1
    if flag == 0:
        answer += 1
    
print(answer)

Measured memory_bytes: 42608
def digitsum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

N = int(input())
summin = 10**5
for i in range(1,int(N/2)+1) : 
	A = i
	B = N - i

	sumab = digitsum(A) + digitsum(B)
	if (summin > sumab) :
		summin = sumab

print(summin)

Measured memory_bytes: 3060
N,M=[int(x) for x in input().rstrip().split()]
A=[int(x) for x in input().rstrip().split()]
sum_A=sum(A)
cnt=0
for i in range(len(A)):
    if 4*M*A[i]<sum_A:
        continue
    else:
        cnt+=1
if M<=cnt:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, maxi = 0;
	cin >> n;
	double s = 0;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		s += x;
		maxi = max(maxi, x);
	}
	s -= maxi / 2;
	cout << s;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)

def f(a, l, r)
    return false if l >= r
    i = l
    i += 1 until i > r || a[i] != a[l]
    return true if i > r
    return true if i > l + 1 && f(a, i, r)

    j = i
    loop do
        j += 1 until j > r || a[j] == a[l]
        break if j > r
        return true if f(a, i, j - 1) && g(a, j, r)

        j += 1 until j > r || a[j] != a[l]
        break if j > r
    end
    return false
end

def g(a, l, r)
    return true if l >= r
    i = l
    i += 1 until i > r || a[i] != a[l]
    return true if i > r
    return true if f(a, i, r)

    j = i
    loop do
        j += 1 until j > r || a[j] == a[l]
        break if j > r
        return true if f(a, i, j - 1) && g(a, j, r)

        j += 1 until j > r || a[j] != a[l]
        break if j > r
    end
    return false
end

puts f(a, 0, n - 1) ? 'yes' : 'no'




Measured memory_bytes: 8900
#include "bits/stdc++.h"
#define _CRT_SECURE_NO_WARNINGS
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define Pi pair<int,int>
#define IINF 1e9
#define LINF 1e18
#define vi vector<int>
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 0, 1,0,-1 };
int dy[] = { 1, 0,-1,0 };
int dx8[] = { -1,-1,-1,0,0,1,1,1 };
int dy8[] = { -1,0,1,-1,1,-1,0,1 };

unsigned long long sttoi(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

ull gcd(ull a, ull b) {
	if (b > a)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a%b);
}

int comb(int n, int k) {
	int ans = 1;
	for (int i = 0; i < min(k, n - k); i++) {
		ans *= n - i;
		ans /= i + 1;
	}
	return ans;
}

ll mod_pow(ll n, ll p, ll mod) {
	if (p == 0) return 1 % mod;
	if (p < 2) {
		return n % mod;
	}
	else {
		ll d = 2, value = (n%mod)*(n%mod) % mod;
		while (d * 2 < p) { d *= 2;	value *= value;	value %= mod; }
		value %= mod;
		return ((value%mod) * (mod_pow(n, p - d, mod) % mod)) % mod;
	}
}

bool isPrime(int n) {
	if (n <= 1)return false;
	if (n == 2)return true;
	if (n % 2 == 0)return false;
	for (int i = 3; i*i <= n; i += 2) {
		if (n%i == 0)return false;
	}
	return true;
}

void solve() {
	int n;
	cin >> n;
	int count = 0;
	vector<pair<int,int> > v;
	rep(i, n) {
		int a;
		cin >> a;
		v.push_back(mp(a,i%2));
	}
	sort(v.begin(), v.end());
	rep(i, n) {
		if (v[i].second != i % 2) {
			count++;
		}
	}
	P(count / 2);
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <cmath>
#include <limits>
#include <functional>
#include <algorithm>

using namespace std;

template<typename T, int VALUE_N>
class SegmentTree {
	const T INIT_VALUE;
	const function<T(T, T)> mergeFunc;
	const int LEAF_N = 1 << (int)(ceil(log2(VALUE_N)));
	const int NODES_N = LEAF_N * 2 - 1;
	vector<T> nodes;
	inline int leafIndex(int i) { return LEAF_N - 1 + i; }
	inline int parentIndex(int i) { return (i - 1) / 2; }
	inline int childLIndex(int i) { return 2 * i + 1; }
	inline int childRIndex(int i) { return 2 * i + 2; }
	// [a,b) query. current k node == [l,r)
	T query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INIT_VALUE;
		if (a <= l && r <= b) return nodes[k];
		int mid = (l + r) / 2;
		return mergeFunc(query(a, b, childLIndex(k), l, mid), query(a, b, childRIndex(k), mid, r));
	}
public:
	SegmentTree(T iniValue, function<T(T,T)> mergeF) : nodes(NODES_N), INIT_VALUE(iniValue), mergeFunc(mergeF) {
		for (int i = leafIndex(0); i < leafIndex(LEAF_N); i++) {
			nodes[i] = INIT_VALUE;
		}
		for (int i = parentIndex(leafIndex(LEAF_N - 1)); i >= 0; i--) {
			nodes[i] = mergeFunc(nodes[childLIndex(i)], nodes[childRIndex(i)]);
		}
	}
	void update(int valueI, T value) {
		int nodeI = leafIndex(valueI);
		nodes[nodeI] = value;
		while(nodeI > 0) {
			nodeI = parentIndex(nodeI);
			nodes[nodeI] = mergeFunc(nodes[childLIndex(nodeI)], nodes[childRIndex(nodeI)]);
		}
	}
	// [a,b) query
	T query(int a, int b) {
		return query(a, b, 0, 0, LEAF_N);
	}
};

int main() {
	using IntType = long long;
	constexpr IntType inf = ((IntType)1 << 31) - 1;
	constexpr int MAX_ELEM_NUM = 100001;
	SegmentTree<IntType, MAX_ELEM_NUM> s(inf, [](IntType l, IntType r) {return min(l, r); });
	int elemNum, queryNum;
	int com;
	IntType x, y;
	cin >> elemNum >> queryNum;
	for (int qI = 0; qI < queryNum; qI++) {
		cin >> com >> x >> y;
		switch (com) {
		case 0:
			s.update(x, y);
			break;
		case 1:
			IntType ret = s.query(x, y + 1);
			cout << ret << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 4792
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<cstdio>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef pair<ll,int> LL_IP;


#define ARRAY_MAX 101

int main(){


    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    double ans = -INF;
    int ans_water,ans_sugar;

    for(int i = 0;100*a*i <= f;i++){
        for(int j = 0;100*a*i+100*b*j <= f;j++){
            for(int k = 0;100*a*i+100*b*j+c*k <= f && c*k <= (a*i+b*j)*e;k++){
                for(int l = 0;100*a*i+100*b*j+c*k+d*l <= f && c*k+d*l <= (a*i+b*j)*e;l++){

                    int water = 100*a*i+100*b*j;
                    int sugar = c*k+d*l;
                    if(ans < 100*sugar/(double)(water+sugar)){
                        ans = 100*sugar/(double)(water+sugar);
                        ans_water = water;
                        ans_sugar = sugar;
                    }


                }
            }
        }
    }
    printf("%d %d\n",ans_water+ans_sugar,ans_sugar);


    return 0;
}

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

int main() {
  
  int A, B;
  cin >> A >> B;
  
  	if (A > B) {
      cout << A + A - 1 << endl;
    }
  	else if (A < B) {
      cout << B + B - 1 << endl;
    }
  	else {
      cout << A + B << endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  int R;
  cin >> R;
  
  if(N >= 10){
    cout << R << endl;
  }
    
    else{
      cout << R + 100 * (10 - N) << endl;
    }
  
}
      
  

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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

vector<string> split(string s, string t){
  vector<string> ret;
  int p = s.find(t);
  while(p != (int)s.npos){
    ret.emplace_back(s.substr(0, p));
    s = s.substr(p+(int)t.size());
    p = s.find(t);
  }
  ret.emplace_back(s);
  return ret;
}

signed main() {
  int N, K, C; 
  cin >> N >> K >> C;

  string s;
  cin >> s;

  vector<int> L, R;
  REP(i, N){
    if(s[i] == 'o'){
      L.emplace_back(i);
      i += C;
    }
  }
  RREP(i, N){
    if(s[i] == 'o'){
      R.emplace_back(i);
      i -= C;
    }
  }
  reverse(ALL(R));

  vector<int> ans;
  REP(i, L.size()){
    if(L[i] == R[i]) ans.emplace_back(L[i]+1);
  }

  if(ans.size() <= K){
    for(auto p : ans) cout << p << endl;
  }

  return 0;
}

Measured memory_bytes: 6644
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

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

  if (n%2 == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  ll a2 = 0, a5 = 0;
  for (ll x = 2; x <= (ll)1e18; x *= 2) {
    a2 += n/x;
  }
  for (ll x = 10; x <= (ll)1e18; x *= 5) {
    a5 += n/x;
  }
  
  if (n == (ll)1e18) ans++;


  cout << min(a2,a5) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n, i;
    int a[100];

    scanf("%d", &n);
    for(i = 0; i < n; i++){
       scanf("%d", &a[i]);
    }
    for(i = 0; i < n; i++){
       if(i)
           printf(" ");
       printf("%d", a[n - 1- i]);
    }
    puts("");
    return 0;
}

Measured memory_bytes: 1740
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

const int INF = 1e9;

int h, w;
vector<vector<char>> grid;
vector<vector<int>> dist;

void dfs(int y, int x, int d){
	if(dist[y][x] <= d) return;
	dist[y][x] = d;
	if(y == h-1 && x == w-1) return;
	if(x+1 < w && grid[y][x+1] == '#') dfs(y, x+1, d+1);
	if(y+1 < h && grid[y+1][x] == '#') dfs(y+1, x, d+1);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> h >> w;
	grid.resize(h, vector<char>(w));
	dist.resize(h, vector<int>(w, INF));
	int cnt = 0;
	rep(i,h)rep(j,w){
		cin >> grid[i][j];
		if(grid[i][j] == '#') cnt++;
	}
	if(grid[0][0] != '#'){
		cout << "Impossible" << endl;
		return 0;
	}
	dfs(0, 0, 1);
	if(cnt == dist[h-1][w-1]) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,b;
int main(){
	cin>>s;
	b=s;reverse(s.begin(),s.end());
	for(int i=0;i<s.size();i++)
		switch(s[i]){
			case 'b':s[i]='d';break;
			case 'd':s[i]='b';break;
			case 'p':s[i]='q';break;
			case 'q':s[i]='p';break;
		}
	s==b?puts("Yes"):puts("No");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stack>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <cmath>
#include <stdlib.h>
#include <unordered_map>
#define ll long long
using namespace std;
int a[100];
int main()
{
    int n;
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<a[2]*10+a[1]+a[0];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    if(N >= 10)cout << R << endl;
    else{
        int ans = R + 100*(10-N);
        cout << ans << endl;
    }

    return 0;
}

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

int main(void){
	int i,j,N,A[200005],temp,submax=0,max=0,count=-1;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	
	//max and submax決定
	for(i=0;i<N;i++){
		if(A[i]>max){
			max = A[i];
		}else{
			if(A[i] > submax){
				submax = A[i];
			}
		}
	}

	/* 最大値と等しい行数をカウント */
	for(i=0;i<N;i++){
		if(A[i]==max){
			count++;
		}
	}
	
	//出力処理
	for(i=0;i<N;i++){ 
		for(i=0;i<N;i++){
			if(A[i]!=max){
				printf("%d\n",max);
			}else{
				if(count>0){
					printf("%d\n",max);
				}else{
					printf("%d\n",submax);
				}
			}
		}
	}
}

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

typedef pair<int,int> P;

int main(){
  int s;
  cin >> s;
  int u = s/100;
  int l = s%100;
  if(1<=u&&u<=12){
    if(1<=l&&l<=12) cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }else{
    if(1<=l&&l<=12) cout << "YYMM" << endl;
    else cout << "NA" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<=m;i++)
#define read(n) cin>>n;
#define write(n) cout<<n;
using namespace std;
const int N=12;
int n,m;
int k,ans;
char c[N][1005];
//inline int cal(int al,int ar,int bl,int br){return (sum[bl][br]-sum[al-1][br]-sum[bl][ar-1]+sum[al-1][ar-1]);}
/*int dfs(int al,int ar,int bl,int br)
{
	if(vis[al][ar][bl][br])return dp[al][ar][bl][br];
	vis[al][ar][bl][br]=true;
	if(cal(al,ar,bl,br)<=k)return 0;
	int res=1e9;
	for(int i=al;i<bl;i++)
		res=min(res,dfs(al,ar,i,br)+dfs(i+1,ar,bl,br)+1);
	for(int i=ar;i<br;i++)
		res=min(res,dfs(al,ar,bl,i)+dfs(al,i+1,bl,br)+1);
	return dp[al][ar][bl][br]=res;
}*/
int check(int mask)
{
	int res=0,cnt[12],add=0;
	for(int i=0;i<12;i++)cnt[i]=0;
	for(int j=1;j<=m;j++)
	{
		int ji=0;
		add=0;
		bool flag=false;
		for(int i=1;i<=n;i++)
		{
			add+=c[i][j]-'0';
			if(mask&(1<<(i-1)))
			{
				if(cnt[ji]+add>k)flag=true;
				if(add>k)return 1e9;
				if(flag)break;
				cnt[ji++]+=add;
				add=0;
			}
		}
		if(cnt[ji]+add>k)flag=true;
		else cnt[ji]+=add;
		if(add>k)return 1e9;
		add=0;
		ji=0;
		if(flag)
		for(int i=1;i<=n;i++)
		{
			add+=c[i][j]-'0';
			if(mask&(1<<(i-1)))
				cnt[ji++]=add,add=0;
		}
		if(flag)cnt[ji]=add;
		res+=flag;
	}
	return res;
}
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>c[i][j];
	ans=1e9;
	for(int i=0;i<(1<<n);i++)
		ans=min(ans,check(i)+__builtin_popcount(i));
	cout<<ans<<"\n";
	return 0;
}

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

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int N, K;
  double sum = 0.0;
  double ans;
  cin >> N >> K;
  vector<int> p(N);
  rep(i, N)
    cin >> p[i];
  rep(i, K){
    sum += (double)(1+p[i])/2;
  };
  ans = sum;
  rep(i, N-K) {
    sum = sum-(double)(1+p[i])/2+(double)(1+p[i+K])/2;
    // cout << i << ' ' << sum << endl;
    if (ans < sum)
      ans = sum;
  }
  cout << setprecision(7) << ans << endl;
}


Measured memory_bytes: 1024
s = input()
a = int(s[:2])
b = int(s[2:])


if 1 <= a <= 12 and 1 <= b <= 12:
    print('AMBIGUOUS')
elif 1 <= a <= 12 and (b == 0 or b > 12):
    print('MMYY')
elif 1 <= b <= 12 and (a == 0 or a > 12):
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 9172
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

#define INF INT_MAX
vi seg;
int n;

void update(int index, int x) {
  seg[n + index] = x;
  for (int i = n + index; i >= 2; i /= 2) {
    seg[i/2] = min(seg[i], seg[i^1]);
  }
}

// seg[k] : [l, r)
int find(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) {
    return INF;
  }
  if (a <= l && r <= b) {
    return seg[k];
  } else {
    return min(find(a, b, k*2, l, (l+r)/2), find(a, b, k*2+1, (l+r)/2, r));
  }
}

int main() {
  int n_, q;
  scanf("%d %d", &n_, &q);
  n = (1 << (int)(ceil(log2(n_))));
  seg.assign(2*n, INT_MAX);
  int c, x, y;
  rep (i, q) {
    scanf("%d %d %d", &c, &x, &y);
    if (c == 0) {
      update(x, y);
    } else {
      printf("%d\n", find(x, y+1, 1, 0, n));
    }
  }

  return 0;
}

Measured memory_bytes: 4044
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
k = INT()
x = INT()
y = INT()

if n <= k:
    print(n * x)
else:
    print(k * x + (n - k) * y)


Measured memory_bytes: 5384
n,k  = map(int,input().split())
h = list(map(int,input().split()))

dp = [0]*(n+1)
dp[0] = 0

for i in range(1,n):
  dp[i] = dp[i-1] + abs(h[i]-h[i-1])
  for j in range(2,min(i+1,k+1)):
    dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))    
  #print(dp[i])
print(dp[n-1])

Measured memory_bytes: 84672
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		int a = sc1.nextInt();
		int b = sc1.nextInt();
		int t = sc1.nextInt();

		int ans = t / a * b;

		System.out.println(ans);

		sc1.close();

	}

}

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

#define MOD 1000000007
#define INF 1000000001

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


int main(int argc, char const *argv[]) {
    int N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }

    vector<vector<ll>> dp(N+1, vector<ll>(W+1, 0));
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= W; ++j) {
            dp[i][j] = dp[i-1][j];
            if (w[i-1] <= j){
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]] + v[i-1]);
            }
        }
    }
    cout << dp[N][W] << endl;

    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

struct COM {
    vector<ll> inv, fac, finv;
    COM(int N) : inv(N), fac(N), finv(N) {
        inv[1] = 1;
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        for (int i = 2; i < N; ++i) {
            inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
            fac[i] = fac[i - 1] * i % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    ll calc(int a, int b) {
        return (fac[a] * finv[b] % MOD) * finv[a - b] % MOD;
    }
};

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

    int S;
    cin >> S;
    COM com(S * 2);
    ll ans = 0;
    int cnt = 0;
    while (S >= 0) {
        cnt++;
        S -= 3;
        if (S < 0)
            break;
        ans += com.calc(S + cnt - 1, S);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


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

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

using namespace std;

//v.push_back(123);
//sort(v.begin(), v.end(),greater<int>());
//for(int x : v) {cout << x << endl;}

//for(int x: v) cout << x << endl;
//vector<vector<char>> v(H, vector<char>(W));
//vector<int> v(1000);

signed main(){
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int count = 0;
  rep(i, N/R+1){
    rep(j, N/G+1){
      if((N-i*R-j*G)%B==0 && (N-i*R-j*G)>=0){
        count++;
      }
    }
  }

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


Measured memory_bytes: 256
import sys
import math
import bisect
import heapq
from collections import defaultdict

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)

Measured memory_bytes: 3984