akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <bitset>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int ans = INF;

int A[85][85], B[85][85], C[85][85];
bitset<25000> dp[85][85];

int main(void) {
    int H, W;
    cin >> H >> W;
    rep(i, 0, H) rep(j, 0, W) cin >> A[i][j];
    rep(i, 0, H) rep(j, 0, W) cin >> B[i][j];

    rep(i, 0, H) rep(j, 0, W) C[i][j] = abs(A[i][j]-B[i][j]);

    dp[0][0][12500+C[0][0]] =  dp[0][0][12500-C[0][0]] = 1;

    rep(i, 0, H) rep(j, 0, W) {
      int x = C[i][j];
        if (i-1>=0) {
            dp[i][j] |= (dp[i-1][j]>>x);
            dp[i][j] |= (dp[i-1][j]<<x);
        }

        if (j-1>=0) {
           dp[i][j] |= (dp[i][j-1]>>x);
           dp[i][j] |= (dp[i][j-1]<<x);
        
        }
    }

    rep(i, 0, 25000) if (dp[H-1][W-1][i]) ans = min(ans, abs(i-12500));
    
  
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 23596
#include<iostream>

using namespace std;

int main(){
  int a,b,c,d;
  int n=0;
  cin >> a >> b >> c;
  for(int x=a;x<=b;x++){
  d=c%x;
  if(d==0){
    n++;
  }}
  cout << n << endl;
  return 0;
}



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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 100000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,dp[li];
int cev;
string s;
vector<int> v;

main(void){
	scanf("%lld",&n);
	FOR scanf("%lld",&a[i]);
	FOR dp[i]=inf;
	dp[1]=0;
	FOR{
		dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
		dp[i+1]=min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));
	}
	printf("%lld\n",dp[n]);
	return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

void solve(long long N, std::vector<long long> a)
{
    int free = 0;
    vector<bool> existColor(8, false);
    REP(i, N)
    {
        int rate = a[i];
        if (rate <= 399)
        {
            existColor[0] = true;
        }
        else if (rate <= 799)
        {
            existColor[1] = true;
        }
        else if (rate <= 1199)
        {
            existColor[2] = true;
        }
        else if (rate <= 1599)
        {
            existColor[3] = true;
        }
        else if (rate <= 1999)
        {
            existColor[4] = true;
        }
        else if (rate <= 2399)
        {
            existColor[5] = true;
        }
        else if (rate <= 2799)
        {
            existColor[6] = true;
        }
        else if (rate <= 3199)
        {
            existColor[7] = true;
        }
        else
        {
            free++;
        }
    }

    int cnt = 0;
    REP(i, 8)
    {
        if (existColor[i])
        {
            cnt++;
        }
    }

    if (free == 0)
    {
        cout << cnt << " " << cnt << endl;
    }
    else
    {
        if (cnt == 0)
        {
            cout << 1 << " " << free << endl;
        }
        else
        {
            cout << cnt << " " << cnt + free << endl;
        }
    }
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    if(S == "Sunny"){
        cout << "Cloudy" << endl;
        return 0;
    }else if (S == "Cloudy"){
        cout << "Rainy" << endl;
        return 0;
    }else{
        cout << "Sunny" << endl;
    }
    return 0;
}


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

int main() {
  string S;
  cin>>S;
  
   if(S=="hi"||S=="hihi"||S=="hihihi"||S=="hihihihi"||S=="hihihihihi"){
     cout<<"Yes"<<endl;
   }
  
   else{
     cout<<"No"<<endl;
   }
}

Measured memory_bytes: 256
M=999;main(n,i,j,k,a,b,c){
    double p=atan(1)*4,X[100],Y[100],x,y;
    for(;scanf("%d",&n),n;printf("%d\n",a)){
        for(i=0;i<n;i++)scanf("%lf,%lf",X+i,Y+i);
        for(a=i=0;i<n;i++){
            for(b=k=0;k<M;k++){
                x=X[i]+cos(p*k/M),y=Y[i]+sin(p*k/M);
                for(c=0,j=i;j<n;j++){
                    if((X[j]-x)*(X[j]-x)+(Y[j]-y)*(Y[j]-y)<1+1e-7)c++;
                }
                if(b<c)b=c;
            }
            if(a<b)a=b;
        }
    }
exit(0);}

Measured memory_bytes: 644
#include<bits/stdc++.h>
    using namespace std;
    int main(){
      string s,t;
      cin >> s;
      cin >> t;
      sort(s.begin(),s.end());
      sort(t.begin(),t.end());
      reverse(t.begin(),t.end());
      //cout << s << endl << t << endl;
      if(t>s) cout << "Yes";
      else cout << "No";
    }

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
count = 0
l_array = []
r_array = []
for i, X in enumerate(A):
    l_array.append(i + X)
    r_array.append(i - X)

counter = Counter(r_array)

for x in l_array:
    count += counter.get(x, 0)
print(count)


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

int way(int a[],int n){
    int sum=0,sum1=0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                    sum=a[i]*a[j];
                    sum1=sum1+sum;
            }
        }
    return sum1;
}

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    cout<<way(a,n);
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Ruiwa():
    def __init__(self, a):
        self.H = h = len(a)
        self.W = w = len(a[0])
        self.R = r = a
        for i in range(h):
            for j in range(1,w):
                r[i][j] += r[i][j-1]

        for i in range(1,h):
            for j in range(w):
                r[i][j] += r[i-1][j]

    def search(self, x1, y1, x2, y2):
        if x1 > x2 or y1 > y2:
            return 0

        r = self.R
        rr = r[y2][x2]
        if x1 > 0 and y1 > 0:
            return rr - r[y1-1][x2] - r[y2][x1-1] + r[y1-1][x1-1]
        if x1 > 0:
            rr -= r[y2][x1-1]
        if y1 > 0:
            rr -= r[y1-1][x2]

        return rr

def main():
    n,m = LI()
    na = [LI() for _ in range(n)]
    xd = set()
    yd = set()
    for x,y in na:
        xd.add(x)
        yd.add(y)

    xl = sorted(list(xd))
    yl = sorted(list(yd))
    xx = {}
    yy = {}
    for i in range(len(xl)):
        xx[xl[i]] = i
    for i in range(len(yl)):
        yy[yl[i]] = i
    a = [[0]*(len(yl)+1) for _ in range(len(xl)+1)]
    for x,y in na:
        a[xx[x]][yy[y]] += 1
    rui = Ruiwa(a)
    r = []
    for _ in range(m):
        x1,y1,x2,y2 = LI()
        xx1 = bisect.bisect_left(xl, x1)
        yy1 = bisect.bisect_left(yl, y1)
        xx2 = bisect.bisect(xl, x2) - 1
        yy2 = bisect.bisect(yl, y2) - 1
        r.append(rui.search(yy1,xx1,yy2,xx2))


    return '\n'.join(map(str,r))



print(main())



Measured memory_bytes: 959736
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]


N, M = Is()
H = LI()
notgood = [False]*N

for i in range(M):
    a, b = Is()
    a -= 1
    b -= 1
    if H[a] > H[b]:
        notgood[b] = True
    elif H[b] > H[a]:
        notgood[a] = True
    else:
        notgood[a] = True
        notgood[b] = True

ans = 0
for i in range(N):
    if not notgood[i]:
        ans += 1

print(ans)

Measured memory_bytes: 85140
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#define endl '\n'
using namespace std;
int main()
{
	int s;
	cin>>s;
	vector<int> v;
	vector<int>::iterator it;
	v.push_back(s);
	int ans = 0;
	while(1)
	{
	    ans++;
		if(s%2==0)
			s=s/2;
		else 
		    s = (3*s)+1;
		it = find(v.begin(), v.end(),s);
		if(it==v.end())v.push_back(s);
		else if(it!=v.end()){
			v.push_back(s);
			break;
		}
	}
	cout<<ans+1<<endl;
	return 0;
}

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

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

    string s;
    long long count[5] = {0};
    char march[5] = {'M', 'A', 'R', 'C', 'H'};
    for(int i=0; i<n; i++){
        cin >> s;
        for(int j=0; j<5; j++){
            if(s[0] == march[j]){
                count[j]++;
            }
        }
    }

    long long num = 0;
    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            for(int k=j+1; k<5; k++){
                num += count[i] * count[j] * count[k];
            }
        }
    }
    cout << num << endl;
  
    return 0;
}


Measured memory_bytes: 256
n,*o=open(0)
n=int(n)
r=list(range(n))
print(sum((n-a-b)*all(o[(i+b)%n][(a+j)%n]==o[(j+b)%n][(a+i)%n]for i in r for j in r[i:])for a,b in zip(r+[0]*n,[0]*~-n+r)))

Measured memory_bytes: 41452
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
	string s;
	cin>>s;
	if(s.length()==2) cout<<s<<endl;
	else for(int i=2;i>=0;i--){
      cout<<s[i];
    }
	return 0;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 29.09.2018 15:20:39       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> x(n), y(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  vector<long long> d;
  vector<string> s(n, "");
  if ((x[0] & 1) == (y[0] & 1)) {
    d.push_back(1);
    for (int i = 0; i < n; i++) {
      s[i].push_back('U');
      y[i]--;
    }
  }
  long long step = 1;
  while (step < (1LL << 33)) {
    d.push_back(step);
    for (int i = 0; i < n; i++) {
      if ((x[i] & 1) == (y[i] & 1)) {
        cout << -1 << '\n';
        return 0;
      }
      if (x[i] & 1) {
        if (((x[i] - 1) & 2) != (y[i] & 2)) {
          x[i]--;
          s[i].push_back('R');
        } else {
          x[i]++;
          s[i].push_back('L');
        }
      } else {
        if (((y[i] - 1) & 2) != (x[i] & 2)) {
          y[i]--;
          s[i].push_back('U');
        } else {
          y[i]++;
          s[i].push_back('D');
        }
      }
      x[i] /= 2;
      y[i] /= 2;
    }
    step <<= 1;
  }
  d.push_back(step);
  for (int i = 0; i < n; i++) {
    assert(x[i] * x[i] + y[i] * y[i] == 1);
    s[i].push_back(x[i] == 1 ? 'R' : (x[i] == -1 ? 'L' : (y[i] == 1 ? 'U' : 'D')));
  }
  int m = (int) d.size();
  cout << m << '\n';
  for (int i = 0; i < m; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << d[i];
  }              
  cout << '\n';
  for (int i = 0; i < n; i++) {
    cout << s[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
vector<string> split( string s, string c )
{
	vector<string> ret;
	for( int i=0, n; i <= s.length(); i=n+1 ){

		n = s.find_first_of( c, i );
		if( n == string::npos ) n = s.length();
		string tmp = s.substr( i, n-i );
		ret.push_back(tmp);
	}
	return ret;
}
string num[13] = {"1","2","3","4","5","6","7","8","9","10","11","12","13"};
int main(void){
  string tmp;
  while(cin>>tmp){
    vector<string> cardstr = split(tmp,",");
    vector<int> card;
    REP(i,cardstr.size()){
      REP(j,13){
        if(cardstr[i]==num[j]){
          card.push_back(j+1);
        }
      }
    } 
    sort(card.begin(),card.end());
    int c[3]={0};
    bool st1 = false;
    bool st2 = true;
    //ツカツウツδ督ト
    for(int i=1; i<=13; i++){
      if(count(card.begin(),card.end(),i)>=2){
        c[count(card.begin(),card.end(),i)-2]++;
      }
    }
    //ツスツトツδ個ーツト
    if(card[0]==1&&card[1]==10&&card[2]==11&&card[3]==12&&card[4]==13)
      st1 = true;
    for(int i=1; i<5; i++){
      if(card[i]-card[i-1]!=1){
        st2 = false;
        break;
      }
    }
    if(c[2]){
      cout<<"four card"<<endl;
    }else if(c[1]&&c[0]){
      cout<<"full house"<<endl;
    }else if(st1||st2){
      cout<<"straight"<<endl;
    }else if(c[1]){
      cout<<"three card"<<endl;
    }else if(c[0]==2){
      cout<<"two pair"<<endl;
    }else if(c[0]==1){
      cout<<"one pair"<<endl;
    }else{
      cout<<"null"<<endl;
    }
  }
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  if((N-(N%1000))/1000 == (N/100)%10 && (N/100)%10 == (N%100)/10)
    cout << "Yes" << endl;
  else if((N/100)%10 == (N%100)/10 && (N%100)/10 == N-(N/10*10))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<tuple<string, int, int>> restaurant(n);
    for (int i = 0; i < n; ++i) {
        string s;
        int p;
        cin >> s >> p;
        restaurant[i] = make_tuple(s, 100-p, i+1);
    }
    sort(restaurant.begin(), restaurant.end());
    for (int i = 0; i < n; ++i) cout << get<2>(restaurant[i]) << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include<string>
#include <bitset>

#define SIZE 100001
typedef long long ll;
using namespace std;

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

    int W=0,R=0;
    for(int i = 0 ; i < N ;i++){
        if(c[i] == 'R'){
            R++;
        }
    }
    int ans = R;
    for(int i=0 ; i < N ; i++){
        if(c[i] == 'R'){
            R--;
        }else{
            W++;
        }
        if(max(R,W) < ans){
            ans = max(R,W);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int a[n],b[n];
	for(int i = 0; i < n; i++)	cin >>a[i];
	b[0] = 0;
	b[1] = abs(a[1] - a[0]);
	for(int i = 2; i < n; i++){
		int z = b[i - 1] + abs(a[i] - a[i-1]);
		int z1 = b[i-2] + abs(a[i] - a[i-2]);
		b[i] = min(z,z1);
	}
	cout<<b[n - 1];
}

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

typedef long long ll;

using namespace std;

int main() {
    int N, cnt = 0, i;

    cin >> N;

    for (i = 1; i <= N; i++) {
        if (i >= 10 && i <= 99) {
            continue;
        } else if (i >= 1000 && i <= 9999) {
            continue;
        } else if (i >= 100000 && i <= 999999) {
            continue;
        } 

        cnt++;

    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3584
from itertools import product

s = str(input())
n = len(s)
s = list(s)

sum = 0
for bit in product([0,1],repeat=n-1):
    x = ["+"] * n
    siki = ""
    for i,j in enumerate(bit):
        #print(bit,i,j)
        if j == 1:
            x[i] = ""
    for k in range(n):
        if k != n-1:
            siki = siki + str(s[k])+str(x[k]) 
        else:
            siki = siki + str(s[k])
    sum += eval(siki)
print(sum)

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

public class Program
{
    static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int sum = 0;
        foreach (var i in a)
        {
            sum += i;
        }

        Console.WriteLine(sum <= n ? n - sum : -1);
    }
}

Measured memory_bytes: 28612
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt()
    val cl = IntArray(9)
    A.forEach { a ->
        cl[when (a) {
            in    1.. 399 -> 0
            in  400.. 799 -> 1
            in  800..1199 -> 2
            in 1200..1599 -> 3
            in 1600..1999 -> 4
            in 2000..2399 -> 5
            in 2400..2799 -> 6
            in 2800..3199 -> 7
            else -> 8
        }] += 1
    }
    var min = cl.dropLast(1).count { it > 0 }
    val max = min + cl[8]
    if (min == 0 && cl[8] > 0) min = 1
    println("$min $max")
//System.err.println(cl.joinToString())
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong(offset: Long = 0L) = listOfString().map { it.toLong() + offset}


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

int main ()
{
  long n,m;
  cin >> n >> m;
  long t = max((m -2*n) /4, (long)0);
  m -= 2*t;
  n += t;
  while(true){
    
    if(n * 2 >= m)
 	{
    	cout << m/2<< endl;
   		return 0;
  	}
    m-=2;n++;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define P pair<int,int>
#define SET set<int>
#define mp map<int,int>
#define mk make_tuple
#define got(container,num) get<num-1>(container)
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
using namespace std;
const int INF=LLONG_MAX-1e10;
const int maxn=1e6+1e5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn],ans;
int c[maxn]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
main()
{
    IOS
    cin>>n;
    out(c[n-1])
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define SIZE 1000000 
int main() {
 
    int A[SIZE],i, N,H,sum=0;
    scanf("%d %d",&H, &N);
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
        sum+=A[i];
    }
    if(sum>=H){
        printf("Yes\n");
    }
    else{
         printf("No\n");
    }
    
    return 0;
}



Measured memory_bytes: 1984
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
//char a[55][55];
int dx[] = {1,0,-1,0,1,1,-1,-1};
int dy[] = {0,1,0,-1,1,-1,-1,1};
int main()
{
	dhoom;
	int n , k;
	cin >> n >> k;
	int ans = 1;
	while(n != 0){
		ans = min(ans * 2 , ans + k);
		n--;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
s = input()
num_overopen = 0
num_overclose = 0
import collections
q = collections.deque([])
for i in range(n):
    if s[i] == "(":
        q.append("(")
    if s[i] == ")":
        if len(q) == 0:
            num_overclose += 1
        else:
            q.pop()
print( ("(" * num_overclose) + s + (")" * len(q)))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int n, m; cin >> n >> m;
    priority_queue<int> pq;

    REP(i, n) {
        int x; cin >> x;
        pq.push(x);
    }

    REP(i, m) {
        int x = pq.top(); pq.pop();
        pq.push(x / 2);
    }

    ll ans = 0;
    while (!pq.empty()) {
        ans += pq.top(); pq.pop();
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 892
s=int(input())
a=s//100
b=s%100
if a>=1 and a<=12:
    if b>=1 and b<=12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if b>=1 and b<=12:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 3060
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	for(int n;scanf("%d",&n),n;){
		vector<string> name(n);
		vector<int> wei(n),safe(n),perm(n);
		for(int i=0;i<n;i++){
			char nm[21];
			scanf("%s%d%d",nm,&wei[i],&safe[i]);
			name[i]=nm;
			perm[i]=i;
		}

		vector<int> opt(n);
		double gopt=-1;
		do{
			bool b=true;

			int wsum=0,g=0;
			for(int i=0;i<n;i++){
				int now=perm[i];
				if(wsum>safe[now]){
					b=false;
					break;
				}
				wsum+=wei[now];
				g+=(i+1)*wei[now];
			}

			if(!b)	continue;

			if(gopt<(double)g/wsum){
				gopt=(double)g/wsum;
				opt=perm;
			}
		}while(next_permutation(perm.begin(),perm.end()));

		for(int i=n-1;i>=0;i--)	puts(name[opt[i]].c_str());
	}

	return 0;
}

Measured memory_bytes: 804
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
void solve()
{
   ld L;cin>>L;
   cout<<sp(18)<<(L/3)*(L/3)*(L/3)<<"\n";
}
int main()
{
   fastio
   solve();
  return 0;
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n;
	cin >> n;
	vector<long long> a(n);
	long long s = 0;
	for (auto&& ai : a)
	{
		cin >> ai;
		s += ai;
	}
	long long s1 = a[0];
	long long s2 = s - s1;
	long long mind = abs(s1 - s2);
	for (int i = 1; i < n-1; i++)
	{
		s1 += a[i];
		s2 -= a[i];
		mind = min(mind, abs(s1 - s2));
	}
	cout << mind << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template<class _T> static void getint(_T& a) {
	if (sizeof(_T) > sizeof(int)) {
		scanf("%lld", &a);
	}
	else {
		scanf("%d", &a);
	}
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	LLONG N, K;
	get(N, K);

	LLONG ans = 0;
	if (K == 0) {
		ans = N * N;
	}
	else {
		for (LLONG b = 1; b <= N; b++) {
			ans += std::max(((N / b) * (b - K)), 0LL);
			ans += std::max(((N % b) - K + 1), 0LL);
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3772
N, X = gets.chomp.split(" ").map(&:to_i)

$lengths = [1]
$pats = [1]

(1..N).each do |i|
  $lengths[i] = $lengths[i - 1] * 2 + 3
  $pats[i] = $pats[i - 1] * 2 + 1
end

# レベル n バーガーの、下から x 枚のうちパティの枚数を返す
def rec(n, x)
  return 1 if n == 0
  sum = 0
  x -= 1
  if x > 0
    if x >= $lengths[n - 1]
      sum += $pats[n - 1]
      x -= $lengths[n - 1]
    else
      sum += rec(n - 1, x)
      return sum
    end
  end
  if x > 0
    sum += 1
    x -= 1
  end
  if x > 0
    if x >= $lengths[n - 1]
      sum += $pats[n - 1]
      x -= $lengths[n - 1]
    else
      sum += rec(n - 1, x)
      return sum
    end
  end
  sum
end

puts rec(N, X)


Measured memory_bytes: 1788
x=int(input())
if  x<600:
    print(8)
elif x<800:
    print(7)
elif x<1000:
    print(6)
elif x<1200:
    print(5)
elif x<1400:
    print(4)
elif x<1600:
    print(3)
elif x<1800:
    print(2)
else:
    print(1)

Measured memory_bytes: 9176
N, M = map(int, input().split())

L = []
R = []
l = 0
r = 10 ** 6
for i in range(M):
    a,b = map(int, input().split())
    L.append(a)
    R.append(b)

for i in range(M):
    if l < L[i]:
        l = L[i]
    if r > R[i]:
        r = R[i]

ans = r-l+1
if ans > 0:
    print(ans)
else:
    print("0")

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

vector<vector<int>> cg;
vector<int> pft(10, INT_MAX);

void f(int cur, int cost, int st, vector<bool> check)
{
	if (pft[st] < cost) {
		return;
	}

	if (cur == 1) {
		pft[st] = cost;
		return;
	}

	for (int i = 0; i < 10; ++i) {
		if (check[i]) {
			continue;
		}
		check[i] = true;
		int newcost = cost + cg[cur][i];
		f(i, newcost, st, check);
		check[i] = false;
	}
}

int main()
{
	int h, w;
	cin >> h >> w;

	cg.resize(10, vector<int>(10));
	for (auto& i : cg) {
		for (auto& j : i) {
			cin >> j;
		}
	}

	vector<vector<int>> mat(h, vector<int>(w));
	for (auto& i : mat) {
		for (auto& j : i) {
			cin >> j;
		}
	}

	pft[1] = 0;
	for (int i = 0; i < 10; ++i) {
		if (i == 1) {
			continue;
		}
		vector<bool> check(10, false);
		check[i] = true;
		int cost = 0;
		f(i, cost, i, check);
	}

	int ret = 0;
	for (auto& i : mat) {
		for (auto& j : i) {
			if (j == -1) {
				continue;
			}
			ret += pft[j];
		}
	}
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def main():
    N,M=mis()
    A = lmis()
    S = sum(A)
    ok = sum((4*M)*a>=S for a in A)
    if ok >= M:
        print(Yes)
    else:
        print(No)



main()







Measured memory_bytes: 5680
#include<iostream>
#include<algorithm>
#include <vector>
#include <set>
#include <math.h>

	
using namespace std;
long long MOD=1000000007;

int main(){
	long long N,k;
	cin>>N>>k;
	long long A[N];
	for(int i=0;i<N;i++)cin>>A[i];
	long long d1=0;
	long long d2=0;
	for(int i=0;i<N;i++){
		for(int j=i;j<N;j++){
			if(A[i]>A[j]){
				d1++;
				//cout<<A[i]<<A[j]<<endl;;
			}
			if(A[i]<A[j])d2++;
		}
	}
	long long ans=0;
	//cout<<d1<<d2;
	ans+=(k*(k+1)/2)%MOD*d1%MOD;
	ans+=(k*(k-1)/2)%MOD*d2%MOD;
	cout<<ans%MOD<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 2 * (1e5 + 5), INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> N;
  va.resize(N);

  rep(i, 0, N - 1) { cin >> va[i]; }
}
void solve() {
  int now = 1;
  for (auto ss : va) {
    if (ss == now) {
      debug(now);
      debug2(ss, now);
      now++;
    }
  }

  int ans = N - now + 1;
  if (ans == N) {
    cout << -1 << endl;
    return;
  } else {
    cout << N - now + 1 << endl;
  }

  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=200005;
const int MOD=1000000007;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b;cin>>a>>b;
	if(a<=5)cout<<"0\n";
	else if(a<=12)cout<<b/2<<"\n";
	else cout<<b<<"\n";
}
/*
1 3
#.#


2 3
#.#
..#

3 3
##.
#.#
..#

3
2 5
6 1
3 7
Ans:6

4
3 7
2 9
8 16
10 8
Ans:9
*/


Measured memory_bytes: 256
def insertion_sort(A):
    global N 
    for i in range(1, N):
        key = A[i]
        j = i - 1
        while A[j] > key and j >= 0:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = key
        print(' '.join(list(map(str, A))))
    return 
N = int(input())
A = list(map(int, input().split()))
print(' '.join(list(map(str, A))))
insertion_sort(A)



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

int64_t gcd(int64_t x,int64_t y) {
	if (x == y) return x;
  else if (x > y) { 
    swap(x, y);
  }
  int64_t g = y % x;
  while (g != 0) {
  	g = y % x;
    y = x;
    x = g;  
    if(g == 0) x = y;
  } 
  return x;
}

int64_t lcm(int64_t x, int64_t y) {
	return x * y / gcd(x, y);
} 
int64_t f(int64_t X, int64_t x, int64_t y) {
	return X - (X / x + X / y - X / lcm(x, y));

}
int main() {
 int64_t a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << f(b, c, d) - f(a-1, c, d) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    ll N;
    cin>>N;
    vector<ll>A(N);
    vector<ll>B(N);
    ll ma=-1000000000;
    rep(i,N){
        cin>>A[i];
        cin>>B[i];
        if(ma<A[i]){
            ma=A[i];
        }
    }
    rep(i,N){
        if(ma==A[i]){
            cout<<A[i]+B[i]<<endl;
        }
    }
}

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

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define rep(i, n) for (i = 0; i < n; i++)

int main() {
    ll Q, t, a, b;
    ll i;
    ll minimum = 0;

    multiset<ll> xs_left, xs_right;
    xs_left.insert(-1e10);
    xs_right.insert(1e10);

    cin >> Q;
    rep(i, Q) {
        cin >> t;
        if (t == 1) {
            cin >> a >> b;
            auto left_max_itr = (--xs_left.end());
            auto right_min_itr = xs_right.begin();
            minimum += b; 
            if (a <= *left_max_itr) {
                minimum += *left_max_itr - a;
                xs_right.insert(*left_max_itr);
                xs_left.erase(left_max_itr);
                xs_left.insert(a);
                xs_left.insert(a);
            } else if (*right_min_itr <= a) {
                minimum += a - *right_min_itr;
                xs_left.insert(*right_min_itr);
                xs_right.erase(right_min_itr);
                xs_right.insert(a);
                xs_right.insert(a);
            } else {
                xs_left.insert(a);
                xs_right.insert(a);
            }
        } else {
            cout << *(--xs_left.end()) << ' ' << minimum << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 22424
#include<stdio.h>

#define INFTY 1<<21
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int prim(int);

int M[MAX][MAX],color[MAX],d[MAX],p[MAX];

int main(){
  int n,i,j,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&k);
      if(k==-1)M[i][j]=INFTY;
      else M[i][j]=k;
    }
  }
  printf("%d\n",prim(n));
  return 0;
}

int prim(int n){
  int i,j,mincost,u,cost=0;
  for(u=0;u<n;u++){
    color[u]=WHITE;
    d[u]=INFTY;
    p[u]=-1;
  }
  d[0]=0;

  while(1){
    mincost=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	u=i;
	mincost=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(j=0;j<n;j++){
      if(color[j]!=BLACK && M[u][j]!=INFTY){
	if(M[u][j]<d[j]){
	  d[j]=M[u][j];
	  p[j]=u;
	  color[j]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1)cost+=M[i][p[i]];
  }
  return cost;
}
    
    
  



Measured memory_bytes: 2052
/*
  Reference:-
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1000000007;
const int N=1e5+5;
vector<int> adj[N];
int vis[N];
ll white[N],black[N];
ll add(ll a,ll b){
    ll c=(a*b)%mod;
    return c;
}
void dfs(int x){
    vis[x]=1;
    ll w=1,b=1,wb=1;
    for(auto ch:adj[x]){
        if(vis[ch]==0){
            dfs(ch);
            w=add(w,white[ch]);
            //b=add(b,black[ch]);
            b=(white[ch]+black[ch])%mod;
            wb=add(wb,b);
        }
    }
    if(w==0&&b==0){
        black[x]=1;
        white[x]=1;
    }
    else{
        black[x]=w;
        white[x]=wb;
    }
    //white[x]=add(white[x],1);
}
int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    forn(i,n-1){
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(1);
    //forn1(i,n+1)cout<<i<<" "<<white[i]<<" "<<black[i]<<endl;
    ll ans=(white[1]+black[1])%mod;
    cout<<ans;

    return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(un ique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(3 * n);
    rep(i, 3 * n) cin >> a[i];
    ll ans = LONG_MIN;
    priority_queue<int> greater_pq;
    priority_queue<int, vector<int>, greater<int>> less_pq;
    vector<ll> fdp(n + 1), ldp(n + 1);
    ll fsum = 0, lsum = 0;
    
    rep(i, n) fsum += a[i];
    fdp[0] = fsum;
    rep(i, n) less_pq.push(a[i]);
    
    reps(i, 1, n + 1) {
        int v = less_pq.top();
        
        if (a[n + i - 1] > v) {
            fsum = fsum + a[n + i - 1] - v;
            less_pq.pop();
            less_pq.push(a[n + i - 1]);
        }
        
        fdp[i] = fsum;
    }
    
    reps(i, 2 * n, 3 * n) lsum += a[i];
    ldp[n] = lsum;
    reps(i, 2 * n, 3 * n) greater_pq.push(a[i]);
    
    rrep(i, n) {
        int v = greater_pq.top();
        
        if (a[n + i] < v) {
            lsum = lsum - (v - a[n + i]);
            greater_pq.pop();
            greater_pq.push(a[n + i]);
        }
        
        ldp[i] = lsum;
    }
    
    rep(i, n + 1) {
        ans = max(ans, fdp[i] - ldp[i]);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4216
N,M = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]

INF = float('inf')
dist = [INF] * N
dist[0] = 0
for i in range(N):
    for a,b,c in ABC:
        a,b,c = a-1,b-1,-c
        if dist[b] > dist[a] + c:
            dist[b] = dist[a] + c
            if i==N-1 and b == N-1:
                print('inf')
                exit()
print(-dist[-1])

Measured memory_bytes: 9344
import itertools
import numpy as np 
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# -------------------
n, m, k = map(int, readline().split())
#print(n)
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
a = [0] + a
b = [0] + b
acc = list(itertools.accumulate(a))
bcc = list(itertools.accumulate(b))

#acc = np.array(acc)
#print(acc)
#bcc = np.array(bcc)

ans = 0
j = m
for i, val in enumerate(acc):
  if (val > k):
    break
  else:
    rest = k - val
    #print(rest)
    #j = m
    #一ループ目がJの最大になるので、外側に置いてOK
    while (bcc[j] > rest):
      j -= 1

    ans = max(ans, j + i)


print(ans)

Measured memory_bytes: 65448
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <limits.h>
#include <math.h>

int main(int argc, char *argv[])
{
    int n, m;
    int l, r;
    int l_all, r_all;
    int i;
    int ans;

    scanf("%d %d", &n, &m);

    l_all = 1;
    r_all = n;

    for (i = 0; i < m; i++) {
        scanf("%d %d", &l, &r);
        if (l_all < l) {l_all = l;}
        if (r_all > r) {r_all = r;}
    }

    ans = r_all - l_all + 1;
    if (ans < 0) {ans = 0;}

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
// Problem : C - Tsundoku
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 100005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub uppper_bound
using namespace std;
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	int n,m,k;
	cin >> n >> m >> k;
	int a[n],b[m];
	int ans = 0;
	rep(i,0,n)
	cin >> a[i];
	rep(i,0,m)
	cin >> b[i];
	rep(i,0,n)
	{
		if(a[i] <= k)
		{
			k-=a[i];
			ans = max(ans,i+1);
		}
		else break;
	}
	int ind = ans-1;
	int j = 0;
	while(ind >= -1)
	{
		while(j < m and b[j] <= k)
		{
			k -= b[j];
			j++;
		}
		ans = max(ans,ind+1+j);
		if(ind ==-1)
		break;
		k += a[ind];
		ind--;
	}
	cout << ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 6708
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

long n;
long u,v;
long a;

int main(){
    scanf("%ld", &n);
    a = n*(n+1)*(n+2)/6;
    for(ll i = 1;i < n;i++){
        scanf("%ld %ld", &u, &v);
        if(u < v) a -= u * (n-v+1);
        else a -= v * (n-u+1);
    }
    printf("%ld\n", a);
}


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

#define inf  1e18
#define int  long long
#define float double
#define endl  "\n"
#define w(t)  int t;cin>>t;while(t--)
#define str  to_string
#define vci  vector<int>
#define vcs  vector<string> 
#define mp   make_pair
#define pb   push_back
#define pii   pair<int,int>
#define pis   pair<int,string>
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define mod   1000000007
random_device rd;
mt19937 rand_gen(rd());
#define setbits(x)     __builtin_popcountll(x)
#define trailzero(x)   __builtin_ctzll(x)
#define shuffle(vc) shuffle(vc.begin(), vc.end(), rand_gen);
#define decimal(x,value)  cout<<fixed<<setprecision(x)<<value
void io()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("/home/kashif/cp/input.txt","r",stdin);
		
		freopen("/home/kashif/cp/output.txt","w",stdout);
	#endif

}
int n,p;
int dp[100005];
int h[100005]={0};
int ans(int h[],int k)
{
	
	if(k>=n)
		return dp[k]=0;
	if(k==n-1)
		return dp[k]=abs(h[k]-h[k+1]);
	int &a=dp[k];
	if(a!=-1)
		return a;
	
	else
	{
		a=inf;
		for(int i=1;i<=p && (k+i)<=n;i++)
		{
			a=min(a,abs(h[k]-h[k+i])+ans(h,k+i));
		}
	}
	return a;

}
//


int32_t main()
{
	
	fastio();
	io();
	memset(dp,-1,sizeof(dp));
	cin>>n>>p;
	
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
	}
	cout<<ans(h,1)<<endl;


	
	
}


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

typedef long long int ll;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, k;
	cin >> n >> k;
	int arr[n];
	for (int i = 0; i < n; i++) cin >> arr[i];
	sort(arr, arr+n);
	int sum = 0;
	for (int i = 0; i < k; i++)
		sum += arr[i];
	cout << sum << '\n';
}

Measured memory_bytes: 3652
def _gcd(a, b)
  if a > b
    return a if b == 0

    _gcd(b, a % b)
  else
    return b if a == 0

    _gcd(a, b % a)
  end
end

def gcd(numbers)
  ans = numbers.first

  numbers[1..-1].each do |n|
    ans = _gcd(ans, n)
  end

  return ans
end

N, X = gets.split.map(&:to_i)
Xn = gets.split.map(&:to_i)

diff = Xn.map do |x|
  (X - x).abs
end

puts gcd(diff)


Measured memory_bytes: 9220
#include<iostream>
#include<stack>
#include<string>

int main()
{
  int k,r,l,num;
  std::stack<int> st;
  std::string str;
  while(std::cin>>str){
    if('0'<=str[0]&&str[0]<='9'){
      k=1,num=0;
      for(int i=str.size()-1;i>=0;--i){
	num+=k*(str[i]-'0');
	k*=10;
      }
      st.push(num);
    }
    else{
      r=st.top();
      st.pop();
      l=st.top();
      st.pop();
      if(str[0]=='+')st.push(l+r);
      else if(str[0]=='-')st.push(l-r);
      else if(str[0]=='*')st.push(l*r);
    }
  }
  std::cout<<st.top()<<"\n";
 
  return 0;
}



Measured memory_bytes: 3148
K = int(input())

A = [0 for _ in range(K)]
for i in range(K):
    if i == 0:
        mod = 7 % K
    else:
        mod = (10 * A[i-1] + 7) % K
    A[i] = mod
    if mod == 0:
        print(i+1)
        exit()
print(-1)


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

using namespace std;

const int DIM = 1e5 + 7;

int v[DIM];

main()
{
	int n;
	cin >> n;
	
	n--;
	
	for(int i = 1; i <= n; i++)
		cin >> v[i];
	
	int sum = v[1] + v[n];
	
	for(int i = 1; i < n; i++)
		sum += min(v[i], v[i + 1]);
	
	cout << sum;
}

Measured memory_bytes: 256