akhauriyash/Code-Regression huggingface dataset:
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n1 = Number(lines.shift());
  const arr1 = lines.shift().split(' ').map(Number);
  const n2 = Number(lines.shift());
  const arr2 = lines.shift().split(' ').map(Number);

  const solve = memoization(function(i, m) {
    if (m == 0) return true;
    if (i >= n1) return false;
    return solve(i + 1, m) || solve(i + 1, m - arr1[i]);
  });

  arr2.map(m => solve(0, m) ? 'yes' : 'no').forEach(res => console.log(res));
})();

function memoization(f) {
  var cache = {};
  function innerFunc(...param) {
    let c = cache[param];
    if (typeof c !== 'undefined') {return c;}
    return cache[param] = f(...param);
  }
  return innerFunc;
}



Measured memory_bytes: 24412
N, K = map(int, input().split())
if K > (N - 1) * (N - 2) // 2:
  print(-1)
else:
  M = N * (N - 1) // 2 - K
  print(M)
  for i in range(2, N + 1):
    print(1, i)
  M -= N - 1
  for i in range(2, N + 1):
    for j in range(i + 1, N + 1):
      if M == 0:
        break
      print(i, j)
      M -= 1
    if M == 0:
      break

Measured memory_bytes: 3608
#include<cstdio>
#include<cstdlib>
#include<stack>

using namespace std;

int main() {
        stack<int> s;
        char c[20];
        int a,b;

        while (scanf("%s", c) != EOF) {
                if (c[0] == '+' || c[0] == '-' || c[0] == '*') {
                        a = s.top();
                        s.pop();
                        b = s.top();
                        s.pop();
                        if ( c[0] == '+') s.push(b + a);
                        else if (c[0] == '-') s.push(b - a);
                        else s.push(b * a);
                } else {
                        s.push(atoi(c));
                }
        }
        printf("%d\n", s.top());
}

Measured memory_bytes: 1024
//om namah shivaaay//
#include <bits/stdc++.h>
#define Om_namah_Shivaay ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
 #define ll long long
 using namespace std;
 int main()
 {
    Om_namah_Shivaay;
    int s,w;
    cin>>s>>w;
    if(s<=w) cout<<"unsafe";
    if(s>w) cout<<"safe";
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll n;
    cin >> n;
    int a[n+1]={};
    int x,y;
    srep(i,1,n+2){
        int tmp;
        cin >> tmp;
        if(a[tmp]!=0){
            x = a[tmp];
            y = i;
        }else{
            a[tmp] = i;
        }
    }

    COMinit();

    srep(i,1,n+2){
        if(i==1){
            cout << n << endl;
        }else if(i==n+1){
            cout << '1' << endl;
        }else if(i==n){
            if(y-x==1){
                cout << n << endl;
            }else{
                cout << n+1 << endl;
            }
        }else{
            ll ans = 0;
            // not use
            ans += COM(n-1,i) % MOD;
            // x use
            ans = (ans + COM(n-1,i-1)%MOD) % MOD;
            // y use
            ans = (ans + COM(n-1,i-1)%MOD) % MOD;
            // gojohou
            ans -= COM(n+1-(y-x+1),i-1) % MOD;
            ans = (ans + MOD) % MOD;
            // x&y use
            ans = (ans + COM(n-1,i-2)%MOD) % MOD;
            cout << ans << endl;
        }
    }

    //cout << x << y;

    return 0;
}
 
 


Measured memory_bytes: 13568
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


N = I()
A = LMI()

avg = sum(A) // N

ans = float('inf')
for a in [avg - 1, avg, avg + 1]:
    cost = 0
    for b in A:
        cost += (a - b) ** 2
    ans = min(ans, cost)
print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    string ss = "";
    int tmp = 0;
    for(int i = 0; i < N; i++){
        if (s[i] == '(') {
            tmp++;
            ss = ss + "(";
        }
        else if(s[i] == ')' && tmp > 0){
            ss = ss + ')';
            tmp--;
        }else {
            ss = '(' + ss + ')';
        }
    }
    if (tmp > 0){
        REP(j, tmp) ss = ss + ')';
    }
    cout << ss << endl;

    return 0;
}


Measured memory_bytes: 1016
Z = []
for s in input():
  Z.append(int(s))

def dfs(index, value, ops):
  if index == 4:
    if value == 7:
      print("{}{}{}{}{}{}{}=7".format(Z[0],ops[0],Z[1],ops[1],Z[2],ops[2],Z[3]))
      # print(f"{Z[0]}{ops[0]}{Z[1]}{ops[1]}{Z[2]}{ops[2]}{Z[3]}=7")
      exit()
    return
  dfs(index + 1, value + Z[index], ops + ["+"])
  dfs(index + 1, value - Z[index], ops + ["-"])

dfs(1, Z[0], [])

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <vector>

#define int long long

typedef long long LL;

const int MAXN = 100000;
const int MAXP = 2500;

int N;
LL A[MAXN + 5];

int Vis[MAXN + 5];
std::vector<int> P;

void GetPrimes(int n) {
	for (int i = 2; i <= n; i++) {
		if (!Vis[i])
			P.push_back(i);
		for (int j = 0; j < (int)(P.size()) && i * P[j] <= n; j++) {
			Vis[i * P[j]] = true;
			if (i % P[j] == 0)
				break;
		}
	}
}

std::map<LL, bool> Met;
std::map<LL, int> Cnt, Opp;

signed main() {
	GetPrimes(MAXP);
	scanf("%d", &N);
	int Ans = 0;
	for (int i = 1; i <= N; i++) {
		scanf("%lld", &A[i]);
		LL tmp = A[i], res = 1, opp = 1;
		for (int j = 0; (LL)P[j] * P[j] * P[j] <= tmp; j++) {
			if (A[i] % P[j] == 0) {
				int cnt = 0;
				while (A[i] % P[j] == 0) {
					cnt++;
					A[i] /= P[j];
				}
				if (cnt % 3 == 1)
					res *= P[j], opp *= P[j] * P[j];
				else if (cnt % 3 == 2)
					res *= P[j] * P[j], opp *= P[j];
			}
		}
		res *= A[i];
//		printf("     [%lld]\n", res);
		if (res == 1) {
			Ans += !Ans;
			continue;
		}
		LL s = (LL)sqrt(A[i]);
		if (s * s == A[i])
			Opp[res] = opp * s;
		else
			Opp[res] = opp * A[i] * A[i];
		Cnt[res]++;
//		printf("  -> [%lld]\n", Opp[res]);
	}
	for (std::map<LL, int>::iterator it = Cnt.begin(); it != Cnt.end(); ++it) {
		LL num = it->first; int cnt = it->second;
		if (!Met.count(num)) {
			Met[Opp[num]] = Met[num] = true;
			Ans += std::max(Cnt[Opp[num]], cnt);
		}
	}
	printf("%d", Ans);
	return 0;
}


Measured memory_bytes: 35340
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
struct bian{
	int next,point,w;
}b[210000];
int size[210000],num,where,root,p[110000],len,n;
long long w[110000];
void ade(int k1,int k2,int k3){
	b[++len]=(bian){p[k1],k2,k3}; p[k1]=len;
}
void add(int k1,int k2,int k3){
	ade(k1,k2,k3); ade(k2,k1,k3);
}
void dfs(int k1,int k2){
	for (int i=p[k1];i;i=b[i].next){
		int j=b[i].point;
		if (j!=k2){
			dfs(j,k1); size[k1]+=size[j];
		}
	}
	size[k1]++;
}
vector<int>ro;
void dfs1(int k1,int k2){
	int ans=n-size[k1];
	for (int i=p[k1];i;i=b[i].next){
		int j=b[i].point;
		if (j!=k2){
			dfs1(j,k1); ans=max(ans,size[j]);
		}
	}
	if (ans<num){
		num=ans; ro.clear(); ro.push_back(k1);
	} else if (ans==num) ro.push_back(k1);
}
void dfs2(int k1,int k2){
	size[k1]=1;
	for (int i=p[k1];i;i=b[i].next){
		int j=b[i].point;
		if (j!=k2){
			w[j]=w[k1]+b[i].w;
			dfs2(j,k1); size[k1]+=size[j];
		}
	}
}
long long findmax(int k1,int k2){
	long long ma=w[k1];
	for (int i=p[k1];i;i=b[i].next){
		int j=b[i].point;
		if (j!=k2) ma=min(ma,findmax(j,k1));
	}
	return ma;
}
long long calc(int root){
//	cout<<"calc "<<root<<endl;
	memset(w,0x00,sizeof w);
	dfs2(root,0); int ma=0; long long ans=0,ww=1e18;
	for (int i=1;i<=n;i++) ans+=w[i]*2;
	for (int i=p[root];i;i=b[i].next){
		int j=b[i].point;
		if (size[j]*2==n){
			ans-=w[j],ma=1;
		}
	}
	sort(w+1,w+n+1); 
	if (ma==0) ans-=w[2];
	return ans;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		int k1,k2,k3; scanf("%d%d%d",&k1,&k2,&k3); add(k1,k2,k3);
	}
	dfs(1,0); num=n; dfs1(1,0);
	long long ans=0;
	for (int i=0;i<ro.size();i++) ans=max(ans,calc(ro[i]));
	cout<<ans<<endl; return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
ll fac[2000007],finv[2000007],inv[2000007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<2000007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
ll solve(ll a,ll b){
    return com(a+b,b)-1;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cominit();
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    c++;d++;
    ll ans=0;
    ans+=solve(c,d);
    ans-=solve(c,b);
    ans-=solve(a,d);
    ans+=solve(a,b);
    cout<<(ans%mod+mod)%mod<<endl;
    return 0;
}


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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}

int main(void){
  
  int i,m=0,result=0;
  char s[4];
    scanf("%s",s);
  
  for(i=0;i<3;i++)
  if(s[i]=='R'){
    m++;
    result = max(result,m);
  }else{
    m=0;
  }
  printf("%d",result);

  return 0;
  
}

Measured memory_bytes: 1728
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x

_, *Q = map(int, open(0).read().split())
for a, b, c, d in zip(*[iter(Q)] * 4):
	if a < b or d < b:
		print("No")
		continue
	if c >= b:
		print("Yes")
		continue
	a %= b
	g = gcd(b, d)
	# b - g + a - g * (a // g) < b
	if b - g + a - g * (a // g) > c:
		print("No")
	else:
		print("Yes")

Measured memory_bytes: 3188
N,K=map(int,input().split())
p=input().split()
P=[int(z) for z in p]
hopes=[(1+a)/2 for a in P]
S=sum(hopes[:K])
answers=[S]
for a in range(1,N-K+1):
    S=S+hopes[a+K-1]-hopes[a-1]
    answers.append(S)
print(max(answers))


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

int main(){
  string s;
  cin >> s;
  int ans = 1000000;
  for(int i=0; i<s.length()-2; i++){
    int x;
    x=(s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
    if(abs(x-753) < ans){
      ans = abs(x-753);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iK = int.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            if (iN % iK != 0) { iOut = 1; }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a.at(i);
    int ans = 0;
    int lamp = 1; 
    for (int i = 0; i < N; i++) {
        lamp = a.at(lamp - 1);
        ans++;
        if (lamp == 2) break;
        else if (lamp == 1) {
            ans = -1;
            break;
        }
        else if (i == N - 1) ans = -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
#define ll long long
#define fin(x) scanf("%lld",&x)
#define fout(x) printf("%lld\n",x)
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
#define cases int t;  scanf("%d",&t);   while(t--)
#define MOD 1000000007
#define MAXN 1234567
#define read() freopen("lele.txt","r",stdin)
#define write() freopen("dede.txt","w",stdout)

using namespace std;

int main()
{
    ll A, B, C;
    fin(A); fin(B); fin(C);
    if(C >= A && C <= B)
        puts("Yes");
    else
        puts("No");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
  int i = 0,len = 0,j,k=0,l=0;

  char S[100];
  char T[100];
  char U[100];
  
  scanf("%s",S);
  scanf("%s",T);

  while(S[len]){
  	len++;
  }
  
  while(l<len){

	U[0] = S[len-1];
	for(j=1;j<len;j++){
		U[j]=S[j-1];
	}
	for(j=0;j<len;j++){
		S[j]=U[j];
	}
	while(U[k] == T[k] && U[k] != '\0'){
		k++;
	}
	if(k==len){
		i = 1;
		break;
	}
		k=0;
		l++;
	}
	if(i == 0)
		printf("No\n");
	else
		printf("Yes\n");
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N],n;
int main()
{
	scanf("%d",&n);
	int sum=0,sum1=0,sum2=0,sum3=0,x=-1,y=-1,z=-1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==0)sum++;else
		if(x==-1)x=a[i],sum1=1;else
		if(a[i]==x)sum1++;else
		if(y==-1)y=a[i],sum2=1;else
		if(a[i]==y)sum2++;else
		if(z==-1)z=a[i],sum3=1;else
		if(a[i]==z)sum3++;else
		{
			puts("No");
			return 0;
		}
	}
	if(sum==n)
	{
		puts("Yes");
		return 0;
	}
	if(n%3!=0)
	{
		puts("No");
		return 0;
	}
	if(sum1!=0&&sum2!=0&&sum3!=0)
	{
		if((sum1==sum2)&&(sum2==sum3)&&((x^y^z)==0))
			puts("Yes");else puts("No");
		return 0;
	}
	if(sum2!=0||sum3!=0)
	{
		puts("No");
		return 0;		
	}
	if(sum*2==sum1)puts("Yes");else
		puts("No");
	return 0;
}

Measured memory_bytes: 640
X = int(input())
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

tmp = primes(2*X)

for i in range(len(tmp)):
    if tmp[i]>X:
        print(tmp[i])
        break
    elif tmp[i]==X:
        print(X)
        break

Measured memory_bytes: 5388
fun main(args: Array<String>) {

    val q = readLine()!!.toInt()
    repeat(q) {
        val ps = readLine()!!.split(' ').map { it.toInt() }
        val s1 = T2A.Segment(T2A.Point(ps[0], ps[1]), T2A.Point(ps[2], ps[3]))
        val s2 = T2A.Segment(T2A.Point(ps[4], ps[5]), T2A.Point(ps[6], ps[7]))
        println(if (s1.isOrthogonal(s2)) 1 else if (s1.isParallel(s2)) 2 else 0)
    }

}

private class T2A {

    data class Point(val x: Int, val y: Int) {

        fun dot(p: Point): Int {
            return x * p.x + y * p.y
        }

        fun cross(p: Point): Int {
            return x * p.y - y * p.x
        }

        operator fun minus(p: Point): Point {
            return Point(x - p.x, y - p.y)
        }

    }

    data class Segment(val p1: Point, val p2: Point) {

        fun isOrthogonal(s: Segment): Boolean {
            return (p2 - p1).dot(s.p2 - s.p1) == 0
        }

        fun isParallel(s: Segment): Boolean {
            return (p2 - p1).cross(s.p2 - s.p1) == 0
        }

    }

}



Measured memory_bytes: 36280
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)



signed main(){
  int n,m;
  cin>>n>>m;
  int s=0;
  lp(i,n){
    int x;
    cin>>x;
    s+=x;
  }
  int ans=0;
  lp(i,m){
    int x;
    cin>>x;
    ans+=x*s;
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 3100
#include <stdio.h>

int main(void)
{
    char s[100001];
    scanf("%s", s);
    int ans = 0;
    char t = s[0];
    for(int i = 1; s[i] != '\0'; i++){
        if (s[i] != t) {
            ans++;
            t = s[i];
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/
#include <bits/stdc++.h>
#define newline ("\n")
#define deb(x) cerr << (#x) << " = " << (x) << '\n'
#define FOR(x, n) for (int x = 0; x < n; x++)
#define PI (3.141592653589)

#define MOD 1000000007
using namespace std;

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

    // Pikachu, I choose you
    int n, k;
    cin >> n >> k;
    int arr[n + 1];
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    int dp[n + 1];
    for (int i = 1; i <= n; i++)
    {
        if (i == 1)
        {
            dp[i] = 0;
            continue;
        }
        dp[i] = INT_MAX/2;

            for (int j = max(i - k , 1); j < i; j++)
            {
                dp[i] = min(dp[i] , dp[j] + abs(arr[i] - arr[j]));
            }
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc120/tasks/abc120_c

import itertools
import collections
import bisect

def main():
    S = list(input())
    zero_n = S.count("0")
    one_n = S.count("1")
    print(min(zero_n, one_n) * 2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
int n,v[55];double s;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>v[i];
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<n;j++)
		if(v[j]>v[j+1])swap(v[j],v[j+1]);
	s=s+v[1];
	for(int i=2;i<=n;i++)
	{
		s=(s+v[i])/2;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.append(0)
ans = 0
for i in range(n):
    ans += a[i] // 2
    a[i] %= 2
    if a[i] == 1 and a[i + 1] >= 1:
        ans += 1
        a[i + 1] -= 1
print(ans)

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

class Main {
	Scanner sc;
	int N;
	int[] P;
	
	private void calc() {
		sc = new Scanner(new BufferedInputStream(System.in));
		int N = sc.nextInt();
		P = new int[N];
		for (int i = 0; i < N; i++) P[i] = Integer.parseInt(sc.next());

		int c = 0;
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			if (min > P[i]) c++;
			min = Math.min(min, P[i]);
		}

		System.out.println(c);
	}

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


Measured memory_bytes: 50804
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long[] a = new long[n];
      long sum = 0;
      for(int i = 0;i < n;i++){
        a[i]=sc.nextInt();
        sum += a[i];
      }
      long x = a[0];
      long min = Math.abs(sum-2*a[0]);
      for(int i = 1;i < n-1;i++){
        x += a[i];
        min = Math.min(min,Math.abs(sum-2*x));
      }
      System.out.println(min);
    }
}


Measured memory_bytes: 77708
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int ta=1;
  for(int i=0;i<n;i++){
      if(ta<k){
          ta *= 2;
      }
      else{
          ta += k;
      }
  }
  cout<<ta<<endl;
  return 0;
}


Measured memory_bytes: 256
N,T = map(int,input().split())
Data = [0]*(T+1)
Ans  = [0]*(T+1)
for _ in range(N):
    l,r = map(int,input().split())
    Data[l] += 1
    Data[r] -= 1

Ans[0] = Data[0]
for i in range(1,T+1):
    Ans[i] = Data[i]+Ans[i-1]
print(max(Ans))


Measured memory_bytes: 10208
import collections

n = int(input())
ls = [input() for i in range(n)]    
c = collections.Counter(ls)

count = c.most_common()[0][1]
ans = []
p = c.most_common()
for i in range(len(c)):
    if p[i][1] == count:
        ans.append(p[i][0])
    else:
        break   
ans = sorted(ans)
for i in ans:
    print(i)

Measured memory_bytes: 49172
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_sum = [0]
for i in range(N):
    A_sum.append(A[i] + A_sum[i])
B_sum = [0]
for i in range(M):
    B_sum.append(B[i] + B_sum[i])    
import bisect
ans = 0
for i in range(N+1):
    a = A_sum[i]
    if K-a >=0:
        b_idx = bisect.bisect(B_sum, K-a) - 1
        if b_idx  < 0:
            b_idx = 0
        ans = max(ans, i+b_idx)
print(ans)

Measured memory_bytes: 132476
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  char c; cin >> c;
  cout << (char)(c+1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll N;
    cin >> N;
    vector<ll>v(N);
    for(ll i = 0; i < N; i++)cin >> v[i];
    ll ans = 0;
    for(ll d = 1; d < N; d++){
        ll score = 0;
        for(ll j = 0; j < N - d; j += d){
            score += v[j] + v[N - 1 - j];
            if((N - 1) % d == 0 && j >= N - 1 - j){
                break;
            }
            ans = max(ans, score);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int r;

int main() {
  cin >> r;
  if(r <= 1199)
    cout << "ABC" << endl;
  else if(r <= 2799)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int result[50];
  REP(i, 51) result[i] = 0;
  REP(i, m)
  {
    int a, b;
    cin >> a >> b;

    result[a] += 1;
    result[b] += 1;
  }

  FOR(i, 1, n+1) cout << result[i] << "\n";

  return(0);
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 500000
#define SENTINEL 1000000001

int count;
int L[MAX/2+2],R[MAX/2+2];

void merge(int a[MAX],int n,int left,int mid,int right){
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;i++)L[i]=a[left+i];
	for(int i=0;i<n2;i++)R[i]=a[mid+i];
	L[n1]=SENTINEL;
	R[n2]=SENTINEL;
	int i=0,j=0;
	for(int k=left;k<right;k++){
		count++;
		if(L[i]<=R[j]){
			a[k]=L[i++];
		}
		else a[k]=R[j++];
	}
}

void mergeSort(int a[MAX],int n,int left,int right){
	if(left+1<right){
		int mid=(left+right)/2;
		mergeSort(a,n,left,mid);
		mergeSort(a,n,mid,right);
		merge(a,n,left,mid,right);
	}
}

int main(void){
	int a[MAX],n,i;
	count=0;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	
	mergeSort(a,n,0,n);
	
	for(int i=0;i<n;i++){
		if(i)printf(" ");
		printf("%d",a[i]);
	}
	printf("\n");
	
	printf("%d\n",count);
	
	return 0;
}


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans


void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    T.erase((int)S.size());
    Yes(T == S);


    solve();
    return 0;
}


Measured memory_bytes: 3656
/*
  AUTHOR:SOURABH
  CREATED:19:01:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll n,a,b,i;
    cin>>a>>b;
    string s="";
    if(a>b)
    {
        fn(i,a)
        s+=48+b;
    }
    else
    {
        fn(i,b)
        s+=48+a;
    }
    cout<<s;
}








Measured memory_bytes: 256
/*
 * @Author: Kaizyn
 * @Date: 2020-06-20 19:56:11
 * @LastEditTime: 2020-06-20 20:02:18
 */ 
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;

int x;

inline void solve() {
  cin >> x;
  for (int i = 1; ; ++i) {
    if (i*x%360 == 0) {
      cout << i << endl;
      return;
    }
  }
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll h;cin >> h;
    ll coeff = 1;
    ll ans = 0;
    while(h>0){
        ans += coeff;
        h /= 2;
        coeff *= 2;
        
    }
    cout << ans << endl;
}

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

#define MAX_LEN (100000)
#define NUM_MOD (1000000007L)

int main() {
  // read inputs
  int N;
  char cs[MAX_LEN + 1];
  scanf("%s", cs);
  N = strlen(cs);

  // calculate powers of 3
  long pow3s[MAX_LEN + 1] = {};
  pow3s[0] = 1;
  for (int i = 0; i < N; i++) {
    pow3s[i + 1] = 3 * pow3s[i] % NUM_MOD;
  }

  // solve
  long cnts[3][4] = {}, cntQ = 0;
  for (int i = 0; i < N; i++) {
    switch (cs[i]) {
      case 'A':
        cnts[0][0] = (cnts[0][0] + 1) % NUM_MOD;
        break;
      case 'B':
        for (int j = 0; j < 4; j++) {
          cnts[1][j] = (cnts[1][j] + cnts[0][j]) % NUM_MOD;
        }
        break;
      case 'C':
        for (int j = 0; j < 4; j++) {
          cnts[2][j] = (cnts[2][j] + cnts[1][j]) % NUM_MOD;
        }
        break;
      case '?':
        cntQ++;
        for (int j = 1; j < 4; j++) {
          cnts[2][j] = (cnts[2][j] + cnts[1][j - 1]) % NUM_MOD;
        }
        for (int j = 1; j < 4; j++) {
          cnts[1][j] = (cnts[1][j] + cnts[0][j - 1]) % NUM_MOD;
        }
        cnts[0][1] = (cnts[0][1] + 1) % NUM_MOD;
        break;
    }
  }

  long ans = 0;
  for (int j = 0; j < 4; j++) {
    ans = (ans + pow3s[cntQ - j] * cnts[2][j]) % NUM_MOD;
  }
  printf("%ld\n", ans);
}

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

int cnt[1000*1000+2];
bool ok;
void factorize(int n)
{
//    cout<<n<<"*"<<endl;
    if(n%2==0)
    {
        while(n%2==0) n/=2;
        cnt[2]++;
        if(cnt[2]>1) ok=0;
//        cout<<2<<endl;
    }
    for(int i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        {
            while(n%i==0) n/=i;
            cnt[i]++;
            if(cnt[i]>1) ok=0;
//            cout<<i<<endl;
        }
    }
    if(n>2)
    {
        cnt[n]++;
        if(cnt[n]>1) ok=0;
//        cout<<n<<endl;
    }
}
int32_t main()
{
    int n;scanf("%d",&n);
    vector <int> N(n);
    int cgcd=0;ok=1;
    for(int &x : N) scanf("%d",&x),cgcd=__gcd(cgcd,x);
    for(int x : N) {factorize(x);if(!ok) break;}
    if(ok) printf("pairwise coprime\n"),exit(0);
    if(cgcd==1) printf("setwise coprime\n"),exit(0);
    printf("not coprime\n");
    return 0;
}
/*


*/



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

int main(){
    int n,m,sum=0;
    cin>>n;
    vector<int> t(n);
    for(int i=0; i<n; i++) {
        cin>>t[i];
        sum += t[i];
    }
    cin>>m;
    vector<int> p(m),x(m);
    for(int i=0; i<m; i++) cin>>p[i]>>x[i];
    int res = sum;
    for(int i=0; i<m; i++) {
        res += x[i] - t[p[i]-1];
        cout<<res<<"\n";
        res = sum;
    }
}

Measured memory_bytes: 256
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

# アームが伸びる範囲に置き換える
a = []
for i in range(N):
    a.append([XL[i][0] - XL[i][1], XL[i][0] + XL[i][1]])
# アームが届く最大座標でソートする
a = sorted(a, key=lambda x: x[1])

ans = 0
cur = - float('inf')
for i in range(N):
    if a[i][0] >= cur:
        ans += 1
        cur = a[i][1]
print(ans)

Measured memory_bytes: 43560
#include "bits/stdc++.h"
using namespace std;
int A, B, C, D, E;
int solve(int from) {
	int sum = 0;
	if (from < 0) {
		return -from*C + D +100 * E;
	}
	else {
		return (100 - from)*E;
	}
}


int main() {
	cin >> A >> B >> C >> D >> E;
	cout << solve(A) - solve(B) << endl;
	return 0;
}

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

int N, M;
vector<pair<int, int>> A;

bool cmp (pair<int, int> a, pair<int, int> b) { return a.second < b.second; }

int main () {
    cin >> N >> M;
    A.resize(M);
    for (int i=0; i<M; ++i) cin >> A[i].first >> A[i].second;

    sort(A.begin(), A.end(), cmp);
    int ans = 1;
    int ib = A[0].second;
    for (int i=1; i<M; ++i) {
        if (A[i].first >= ib) {
            ib = A[i].second;
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    int n,k,c;
    string s;
    cin >> n >> k >> c;
    cin >> s;
    auto getPositions = [&](){
        vector<int> res;
        for(int i = 0; i < n && res.size() < k;){
            if(s[i] == 'o'){
                res.push_back(i);
                i += c + 1;
            } else{
                i++;
            } 
        }
        return res;
    };

    auto l = getPositions();
    reverse(s.begin(),s.end());
    auto r = getPositions();
    rep(i,k) r[i] = n-1 - r[i];
    reverse(s.begin(),s.end());

    vector<int> lastL(n+1,-1),lastR(n+1,-1);
    rep(i,k) lastL[l[i]+1] = i;
    for(int i=0;i<n;i++){
        if(lastL[i+1] == -1) lastL[i+1] = lastL[i];
    }
    
    rep(i,k) lastR[r[i]] = i;
    for(int i=n-1;i>=0;i--){
        if(lastR[i] == -1) lastR[i] = lastR[i+1];
    }

    for(int i=0;i<n;i++){
        if( s[i] == 'x') continue;
        int li = lastL[i];
        int ri = lastR[i+1];
        int cnt=0;
        if(li != -1) cnt += li + 1;
        if(ri != -1) cnt += ri + 1;
        if(li != -1 && ri != -1 && abs(r[ri] - l[li]) <= c )
            cnt--;
        if(cnt >= k) continue;
        cout << i+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 4984
import math

N, M = map(int, input().split())
MOD = 10**9+7

def trial_division(n):
  #素因数を格納するリスト
  factor = []
  #2から√n以下の数字で割っていく
  tmp = int(math.sqrt(n)) + 1
  for num in range(2,tmp):
    cnt = 0
    while n % num == 0:
      n //= num
      cnt += 1 
    if cnt != 0:
      factor.append(cnt)
  #リストが空ならそれは素数
  if not factor:
    return []
  else:
    if n != 1:
      factor.append(1)
    return factor

from operator import mul
from functools import reduce

def cmb(n,r):
  r = min(n-r,r)
  if r == 0: return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under

ans = 1
cnts = trial_division(M)
for cnt in cnts:
  ans = ans * (cmb(cnt+N-1, cnt))%MOD

# print(cnts)
print(ans)


Measured memory_bytes: 38512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    int K, A, B;
    cin >> K >> A >> B;
    for(int i=A;i<=B;i++){
        if(i % K == 0){
            cout << "OK" << endl;
            return;
        }
    }
    cout << "NG" << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 3612
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           node(a,b,c)                 mp(mp(a,b),c)
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
vector<int>adj[M];
int n,m;
int in[M];
int par[M];
void dfs(int u)
{
    for(auto v:adj[u])
    {
         if(in[v]==1)
         {
             par[v]=u;
         }
         else
         {
             in[v]--;
         }
    }
    for(auto v:adj[u])
    {
        if(par[v]==u)
        {
            dfs(v);
        }
    }
}
 main()

{
    fast
    cin>>n>>m;
    f(i,1,n-1+m)
    {
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        in[v]++;
    }
    int root=0;
    f(i,1,n)
    {
        if(in[i]==0)root=i;
    }
    dfs(root);
    f(i,1,n)
    {
        cout<<par[i]<<"\n";
    }
    return 0;

}





































Measured memory_bytes: 15340
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    cout<<max({a+b,a-b,a*b})<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

ans = [0]*8
leng = 0

for i in range(N):
    if 1 <= A[i] <= 399:
        ans[0] = 1
    elif 400 <= A[i] <= 799:
        ans[1] = 1
    elif 800 <= A[i] <= 1199:
        ans[2] = 1
    elif 1200 <= A[i] <= 1599:
        ans[3] = 1
    elif 1600 <= A[i] <= 1999:
        ans[4] = 1
    elif 2000 <= A[i] <= 2399:
        ans[5] = 1
    elif 2400 <= A[i] <= 2799:
        ans[6] = 1
    elif 2800 <= A[i] <= 3199:
        ans[7] = 1
    else:
        leng += 1

mi = sum(ans) if sum(ans) > 0 else 1
print(mi, sum(ans) + leng)


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,j,N,M,a,b,ans=0;
  cin>>N;
  vec v(N);
  rep(i,N)cin>>v[i];
  v.pb(0);
  vsort(v);
  rep1(i,N+1){
    if((v[i]-v[i-1])%2){
      ans^=N-i+1;
    }
  }
  if(ans){
    cout<<"first"<<endl;
  }else{
    cout<<"second"<<endl;
  }
  return 0;
}

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

int main()
{
    int a[3],i,large=0;
    for(i=0;i<3;i++)
        cin>>a[i];

    for(i=0;i<3;i++)
    {
        if(a[i]>large)
            large=a[i];
    }

    int ssum=0;

    for(i=0;i<3;i++)
    {
        ssum=ssum+a[i];
    }

    cout<<ssum-large;
    return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a + b >= c)
    cout << "Yes" << endl;
    else
      cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,k,s[100],b[100][100];
  bool flag1,flag2;

  while(cin >>n >>k && n!=0 && k!=0){
    flag2=true;
    for(int j=0;j<k;j++) cin >>s[j];

  for(int i=0;i<n;i++){
    for(int j=0;j<k;j++){
      cin >> b[i][j];

      if(s[j] >= b[i][j]){
	s[j]-= b[i][j];
	flag1=true;}
      else{
	flag2=false;
      }
    }
  }
  
  if(flag2 ==false) cout<<"No"<<endl;
  else if(flag1 ==true) cout<<"Yes"<<endl;
  }
  return 0;}

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

// long long gcd(long long a, long long b) {
//   if (b == 0) return a;
//   return gcd(b, a % b);
// }
//
// long long lcm(long long a, long long b) {
//   return a / gcd(a, b) * b;
// }

int64_t gcd(int64_t a, int64_t b) {
  if (a == 0 || b == 0) return a + b;
  return (a < b ? gcd(a, b - a) : gcd(b, a - b));
}

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

int main() {
  int64_t a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
}

Measured memory_bytes: 3080
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;

struct Node {
    char c;
    int v;
};

void bubbleSort(Node a[], int N) {
    bool flag = true;
    for (int i = 0; flag; i++) {
        flag = false;
        for (int j = N-1; j > i; j--) {
            if (a[j-1].v > a[j].v) {
                swap(a[j-1].c, a[j].c);
                swap(a[j-1].v, a[j].v);
                flag = true;
            }
        }
    }
}

void selectionSort(Node a[], int N) {
    for (int i = 0; i < N; i++) {
        int mi = i;
        for (int j = i + 1; j < N; j++) {
            if (a[j].v < a[mi].v) {
                mi = j;
            }
        }
        swap(a[i].v, a[mi].v);
        swap(a[i].c, a[mi].c);
    }
}

bool isStable(Node a1[], Node a2[], int N) {
    for (int i = 0; i < N; i++) {
        if (a1[i].c != a2[i].c) {
            return false;
        }
    }
    return true;
}

void print(Node a[], int N) {
    for (int i = 0; i < N; i++) {
        if (i > 0) printf(" ");
        printf("%c%d", a[i].c, a[i].v);
    }
    printf("\n");
}

const int MAX = 50;
int n;
Node a1[MAX];
Node a2[MAX];

int main() {
    //freopen("in.txt", "r", "stdin");
    //freopen("out.txt", "w", "stdout");
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        char s[10];
        scanf("%s", s);
        a1[i].c = a2[i].c = s[0];
        a1[i].v = a2[i].v = s[1] - '0';
    }
    bubbleSort(a1, n);
    print(a1, n);
    printf("Stable\n");
    selectionSort(a2, n);
    print(a2, n);
    if (isStable(a1, a2, n)) {
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }
    return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){

    int n,m;cin>>n>>m;
    vi a(n);
    inputarr(a,n);
    sort(all(a),greater<int>());
    int sum=0;
    for(auto i:a) sum+=i;
    for(int i=0;i<m;i++){
        if(a[i]*4*m<sum) return cout<<"No",0;
    }
    cout<<"Yes";


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


Measured memory_bytes: 256
from operator import itemgetter


def main():
    n = int(input())
    data = sorted([[int(i) for i in input().split()] for _ in range(n)], key=itemgetter(2), reverse=True)
    if data[0][2] == 1 and (n == 1 or data[1][2] == 0):
        print(*data[0])
        return
    test, *valid = data

    for x in range(101):
        for y in range(101):
            h = abs(test[0] - x) + abs(test[1] - y) + test[2]
            for v in valid:
                if max(h - abs(x - v[0]) - abs(y - v[1]), 0) != v[2]:
                    break
            else:
                print(x, y, h)
                return

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064