akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
ll dp[111][111][5555];
int main() {
    int n,a;
    cin>>n>>a;
    vector<int> x(n);
    rep(i,n){
        cin>>x[i];
    }
    dp[0][0][0]=1;
//    for(int i=0;i<n;i++){
//        for(int j=0;j<n;j++){
//         for(int k=0;k<=5000;k++){
//             dp[i+1][j][k]+=dp[i][j][k];
//             if(k>=x[i]){
//                 dp[i+1][j+1][k]+=dp[i][j][k-x[i]];
//             }
//         }
//        }
//    }
sort(x.begin(),x.end());
ll c=max(x[n-1],a);

    for(int i=0;i<n;i++){
        for(int j=0;j<=i+1;j++){
            for(int k=0;k<=c*50;k++){
                dp[i+1][j][k]+=dp[i][j][k];
                if(k>=x[i]){
                    dp[i+1][j+1][k]+=dp[i][j][k-x[i]];
                }
            }
        }
    }




    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=dp[n][i][i*a];
    }
    cout<<ans<<endl;




    return 0;
}


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

int main(){
  int n,m,sum=0; cin>>n; int t[n];
  for(int i=0;i<n;i++){
    cin>>t[i];
    sum+=t[i];
  }
  cin>>m; int p[m],x[m];
  for(int i=0;i<m;i++)cin>>p[i]>>x[i];
  for(int i=0;i<m;i++){
    int ans=sum;
    ans=sum-t[p[i]-1]+x[i];
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k ;
  cin>>n>>k;
  int count = 0;
  int d;
  int a;
  vector<int>vis(n+1,0);
  while(k--){
    cin>>d;
    while(d--){
      cin>>a;
      vis[a] = 1;
  }
  }
    for(int i=1;i<n+1;i++){
      if(vis[i]==0){
        count++;
      }
    }
  
    cout<<count;
  return 0;
}

Measured memory_bytes: 3628
N, K = map(int, input().split())
ans = 0
# Dice
p_d = 1 / N
lst_dice = [int(i) + 1 for i in range(N)]
# Coin
p_c = 1 / 2


for p in lst_dice:
    j = 0
    while 2**j < K / p:
        j += 1
    # print(j)
    p_tmp = p_d * (1 / 2) ** j
    ans += p_tmp


print(ans)

Measured memory_bytes: 7064
fun main(args: Array<String>) {
    val n = readLine()!!.split(" ").map { it.toInt() }[0]
    var count:Long = 0
    for (i in 0..n){
        var iDouble = i.toDouble()
        val threeDouble = 3.toDouble()
        val fiveDouble = 5.toDouble()
        val threeAmari = iDouble % threeDouble
        val fiveAmari = iDouble % fiveDouble
        if (threeAmari != 0.toDouble()){
            if (fiveAmari != 0.toDouble()){
                count += i
            }
        }
    }
    println(count)
}

Measured memory_bytes: 36504
#include <stdio.h>
int main()
{
	int a, b ,c;
	int tmp;
	int i;

	scanf("%d %d %d", &a, &b, &c);

	for (i = 0; i <= 1; i++) {
		if (a > b) {
			tmp = a;
			a = b;
			b = tmp;
		}
		if (b > c) {
			tmp = b;
			b = c;
			c = tmp;
		}
	}


	printf("%d %d %d\n", a, b, c);
	
	return 0;
}


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

int main(){
    int r, d, x;
    cin >> r >> d >> x;
    int ans = 0;
    for(int i=0; i<10; i++){
        x = x*r-d;
        cout << x << endl;
    }
    return 0;
}

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

int main(void) {
    char c[2][3];
    cin >> c[0];
    cin >> c[1];
    if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]) cout << "YES";
    else cout << "NO";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
          
 
int main() {
    int a[3] , b = 1;
    cin >> a[0] >> a[1] >> a[2];
    sort( a , a + 3 );
    if ( a[0] != a[1] ) b++;
    if ( a[1] != a[2] ) b++;
    cout << b;
}



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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int A, B, K;
signed main() {
    cin >> A >> B >> K;
    for (int i = 100; i > 0; i--) {
        if (A % i == 0 && B % i == 0) {
            K--;
            if (K == 0) {
                cout << i << endl;
                return 0;
            }
        }
    }
}

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

#define ll                  long long
#define ld                  long double
#define pb                  push_back
#define mp                  make_pair
#define fi                  first
#define se                  second
#define all(c)              (c).begin(),(c).end()
#define for0(i, n)          for (ll i = 0; i < n; ++i)
#define for1(i, n)          for (ll i = 1; i <= n;++i)
#define for2(i, n)          for (ll i = 1; i < n; ++i)
#define for3(i, k, n)       for (ll i = k; i < n; ++i)
#define input(a, i, n)      for (int i = 0; i < n; ++i) {cin >> a[i]; }
#define output(a, i, n)     for (int i = 0; i < n; ++i) {cout << a[i] << ' '; }
//cout.precision(12);

using namespace std;

int64_t TN = 1;

void solve()
{
    int64_t n, k = 0;
    cin >> n;
    int64_t a[n], b[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; ++i) {
        if (a[i] == b[i]) k++;
        else k = 0;
        if (k == 3) {
            cout << "Yes";
            return;
        }
    }
    cout << "No";
}

int main()
{
    //cin >> TN;
    for (int i = 0; i < TN; ++i) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main() 
{
  int a,b,c,k;
  cin>>a>>b>>c;
  cin>>k;
  int i;
  for(i=0;i<k;i++)
  {
      if(a<b&&b<c)
      {
      cout<<"Yes";
      break;
      }
      else
      {
          if(a>=b)
          {
           b=b*2;
           
          }
          else if(b>=c)
          {
              c=c*2;
              
          }
      }
  }
  if(i==k&&(a<b)&&(b<c))
  cout<<"Yes";
  if(i==k&&(a>=b||b>=c))
  cout<<"No";
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define Endl endl
typedef long long ll;
const int MAXN = (int)1e5 + 5;
ll n, m, x, y;
bool cmp(const pair<ll, ll>& a, const pair<ll, ll>& b)
{
	if (a.first == b.first)
		return a.second < b.second;
	else
		return a.first > b.first;
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> n >> m)
	{
		vector<pair<ll, ll>> v;
		for (int i = 1; i <= n&&cin >> x >> y; ++i)
			if (x <= m)
				v.emplace_back(x, y);
		sort(v.begin(), v.end(), cmp);
		ll sum = 0, d = 0;
		priority_queue<ll, vector<ll>, greater<ll>> pq;
		for (auto i : v)
		{
			if (d + i.first <= m&&pq.size() < m)
				d++;
			else
				pq.pop();
			pq.emplace(i.second);
		}
		while (!pq.empty())
			sum += pq.top(), pq.pop();
		cout << sum << endl;
	}
}
/*
3 4
4 3
4 1
2 6

3 4
4 3
4 1
2 2

5 3
1 2
1 3
1 4
2 1
2 3

1 1
2 1
*/

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  for(int i = 0; i < n; i++) {
      cin >> A[i];
  }
  sort(A.begin(), A.end());
  int sum = 0;
  for(int i = 0; i < k; i++) {
    sum += A[i];
  }
  cout << sum << endl;

}

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

int main() {
    int a,b; cin >> a >> b;
    if(a>b)cout << "a > b" << endl;
    else if(a<b)cout << "a < b" << endl;
    else cout << "a == b" << endl; 

    return 0;
}


Measured memory_bytes: 3104
import itertools
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]

if M==0:
    print(0)
    exit()

ans = 0
for ptn in itertools.product([1,-1],repeat=3):
    results = []
    for row in src:
        results.append(sum([m*a for m,a in zip(ptn,row)]))
    ans = max(ans, sum(sorted(results)[-M:]))
print(ans)

Measured memory_bytes: 3284
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    REP(i, n) cin >> a[i];
    if (n % 2 == 0) {
        REP(i, n / 2) {
            b[i] = a[n - i * 2 - 1];
            b[n / 2 + i] = a[i * 2];
        }
    } else {
        REP(i, n / 2) {
            b[i] = a[n - i * 2 - 1];
            b[n / 2 + i + 1] = a[i * 2 + 1];
        }
        b[n / 2] = a[0];
    }
    REP(i, n - 1) {
        cout << b[i] << " ";
    }
    cout << b[n - 1] << endl;
}


Measured memory_bytes: 3712
N, A, B, C, D = map(int, input().split())

if N%A == 0:x = N//A *B    
else:       x = (N//A +1) *B

if N%C == 0:y = N//C *D
else:       y = (N//C +1) *D

if x<=y: print(x)
else:    print(y) 


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define mod 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a;
    cin>>a;
    cout<<a+(a*a)+(a*a*a);
    return 0;
}

Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353LL
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
#define ll long long
long double dp[160][1000] = {};
long double calc_area(long double back_y, long double next_y, long double h) {
	if (back_y > next_y) swap(back_y, next_y);
	long double ans = 0;
	if (back_y == h) {
		ans += (next_y - h) / (long double)2.00;
	}
	else if (back_y < h) {
		if (next_y <= h) {
			ans += (h - next_y);
			ans += (next_y - back_y) / 2.00;
		}
		else {
			h -= back_y;
			next_y -= back_y;
			back_y = 0;
			long double crossing = h / (next_y - back_y);
			ans += h * crossing / 2.00;
			ans += (next_y - h) * (1.00 - crossing) / 2.00;
		}
	}
	else if (back_y > h) {
		ans += (back_y-h);
		ans += (next_y - back_y) / 2.00;
	}
	return ans;
}
int main(){
	int n;
	cin >> n;
	REP(i, 160) {
		REP(q, 1000) {
			dp[i][q] = LONG_INF;
		}
	}
	dp[0][1] = 0;
	REP(i, n) {
		double border = 0;
		cin >> border;
		REP(q, 300) {
			if (q == 0) continue;
			REP(j, 300) {
				if (j == 0) continue;
				double back_y = q;
				double next_y = j;
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][q] + calc_area(back_y, next_y, border));
			}
		}
	}
	long double ans = LONG_INF;
	REP(i, 1000) {
		ans = min(ans, dp[n][i]);
	}
	cout << fixed << setprecision(10);
	cout << ans << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;
template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}

int main(int argc, char *argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG = 1;}
  
  int N; cin>>N;
  string s; cin>>s;

  int right = N-1;
  int count = 0;
  REP(left,N){
    if(s[left]=='W'){
      while(s[right]!='R' && left<right){
        --right;
      }
      if(s[right]=='R'){
        ++count;
        s[left] = 'R';
        s[right] = 'W';
      }else{
        break;
      }
    }
  }
  cout << count << "\n";
}

Measured memory_bytes: 3724
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

const int maxn=1e3+20;

ll x[maxn],y[maxn];
int n;
int X[maxn],Y[maxn];
int m;
ll d[maxn],suf[maxn];

inline void init()
{
	n=read();
	REP(i,1,n)x[i]=read(),y[i]=read();
	int t=0;
	t=x[1]+y[1]&1;
	REP(i,2,n)if(x[i]+y[i]-t&1)puts("-1"),exit(0);
	REP(i,0,30)d[++m]=1<<30-i;
	if(!t)d[++m]=1;
	DREP(i,m,1)suf[i]=suf[i+1]+d[i];
	printf("%d\n",m);
	REP(i,1,m)printf("%d ",d[i]);puts("");
}

inline void doing()
{
	REP(i,1,n)
	{
		REP(j,1,m)
		{
			if(abs(x[i]-d[j])+abs(y[i])<=suf[j+1])x[i]-=d[j],putchar('R');
			else if(abs(x[i]+d[j])+abs(y[i])<=suf[j+1])x[i]+=d[j],putchar('L');
			else if(abs(x[i])+abs(y[i]-d[j])<=suf[j+1])y[i]-=d[j],putchar('U');
			else y[i]+=d[j],putchar('D');
		}
		puts("");
	}
}

int main()
{
	init();
	doing();
	return 0;
}



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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

static const int MAX = 100000;
static const int BLACK = -1;
static const int WHITE = 0;
static const int GLAY = 1;
static const int INFTY = 1e9;

int n;
vector<pair<int, int>> adj[MAX];

void pdai(){
	priority_queue<pair<int, int>> PQ;
	int d[MAX];
	int color[MAX];
	rep(i, n){
		d[i] = INFTY;
		color[i] = WHITE;
	}
	PQ.push(make_pair(0, 0));
	color[0] = GLAY;
	d[0] = 0;
	while(!PQ.empty()){
		pair<int, int> f = PQ.top();PQ.pop();
		int u = f.second;
		color[u] = BLACK;
		if(d[u] < f.first*(-1)) continue;
		for(int i = 0; i < adj[u].size(); i++){
			int v = adj[u][i].first;
			if(color[v] != BLACK && d[v] > d[u] + adj[u][i].second){
				d[v] = d[u] + adj[u][i].second;
				PQ.push(make_pair(d[v]*(-1), v));
				color[v] = GLAY;
			}
		}
	}
	rep(i, n){
		if(d[i] == INFTY) d[i] = -1;
		cout << i << " " << d[i] << endl;
	}
}

int main(){
	cin >> n;
	int u, k, v, c;
	rep(i, n){
		cin >> u >> k;
		rep(j, k){
			cin >> v >> c;
			adj[u].push_back(make_pair(v, c));
		}
	}
	pdai();
}



Measured memory_bytes: 10076
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
// Fraction a/b, where b > 0. Ensure |a|, |b| < 2^31.
struct Fraction {
	ll a, b;
	Fraction() : Fraction(0) {}
	Fraction(ll x) : a(x), b(1) {}
	Fraction(ll _a, ll _b) : a(_a), b(_b) {
		assert(b != 0);
		if (b < 0) {
			b = -b;
			a = -a;
		}
		ll g = __gcd(abs(a), b);
		a /= g;
		b /= g;
	}
	friend bool operator==(const Fraction& a, const Fraction& b) { return a.a == b.a && a.b == b.b; }
	friend bool operator!=(const Fraction& a, const Fraction& b) { return !(a == b); }
	friend bool operator<(const Fraction& a, const Fraction& b) { return (__int128)a.a * b.b < (__int128)b.a * a.b; }
	friend bool operator>(const Fraction& a, const Fraction& b) { return b < a; }
	friend bool operator<=(const Fraction& a, const Fraction& b) { return a < b || a == b; }
	friend bool operator>=(const Fraction& a, const Fraction& b) { return b < a || a == b; }
	friend Fraction operator+(Fraction a, const Fraction& b) { return Fraction(a.a * b.b + b.a * a.b, a.b * b.b); }
	friend Fraction operator-(Fraction a, const Fraction& b) { return Fraction(a.a * b.b - b.a * a.b, a.b * b.b); }
	friend Fraction operator*(Fraction a, const Fraction& b) { return Fraction(a.a * b.a, a.b * b.b); }
	friend Fraction operator/(Fraction a, const Fraction& b) { return Fraction(a.a * b.b, a.b * b.a); }
	Fraction& operator+=(const Fraction& f) { return *this = *this + f; }
	Fraction& operator-=(const Fraction& f) { return *this = *this - f; }
	Fraction& operator*=(const Fraction& f) { return *this = *this * f; }
	Fraction& operator/=(const Fraction& f) { return *this = *this / f; }
	friend ostream& operator<<(ostream& os, const Fraction& x) { return os << x.a << "/" << x.b; }
};
int main() {
	int n;
	scanf("%d", &n);
	vector<pair<int, int>> vec;
	ll suma = 0;
	for (int i = 0; i < n; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		suma += a;
		vec.emplace_back(max(a, b), b);
	}
	sort(vec.begin(), vec.end(), greater<pair<int, int>>());
	ll sumab = 0;
	int k;
	for (k = 0; k < n; ++k) {
		sumab += vec[k].first;
		if (sumab >= suma) break;
	}
	Fraction ret = n;
	for (int i = 0; i < n; ++i) {
		ll rem = sumab - vec[min(i, k)].first;
		assert(rem < suma);
		if (rem + vec[i].second >= suma) {
			ll fr = suma - rem;
			assert(fr <= vec[i].second);
			ret = min(ret, k + Fraction(fr, vec[i].second));
		}
	}
	ret = 1 - ret / n;
	printf("%lld %lld\n", ret.a, ret.b);
}


Measured memory_bytes: 1400
prime = [1]*(100001)
prime[0] = 0
prime[1] = 0
for i in range(2,100001):
    if prime[i]:
        for j in range(i*i,100001,i):
            prime[j] = 0

for i in range(100000,-1,-1):
    if prime[i]:
        if prime[(i+1)//2] != 1:
            prime[i] = 0

from itertools import accumulate
accum = list(accumulate(prime))

Q = int(input())
for _ in range(Q):
    l,r = map(int,input().split())
    print(accum[r]-accum[l-1])


Measured memory_bytes: 80228
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

long long int a = 0, b = 0, c = 1, x = 0, y = 0, z = 0, maxy = -1, mini = 9999, counter = 0,startp=0,endp=0,checker=0;
std::vector<unsigned long long int> vec{}, vecsec{};
int iremono[100001];
std::vector<long long int>kinds{}, ans{}, kaku{};
char moji;
bool okada = false,okada2=false;
std::string output, output2, input, one, two;
char cutcount[201];
int kakunou2[50][50] = {};

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int main()
{
	cin >> a>>b;
	x=pow(2, b);
	cout << ((a - b) * 100 + 1900 * b)*x << endl;
}

	
	





Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, D = MI()
    D2 = pow(D, 2)

    cnt = 0
    for i in range(N):
        x, y = MI()
        d2 = pow(x, 2) + pow(y, 2)

        if d2 <= D2:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9256
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9+5;

void solve(){
    int n;
    cin>>n;
    vector<int>a(n),dp(n,INF);
    for(int i=0;i<n;i++){
        cin>>a[i];        
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j:{i+1,i+2}){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}

int main(){
    // int t;
    // cin>>t;
    // while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>

using namespace std;

#define rep(p,q) for(int i = p;i < q;i++)

vector<pair<int, int>> index = vector<pair<int, int>>();



int main(void) {

	int n;


	cin >> n;

	vector<int> b = vector<int>();
	vector<int> ans = vector<int>();
	rep(0, n) {
		int num;
		cin >> num;
		b.push_back(num);
	}
	rep(0, n) {
		for (int j = b.size() - 1; 0 <= j; j--) {
			if (b[j] == j + 1) {
				vector<int>::iterator it = ans.begin();
				ans.insert(it,b[j]);
				vector<int>::iterator itb = b.begin();
				b.erase(itb + j);
				break;
			}
		}
	}

	if (ans.size() == n) {
		rep(0, n) cout << ans[i] << endl;
	}
	else cout << -1 << endl;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import itertools

N = int(input())
F = []
for i in range(N):
    F.append(list(map(int, input().split())))
P = []
for i in range(N):
    P.append(list(map(int, input().split())))

# 重複順列で自分の店の全パターンを出す
me_list = list(itertools.product([True, False], repeat=10))

# 初期値は利益の最小値
me_p = -float("inf")
# 自分の店の全パターンループ
for i in range(len(me_list)):

    # 一度も営業しないパターンを除く
    if not any(me_list[i]):
        continue

    tmp_p = 0
    # 他店の数でループ
    for j in range(N):

        cnt = 0
        # 月～金のAMPMループ
        for k in range(10):

            # 他店との営業重複カウント
            if me_list[i][k] and F[j][k]:
                cnt += 1
        
        # 各店舗との重複数に応じた利益を合算していく
        tmp_p += P[j][cnt]

    # 合算した利益を現状の最高値と比較して置き換えていく
    me_p = max(me_p, tmp_p)   

print(me_p)

Measured memory_bytes: 3188
/**
        	C++14 (GCC 5.4.1)
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main(){
    int A, B;

    cin >> A >> B;

    if(A / 10 == 0 && B / 10 == 0){
        cout << A * B <<endl;
     }
     else {
         cout << -1 << endl;
     }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <map>

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

using namespace std;

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

	int f[9][9];
	bool flag[9][9];
	map<int,int> ma;
	bool first = true;
	
	while(n--)
	{
		memset(f,0,sizeof(f));

		rep(i,9)
		{
			rep(j,9)
			{
				flag[i][j] = false;
			}
		}

		rep(i,9)
		{
			rep(j,9)
			{
				cin >> f[i][j];
			}
		}

		rep(i,9)
		{
			ma.clear();
			rep(j,9)
			{
				ma[f[i][j]-1]++;
			}

			rep(j,9)
			{
				if(ma[f[i][j]-1] > 1)
				{
					flag[i][j] = true;
				}
			}
		}
		
		
		rep(i,9)
		{
			ma.clear();
			
			rep(j,9)
			{
				ma[f[j][i]-1]++;
			}

			rep(j,9)
			{
				if(ma[f[j][i]-1] > 1)
				{
					flag[j][i] = true;
				}
			}
		}

		int count = 0;
		int x = 0,y = 0;
		while(count != 9)
		{
			ma.clear();
			REP(i,x,x+3)
			{
				REP(j,y,y+3)
				{
					ma[f[i][j]-1]++;
				}
			}

			REP(i,x,x+3)
			{
				REP(j,y,y+3)
				{
					if(ma[f[i][j]-1] > 1)
					{
						flag[i][j] = true;
					}
				}
			}

			if(x+2 == 8)
			{
				if(y+2 == 8)
				{
					break;
				}
				x = 0;
				y += 3;
			}
			else
			{
				x += 3;
			}
		}

		if(first)
		{
			first = false;
		}
		else
		{
			cout << endl;
		}

		rep(i,9)
		{
			rep(j,9)
			{
				if(flag[i][j])
				{
					cout << "*" << f[i][j];
				}
				else
				{
					cout << " " << f[i][j];
				}
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1196
use std::io::{stdin, Read};
use std::str::FromStr;
 
fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}
 
fn main() {
    let x: i64 = read().unwrap();
    let n: i64 = x / 100;
    let remained: i64 = x % 100;
    let mut a: i64 = remained;
    if remained <= 5 * n {
        println!("1");
    } else {
        println!("0");
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int L = sc.nextInt();
        int R = sc.nextInt();
        int d = sc.nextInt();

        int count = 0;
        for (int i = L; i <= R; i++) {
            count += i % d == 0 ? 1 : 0;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 35576
#include <stdio.h>

int main(){
  int k; // kこ連続して黒
  int x; // xは確実に黒
  int low=0,high=0;

  scanf("%d %d", &k,&x); // 3 7
  low = x -k +1; //5
  high = x+k -1; //9

  if(low < high){ //5<9
    while(low<=high){

      printf("%d ", low);
      low++;
    }
  }else{

    while(low>=high){

    printf("%d ", high);
        high++;
      }

  }

printf("\n");
return 0;
}


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

// マクロ //
#define rep(i,N) for(int i = 0; i < (int)(N); i++)
#define req(i,f,N) for(int i = f; i < (int)(N); i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using plili = pair<lint, lint>;
using vplili = vector<plili>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd_(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    int N;
    cin >> N;

    N %= 10;
    if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9) {
        cou("hon");
    }
    elif(N == 3) {
        cou("bon");
    }
    else {
        cou("pon");
    }


}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll N, K; cin >> N >> K;
    vll V(N); rep(i, N) cin >> V[i];

    ll maxn = -inf;
    for (ll x = 0; x <= min(N, K); x++) {
        // x: sum of a + b
        for (ll a = 0; a <= x; a++) {
            ll b = x - a;
            deque<ll> que(V.begin(), V.end());
            priority_queue<ll, vector<ll>, greater<ll>> pque;
            rep(i, a) pque.push(que.front()), que.pop_front();
            rep(i, b) pque.push(que.back()), que.pop_back();
            rep(i, K - x) if (pque.size() && pque.top() < 0) pque.pop();
            ll total = 0;
            while (pque.size()) total += pque.top(), pque.pop();
            maxn = max(maxn, total);
        }
    }
    cout << maxn << endl;
    return 0;
}

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

string longestRepeatedSubstring(string str) 
{ 
	int n = str.length(); 
	int LCSRe[n+1][n+1]; 

	memset(LCSRe, 0, sizeof(LCSRe)); 

	string res; 
	int res_length = 0; 
	int i, index = 0; 
	for (i=1; i<=n; i++) 
	{ 
		for (int j=i+1; j<=n; j++) 
		{ 
			if (str[i-1] == str[j-1] && 
				LCSRe[i-1][j-1] < (j - i)) 
			{ 
				LCSRe[i][j] = LCSRe[i-1][j-1] + 1; 

			
				if (LCSRe[i][j] > res_length) 
				{ 
					res_length = LCSRe[i][j]; 
					index = max(i, index); 
				} 
			} 
			else
				LCSRe[i][j] = 0; 
		} 
	} 


	if (res_length > 0) 
		for (i = index - res_length + 1; i <= index; i++) 
			res.push_back(str[i-1]); 

	return res; 
} 

int main() 
{ 
  	int n;
  	cin >> n;
	string str; 
	cin >> str;
	cout << longestRepeatedSubstring(str).size(); 
	return 0; 
} 


Measured memory_bytes: 97920
n = int(input())
s = []
for i in range(n):
    s.append(input())
s.sort()
# print(s)
m = 1
cnt = [1]
ans = []
for i in range(1,n):
    if s[i] == s[i-1]:
        cnt[-1] += 1
    else:
        if cnt[-1] > m:
            ans = [s[i-1]]
        elif cnt[-1] == m:
            ans.append(s[i-1])
        m = max(m, cnt[-1])
        cnt.append(1)
    if i == n-1 and cnt[-1] > m:
        ans = [s[i]]
    elif i == n-1 and cnt[-1] == m:
        ans.append(s[i])
print('\n'.join(ans))

Measured memory_bytes: 124288
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        long sum = 0;
        long res = Long.MAX_VALUE;
        for(int i = 0; i < n; i++) {
            A[i] = Integer.parseInt(sc.next());
            sum += A[i];
        }
        long tmp = 0;
        for(int i = 0; i < n-1; i++) {
            tmp += A[i];
            res = Math.min(res, Math.abs(2 * tmp - sum));
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 59668
import sys
f = sys.stdin
 
rhombus = oblong = 0
for line in f:
    a, b, c = map(int, line.split(','))
    if a == b:
        rhombus += 1
    if a * a + b * b == c * c:
        oblong += 1
 
print(oblong)
print(rhombus)


Measured memory_bytes: 5596
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      mut bs: [usize; n],
    }

    let mut ans = vec![];
    while bs.len() > 0 {
        let mut index = bs.len();
        for i in (0..bs.len()).rev() {
            if bs[i] == i+1 {
                ans.push(bs[i]);
                index = i;
                break;
            }
        }
        if index == bs.len() {
            return println!("{}", -1);
        }
        bs.remove(index);
    }
    ans.reverse();
    for a in ans {
        println!("{}", a);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const int ss=3e5+5;



 
int main()
{

    int t=1;
    // cin>>t;
    while(t--)
    {
        ll r,b,g;
        cin>>r>>b>>g;
        ll k;
        cin>>k;
        while(k and r>=b)
        {
            b*=2;
            k--;
        }
        while(k and b>=g)
        {
            k--;
            g*=2;
        }
        if(g>b and b>r)
        {
            cout<<"Yes";
        }
        else
        {
            cout<<"No";
        }

    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second

const int MAXn = 5005;
int deg[MAXn],mx[MAXn];
int fa[MAXn],dep[MAXn];
int ans,col[MAXn],pr[MAXn];
bool vis[MAXn];
vector<int> e[MAXn];
pair<int,int> d[MAXn],tmp[MAXn];
void dfs1(int x,int p){
    fa[x] = p;
    dep[x] = dep[fa[x]] + 1;
    for (auto i:e[x]) {
        if (i == p) continue;
        dfs1(i,x);
    }
}
int LCA(int x,int y){
    while (x != y) {
        if (dep[x] < dep[y]) swap(x,y);
        x = fa[x];
    }
    return x;
}
void dfs2(int x) {
    for (auto i:e[x]) {
        if (i == fa[x]) continue;
        dfs2(i);
        mx[x] += mx[i];
    }
    ans += min(mx[x],2);
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,m;
    cin >> n >> m;
    for (int i=0;i<n-1;++i) {
        int u,v;
        cin >> u >> v;
        e[u].emplace_back(v);
        e[v].emplace_back(u);
        deg[u]++, deg[v]++;
    }
    dfs1(1,0);
    for (int i=1;i<=m;++i) {
        cin >> d[i].X >> d[i].Y;
        tmp[i] = d[i];
        mx[d[i].X]++, mx[d[i].Y]++, mx[LCA(d[i].X,d[i].Y)] -= 2;
    }
    dfs2(1);

    for (int c=0;c<n-1;++c) {
        int now = 0;
        for (int i=2;i<=n;++i) {
            if (!vis[i] && deg[i] == 1) {
                now = i;
                break;
            }
        }
        vis[now] = true;
        int tmpfa = 0;
        for (auto i:e[now]) {
            if (!vis[i]) {
                tmpfa = i;
                break;
            }
        }

        deg[tmpfa]--;
        int ta = 0, tb = 0;
        for (int i=1;i<=m;++i) {
            if ((tmp[i].X == now) ^ (tmp[i].Y == now)) {
                if (ta == 0) ta = i;
                else tb = i;
            }
        }

        if (!ta && !tb) continue;
        if (!tb) {
            if (tmp[ta].X == now) tmp[ta].X = tmpfa;
            else tmp[ta].Y = tmpfa;
            continue;
        }
        if (tmp[ta].X == now) {
            if (tmp[tb].X == now) {
                tmp[ta].X = tmp[tb].Y;
                col[tb] ^= 1;
            }
            else tmp[ta].X = tmp[tb].X;
        }
        else {
            if (tmp[tb].Y == now) {
                tmp[ta].Y = tmp[tb].X;
                col[tb] ^= 1;
            }
            else tmp[ta].Y = tmp[tb].Y;
        }
        pr[tb] = ta;
        tmp[tb].X = tmp[tb].Y;
        for (int i=1;i<=m;++i) {
            if ((tmp[i].X == now) ^ (tmp[i].Y == now)) {
                if (tmp[i].X == now) tmp[i].X = tmpfa;
                else tmp[i].Y = tmpfa;
            }
        }
    }
    for (int i=1;i<=m;++i) {
        if (pr[i]) col[i] ^= col[pr[i]];
    }
    
    cout << ans << endl;
    for (int i=1;i<=m;++i) {
        if (col[i]) swap(d[i].X,d[i].Y);
        cout << d[i].X << " " << d[i].Y << endl;
    }
}


Measured memory_bytes: 4028
N = int(input())
S = str(N)
M = len(S)
dp = [[-1*10**9 for i in range(2)] for j in range(M + 1)]
dp[0][1] = 0
for i in range(M):
    for d in range(10):
        if d < ord(S[i]) - 48:
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + d, dp[i][1] + d)
        elif d == ord(S[i]) - 48:
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + d)
            dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + d)
        else:
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + d)

print(max(dp[M]))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>

using namespace std;

#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,n) FOR(i,0,n)

int n, m;
int v[100];

bool check(int x) {
	int cnt = 0, pos = 0;
	while (pos < n) {
		cnt++;
		int now = v[pos++];
		while (pos < n && now + v[pos] <= x) now += v[pos++];
	}
	
	return cnt <= m;
}

int main() {
	while (cin >> m >> n, n || m) {
		REP(i, n) scanf("%d", &v[i]);
		
		int r = 1500000, l = -1;
		
		REP(i, n) l = max(l, v[i] - 1);
		
		while (r - l > 1) {
			int mid = (r + l) / 2;
			if (check(mid)) r = mid;
			else l = mid;
		}
		
		cout << r << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1244
K = int(input())
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

S = K*(K+1)/2

for a in range(1,K):
    for b in range(a+1,K+1):
        S += 6*(math.gcd(a,b))

for i in range(1,K-1):
    for j in range(i+1,K):
        for k in range(j+1,K+1):
            S += 6*(gcd(i,j,k))

print(int(S))
            


Measured memory_bytes: 9656
#include <stdio.h>
#include <stdlib.h>

int euclid( int a, int b)
{
	int temp;
	if (a < b)
	{
		temp = a; a = b; b = temp;
	}
	if (b < 1)
	{
		return -1;
	}
	if (a % b == 0)
		return b;

	return euclid(b, a % b);
}

int main(void)
{
	char buf[4];
	char *str;
	int a, b, c, k, sum;
	int tmp;
	int count = 0;
	a = b = c = sum = 0;

	if (scanf("%3s", buf) != 1)
	{
		return 1;
	};
	str = buf;
	k = atoi(buf);
	for (a = 1; a <= k; a++)
	{
		for (b = 1; b <= k; b++)
		{
			for (c = 1; c <= k; c++)
			{
				tmp = euclid(a, b);
				tmp = euclid(tmp, c);
				sum += tmp;
			}
		}
	}
	printf("%d\n", sum);
	return (0);
}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main(){
  int n, m; cin >> n >> m;
  vector<int> a(m);
  int sum = 0;
  for(int i=0; i<m; i++) {cin >> a[i]; sum += a[i];}
  if (n < sum) cout << -1 << endl;
  else cout << n - sum << endl;

}

// EOF


Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main() {
	string str;
	cin >> str;
	char rec;
	int count = 0;
	rep(j, str.length()) {
		rec = str[j];
		rep(i, str.length()) {
			if (str[i] == str[j]) {
				count++;
			}
		}
		if (count % 2 != 0) {
			break;
		}
		count = 0;
	}
	if (count == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

template<typename T>
void print_old(vector<T>vec){
    for(int i=0; i< vec.size(); i++)
      cout<< vec[i]<<" ";
}
//  prints any type which supports iterators...
template <class T>
void print(T& c){
   for( typename T::iterator i = c.begin(); i != c.end(); i++ ){
      std::cout << *i << " ";
   }
   cout<< "\n";
}
// void f(const vector< int >& v) {
// int r = 0;
// tr(v, it) {
// r += (it)(*it);
// }
// return r;
// }
typedef vector< int > vi;
typedef pair< int,int > pii;
typedef vector<string> vs;
typedef vector<vi> vv;
#define sz(a) int((a).size())
#define pb push_back
#define forn(n) for(int i =0 ; i< n; i++)
#define all(c) c.begin(), c.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define ll long long
const int inf = 1e9 +5;


int main(){
    fastio;
   //  int t;
   //  cin>> t;
    int t = 1;
    while(t--){
      int n;
      cin>> n;
      int a, b,c;
      // cost when last selection was i is cost[i];
   vector<int> cost1(3,0);
    for(int day = 1; day <= n; day++){
        vector<int> da(3, 0);

     cin >> da[0] >> da[1] >> da[2];
     vector<int> cost_temp(3,0);

     for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
           if(j != i){
              cost_temp[j] = max(cost_temp[j], cost1[i] + da[j]);
           }
        }
        
     }
     cost1 = cost_temp;
     }

   int ans = max(cost1[0], cost1[1]);
   ans = max(ans, cost1[2]);
   cout<< ans << "\n";
   
     
        
    }
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
using namespace std;
int H, W; string S[100]; bool used[100][100];
void solve(int x, int y) {
	if (used[y][x]) { printf("LOOP\n"); return; } used[y][x] = true;
	switch (S[y][x]) {
		case '.': printf("%d %d\n", x, y); break;
		case '>': solve(x + 1, y); break;
		case '<': solve(x - 1, y); break;
		case 'v': solve(x, y + 1); break;
		case '^': solve(x, y - 1); break;
	}
}
int main() {
	while (true) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0) break;
		for (int i = 0; i < H; i++) cin >> S[i];
		for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) used[i][j] = false;
		solve(0, 0);
	}
	return 0;
}

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

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
#define DRT() int t; si(t); while(t--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//# define M_PI           3.14159265358979323846264338327950288
// DSU
void IO(){
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
}

int main(){
	IO();
	LL n,k;
	cin>>n>>k;
	LL t = ((n-1)*(n-2))/2;
	if(k > t){
		cout<<-1;
		return 0;
	}
	VVI g(n);
	rep(i,1,n){
		g[0].PB(i);
	}
	int how = t - k;
	int cnt = 0;
	rep(i,1,n){
		rep(j,i+1,n){
			if(cnt == how)
				break;
			g[i].PB(j);
			cnt++;
		}
		if(cnt == how)
			break;	
	}
	LL ed = 0;
	rep(i,0,n){
		ed += SZ(g[i]);
	}
	cout<<ed<<"\n";
	rep(i,0,n){
		for(auto it : g[i]){
			cout<<i+1<<" "<<it+1<<"\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3624
def questionnarie(a, m)
  dataset = m.times.map{ |x| [0, x+1]} # [生徒の投票数,場所の番号]
  # 投票数を数え上げる.
  a.each do |list|
    list.each_with_index do |x, i|
      dataset[i][0] += x
    end
  end
  # 投票数でソートする.
  # reverseを使わずにすむように、また投票数が同じ場合、番号順に並ぶようにsort_byを使う。
  puts dataset.sort_by{|votes, id| [-votes, id]}.map{|v, id| id}.join(' ')
end

if __FILE__ == $0
  loop do
    n, m = gets.split.map(&:to_i)
    break if n.zero? && m.zero?
    a = n.times.map{gets.split.map(&:to_i)}
    questionnarie(a, m)
  end
end

Measured memory_bytes: 6812