akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int coun[105][105][105];
vector<int>x,y,z;
int rx[52][2], ry[52][2], rz[52][2];
int a[52],b[52],c[52],d[52],e[52],f[52];
int n,m;

int compress1(){
	for(int i = 0;i < n;i++){
		x.push_back(a[0]);
		x.push_back(d[0]);
	}
	sort(x.begin(), x.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	for(int i = 0;i < n;i++){
		rx[i][0] = find(x.begin(),x.end(),a[i])-x.begin();
		rx[i][1] = find(x.begin(),x.end(),d[i])-x.begin();
	}
	return 0;
}

int main()
{
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++)
    {
      scanf("%d %d %d %d %d %d",&a[i],&b[i],&c[i],&d[i],&e[i],&f[i]);
       x.push_back(a[i]);
       x.push_back(d[i]);
       y.push_back(b[i]);
       y.push_back(e[i]);
       z.push_back(c[i]);
       z.push_back(f[i]);
    }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  sort(z.begin(),z.end());
  x.erase(unique(x.begin(),x.end()),x.end());
  y.erase(unique(y.begin(),y.end()),y.end());
  z.erase(unique(z.begin(),z.end()),z.end());
  for(int i=0;i<n;i++)
    {
      int r1=find(x.begin(),x.end(),a[i])-x.begin();
      int r2=find(x.begin(),x.end(),d[i])-x.begin();
      int r3=find(y.begin(),y.end(),b[i])-y.begin();
      int r4=find(y.begin(),y.end(),e[i])-y.begin();
      int r5=find(z.begin(),z.end(),c[i])-z.begin();
      int r6=find(z.begin(),z.end(),f[i])-z.begin();
      for(int i=r1;i<r2;i++)
    {
      for(int j=r3;j<r4;j++)
        {
          for(int k=r5;k<r6;k++)
        {
          coun[i][j][k]++;
        }
        }
    }
    }
  long long ans=0;
  for(int i=0;i<=100;i++)
    {
      for(int j=0;j<=100;j++)
    {
      for(int k=0;k<=100;k++)
        {
          if(coun[i][j][k]>=m)
        {
          long long s1=(x[i+1]-x[i]),s2=(y[j+1]-y[j]),s3=(z[k+1]-z[k]);
          ans+=s1*s2*s3;
        }
        }
    }
    }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 6620
#include <iostream>
#include <map>
#include <cstdio>
#include <cstring>
using namespace std;

int bit[400001] , N;
int num[400001];
int lst[400001];
map<int,int> xxx;


int add(int x,int a){
	while(x<=N){ bit[x]+=a; x += x & -x; }
}
int get(int x){
	int ans = 0;
	while(x) ans += bit[x] , x -= -x & x; 
	return ans;
}

int getPos(int num){
	int l = 1 , r = N;
	while(l != r){
		int m = (l+r) / 2;
		if(get(m) < num){
			l = m+1;
		}else{
			r = m;
		} 
	}
	return l;
}

int main(){
	int lim;
	while(scanf("%d%d",&N,&lim) && lim){
		memset(bit,0,sizeof(bit));
		memset(num,-1,sizeof(num));
		xxx.clear();
		int cur = 0 , head = 1;
		for(int i = 1 ; i <= N ; i++){
			
			int q,x;
			scanf("%d%d",&q,&x);
			if(q==0){
				xxx[x] = i;
				num[i] = x;
				add(i,1);
				cur++;
			}else if(q==1){
				num[getPos(x)] = -1;
				add(getPos(x),-1);
				cur--;
			}else if(q==2){
				printf("%d\n",num[getPos(x)]);
			}else if(q==3){
				add(xxx[x],-1);
				num[xxx[x]] = -1;
				cur--;
			}
			while(cur > lim){
				if(num[head] != -1){
					num[head] = -1;
					add(head,-1);
					cur--;
				}
				head++;
			}
		}
		puts("end");
	}
}

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

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

    for (int i=0; i<N; i++)
    {
        int x, y, b, p;
        cin>>x>>y>>b>>p;

        int p1 = x*b + y*p;
        int p2 = x*max(b,5) + y*max(p,2);
        p2 -= p2*2/10;
        cout<<min(p1,p2)<<endl;
    }
}

Measured memory_bytes: 1160
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil

(defun decompose (n prime-table)
  (map 'vector
       (lambda (p)
         (loop for i from 0
               do (multiple-value-bind (quot rem) (floor n p)
                    (if (zerop rem)
                        (setf n quot)
                        (return i)))))
       prime-table))

(defun count-4-4-2 (table)
  (let ((num2~3 (loop for i across table count (<= 2 i 3)))
        (num4~ (loop for i across table count (<= 4 i))))
    (+ (floor (* num2~3 num4~ (- num4~ 1)) 2)
       (floor (* num4~ (- num4~ 1) (- num4~ 2)) 2))))

(defun count-14-4 (table)
  (let ((num4~13 (loop for i across table count (<= 4 i 13)))
        (num14~ (loop for i across table count (<= 14 i))))
    (+ (* num14~ (- num14~ 1))
       (* num14~ num4~13))))

(defun count-24-2 (table)
  (let ((num2~23 (loop for i across table count (<= 2 i 23)))
        (num24~ (loop for i across table count (<= 24 i))))
    (+ (* num24~ (- num24~ 1))
       (* num24~ num2~23))))

(defun count-74 (table)
  (loop for i across table count (<= 74 i)))

(defun main ()
  (let* ((n (read))
         (prime-table (coerce (loop for x from 2 to n
                                    when (sb-impl::positive-primep x)
                                    collect x)
                              'vector))
         (factor-table (make-array (length prime-table) :element-type 'uint16)))
    (loop for k from 1 to n
          do (map-into factor-table #'+ factor-table (decompose k prime-table)))
    (println (+ (count-4-4-2 factor-table)
                (count-14-4 factor-table)
                (count-24-2 factor-table)
                (count-74 factor-table)))))

#-swank(main)


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

int main(){
	vector<vector<int>> grid(3, vector<int>(3));
  	int x[3], y[3];
  
  	for(int i = 0; i < 3; i++){
    	for(int j = 0; j < 3; j++){
        	cin >> grid.at(i).at(j);
        }
    }
  
  	x[0] = 0;
  	for(int i = 0; i < 3; i++){
    	y[i] = grid[0][i] - x[0];
    }
  	for(int i = 0; i < 3; i++){
    	x[i] = grid[i][0] - y[0];
    }
  	
  	bool judge = true;
  	for(int i = 0; i < 3; i++){
    	for(int j = 0;j < 3; j++){
        	if(x[i] + y[j] != grid[i][j]){
            	judge = false;
              	break;
            }
        }
      	if(judge == false){
        	break;
        }
    }
  	if(judge == false){
    	cout << "No" << endl;
    }else{
    	cout << "Yes" << endl;
    }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 61;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<double> A(n);
    rep(i, n) cin >> A[i];

    double bunbo = 0;
    rep(i, n) bunbo += 1 / A[i];

    cout << 1 / bunbo << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define c first
#define p second.first
#define k second.second
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> NP;
int n,m,l,a,b,d,e;
int E[101][101],D[101][101],an[101][101];

NP MP(int A,int B,int C){return NP(A,P(B,C));}

int main(){
  while(cin>>n>>m>>l,n){
    memset(D,-1,sizeof(D));
    for(int i=0;i<m;i++)
      cin>>a>>b>>d>>e, E[a][b]=E[b][a]=e, D[a][b]=D[b][a]=d;
    for(int i=0;i<=l;i++)
      for(int j=1;j<=n;j++)an[i][j]=100000000;

    priority_queue<NP, vector<NP>,greater<NP> > q;
    q.push(MP(0,1,l));
    while(!q.empty()){
      NP w=q.top();q.pop();
      if(an[w.k][w.p]<=w.c)continue;
      an[w.k][w.p]=w.c;
      for(int i=1;i<=n;i++){
	if(D[i][w.p]==-1)continue;
	if(w.k>=D[i][w.p])q.push(MP(w.c,i,w.k-D[i][w.p]));
	q.push(MP(w.c+E[i][w.p],i,w.k));
      }
    }
    int ans=1e9;
    for(int i=0;i<=l;i++)ans=min(ans,an[i][n]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 12088
#include<stdio.h>
#include<cstdlib>
#include<fstream>
#include<iostream>
#include<string>
#include<sstream>

using namespace std;

int main(){
    string S;
    string T;
    int ans=0;

    cin >> S;
    cin >> T;

    for (int i = 0; i < 3; i++){
        if(S[i]==T[i]){
            ans++;
        }
    }
    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var x = Abs(long.Parse(line[0]));
        var k = long.Parse(line[1]);
        var d = long.Parse(line[2]);
        getAns(x, k, d);
    }
    static void getAns(long x, long k, long d)
    {
        var t = x / d;
        if (t >= k) { Console.WriteLine(Abs(x - k * d)); return; }
        if ((k - t) % 2 == 0) Console.WriteLine(Abs(x - t * d));
        else Console.WriteLine(Abs(x - d * (t + 1)));
    }
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

// B

bool ok(ll A,ll B,ll C) {
  if( ( B > A ) && ( C > B ) ) return true;
  return false;
}

bool dfs(ll A,ll B,ll C, int rem) {
  if( ok(A,B,C) ) return true;
  if( rem <= 0 ) {
    return ok(A,B,C);
  }
  if( dfs(A*2LL, B, C, rem-1) ) return true;
  if( dfs(A, B*2LL, C, rem-1) ) return true;
  if( dfs(A, B, C*2LL, rem-1) ) return true;
  return false;
}

int main() {
  int A,B,C;
  int K;
  cin >> A >> B >> C;
  cin >> K;
  cout << ( dfs(A,B,C,K) ? "Yes" : "No" ) << endl;
  return 0;
}


Measured memory_bytes: 3648
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String ans = "APPROVED";
    for (int i = 0; i < N; i++) {
      int A = sc.nextInt();
      if (A % 2 == 0 && A % 3 != 0 && A % 5 != 0) ans = "DENIED";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23636
#Educational-DP A
n = int(input())
h = list(map(int,input().split()))

dp = [-1 for _ in range(n)]
dp[0] = 0

for i in range(1,n):
    if i > 1:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))  
    else:
        dp[i] = dp[i-1]+abs(h[i]-h[i-1])

#print(dp)
print(dp[-1])

Measured memory_bytes: 20536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner=new Scanner(System.in);
      long a=scanner.nextInt();
      long b=scanner.nextInt();
      long c=scanner.nextInt();
      long k=scanner.nextInt();
      long sum=0;
    
    	 if(k>=a&&(k-a-b)>c) {
    		 sum=a*1;
    		 k=k-a;
    	 }
    	 else if(k<a) {
    		 sum=k;
    	 }
    	 else if((k-a)<=b) {
    		 sum=a*1;
    	 }
    	 else if((k-a-b)<=c) {
    		 sum=a+(k-a-b)*(-1);
    	 }
    	System.out.println(sum);
    	 
     
   
	}

}

Measured memory_bytes: 35796
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll h, w;
ll c[10][10];
ll a[1000][1000];

int main() {
	cin >> h >> w;
	rep(i, 10)rep(j, 10)cin >> c[i][j];
	rep(k, 10) {
		rep(i, 10) {
			rep(j, 10) {
				c[i][j] = min(c[i][k] + c[k][j], c[i][j]);
			}
		}
	}
	ll ans = 0;
	rep(i, h)rep(j, w) {
		cin >> a[i][j];
		if (abs(a[i][j]) == 1)continue;
		ans += c[a[i][j]][1];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a;
	int b;
	int c;
	cin >> a >> b >> c;
	if ((a<=c and c<=b) or (b<=c and c<=a)){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import itertools

N = int(input())
L = [[int(l) for l in input().split()] for _ in range(N)]

ans = 0

l = [int(i) for i in range(N)]
for P in itertools.permutations(l):
    for i in range(1, N):
        ans += ((L[P[i-1]][0]-L[P[i]][0])**2 + (L[P[i-1]][1]-L[P[i]][1])**2)**0.5
        
def f(n):
    if n == 0:
        return 1
    else:
        return n*f(n-1)
    
print(ans/f(N))

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,k;
bool g[252][252];

int main(){
  scanf("%d%d",&n,&k);
  REP(b,9){
    int s = 1<<b;
    REP(i,n)if(i!=s && (i&s)){
      g[min(i,s)][max(i,s)] = true;
    }
  }
  int m = 0;
  REP(i,n)REP(j,n)if(g[i][j])m++;
  printf("%d\n",m);
  REP(i,n)REP(j,n)if(g[i][j])printf("%d %d\n",i+1,j+1);
  fflush(stdout);

  REP(_,k){
    int ans = 0;
    REP(b,9){
      int s = 1<<b;
      if(s>=n)break;
      printf("%d\n",s+1);fflush(stdout);
      char buf[10];
      scanf("%s",buf);
      if(buf[0]=='Y'){
        ans = -1; break;
      }else if(buf[1]=='e'){
        ans ^= s;
      }
    }
    if(ans != -1){
      printf("%d\n",ans+1);fflush(stdout);
      char buf[10];
      scanf("%s",buf);
      assert(buf[0]=='Y');
    }
  }
  return 0;
}



Measured memory_bytes: 3344
#include <iostream>
using namespace std;
string s;
int a, b, c;
int main() {
    cin >> s;
    for(int i = 0 ; i < (int)s.size() ; i++){
        if(s[i] == 'a')
            a++;
        else if(s[i] == 'b')
            b++;
        else
            c++;
    }
    if(abs(a-b) <= 1 && abs(b-c) <= 1 && abs(c - a) <= 1)
        cout << "YES";
    else
        cout << "NO";
	return 0;
}


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

using namespace std;

int main(){
  int i,j,n,m,x,a=0,b=0;
  vector <int> v;
  
  cin>>n>>m>>x;
  for(i=0;i<n+1;i++){
     v.push_back(0);
  }
  
  for(i=0;i<m;i++){
    cin>>j;
    v[j]=1;
  }
  
  for(i=x;i<n+1;i++){
    if(v[i]==1)
      a++;
  }
  
  for(i=x;i>=0;i--){
    if(v[i]==1)
      b++;
  }
  
  cout<<min(a,b)<<endl;
   
  
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef priority_queue<int> pqb;
typedef priority_queue<int, vi, greater<int> > pqs;

#define iamtheflash         ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod                 1000000007
#define debug1(x)           cout<<"#x: "<<x<<"\n"
#define debug2(x,y)         cout<<"#x: "<<x<<" #y: "<<y<<"\n"
#define debug3(x,y,z)       cout<<"#x: "<<x<<" #y: "<<y<<" #z: "<<z<<"\n"
#define debug4(x,y,z,w)     cout<<"#x: "<<x<<" #y: "<<y<<" #z: "<<z<<" #w: "<<w<<"\n"
#define rep(i,n)            for(int i=0;i<(n);i++)
#define repl(i,n)           for(ll i=0;i<(n);i++)
#define fori(i,a,b)         for(int i=(a);i<=(b);i++)
#define forl(i,a,b)         for(ll i=(a);i<=(b);i++)
#define ford(i,a,b)         for(int i=(a);i>=(b);i--)
#define fordl(i,a,b)        for(ll i=(a);i>=(b);i--)
#define pb                  push_back
#define mp                  make_pair
#define ff                  first
#define ss                  second
#define mid(s,e)            (s+(e-s)/2)
#define setbits(x)          __builtin_popcountll(x)
#define zrobits(x)          __builtin_ctzll(x)
#define ps(x,y)             fixed<<setprecision(y)<<x
#define w(x)                int x; cin>>x; while(x--)
#define in(x)               int x; cin>>x;
#define ins(x)              string x; cin>>x;
#define endl                '\n'
#define infi                INT_MAX
#define infll               LLONG_MAX
#define infim               INT_MIN
#define infllm              LLONG_MIN
#define mk(arr,n,type)      type *arr = new type[n];
#define umap(x,type1,type2) unordered_map<type1, type2 > x;

struct item {
	int wt;
	int val;
};

ll solve(item* a, int n, int w) {
	ll dp[n + 1][w + 1];

	fori(i, 0, w) {
		dp[1][i] = 0;
	}
	dp[1][a[1].wt] = a[1].val;

	fori(i, 2, n) {
		fori(wt, 0, w) {
			dp[i][wt] = dp[i - 1][wt];
			if (a[i].wt > wt) {
				continue;
			}
			dp[i][wt] = max(
			                dp[i][wt],
			                a[i].val + dp[i - 1][wt - a[i].wt]
			            );
		}
	}

	return *max_element(dp[n], dp[n] + w + 1);
}

int32_t main() {
	iamtheflash

	in(n);
	in(w);

	mk(a, n + 1, item);
	fori(i, 1, n) {
		cin >> a[i].wt >> a[i].val;
	}

	cout << solve(a, n, w);

	return 0;
}


Measured memory_bytes: 78336
n = int(input())
h = list(map(int, input().split()))
ans = 0
x = 0
for i in range(n - 1):
    if h[i] >= h[i + 1]:
        x += 1
        if i == n - 2:
            ans = max(ans, x)
    else:
        ans = max(ans, x)
        x = 0
print(ans)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#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 itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl; 
#define MOD llong(1e9 +7)

int main(){
    int n;
    cin >> n;
    llong ans=1;
    FOR(i,1,n+1){
        ans *= i;
        ans %=MOD;
    }
    print(ans);
}

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

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		boolean flag = true;

		String[] s = new String[N];

		int len = 0;

		for(int i=0;i<N;i++) {

			s[i] = sc.next();

			if(i > 0) len = s[i-1].length();

			if(i>0 && s[i].charAt(0) != s[i-1].charAt(len-1)) {

				System.out.println("No");

				flag = false;

				break;
			}

			for(int j=0;j<i;j++) {

				if(s[i].equals(s[j])) {

					System.out.println("No");

					flag = false;

					break;
				}
			}
		}

		if(flag == true) {

			System.out.println("Yes");
		}




	}

}


Measured memory_bytes: 23636
import sys

s = input()
plus_num = len(s) - 1
if plus_num == 0:
    print(s)
    sys.exit(0)

f = '0%sb' % plus_num
plus_list = [format(i, f) for i in range(2 ** plus_num)]
result = 0

for plus in plus_list:
    ans = 0
    tmp = int(s[0])
    for i, v in enumerate(s[1:]):
        if plus[i] == '0':
            tmp = tmp * 10 + int(v)
        else:
            ans += tmp
            tmp = int(v)
    ans += tmp
    result += ans

print(result)


Measured memory_bytes: 3064
import java.util.*;


public class Main {
     public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
//        String s = sc.nextLine();
//        int k = sc.nextInt();
//        int a = sc.nextInt();
//        int b = sc.nextInt();        
        int s = sc.nextInt();
        int w = sc.nextInt();
        sc.close();
        if(s <= w){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
//        System.out.println(s);
//        if(s.contains("RRR")){
//            System.out.println(3);
//        }else if(s.contains("RR")){
//            System.out.println(2); 
//        }else if(s.contains("R")){
//            System.out.println(1);
//        }else{
//             System.out.println(0);
//        }
//        String s = sc.nextLine();
//        String t = sc.next();
//        String[] arr =  s.split("　");
//        sc.close();
//        System.out.println("input: "+ s);
//        System.out.println("k:" + k);
//        System.out.println("a:" + a);
//        System.out.println("b:" + b);
//        String ans = "NG";
//        for(int x = a; x<=b; x++){
//            if(x%k == 0){
//                ans = "OK";
//            }
//        }
//        System.out.println(ans);
//        \
//        System.out.println("arr[1]:" + arr[1]);
//
//        if(s.equals("ABC")){
//            System.out.println("ARC");
//        }else{
//            System.out.println("ABC");
//        }
//        String[] arr1 =  s.split("");
//        String[] arr2 =  t.split("");
////        List<String> list1 = Arrays.asList(s.split(""));
//        List list1 = new LinkedList(Arrays.asList(s.split("")));
////        List<String> list2 = Arrays.asList(t.split(""));
//        List list2 = new LinkedList(Arrays.asList(t.split("")));
////        int num = Integer.parseInt(arr[arr.length - 1]);
//        list2.remove(arr2.length - 1);
////        System.out.println(list1);
////        System.out.println(list2);
//         if(list1.toString().contentEquals(list2.toString())){
//             System.out.println("Yes");
//         }else{
//             System.out.println("No");
//         }
//        switch(num){
//            case 3:
//                System.out.println("bon");
//                break;
//            case 0:
//            case 1:
//            case 6:
//            case 8:
//                System.out.println("pon");
//                break;
//            default:
//                System.out.println("hon");
//                break;
//        }
//        String[] array = str.split(" ");
//        int sum = 0;
//        for(int i=0; i<array.length; i++) {
//            int num = Integer.parseInt(array[i]);
//            sum += num;
//        }
//        System.out.println(15-sum);
    }
}

Measured memory_bytes: 35896
#include<cstdio>

int main() {

    int x,y;
    while(1){
        scanf("%d %d",&x,&y);
        
        if (x == 0 && y == 0) break;

        int a,b;

        if (x > y){
            b = x;
            a = y;
        }else{
            a = x;
            b = y;
        }
        printf("%d %d\n",a,b);

        
    }
}


Measured memory_bytes: 2548
#include <cstdio>
#include <cctype>
#include <utility>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	int w = 0;
	for (int c: {1, 5, 10, 50, 100, 500})
		w += in() * c;
	outl((int) w >= 1000);
}


Measured memory_bytes: 2620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 6 - A - B;
  cout << ans << '\n';  
  return 0;
}

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

addtime=0
nowtime=0
for i in range(N):
  a=AB[i][0]
  b=AB[i][1]
  nowtime+=a
  if nowtime>b:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 39700
n,w=map(int,input().split( ))
V = []
W = []
#大文字小文字は紛らわしいか

for i in range(n):
    v,t = map(int, input().split( ))
    V.append(v)
    W.append(t)
#####W取得前にwmax求めてどうする


Pos = [[0 for w2 in range(w+1)] for j in range(n)]
Able = []

for i in range(n):
     for w1 in range(w+1):#w含まないと
         if w1 >= W[i]:
             Pos[i][w1] = max(Pos[i-1][w1-W[i]] + V[i], Pos[i-1][w1])
             #print(i,V[i],Pos[i-1][w1-W[i]], Pos[i-1][w1])
         else:
             Pos[i][w1] = Pos[i-1][w1]
         if Pos[i][w1] > 0:
            Able.append(Pos[i][w1])
#print(*Pos)
#print(*Able)

print(Able[-1])



Measured memory_bytes: 49484
#!/usr/bin/env ruby

x1, y1, x2, y2 = gets.split.map &:to_i

dx, dy = x2 - x1, y2 - y1

x3, y3 = x2 - dy, y2 + dx
x4, y4 = x3 - dx, y3 - dy

puts [x3, y3, x4, y4].join(" ")

Measured memory_bytes: 1788
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let a = get!(usize);
    println!("{}",a.pow(3));
}


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


class Cell{
public:
  int d, r, rd, ld;
  Cell(int d = 0, int r = 0, int rd = 0, int ld = 0)
    : d(d), r(r), rd(rd), ld(ld) {}
  int max() {
    if(d >= r && d >= rd && d >= ld) return d;
    if(r >= d && r >= rd && r >= ld) return r;
    if(rd >= d && rd >= r && rd >= ld) return rd;
    if(ld >= d && ld >= r && ld >= rd) return ld;
  }
};

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    string data[n+1];

    data[0] = "";
    for(int i = 0; i < n+2; i++) {
      data[0] += "0";
    }
    for(int i = 1; i < n+1; i++) {
      string str;
      cin >> str;
      data[i] = "0" + str + "0";
    }

    Cell c[n+1][n+1];
    for(int i = 1; i < n+1; i++) {
      for(int j = 1; j < n+1; j++) {
	if(data[i][j] == '1') {
	  c[i][j].d = c[i-1][j].d + 1;
	  c[i][j].r = c[i][j-1].r + 1;
	  c[i][j].rd = c[i-1][j-1].rd + 1;
	  c[i][j].ld = c[i-1][j+1].ld + 1;
	} else if(data[i][j] == '0') {
	  c[i][j].d = c[i][j].r = c[i][j].rd = c[i][j].ld = 0;
	}
      }
    }

    int max = -1;
    for(int i = 1; i < n+1; i++) {
      for(int j = 1; j < n+1; j++) {
	if(c[i][j].max() > max) max = c[i][j].max();
      }
    }
    cout << max << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;
using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
//using u64 = long long;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;


int main(int argc, char *argv[])
{
    
    cin.tie(0) ;
    ios::sync_with_stdio(false) ;
    
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    u64 max_product = (u64) a * c;
    max_product = max(max_product,(u64) a * d);
    max_product = max(max_product,(u64) b * c);
    max_product = max(max_product,(u64) b * d);
    
    cout << max_product << endl;
    
    return 0;
    
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld ",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define fo(i,a,b) for(int i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define ll long long
const int M=1e9+7;
#define endl "\n"
const double pyi=3.14159265358979323846;

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

    int arr[n];
    unordered_set<int> stt;
    for(int i=0;i<n;i++)
    {
    	cin>>arr[i];
    	stt.insert(arr[i]);
    }
    
    
    int diff=1e7;
    int ans;
    for(int i=-105;i<105;i++)
    {
    	if(stt.find(i)!=stt.end()) continue;
        if(abs(i-a)<diff)
        {
        	diff=abs(i-a);
        	ans=i;
        }
    }
    cout<<ans<<endl;
    return(0);
}





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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int h, w, k;
    cin >> h >> w >> k;
    LL dp[105][105] = {};
    dp[0][0] = 1;
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            for(int k = 0; k < (1 << (w - 1)); ++k) {
                bool f = true;
                for(int l = 0; l < w - 1; ++l) {
                    if(((k >> l) & 1) && ((k >> (l + 1) & 1))) {
                        f = false;

                    }
                }

                if(!f) continue;
                if(j >= 1 && ((k >> (j - 1)) & 1)) {
                    dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j]) % MOD;

                } else if(j <= w - 2 && ((k >> j) & 1)) {
                    dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD;

                } else {
                    dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;

                }
            }
        }
    }
    cout << dp[h][k - 1] << endl;
    return 0;
}



Measured memory_bytes: 384
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
const int INF = 1e9+7;

int main(int argc, char **argv)
{
	int a, b, res;
	char op;
	for (;;) {
		scanf("%d %c %d", &a, &op, &b);
		switch (op) {
		case '+': res = a + b; break;
		case '-': res = a - b; break;
		case '*': res = a * b; break;
		case '/': res = a / b; break;
		default: return 0;
		}
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 600
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	n <- readInt
	putStrLn $ which "Yes" "No" $ not $ null $ do
		a <- [ 1 .. 9 ]
		b <- [ 1 .. 9 ]
		guard $ a * b == n
		return ()

Measured memory_bytes: 508
N, K, C = map(int, input().split())
S = input()

must = set()
i = len(S)+C
for j in range(K):
  i = S.rindex("o", 0, i-C)
  must.add(i)
if i<=C or "o" not in S[:i-C]:
  i = -C-1
  for j in range(K):
    i = S.index("o", i+C+1)
    if i in must:
      print(i+1)

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

int main(){
	string s;
	cin >> s;
	int counts = 0;
	rep(i,3){
		if(s[i] == 'R') counts++;
	}
		if(counts == 0){
			cout << 0 << endl;
			return 0;
		}
		else if(counts == 1){
			cout << 1 << endl;
			return 0;
		}
		else if(counts == 2){
			if(s[1] == 'R'){
				cout << 2 << endl;
			}
			else{
				cout << 1 << endl;
			}
			return 0;
		}
		else if(counts == 3){
			cout << 3 << endl;
		}
}

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

int main() {

  int N;
  cin >> N;

  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }

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

  double answer = v[0];

  for (int i = 1; i < N; i++) {
    answer = (answer + v[i]) / 2;
  }

  printf("%.16f", answer);
  printf("\n");

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
#define MOD 998244353
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

int main() {

    int n, m;cin >> n >> m;
    /// firstがto secondがcost
//    const ll INF = 100100100100;
    struct Edge {ll to; ll cost;};
    vector<Edge> g[n];


    rep(i,m) {
        ll l, r; cin >> l >> r;
        ll c; cin >> c;
        Edge edge1 = {r-1, c};
        g[l-1].push_back(edge1);
    }
    rep(i, n-1) {
        Edge edge = {i, 0};
        g[i+1].push_back(edge);
    }
    priority_queue<P, vector<P>, greater<P>> pq;
    //ll d[n];
    //fill(d, d + n, INF);
    vector<ll> d(n, 1e15);
    d[0] = 0;
    pq.push(P(0, 0));

    while(! pq.empty()){
        P p = pq.top(); pq.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (auto e : g[v]) {
//            auto e = g[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                pq.push(P(d[e.to], e.to));
            }
        }
    }

    ll ans = d[n-1];
    if (ans >= 1e15) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 9340
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int inf = 1e9;
const int mod = 1e9 + 7;

int dfs(const vector<string> &s, int i, int j) {
    if (isdigit(s[i][j])) {
        // cout << i << " " << j << " " << s[i][j] << endl;
        return s[i][j] - '0';
    }

    int ret = (s[i][j] == '+' ? 0 : 1);
    int nj = j + 1;
    rep2(ni, i + 1, s.size()) {
        if (nj >= s[ni].size()) break;
        if (s[ni][nj] == '.') continue;
        if (s[i][j] == '+') ret += dfs(s, ni, nj);
        if (s[i][j] == '*') ret *= dfs(s, ni, nj);
    }
    // cout << i << " " << j << " " << ret << endl;
    return ret;
}

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

    int n;
    while (cin >> n, n) {
        vector<string> s(n);
        rep(i, n) cin >> s[i];
        cout << dfs(s, 0, 0) << endl;
    }
}

Measured memory_bytes: 3180
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToList();
        var b = Console.ReadLine().Split().Select(int.Parse).ToList();
        Console.WriteLine(Enumerable.Repeat(0, nm[0]).Select(_ => Console.ReadLine().Split().Select(int.Parse).Zip(b, (x, y) => x * y).Aggregate(nm[2],(x,y) => x + y)).Count(x => x > 0));
    }
}


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

using namespace std;

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

	int n;
	cin >> n;

	vector<long long>a(n);
	for (auto &x : a) cin >> x;

	sort(a.begin(), a.end());
	int number=1;
	for (int i = 0; i < n-1 ; i++) {
		if (a[i] * 2 >= a[i + 1]) number++;
		else number = 1;
		a[i + 1] += a[i];
		//cout << "\nsum=" << sum << "\nnumber=" << number << "\n\n";
	}
	
	cout << number << "\n";
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int[] num = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			num[i] = scanner.nextInt();
			sum += num[i];
		}
		int r = sum;
		int l = r / m;
		while (r - l > 1) {
			int mid = (r + l) / 2;
			if (isTrue(mid, num, m, sum)) {
				r = mid;
			} else {
				l = mid;
			}
		}
		System.out.println(isTrue(l, num, m, sum) ? l : r);
	}

	private boolean isTrue(int mid, int[] num, int m, int sum) {
		int i = 0;
		int k = mid;
		while (true) {
			if (m == 0)
				return false;
			if (i == num.length)
				return true;
			if (k - num[i] >= 0) {
				k -= num[i];
				i++;
			} else {
				m--;
				k = mid;
			}
		}
	}
}

Measured memory_bytes: 64092
#include<bits/stdc++.h>
using namespace std;
char ss[222222];
void gen(vector<vector<int> >&s){
	scanf("%s",ss);
	for(int i=0; ss[i]; i++){
		s[ss[i]-'a'].push_back(i);
	}
	sort(s.begin(),s.end());
}
int main(){
	vector<vector<int> > s1(26),s2(26);
	gen(s1);
	gen(s2);
	puts(s1 == s2 ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 2688
#include<stdio.h>

int main(){
  int a,b;
  int temp;
  scanf("%d%d",&a,&b);
  int m,n;
    if (a>=b){
      m=a;
      n= b;
    }
    else{
      m=b;
      n=a;

    }
    while(n!=0){
      temp=n;
      n=m%n;
      m=temp;
    }
    printf("%d\n",m);
    return 0;
}



Measured memory_bytes: 2084
#include<stdio.h>
#include<string.h>

#define M 1046527
#define L 14
#define NIL (-1)

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
  long long key, i,h;
  key =getKey(str);
  for (i=0;;i++)
    {
      h=(h1(key)+i*h2(key))%M;
      if (strcmp(H[h],str)==0)return 1;
      else if(strlen(H[h])==0)return 0;
    }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key = getKey(str);
  for (i=0;;i++)
    {
      h=(h1(key)+i*h2(key))%M;
      if(strcmp(H[h],str)==0)return 1;
      else if(strlen(H[h])==0)
	{
	  strcpy(H[h],str);
	  return 0;
	}
    }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 16052
def MAP(): return map(int,input().split())

H,W = MAP()
lst = [list(input()) for _ in range(H)]
L = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        #Left
        if lst[i][j]==".":
            L[i][j] = L[i][j-1]+1
        #Up
            U[i][j] = U[i-1][j]+1
        #Right
        if lst[i][-(j+1)]==".":
            R[i][-(j+1)] = R[i][-j]+1
        #Down
        if lst[-(i+1)][j]==".":
            D[-(i+1)][j] = D[-i][j]+1
ans=0
for i in range(H):
    for j in range(W):
        ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)

Measured memory_bytes: 313992
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }return 0; }
#define all(a)  (a).begin(),(a).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
const ll INF =1LL << 62;

int main(){
  ll N ;
  cin >> N;
  string s ;
  cin >> s;
  char str[26] = {'a','b','c','d','e','f','g','h'
    ,'i','j','k','l','m','n','o'
    ,'p','q','r','s','t','u','v','w'
    ,'x','y','z'};
  ll res[26];
  rep(i,26)
    res[i]=1 ;
  rep(i,N){
    rep(j,26){
      if(s[i] == str[j] )
        res[j] ++;
    }
  }
  ll ans =1;
  rep(i,26){
    ans *= res[i];
    ans %= 1000000007 ;
  }
  ans --;
  if(ans ==0){
    cout << 1000000006 <<endl;
    return 0;
  }
  cout << ans <<endl;
}
  
  

Measured memory_bytes: 512
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r =
            new BufferedReader(new InputStreamReader(System.in), 1);
        String is = r.readLine();
        if(!is.contains(" "))
            return;
        String[] sp = is.split(" ");
        int a = Integer.parseInt(sp[0]);
        int b = Integer.parseInt(sp[1]);
        if(a>b)
        	System.out.println("a > b");
        else if(a<b)
        	System.out.println("a < b");
        else if (a==b)
        	System.out.println("a == b");
        else;
      }
}

Measured memory_bytes: 24192
n=int(input())
a=[1]
b=2
s=1
def pr(x):
  for i in range(len(x)):
    print(x[i])
while s<=n:
  a.append(b)
  s+=b
  b+=1
if s==n:
  pr(a)
else:
  c=s-n
  a.remove(c)
  pr(a)

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

int main() {
char str;
while(1) {
scanf("%c", &str);
if(str == '\n'){
std::cout << '\n';
break;
}
else if(static_cast<bool>(islower(str))) {
std::cout << static_cast<char>(toupper(str));
}
else if(static_cast<bool>(isupper(str))) {
std::cout << static_cast<char>(tolower(str));
}
else {
std::cout << str;
}
}
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll p = 1e9+7;
ll fac(int n)
{
    ll res = 1;
    for (ll i = 2;i <= n;i++)
        res = (res * i)%p;
    return res;
}
int main()
{
    int n,m;
    cin >> n >> m;
    if (abs(n-m) >= 2) puts("0");
    else {
        ll a = fac(n);
        ll b = fac(m);
        ll c = a*b%p;
        if (n == m) c = c * 2 %p;
        cout << c << endl;
    }
    return 0;
}

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

class DisjointSet {
public:
    DisjointSet(int n) {
        p.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++) {
            p[i] = i;
            rank[i] = 0;
        }
    }
    int find(int x) {
        if (p[x] == x) {
            return x;
        }
        return p[x] = find(p[x]);
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    void unite(int x, int y) {
        int px = find(x);
        int py = find(y);
        if (px == py) {
            return;
        }
        if (rank[px] < rank[py]) {
            p[px] = py;
        } else {
            p[py] = px;
            if (rank[px] == rank[py]) {
                rank[px]++;
            }
        }
    }
private:
    vector<int> p;
    vector<int> rank;
};

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

    DisjointSet dset(n + 1);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        if (a == 1 || b == 1 || a == n || b == n) {
            dset.unite(a, b);
        }
    }
    if (dset.same(1, n)) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 1792