akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll n, a[100010], ans, zero;
bool sei, fu;
vector<ll> p, m;

ll pow(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return pow(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = pow(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return pow(x, mod - 2);
}

int main(void)
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] > 0)
		{
			sei = true;
			p.push_back(a[i]);
		}
		else if (a[i] < 0)
		{
			fu = true;
			m.push_back(a[i]);
		}
		else
		{
			sei = true;
			fu = true;
			p.push_back(a[i]);
			zero++;
		}
	}
	sort(a, a + n);
	if (sei && fu && m.size())
	{
		for (int i = 0; i < n; i++)
		{
			if (a[i] > 0)
			{
				ans += a[i];
			}
			else
			{
				ans -= a[i];
			}
		}
		cout << ans << endl;
		for (int i = 1; i < p.size(); i++)
		{
			cout << m[0] << ' ' << p[i] << endl;
			m[0] -= p[i];
		}
		for (int i = 0; i < m.size(); i++)
		{
			cout << p[0] << ' ' << m[i] << endl;
			p[0] -= m[i];
		}
	}
	else if (sei)
	{
		ans -= a[0];
		for (int i = 1; i < n; i++)
		{
			ans += a[i];
		}
		cout << ans << endl;
		ll q = a[0];
		for (int i = 1; i < n - 1; i++)
		{
			cout << q << ' ' << a[i] << endl;
			q -= a[i];
		}
		cout << a[n - 1] << ' ' << q << endl;
	}
	else
	{
		ans += a[n - 1];
		for (int i = 0; i < n - 1; i++)
		{
			ans -= a[i];
		}
		cout << ans << endl;
		ll q = a[n - 1];
		for (int i = n - 2; i > 0; i--)
		{
			cout << q << ' ' << a[i] << endl;
			q -= a[i];
		}
		cout << q << ' ' << a[0] << endl;
	}
	int www;
	cin >> www;
}


Measured memory_bytes: 3572
A="abcdefghijklmnopqrstuvwxyz"
n=int(input())
i=1
while n-26**i>0:
    n-=26**i
    i+=1
name=[]
n-=1
for j in range(i):
    temp=n%26
    name.append(A[temp])
    n//=26
for k in name[::-1]: print(k,end="")

Measured memory_bytes: 9188
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
//max_element

int N,M;
vector<int> link[100010];
int ans[100010] = {};

signed main()
{
	cin >> N >> M;
	REP(i, M)
	{
		int a, b;
		cin >> a >> b;
		link[a].push_back(b);
		link[b].push_back(a);
	}

	queue<int> q;
	q.push(1);
	ans[1] = 1;

	while (q.size() > 0)
	{
		int q_size = q.size();
		for (int i = 0; i < q_size; i++)
		{
			int n = q.front();
			q.pop();
			for (int l : link[n])
			{
				if (ans[l] == 0)
				{
					ans[l] = n;
					q.push(l);
				}
			}
		}
	}

	cout << "Yes" << endl;
	for (int i = 2; i <= N; i++)
	{
		cout << ans[i] << endl;
	}
}




Measured memory_bytes: 12884
#include<iostream>
#include<algorithm>

using namespace std;
int main() {
  int n;
  cin>>n;
  int a[n];
  for(int i=0; i<n; i++) {
    cin>>a[i];
  }

  int max=0, index[n], track = 0;
  for(int i=0; i<n; i++) {
    if(a[i] > max) {
      max = a[i];
      track = 0;
      index[track] = i;
      track ++;
    } else if(a[i] == max){
      index[track] = i;
      track++;
    }
  }
  sort(a, a+n);
  int t2 = 0;
  if(track >= 2) {
    for(int i=0; i<n; i++) {
        cout<<max<<endl;
      }
  } else {
    for(int i=0; i<n; i++) {
      if(i!=index[t2]) {
        cout<<max<<endl;
      }else {
        cout<<a[n-2]<<endl;
        t2++;
      }
    }
  }



  return 0;
}


Measured memory_bytes: 3200
#define ll long long
#define pb push_back
#define make_pair mp
#define first f
#define second s
#define upper_bound ub
#define lower_bound lb
#define MOD 1000000007
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;


#define ordered_set tree<pair<ll,ll> , null_type,less<pair<ll,ll> >, rb_tree_tag,tree_order_statistics_node_update>ll fn



void solve(){
    string s,t;
    cin>>s>>t;
    //make t substring of s;
    ll ans=INT_MAX;
    for(ll i=0;i<s.size()-t.size()+1;i++){
        ll tans=0;
        for(ll j=0;j<t.size();j++){
            if(s[i+j]!=t[j]){
                tans++;
            }
        }
        ans=min(ans,tans);
    }
    cout<<ans;
}

int main ()
{
  ios_base::sync_with_stdio (false);
  cin.tie (NULL);
  ll t;
  //cin>>t;
  t = 1;
  while (t)
    {
      solve();t--;
      //cout<<"end of test case"<<endl;
    }
  return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 1000000000;
        for (int i = 0 ; i < s.length() - 2 ; i++) {
            int n = Integer.valueOf(s.substring(i, i+ 3));
            ans = Math.min(ans, Math.abs(n - 753));
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    map<char, int> mp;
    for(int i = 0; i < s.size(); i++)
    {
        mp[s[i]]++;
    }
    bool ok = true;
    for(auto itr = mp.begin(); itr != mp.end(); itr++)
    {
        if(itr->second % 2 != 0) ok = false;
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef unsigned long long int lli;
#define _FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _READ freopen("input.txt","r", stdin);
#define F first
#define S second
using namespace std;
int main()
{
	lli n,m;
	cin>>n>>m;
	if(n==m)
		cout<<"0";
	else if(n>m)
	{
		lli k=m-n%m;
		cout<<min(n%m,k);
	}
	else
	{
		lli k=min(m-n,n);
		cout<<k;
	}
	
	return 0;
}

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

/* 比較関数(小->大) */
/*
int compar(const char *val1, const char *val2) {
    if ( *val1 < *val2 ) {
        return -1;
    } else if ( *val1 == * val2 ) {
        return 0;
    } else {
        return 1;
    }
}
//*/

int compar(const char *a, const char *b){
    return strcmp(a, b);
}

int main(){
    int N, count;
    char buf;
    char S[300000][20] = {};
    scanf("%d", &N);
    for(int i=0; i<N; i++){
        //ぶち込む
        scanf("%s", S[i]);
    }

    //ソートする
    qsort(S, N, sizeof(char)*20,compar);

    //ひとつ前と違ったらカウント増やす
    count = 1;
    for(int i=1; i<N; i++){
        if(strcmp(S[i-1], S[i]))count++;
    }

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

    return 0;
}

Measured memory_bytes: 11216
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    vector<int>vec(3);
    REP(i,3){
        cin >>vec[i];
    }
    sort(vec.begin(),vec.end());
    if((vec[0]!=vec[1] &&vec[1]==vec[2])||(vec[0]==vec[1] &&vec[1]!=vec[2])){
        cout <<"Yes" << endl;
    }
    else{
        cout <<"No"<<endl;
    }
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		System.out.println((int)(3*Math.pow(reader.nextInt(),2)));
	}
	
	public static void solver() {
		// write logic
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


Measured memory_bytes: 21204
import java.util.*;
  
class Main{
  public static void main(String[] args){
    Scanner stdId = new Scanner(System.in);
    int a = stdId.nextInt(); 
    int b = stdId.nextInt(); 
    int c = stdId.nextInt(); 
    ArrayList<Integer> yakusu = new ArrayList<Integer>();
    for(int i=1; i<=c; i++){
      if(c%i == 0) yakusu.add(i);
    }

    int count = 0;
    for(int i=0; i<yakusu.size(); i++){
      if(a<=yakusu.get(i) && yakusu.get(i)<=b) count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 17364
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s =0;
    if(sc.hasNext())
    s= sc.nextInt();
    int points=0;
    points+=(s/500)*1000;
    points+=((s%500)/5)*5;
    System.out.println(points);
  }
}

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

namespace ABC070_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = new int[n].Select(x => long.Parse(Console.ReadLine())).ToArray();
            var lcmm = 1L;
            for (var i=0;i<n;i++)
            {
                lcmm = lcm(lcmm, s[i]);
            }
            Console.WriteLine(lcmm);
        }
        static long lcm(long a,long b)
        {
            return a / gcd(a, b) * b ;
        }
        static long gcd(long a,long b)
        {
            if (b > a)
            {
                return gcd(b, a);
            }
            else
            {
                while(b != 0)
                {
                    long remainder = a % b;
                    a = b;
                    b = remainder;
                }
            }
            return a;
        }
    }
}


Measured memory_bytes: 13268
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);

    final int numberOfMonsters = scanner.nextInt();
    final int numberOfSpecialMove = scanner.nextInt();
    final List<Integer> hitPoints = new ArrayList<>();
    for (int i = 0; i < numberOfMonsters; i++) {
      hitPoints.add(scanner.nextInt());
    }

    final int numberOfMonstersNeedToAttack = numberOfMonsters - numberOfSpecialMove;
    if (numberOfMonstersNeedToAttack <= 0) {
      System.out.println(0);
    } else {
      Collections.sort(hitPoints);
      long totalOfHitPoints = 0;
      for (int i = 0; i < numberOfMonstersNeedToAttack; i++) {
        totalOfHitPoints += hitPoints.get(i);
      }
      System.out.println(totalOfHitPoints);
    }


  }
}

Measured memory_bytes: 54732
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = Add.num;
        var ar1 = Add.arL;
        var ar2 = Add.arL;
        var dis = ar2.Sum() - ar1.Sum();
        var ct1 = 0L;
        var ct2 = 0L;
        for(var i = 0; i < num; i++)
        {
            if (ar1[i] > ar2[i])
                ct1 += ar1[i] - ar2[i];
            else ct2 += (ar2[i] - ar1[i] + 1) / 2;
        }
        WriteLine(ct1 <= dis && ct2 <= dis ? "Yes" : "No");
    }
}

public class Add
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 13024
h,w = map(int, input().split())

if h == 1 or w == 1:
    print(1)
else:
    if h % 2 == 0:
        print(int((h / 2) * w))
    else:
        if w % 2 == 0:
            print(int(((h//2) * w/2) + ((h//2 + 1) * w/2)))
        else:
            print(int(((h//2 + 1) * (w//2+1)) + ((h//2) * (w//2))))


Measured memory_bytes: 9120
N, M = map(int,input().split())
s = [list(map(int,input().split())) for i in range(M)]
p = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    switch = format(i, '010b')
    switch = switch[-N:]
    cn = 0
    for j in range(M):
        t = s[j]
        count = 0
        for k in t[1:]:
            if int(switch[k-1]) == 1:
                count += 1
        if count % 2 == p[j]:
            cn += 1
    if cn == M:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long long n,k;
	cin>>n;
	long long ar[n][3];
	for(int i=0;i<n;i++){
		for (int j=0;j<3;j++){
			cin>>ar[i][j];
		}
	}
	for(int i=n-2;i>=0;i--){  
		ar[i][0]=ar[i][0]+max(ar[i+1][2],ar[i+1][1]);
		ar[i][1]=ar[i][1]+max(ar[i+1][2],ar[i+1][0]) ;
		ar[i][2]=ar[i][2]+max(ar[i+1][1],ar[i+1][0]);
		
	}
	long long ans=ar[0][0];
	ans=max(ans,ar[0][1]);
	ans=max(ans,ar[0][2]);
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
import sys
import math

line = input()
N = line.split(' ')[0]
D = line.split(' ')[1]

count = 0

for i in range(int(N)):
  inputs = input()
  X = int(inputs.split(' ')[0])
  Y = int(inputs.split(' ')[1])
  if(math.sqrt(pow(X,2) + pow(Y,2)) <= int(D) ):
    count = count + 1

print(count)


Measured memory_bytes: 9200
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<string>
#include<queue>

using namespace std;

int modd=1e9+7;
int n;
int len;
vector<long long> dp;

void update(int curn, int l, int r, int ind, long long val){
    //cout<<"updt called "<< curn <<" "<<l<<" "<<r<<" "<<ind<<" "<<val<<endl;
    if(l>r) return;
    if(ind<l || r<ind) return;
    if(l==r){ dp[curn]=val;  return; }

    int lc=2*curn,rc=lc+1;
    int mid=(l+r)/2;
    update(lc,l,mid,ind,val); update(rc,mid+1,r,ind,val);

    dp[curn]=max(dp[lc],dp[rc]); //cout<<"dp[curn] "<< curn <<" "<<max(dp[lc],dp[rc])<<endl;
}

long long range_query(int curn, int l, int r, int s, int e){
    //cout<<"rq called  "<< curn <<" "<<l<<" "<<r<<" "<<s<<" "<<e<<endl;
    if(l>r) return 0;
    if(e<l || r<s) return 0;
    if(s<=l && r<=e){   return dp[curn]; }

    int lc=2*curn,rc=lc+1;
    int mid=(l+r)/2;

    return max( range_query(lc, l, mid, s, e) , range_query(rc, mid+1, r, s, e) );
}

int main(){
    cin>>n;  len=8*n+1;
    vector<int> ht(n);
    vector<long long> val(n);
    for(int i=0; i<n; i++){ cin>>ht[i]; }
    for(int i=0; i<n; i++){ cin>>val[i]; }

    dp.resize(len); for(int i=0; i<len; i++) dp[i]=0;

    for(int i=0; i<n; i++){
        update(1, 1, n, ht[i], range_query(1, 1, n, 1, ht[i]-1) + val[i] );
    }

    cout<<dp[1]<<endl;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 5002

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

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

	set<ll> adj[n];
	For(i,0,n-1){
		ll x,y;cin>>x>>y;x--;y--;
		adj[x].insert(y);
		adj[y].insert(x);
	}
	priority_queue<ll,vector<ll> , greater<ll> > p;
	For(i,0,n){
		ll c;cin>>c;p.push(c);
	}
	vector<ll> leaves;
	For(i,0,n) if(adj[i].size()==1) leaves.pb(i);
	ll ans[n];
	ll final = 0;
	For(i,0,n){
		ll c = p.top();	p.pop();
		if(i!=n-1) final += c;
		ll l = leaves.back();
		leaves.pop_back();

		ans[l] = c;

		ll a = *(adj[l].begin());
		adj[l].erase(a);
		adj[a].erase(l);

		if(adj[a].size()<=1) leaves.pb(a);
	}

	cout<<final<<endl;
	For(i,0,n){
		cout<<ans[i]<<" ";
	}
	cout<<endl;






	
}


Measured memory_bytes: 2048
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#include<tgmath.h>
#include<stdlib.h>
#include<assert.h>
#include<stdio.h>



#define ll long long


/*
_
_._ _..._ . - ',     _.._(`))
'-. `     ' / -._. - '    ', /
)         \            '.
/ _    _ | \
| a    a    /              |
\   . - .;
'-('' ).-', '       ;
'-;           |      .'
\           \    /
| 7.__  _. - \   \
| |  |  ``/ / `  /
/, _|  |   /, _/   /
/, _ / '`-'
*/
using namespace std;


int main()
{
    int n;
    cin >> n;
    while (n != 0) {
        int dig = n % 10;
        if (dig == 7) {
            cout << "Yes";
            return 0;
        }
        n /= 10;
    }
    cout << "No";
}



Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define int long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n;
int ans;

signed main() {
	cin >> n;
	for (int i = 1; (int)i*(i + 1) <= n; i++) {
		if ((n - i) % i == 0&&n%((n-i)/i)==n/((n-i)/i)) {
			int ta = (n - i) / i;
			ans += ta;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    int N;
    scanf("%d", &N);

    int a[100];
    for (int i=0; i<N; ++i)
        scanf("%d", &a[i]);

    int res=1<<28;
    for (int i=-100; i<=100; ++i) {
        int cur=0;
        for (int j=0; j<N; ++j)
            cur += (a[j]-i)*(a[j]-i);

        if (res > cur)
            res = cur;
    }

    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
    
    int N;
    cin >> N;
    int A[2][N];
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++){
            cin >> A[i][j];
        }
    }
    
    int ans = 0;
    int count = 0;
    for (int i = 0; i < N; i++) {
        int sum = A[0][0] + A[1][N-1];
        bool flag = false;
        for (int j = 1; j < N; j++) {
            if (j == N-i || flag) {
                sum += A[1][j-1];
                flag = true;
            }else{
                sum += A[i - count][j];
                
            }
        }
        ans = max(ans, sum);
        count++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

ll F(ll X){
    if(X <= 0)return 0;
    ll f = 0;
    for(ll i = 0, q = 1; i < 40; i++, q <<= 1){
        ll cnt = X / (q * 2) * q;
        cnt += max(0LL, X % (q * 2) - q + 1);
        if(cnt % 2)f += q;
    }
    return f;
}

int main(){

    ll A, B;
    cin >> A >> B;
    ll ans = F(A - 1) ^ F(B);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  static string[] map;
  static int H;
  static int W;
        static void Main(string[] args)
        {
          //入力を受け取る
          var HW = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          H = HW[0];
          W = HW[1];
          map = new string[H];
          
          //キャンバスの情報を登録
          for(int i = 0; i < H ; i++){
            map[i] = Console.ReadLine();
          }
          
          bool flag = true;
          //全数探索で絵を描けるかどうかを調べる
          for(int i = 0; i < H ; i++){
            for(int j = 0; j < W ; j++){
              //4方向を調べる
              if(map[i][j] == '#' && !PossibleDraw(i,j)){

                flag = false;
                break;
              }
            }
            if(!flag){
              break;
            }
          }
          if(H == 1 && W == 1){
            if(map[0][0] == '#'){
              Console.WriteLine("Yes");
            }else{
              Console.WriteLine("No");
            }
          }
          else if(flag){
            Console.WriteLine("Yes");
          }else{
            Console.WriteLine("No");
          }
        }
  
  static bool PossibleDraw(int i,int j){
    //左を見る
    if(j > 0 &&map[i][j-1] == '#'){
      return true;
    }
    //右を見る
    if(j < W-1 &&map[i][j+1] == '#'){
      return true;
    }
    //上を見る
    if(i > 0 &&map[i-1][j] == '#'){
      return true;
    }
    //下を見る
    if(i < H-1 &&map[i+1][j] == '#'){
      return true;
    }
    return false;
  }
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 998244353
#define INF2 1000000000000000000
#define int long long

int num[100010];
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
    if (x == 0) return 0;
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}
int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int D[100010];
    int maxpath = 0;
    rep(i, N) {
        cin >> D[i];
        num[D[i]]++;
        maxpath = max(maxpath,D[i]);
    }
    if (D[0] != 0 || num[0] != 1) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 1;
    rep(i, maxpath) {
        //cout << num[i] << " " << num[i + 1] << endl;
        ans = Mul(ans,power(num[i], num[i + 1]));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  string s,t;cin >> s >> t;
  t += s;
  cout << t << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

bool search(ll X, vector<ll> Y ) {
    bool sech = false;
    rep(i, Y.size()) {
        if (X & Y[i]) sech = true;
    }
    return sech;
}

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

    ll N; cin >> N;
    ll A[200100]; rep(i, N) cin >> A[i];

    vector<ll> B[200100];

    rep(i, N) {
        per(j, 20) {
            if (A[i] >= (1 << j)) {
                B[i].push_back(1 << j);
                A[i] -= (1 << j);
            }
        }
    }

    ll ans = 0, s = 0, t = 0, C = 0;
    
    for (;;) {
        while (t < N && !(search(C, B[t]))){
            rep(i, B[t].size()) C |= B[t][i];
            t ++;
        }
        ans += (t - s);
        rep(i, B[s].size()) C &= ~B[s][i];
        s ++;
        if ( s == N ) break;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 31488
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
def main():
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]
    def unite(x, y):
        x = find(x)
        y = find(y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x, y = y, x
            par[x] += par[y]
            par[y] = x
            return True
    def members(x):
        root = find(x)
        return [i for i in range(n) if find(i) == root]

    n, m, k = map(int, input().split())
    num_of_friends = [-1] * n
    par = [-1] * n
    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        unite(a, b)
        num_of_friends[a] += -1
        num_of_friends[b] += -1
    roots = defaultdict(int)
    #roots = {e: set() for e in range(n)}
    for i2 in range(n):
        roots[find(i2)] += 1
    for i3 in range(n):
        #num_of_friends[i3] += len(roots[find(i3)])
        num_of_friends[i3] += roots[find(i3)]
    for _ in range(k):
        c, d = map(int, input().split())
        c -= 1
        d -= 1
        if find(c) == find(d):
            num_of_friends[c] -= 1
            num_of_friends[d] -= 1

    for i in range(n):
        print(num_of_friends[i], end=' ')

if __name__ == '__main__':
    main()

Measured memory_bytes: 16996
main(i){float a,b,c,d,e,f,g,h;while(~scanf("%f %f %f %f %f %f %f %f",&a,&b,&c,&d,&e,&f,&g,&h))printf(!(a>g||a>h||c<e||d<f)?"YES\n":"NO\n");return 0;}

Measured memory_bytes: 608
N = int(input())
ans1 = ["AC","WA","TLE","RE"]
ans = [0,0,0,0]
for i in range(N):
  a = input()
  if a == "AC":
    ans[0] += 1
  elif a == "RE":
    ans[3] += 1
  elif a == "TLE":
    ans[2] += 1
  else:
    ans[1] +=1
    
for i in range(4):
  print(ans1[i]+" x " + str(ans[i]))
  

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;
int func(int64_t x){
  int count=0;
  while(x>0){
    x/=10;
    count++;}
  return count;
}
int main(){
  int64_t N;
  cin>>N;
  int ans=INF;
  for(int64_t A=1;A<=sqrt(N);A++){
   if(N%A==0) {int64_t B=N/A;
   int keta=max(func(A),func(B));
   ans=min(ans,keta);
  }}
   
  cout<<ans<<endl;
  return 0;
  }

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back


using namespace std;

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {std::cout << x;}
void __print(unsigned x) {std::cout << x;}
void __print(unsigned long x) {std::cout << x;}
void __print(unsigned long long x) {std::cout << x;}
void __print(float x) {std::cout << x;}
void __print(double x) {std::cout << x;}
void __print(long double x) {std::cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) cout << #mat << "::" << endl; printmat(mat,row,col); printpartition;
#define debugv(v,n) cout << #v << ":" << endl; printv(v,0,n-1); printpartition;
#else
#define debug(x...)
#define matdeb(mat,row,col)
#define debugv(v,n)
#endif

const int maxm = 1000000000 + 7;

const ll MOD = 1e9 + 7;
const int INF = 55;
ll dp [INF] [INF * INF];

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


//----------->CODE BEGINS --------------->


int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    IOS;

    int n;
    cin>>n;

    int a;

   set<int>s;

    while(n--)
    {
       cin>>a;
       s.insert(a);
    }

   cout<<s.size()<<endl;

}


Measured memory_bytes: 3648
n,K = map(int,input().split())
a = [0]+list(map(int,input().split()))+[0]
INF = float("inf")
n += 1
dp = [[[INF for i in range(K+1)] for j in range(n+1)] for k in range(n+1)]
dp[0][0][0] = 0
mx = 0
for i in range(1,n+1):
  x = a[i]
  for j in range(i):
    for k in range(1,min(K,i)+1):
      dp[i][j][k] = dp[i-1][j][k-1]
  for k in range(min(K,i)+1):
    for l in range(1,i+1):
      dp[i][i][k] = min(dp[i][i][k],dp[i-1][i-l][k]+max(0,x-a[i-l]))
print(dp[n][n][K])

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

void solve(long long N, vector<long long> t, vector<long long> x, vector<long long> y){
	for (int i = 0; i < N; i++){
		int time = t[i];
		int x_pos = x[i];
		int y_pos = y[i];

		if (time < (x_pos + y_pos)){
			cout << "No" << endl;
			return;
		}

		int val = time - (x_pos + y_pos);
		if ((val % 2) != 0){
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;	
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> x(N-1+1);
	vector<long long> y(N-1+1);
	vector<long long> t(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&t[i]);
		scanf("%lld",&x[i]);
		scanf("%lld",&y[i]);
	}
	solve(N, t, x, y);
	return 0;
}



Measured memory_bytes: 4992
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll a(n);
  PQR big;
  PQ small;
  rep(i,n){
    cin>>a[i];
    big.pu(a[i]);
    small.pu(a[i]);
  }
  ll ans=0;
  ll ss=big.top();
  big.pop();
  ll bb=small.top();
  small.pop();
  ans=abs(bb-ss);
  ll cu=2;
  while(cu<n){
    if(n-cu==1){
      ll now=big.top();
      ans+=max(abs(bb-now),abs(ss-now));
      break;
    }
    ll sss=big.top();
    big.pop();
    ans+=abs(bb-sss);
    ll bbb=small.top();
    small.pop();
    ans+=abs(ss-bbb);
    ss=sss;
    bb=bbb;
    cu+=2;
  }
  COUT(ans);
}

Measured memory_bytes: 2804
def f(b,n):
    if n < b:
        return n
    else:
        return f(b,n//b)+n%b

def get_divisor(n):
    res = []
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            res.append(i)
            res.append(n//i)
    res = list(set(res))
    res.sort()
    return res

n = int(input())
s = int(input())
ans = -1

for b in range(2,int(n**0.5)+1):
    if f(b,n)==s:
        ans = b
        break

if ans==-1 and n>=s:
    div = get_divisor(n-s)
    div.append(n)
    for b in div:
        b += 1
        if f(b,n)==s:
            ans = b
            break

print(ans)

Measured memory_bytes: 43120
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}

#define trace(...) cerr<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,',');
    cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}

int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int n,weight;
int w[110],v[110];

int cache[100005][110];

int dp(int W, int idx){
    if(W<0) return -1e12;
    if(idx>=n+1 && W>=0) return 0;
    int &ans=cache[W][idx];
    if(ans!=-1) return ans;
    ans=0;
    ans=max(dp(W-w[idx],idx+1)+v[idx],dp(W,idx+1));
    return ans;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> weight;
    rep(i,1,n+1) cin >> w[i] >> v[i];
    mst(cache,-1);
    int res=dp(weight,1);
    cout << res;
    return 0;
}

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

using ll = long long;
const ll INF = 1e18;

const int S = 1 << 17;
const int MAXN = 1.1e5;
const int MAXM = 1.1e5;
const int MAXV = 4 * S + MAXM;

int N, M, V;

vector<pair<int, int>> adj[MAXV];
ll dist[MAXV];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> M;
	V = 4 * S + M;
	for (int i = 1; i < S; i++) {
		adj[2*i].emplace_back(i, 0);
		adj[2*i+1].emplace_back(i, 0);
		adj[2*S+i].emplace_back(2*S+2*i, 0);
		adj[2*S+i].emplace_back(2*S+2*i+1, 0);
	}
	for (int i = 1; i <= N; i++) {
		adj[S+i].emplace_back(3*S+i, 0);
		adj[3*S+i].emplace_back(S+i, 0);
	}
	for (int v = 4 * S; v < V; v++) {
		int l, r, c; cin >> l >> r >> c;
		cerr << l << ' ' << r << ' ' << c << '\n';
		r++;
		for (int a = l + S, b = r + S; a < b; a /= 2, b /= 2) {
			if (a & 1) {
				adj[a].emplace_back(v, 0);
				adj[v].emplace_back(2*S+a, c);
				a++;
			}
			if (b & 1) {
				--b;
				adj[b].emplace_back(v, 0);
				adj[v].emplace_back(2*S+b, c);
			}
		}
	}
	for (int i = 0; i < V; i++) {
		dist[i] = INF;
	}
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
	dist[S+1] = 0;
	pq.emplace(dist[S+1], S+1);
	while (!pq.empty()) {
		ll d = pq.top().first;
		int cur = pq.top().second;
		pq.pop();
		if (d != dist[cur]) continue;
		for (auto it : adj[cur]) {
			int nxt = it.first;
			ll nd = d + it.second;
			if (nd < dist[nxt]) {
				dist[nxt] = nd;
				pq.emplace(dist[nxt], nxt);
			}
		}
	}

	if (dist[S+N] == INF) cout << -1 << '\n';
	else cout << dist[S+N] << '\n';

	return 0;
}


Measured memory_bytes: 70124
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 1e6;

ll n, m, k, t;

string s;

vector <ll> S;

ll getf(ll mx) {
    // cout << "MX " << mx << endl;
    ll mn = 0;
    ll q;
    ll d = 0;
    ll cur = 0;
    for (q = 0; q < s.length(); q++) {
        // cout << q << " " << S[q] << endl;
        if (s[q] == '0') {
            // cout << "cur " << cur << endl << endl;
            cur--;
            mn = min(mn, cur);
            continue;
        }
        if (s[q] == '1') {
            cur++;
            // cout << "cur " << cur << endl << endl;
            mn = min(mn, cur);
            continue;
        }
        if (S[q] + d + 2 <= mx) {
            // cout << q << " UP" << endl;
            d += 2;
            cur++;
        }
        else {
            cur--;
        }
        // cout << "cur " << cur << endl << endl;
        mn = min(mn, cur);
    }
    // cout << mx - mn << " GETF" << endl << endl;
    return mx - mn;
}

int main() {
    pyshnapyshnakaa;
    ll q, w, e, a, b, c;
    cin >> s;
    n = s.length();
    S.resize(n);
    ll z = 0;
    ll cur = 0;
    for (q = 0; q < s.length(); q++) {
        if (s[q] == '1') {
            cur++;
        }
        else {
            cur--;
        }
        S[q] = cur;
        z = max(z, cur);
    }
    // cout << "Z " << z << endl;
    for (q = n - 2; q >= 0; q--) {
        S[q] = max(S[q], S[q + 1]);
    }
    ll ans = min(getf(z), getf(z + 1));
    cout << ans;
    return 0;
}


Measured memory_bytes: 12176
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=2e5+5;
char s[maxn];
ll dp[10000+5];

int main(){
	ll n,p;
	cin>>n>>p;
	cin>>(s+1);
	ll ans=0;
	if(p==2||p==5){
		for(int i=1;i<=n;i++){
			if((s[i]-'0')%p==0){
				ans+=i;
			}
		}
	}
	else {
		ll tmp=0;
		ll base=1;
		//dp[0]=1;
		for(int i=n;i>=1;i--){
			tmp=(tmp+(s[i]-'0')*base)%p;
			base=(base*10)%p;
			dp[tmp]++;	
		}
		ans+=dp[0]+1ll*dp[0]*(dp[0]-1)/2;
		for(int i=1;i<=p-1;i++){
			ans+=1ll*(dp[i]-1)*dp[i]/2;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 512
import numpy as np
N, L = map(int, input().split())
if L>=0:
  print(np.sum([L+i-1 for i in range(2, N+1)]))
elif (L<0)and(abs(L)>=N):
  print(np.sum([L+i-1 for i in range(1, N)]))
else:
  print(np.sum([L+i-1 for i in range(1, N+1)]))

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

int n,m;
int a[50],b[50];
bool graph[50][50];
bool visited[50];

void dfs(int v){
	visited[v]=true;
  	for(int v2=0;v2<n;v2++){
    	if(graph[v][v2]==false) continue;
      	if(visited[v2]==true) continue;
      	dfs(v2);
    }
}

int main() {
	cin>>n>>m;
  
  	for(int i=0;i<m;i++){
    	cin>>a[i]>>b[i];
      	a[i]--;b[i]--;
      	graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }
  	int ans=0;
  	for(int i=0;i<m;i++){
    	graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
      	for(int j=0;j<n;j++) visited[j]=false;
    	dfs(0);
      	bool bridge=false;
      	for(int j=0;j<n;j++){
        	if(visited[j]==false) bridge=true;
        }
      	if(bridge) ans++;
      	graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }
  cout<<ans<<endl;
}
  	

Measured memory_bytes: 256
X = int(input())
a = 1

while (5*a**4+10*a**3+5*a**2+1 < X):
    a = a + 1

I = [i for i in range(-a,a+1)]

flag = 0

for i in I:
    for j in range(-a,i+1):
        if (i**5 - j**5 == X):
            print("%d %d" % (i, j))
            flag = 1
    if (flag):
        break

Measured memory_bytes: 9128
#include<bits/stdc++.h>
#define N 100000
using namespace std;
long long  a[N+1],b[N];
int main(){
	long long  n,total=0;
	cin>>n;

	for(int i=0;i<=n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<n;i++){
		if(b[i]==0)continue;
		if(b[i]>=a[i]){
			total+=a[i];
			b[i]-=a[i];
			a[i]=0;
			if(b[i]==0)continue;
		}else{
			total+=b[i];
			continue;
		}
		if(b[i]>=a[i+1]){
			total+=a[i+1];
			//b[i]-=a[i+1];
			a[i+1]=0;
		}else{
			a[i+1]-=b[i];
			total+=b[i];
		}
	}
	cout<<total<<"\n";
}

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

int main() {

	float a, b;
	cin >> a >> b;

	for (int i = 13; i < 1005;i++) {
		if (0.08 * i >= a && 0.08 * i < a+1 && 0.1 * i >= b && 0.1 * i < b + 1) {
			cout << i << endl;
			return 0;
		}
	}

	
	cout << -1 << endl;
	return 0;
}

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

#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define mem(a, i) memset(a, i, sizeof(a))
#define pb push_back
#define int long long
#define ll long long
#define lson node << 1
#define rson (node << 1) + 1
#define endl "\n"

const int maxn = 1e6 + 10;
const int mod = 998244353;
const double pi = acos(-1);

int gcd(int a, int b)
{
  return b ? gcd(b, a % b) : a;
}

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

int qpow(int a, int n)
{
  int b = 1;
  while (n)
  {
    if (n & 1)
      b = a * b % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return b;
}

class Prime_Number
{
public:
  int prime[maxn], s, v[maxn];
  void prime_init(int n)
  {
    for (int i = 2; i <= n; i++)
    {
      if (!v[i])
      {
        prime[s++] = i;
        for (int j = 1; j * i <= n; j++)
          v[i * j] = 1;
      }
    }
  }
};
int a[maxn];
void solve()
{
  int n;
  sll(n);
  for(int i=0;i<n;i++)
  sll(a[i]);
  sort(a,a+n);
  int ans=0;
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      for(int k=j+1;k<n;k++)
      {
        if(a[i]==a[j]||a[j]==a[k])
        continue;
        else if(a[i]+a[j]>a[k])
          ans++;
      }
  cout << ans;
}
signed main()
{
  solve();
  return 0;
}


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

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

using ll = long long;
using Pi = pair < int, int >;

constexpr int INF = (1 << 30) - 1;
constexpr int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
constexpr int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

template < typename T > T gcd(T a, T b) { return ( b ? gcd(b, a % b) : a ); }
template < typename T > T lcm(T a, T b) { return ( a / gcd(a, b) * b ); }

int main()
{
    int M1, D1, M2, D2;

    cin >> M1 >> D1 >> M2 >> D2;

    cout << (M1 == M2 ? 0 : 1) << endl;

    return ( 0 );
}


Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main (int argc, char *argv[]) {
    int w, h, n;
    int ans = 0;
    cin >> w >> h;
    cin >> n;
    int p[n];
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }

    pair<int, int> uzu = make_pair(1, h);   // out
    pair<int, int> rin = make_pair(1, h-1); // in
    for (int i = 0; i < n; ++i) {
        if (p[i] == 0) {
            if (uzu.first < w && uzu.second == h) uzu.first++;
            else if (uzu.first == w && uzu.second > 1) uzu.second--;
            else uzu.first--;
        }
        else {
            if (rin.first < w - 1 && rin.second == h - 1) rin.first++;
            else if (rin.first == w - 1 && rin.second > 2) rin.second--;
            else rin.first--;
        }
        // cout << "---" << endl;
        // printf("uzu: (%d, %d)\n", uzu.first, uzu.second);
        // printf("rin: (%d, %d)\n", rin.first, rin.second);
        if ((abs(uzu.first - rin.first) + abs(uzu.second - rin.second)) == 1) {
            ans++;
            // cout << "cnt" << endl;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3132
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

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

Measured memory_bytes: 3624