akhauriyash/Code-Regression huggingface dataset:
def find(n):
    if root[n] < 0:
        return n
    else:
        root[n] = find(root[n])
        return root[n]
    
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if root[x] > root[y]:
        x, y = y, x
    
    root[x] += root[y]
    root[y] = x
    
def size(x):
    return -root[find(x)]

def same(x,y):
    return find(x) == find(y)

def member(x):
    rt = find(x)
    return [i for i in range(n) if find(i) == rt]

def roots():
    return [i for i, x in enumerate(root) if x < 0]

def member_count(x):
    return len(roots())

def all_group_members():
    return {r: member(r) for r in roots()}

n , m = map(int,input().split())
root = [-1 for i in range(n)]
ans = [0 for i in range(m)]
ans[m-1] = n*(n-1)//2
hasi = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(m)]
for i in reversed(range(m-1)):
    a , b = hasi[i+1]
    if same(a,b):
        ans[i] = ans[i+1]
    else:
        ans[i] = ans[i+1] - size(a)*size(b)
        unite(a,b)
for i in range(m):
    print(ans[i])

Measured memory_bytes: 93492
#include<iostream>
#include<vector>
#include<random>
#include<unordered_map>
using namespace std;

struct card {
	char mark;
	int num;
	int idx;
};

int partition(vector<card>& arr, int left, int right) {
	const int pivot = arr[right].num;
	int pivotIndex = left - 1;

	for (int i = left; i < right; i++) {
		if (arr[i].num <= pivot) {
			pivotIndex++;
			swap(arr[i], arr[pivotIndex]);
		}
	}
	swap(arr[right], arr[++pivotIndex]);

	return pivotIndex;
}

void quicksort(vector<card>& arr, int left, int right) {

	if (left >= right) return;

	int pivotIndex = partition(arr, left, right);

	quicksort(arr, left, pivotIndex - 1);
	quicksort(arr, pivotIndex + 1, right);
}


int main() {
	int N;
	cin >> N;
	vector<card> quick(N);
	unordered_map<int, int> mp;

	for (int i = 0; i < N; i++) {
		cin >> quick[i].mark >> quick[i].num;
		mp[quick[i].num]++;
		quick[i].idx = mp[quick[i].num];
	}

	quicksort(quick, 0, N-1);

	bool stable = true;
	mp.clear();
	for (int i = 0; i < N; i++) mp[quick[i].num] = 1;
	for (int i = 0; i < N; i++) {
		if (mp[quick[i].num] != quick[i].idx) stable = false;
		else mp[quick[i].num]++;
	}

	if (stable) cout << "Stable" << '\n';
	else cout << "Not stable" << '\n';
	for (auto c : quick) cout << c.mark << " " << c.num << '\n';
}


Measured memory_bytes: 4940
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    A, B = read_ints()
    if A == B:
        return 'Draw'
    if (A == 1 and B == 13):
        return 'Alice'
    if (A == 13 and B == 1):
        return 'Bob'
    if A > B:
        return 'Alice'
    return 'Bob'


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 61156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int W_MAX = 3000;

ll dp[55][W_MAX][55];

int main() {
    int n, a;
    cin >> n >> a;
    int x[n];
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) dp[i][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int w = 0; w < W_MAX; w++) {
                if (w >= x[i]) dp[i + 1][w][j] += dp[i][w - x[i]][j - 1];
                dp[i + 1][w][j] += dp[i][w][j];
            }
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += dp[n][i * a][i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 66560
mod = 10 ** 9 + 7
fact = [1]
inv = [1]
for i in range(200000):
  fact.append(fact[i] * (i + 1) % mod)
  inv.append(pow(fact[i + 1], mod - 2, mod))
def ncr(n, r):
  if n < 0 or r < 0 or n - r < 0:
    return 0
  return fact[n] * inv[r] * inv[n - r] % mod
h, w, a, b = map(int, input().split())
ans = ncr(h + w - 2, h - 1)
for i in range(min(a, b)):
  ans -= ncr(h - a + b - 1, h - a + i) * ncr(w - b + a - 1, w - b + i)
print(ans % mod)


Measured memory_bytes: 19040
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        if (N % 2 == 0) {
            System.out.println(0.5f);
        } else {
            System.out.println((N + 1f) / (2 * N));
        }
    }
}

Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int puls = a + b;
		int minus = a - b;
		int times = a * b;
		
		int max = 0;
		
		max = Math.max(puls, minus);
		max = Math.max(max, times);

		System.out.print(max);
		
	} 
}

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

main()
{
  int n;
  cin>>n;
  
  int a[n][3];
  for(int i=0;i<n;++i) cin>>a[i][0]>>a[i][1]>>a[i][2];
  int ans[n][3]={};
  ans[0][0]=a[0][0];
  ans[0][1]=a[0][1];
  ans[0][2]=a[0][2];
  
  for(int i=1;i<n;++i)
  {
	ans[i][0]=a[i][0]+max(ans[i-1][1],ans[i-1][2]);
	ans[i][1]=a[i][1]+max(ans[i-1][0],ans[i-1][2]);
	ans[i][2]=a[i][2]+max(ans[i-1][1],ans[i-1][0]);
  }
  cout<<max(ans[n-1][0],max(ans[n-1][1],ans[n-1][2]));
  
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  uli a, b, c, h, k, n, w, ans = 1, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> n;
  vlli d(n);
  rep(i, 0, n)
  {
    cin >> d[i];

    if (d[i] == 0)
      count++;
  }
  if (count >= 1)
  {
    cout << 0 << endl;
    return 0;
  }
  rep(i, 0, n)
  {
    ans *= d[i];
    if (ans > 1000000000000000000LL || ans <= 0)
    {
      cout << -1 << "\n";
      return 0;
    }
    // cout << "ans: " << ans << "\n";
  }

  if (ans > 1000000000000000000LL)
  {
    cout << -1 << "\n";
  }
  else
  {
    cout << ans << "\n";
  }
}


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

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

Measured memory_bytes: 3620
import numpy as np

n = int(input())
ans = np.Inf

for i in range(1,int(n/2+1)):
    a = str(i)
    b = str(n - i)
    an = 0
    for j in range(len(a)):
        an += int(a[j])
    for k in range(len(b)):
        an += int(b[k])
    if an < ans:
        ans = an
print(ans)

Measured memory_bytes: 12504
#include <iostream>
#include <typeinfo>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
#define LEN 100005
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main(void) {
    ll n;
    cin >> n;
    ll i, j;
    ll cnt, ans=0;
    for(i=1; i<=n; i+=2) {
        cnt=0;
        for(j=1; j<=i; j+=2) {
            if(i%j==0) cnt++;
        }
        if(cnt==8) ans++;
    }
    cout << ans << endl;
    
    
}


Measured memory_bytes: 256
// Fibonacci_Number.cs

using System;

class Fibonacci_Number {
	public static void Main() {

		int n = int.Parse(Console.ReadLine());

		if(n == 0 || n == 1) {
			Console.WriteLine(1);
		} else {

			Console.WriteLine(Fib(n));

		}

	}

	public static int Fib(int n) {

		int[] a = new int[n + 1];
		a[0] = a[1] = 1;

		for(int i = 2; i <= n; i++) {
			a[i] = a[i - 1] + a[i - 2];
		}

		return a[n];

	}

}

Measured memory_bytes: 9200
import java.util.*;
import java.util.Collections;
import java.util.ArrayList;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int a = 0;
        int b = 0;
        ArrayList<Integer> list = new ArrayList<Integer>();

        for(int i=0; i<N; i++){
            list.add(sc.nextInt());
        }

        Collections.sort(list, Collections.reverseOrder());

        for(int i=0; i<N; i++){
            if(i%2==0){
                a += list.get(i);
            }
            else{
                b += list.get(i);
            }
        }
        System.out.println(a - b);
    } 
}

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

#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}

using namespace std;

int main() 
{	
	fast;
	ll a,b; cin>>a>>b;
	if(b >= a) cout << "unsafe" << endl;
	else cout << "safe" << endl;
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;
 
int main(void){
    // Your code here!
    double L;
    
    cin >> L;

    cout << setprecision(24)<<(L/3)*(L/3)*(L/3) << endl;
   
    return 0;
    
}

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

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	while ( stdin.hasNextInt() ) {

	    final int n = stdin.nextInt();
	    System.out.println( ( n + 1 ) * n / 2 + 1 );
	    
	}	
    }
    
}

Measured memory_bytes: 17196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	ll N; cin >> N;
	V<ll> A(N),B(N);
	for(int i = 0; i < N; ++i) cin >> A[i] >> B[i];
	V<P<ll,ll>> ord(N);
	for(int i = 0; i < N; ++i) ord[i] = {B[i],A[i]};
	sort(ALL(ord));

	ll t = 0;
	for(int i = 0; i < N; ++i){
		if(t + ord[i].second <= ord[i].first){
			t += ord[i].second;
		}
		else{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	
	return 0;
}


Measured memory_bytes: 6528
#include <stdio.h>
using namespace std;
int main(void){
    char w; int i,j;
    int Q[123]={0};
    i=97;j=0;
         
         for(int i=0;i<1200;i++){
          scanf("%c",&w);
          Q[w]=Q[w]+1;
          }
    
         while(i<123){
        if(i<122)printf("%c : %d\n",i,Q[i]+Q[i-32]);
        else printf("%c : %d\n",i,Q[i]+Q[i-32]);
        i=i+1;
          }
    
}


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

int main(){
    long long n, k;
    cin >> n >> k;
    long long ans = 0;

    for (int i = k; i <= n+1; ++i){
        ans += i * (n - i + 1) + 1;
        ans %= 1000000007;
    }
    cout << ans << endl;
}

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

int main(){
  int n;
  cin>> n;
  vector<int> w(n);
  for (int i=0; i<n; i++) cin>> w.at(i);
  
  int var=0;
  for (int i=0; i<n; i++) var+=w.at(i); //wの総和
  int ans=2*w.at(n-1)-var; //次のfor ifに入らなかった時の答え
  for (int i=0; i<n-1; i++){
    var-=2*w.at(i); //T=i+1の時のS2-S1
    if (var<=0){ //S2-S1の正負が切り替わる前後を考える
      ans=min(var+2*w.at(i),abs(var));
      break;
    }
  }
  cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, K, a[N];
char s[N];
int main() {
	scanf("%s %d", s + 1, &K);
	n = strlen(s + 1);
	for (int i = 1; i <= n; i++) {
		a[i] = s[i] - 'a';
		if (a[i]) {
			if ((26 - a[i]) <= K) {
				K -= (26 - a[i]);
				a[i] = 0;
			}
		}
	}
	K %= 26;
	if (K) {
		a[n] = (a[n] + K) % 26;
	}
	for (int i = 1; i <= n; i++) putchar(a[i] + 'a');
	return 0;
}

Measured memory_bytes: 4152
#include <cstdio>
#include <cstring>
#define rng(x, y) (0 <= x && x < W && 0 <= y && y < H)
int H, W, n, gx, gy, x[12][12], d[4] = { 1, 0, -1, 0 };
int solve(int sx, int sy, int depth) {
	if (depth++ == n) return ((sx == gx || sy == gy) ? 1 : 0);
	int ret = 0;
	for (int i = 0; i < 4; i++) {
		int tx = sx + d[i], ty = sy + d[i ^ 1];
		while (rng(tx, ty)) {
			if (x[ty][tx] == 1) {
				x[ty][tx] = 0;
				ret += solve(tx, ty, depth);
				x[ty][tx] = 1;
				break;
			}
			tx += d[i];
			ty += d[i ^ 1];
		}
	}
	return ret;
}
int main() {
	while (scanf("%d%d", &W, &H), W | H) {
		n = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				scanf("%d", &x[i][j]);
				if (x[i][j] == 1) n++;
				if (x[i][j] == 2) gx = j, gy = i;
			}
		}
		printf("%d\n", solve(gx, gy, 0));
	}
	return 0;
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, y, z;
	cin >> x >> y >> z;
	x -= z;
	int ans = 0;
	ans += x / (y + z);
	if (x % (y + z) >= y + z) ans++;

	dunk(ans);

	return 0;
}

Measured memory_bytes: 256
import heapq
n, m = [int(x) for x in input().split()]
prices = [-int(x) for x in input().split()]
heapq.heapify(prices)

for _ in range(m):
  maxp = -heapq.heappop(prices)
  heapq.heappush(prices, -(maxp // 2))

print(abs(sum(prices)))

Measured memory_bytes: 14180
/*
гонфлад
*/
#pragma ARCENIY_KIRILLOV_UVIDEL_KROKODILOV
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;



main(){
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b >= c){
        cout << b + c;
    }else
        cout << b + b + a + 1;



}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N, X;
    cin >> N >> X;
    vector<ll> L(N);
    Rep (i, N) cin >> L[i];

    ll now = 0;
    ll ans = N+1;
    Rep (i, N) {
        now += L[i];
        if (now > X) {
            ans = i + 1;
            break;
        }
    }

    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

LL N;
int X, M;

void naive() {
    LL A = X;
    LL ans = A;
    FOR(i, 2, N + 1) {
        A = (A * A) % M;
        ans += A;
    }
    cout << ans << endl;
}

void solve() {
    cin >> N >> X >> M;

    LL loop_cur = -1;
    LL loop_sum = -1;
    int loop_l = -1, loop_r = -1;
    map<LL, pair<int, LL>> vis;
    LL A = X;
    LL ans = A;
    vis[X] = {1, X};
    FOR(i, 2, N + 1) {
        const auto cur = (A * A) % M;
        if (vis.count(cur)) {
            loop_l = vis[cur].first;
            loop_r = i;
            loop_sum = ans + cur - vis[cur].second;
            loop_cur = cur;
            break;
        }
        vis[cur] = {i, ans + cur};
        A = cur;
        ans += A;
    }

    if (loop_l > -1) {
        const auto nokori = N - loop_r;
        const auto matomeru = nokori / (loop_r - loop_l);
        const auto saigo = loop_r + matomeru * (loop_r - loop_l);

        ans += loop_sum * matomeru;

        A = loop_cur;
        ans += A;
        for (LL i = saigo; i < N; i++) {
            const auto cur = (A * A) % M;
            A = cur;
            ans += A;
        }
    }

    cout << ans << endl;
}

int main(void) {
#ifndef ONLINE_JUDGE
    const auto in_stream = freopen("../in.txt", "r", stdin);
    if (in_stream == nullptr) {
        cerr << "ERROR!" << endl;
        return 1;
    }
#endif

    solve();

#ifndef ONLINE_JUDGE
    fclose(in_stream);
#endif
}


Measured memory_bytes: 6688
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll A(N+2);
        rep(i, 1, N+1) cin >> A[i];
        vll diff(N+1);
        rep(i, 0, N+1) diff[i] = abs(A[i+1]- A[i]);
        ll sm = accumulate(all(diff), 0LL);

        rep(i, 1, N+1) {
                ll tmp = sm - (diff[i-1] + diff[i]);
                tmp += abs(A[i+1] - A[i-1]);
                cout << tmp << endl;
        }
}

Measured memory_bytes: 4756
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define INF ((1LL<<62)-(1LL<<31))
#define min(p,q)((p)<(q)?(p):(q))

int a,b;
int m[900],mm;



//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[400010];//適宜変える(ecnt)
	int inv[400010];//逆辺のindex(ecnt)
	int id[900];//適宜変える(vcnt)
}G;
G g;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}
int csort(const void*a,const void*b){
	ll p=(*(E*)a).c,q=(*(E*)b).c;
	return p<q?-1:p>q?1:0;
}
//*
void makeinvedge(){
	//逆辺とidx
	rep(i,0,g.ecnt){
		int l=0,r=g.ecnt;
		while(r-l>1){
			int m=(l+r)/2;
			if(g.e[m].s<g.e[i].g||(g.e[m].s==g.e[i].g&&g.e[m].g<=g.e[i].s))l=m;
			else r=m;
		}
		if(g.e[l].s!=g.e[i].g||g.e[l].g!=g.e[i].s){
			g.e[g.ecnt].s=g.e[i].g;
			g.e[g.ecnt].g=g.e[i].s;
			g.e[g.ecnt].c=0;
			g.ecnt++;
		}
	}
	qsort(g.e,g.ecnt,sizeof(E),esort);
	rep(i,0,g.ecnt){
		int l=0,r=g.ecnt;
		while(r-l>1){
			int m=(l+r)/2;
			if(g.e[m].s<g.e[i].g||(g.e[m].s==g.e[i].g&&g.e[m].g<=g.e[i].s))l=m;
			else r=m;
		}
		g.inv[i]=l;
	}
}
//*/
void readgraph(){
	//適宜変える
	g.vcnt=mm+2;
	rep(i,0,mm){
		if(m[i]<0){
			g.e[g.ecnt].s=mm;
			g.e[g.ecnt].g=i;
			g.e[g.ecnt].c=1;
			g.ecnt++;
		}else{
			g.e[g.ecnt].s=i;
			g.e[g.ecnt].g=mm+1;
			g.e[g.ecnt].c=1;
			g.ecnt++;
		}
		rep(j,i+1,mm){
			int t=abs(m[i]+m[j]);
			//正のやつと負のやつをマッチングするしかないので二部グラフ
			if(t<=a||(b<=t&&t<=a+a)){
				g.e[g.ecnt].s=m[i]<0?i:j;
				g.e[g.ecnt].g=m[i]<0?j:i;
				g.e[g.ecnt].c=1;
				g.ecnt++;
			}
		}
	}
	
	qsort(g.e,g.ecnt,sizeof(E),esort);
//	qsort(g.e,g.ecnt,sizeof(E),csort);
	makeinvedge();

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}



//dinic O(VVE)
//ソースs,シンクtを引いてsからtへの最大流を返す
//*
int dist[1010];//ソースからの距離
int checked[1010];//dfsの行き止まりフラグ
void dinicbfs(int s){
	rep(i,0,g.vcnt)dist[i]=-1;
	dist[s]=0;
	//まだ流せる辺だけを使ってbfs
	int que[1010],qcnt=0;
	que[qcnt++]=s;
	rep(q,0,qcnt){
		int v=que[q];
		rep(i,g.id[v],g.id[v+1])if(g.e[i].c>0&&dist[g.e[i].g]==-1){
			dist[g.e[i].g]=dist[v]+1;
			que[qcnt++]=g.e[i].g;
		}
	}
}
ll dinicdfs(int a,int t,ll m){
	//aはm受け取ってる(⇔aから最大m流せる)
	//いくら流せるかを返す
	if(a==t)return m;
	if(checked[a])return 0;
	ll ans=0;
	checked[a]=1;
	rep(i,g.id[a],g.id[a+1])if(g.e[i].c>0&&dist[g.e[i].g]>dist[a]){
		int b=g.e[i].g;
		ll addedflow=dinicdfs(b,t,min(m,g.e[i].c));
		if(addedflow){
			g.e[i].c-=addedflow;
			g.e[g.inv[i]].c+=addedflow;
			checked[a]=0;
			ans+=addedflow;
			m-=addedflow;
			if(m<=0)break;
		}
	}
	return ans;
}
//ソース,シンク
ll dinic(int s,int t){
	ll ans=0;
	int flag=1;
	while(flag){
		flag=0;//更新フラグ
		dinicbfs(s);
		while(!checked[s]){
			ll addedflow=dinicdfs(s,t,INF);
			ans+=addedflow;
			if(addedflow)flag=1;
		}
		rep(i,0,g.vcnt)checked[i]=0;
	}
	return ans;
}
//*/




int main(){
	int n;
	int ans=0;
	scanf("%d%d%d",&n,&a,&b);
	rep(i,0,n){
		int p,q;
		scanf("%d%d",&p,&q);
		int t=abs(p-q);
		if(t<=a||(b<=t&&t<=a+a))ans++;
		else m[mm++]=p-q;
	}
	readgraph();
	printf("%d\n",ans+dinic(mm,mm+1));
}


Measured memory_bytes: 4808
function Main(input) {
    const total = parseInt(input, 10);
    let counter = 0;
  
    let finish = false;
    for (let i = 1; i <= total; i++) {
        for (let t = 1; t <= total; t++) {
            for (let v = total - (i * t); v <= total; v++) {
                if (v <= 0 || total < (i * t) + v) {
                      break;
                }
                counter++;
            }
            if (total <= i * t) {
                break;
            }
        }
    }
  
  //出力
  console.log(counter);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 32184
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <map>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 60;

ll n, p;

void dfs(string s, char mx) {
  if (s.size() == n) cout << s << '\n';
  else {
    for (char c = 'a'; c <= mx; c++) {
      dfs(s + c, c == mx ? c + 1 : mx);
    }
  }
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> n;
  dfs("", 'a');
  return 0;
}



Measured memory_bytes: 1536
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (k, a, b) = get!(usize, usize, usize);
    if a > b || (a <= b && b - a <= 2) {
        println!("{}", k + 1);
        return;
    }
    let mut ans = 0;
    let mut x = k - (a - 1);
    if x % 2 == 0 {
        ans = (x / 2) * b - (x / 2 - 1) * a;
    } else {
        ans += 1;
        x -= 1;
        ans += (x / 2) * b - (x / 2 - 1) * a;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

    long long sum = 0;

    for(int i = 1; i <= n; i++){
        if(i % 3 == 0 || i % 5 == 0){
            continue;
        }
        sum += i;
    }

    printf("%lld\n", sum);
    return 0;
}

Measured memory_bytes: 3752
#define _CRT_SECURE_NO_WARNINGS 1

#include <set>
#include <map>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i++)
#define per(i,a,b) for(int i = (a) ; i >= (b) ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int INF = 1e9;
const LL mod = 1e9 + 7;
const int maxn = 5e5 + 7;

int a[maxn];
int n;

struct node {
    int l,r;
    int id;
}q[maxn];

bool cmp(node aa,node bb) {
    return aa.r < bb.r;
}

int c[maxn];

int lowbit(int x) {
    return x & (-x);
}

void update(int x,int y) {
    for(int i = x ; i <= n ; i += lowbit(i)) {
        c[i] += y;
    }
}

int query(int x) {
    int ans = 0;
    for(int i = x ; i > 0 ; i -= lowbit(i)) {
        ans += c[i];
    }
    return ans;
}

int vis[maxn];
int ans[maxn];

int main() {
    int m;
	sd(n), sd(m);
    for(int i = 1 ; i <= n ; i++) {
        sd(a[i]);
    }
    for(int i = 1 ; i <= m ; i++) {
		sd(q[i].l), sd(q[i].r);
        q[i].id = i;
    }
    sort(q+1,q+m+1,cmp);
    int cnt = 1;
    for(int i = 1 ; i <= n ; i++) {
        if(vis[a[i]]) {
            update(vis[a[i]],-1) , update(i,1);
            vis[a[i]] = i;
        } else {
            update(i,1);
            vis[a[i]] = i;
        }
        while(q[cnt].r == i) {
            ans[q[cnt].id] = query(q[cnt].r) - query(q[cnt].l - 1);
            cnt++;
        }
    }
    for(int i = 1 ; i <= m ; i++) {
        pd(ans[i]);
    }
    return 0;
}


Measured memory_bytes: 17376
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };


ll solve(ll x){
  //0~xまでのxor和を求める
  //0,1,2,3/4,5,6,7とか4つごとに分けていくと0~3を足したものも、4~7を足したものも0になる、なのでmod4の世界で考えればよくて。例えば0,1,2,3の中でxが0に当てはまるときは何も足さないことと同じなのでxをそのまま返す、1だったら1しか残らないので１を返す、2だったらx+1を、3だったら全部足すので０を返す
  //xの周辺4つ以外は足し合わせで0になってるの気にしないでいい
  switch(x%4){
      case 0:
        return x;
      case 1:
        return 1;
      case 2:
        return x+1;
      case 3:
        return 0;
  }
}

int main() {
    ll A,B;
    cin >> A >> B;
    //0~B - 0~A-1をすればいい
    ll ans = (solve(B)^solve(A-1));//xorの世界では＋もーでも^とればいい
    fin(ans);
    
}
    



Measured memory_bytes: 256
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N, P = map(int, readline().split())
    S = [int(i) for i in readline().strip()[::-1]]

    ans = 0
    if P == 2 or P == 5:
        for i, s in enumerate(S):
            if s % P == 0:
                ans += N - i
        
        print(ans)
        exit()

    a = [0]
    s = 0
    for i in range(N):
        s += S[i] * pow(10, i, P)
        a.append(s % P)
    
    t = Counter(a)

    ans = 0
    for v in t.values():
        ans += v * (v-1) // 2
    
    print(ans)

    


if __name__ == "__main__":
    main()


Measured memory_bytes: 13364
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    ll n; cin >> n;
    string res = "";
    while (n > 0) {
        n--;
        res += (char)('a'+n%26);
        n /= 26;
    }
    reverse(all(res));
    cout << res << endl;
}

Measured memory_bytes: 3612
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	int sum = 0;
	for(int i = 0; i < 3; i++) 
		if (s[i] == 'o') sum += 100;
	cout << 700 + sum << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int W=sc.nextInt();
        int H=sc.nextInt();
        int x=sc.nextInt();
        int y=sc.nextInt();
        int r=sc.nextInt();
        
        if(W>=x+r && 0<=x-r && H>=y+r && 0<=y-r){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    } 
}


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

int main() {
    int N,i,j,k,r=0,x;
    cin >> N;
    vector<int> L(N);

    for(i=0; i<N; i++)
        cin >> L.at(i);
    sort(L.begin(), L.end());

    for(i=N-2; i>=1; i--)
        for(j=i-1; j>=0; j--) {
            x = distance(lower_bound(L.begin(), L.end(), L.at(i)+L.at(j)), L.end());
            r += N-1-i-x;
        }
    
    cout << r << endl;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
X_sorted = sorted(X)
c = X_sorted[(1 + N) // 2 - 1]
d = X_sorted[(1 + N) // 2 + 1 - 1]
for i in range(N):
    if X[i] > c:
        print(c)
    elif X[i] < c:
        print(d)
    else:
        print(d)

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n,m;
	t = 1;
	while(t--) {
	 cin >> n >> m;
	 cout << (n - 1) * (m - 1) << endl;
	}
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		// weight(?????£?????????) loadNum(???????????°) carNUm(?????????????????°) loadList[](???????????????????????????)
		int weight;
		int loadNum = scanner.nextInt();
		int carNum = scanner.nextInt();
		int[] loadList = new int[loadNum];

		// ??????????????????????´? ?????????????????????????????????????????????????±???????
		int sumWeight = 0;
		int max = 0;
		for (int i = 0; i < loadNum; i++) {
			loadList[i] = scanner.nextInt();
			sumWeight = sumWeight + loadList[i];
			if (max < loadList[i]) {
				max = loadList[i];
			}
		}
		weight = sumWeight / carNum;
		if (sumWeight % carNum != 0) {
			weight = weight + 1;
		}
		// ??????????????????????????£????????????????????£??????????????£?????????????????§????????????????´???????
		if (weight < max) {
			weight = max;
		}
		boolean flag = false;
		// ???????????? roop??????????????§?????£?????????????????????????????????
		while (true) {
			roop: {
				// ??????(track)????????????????????????????????????????????????????????????
				// ??????????????????????????????????????¨????????????roop????????¨??§??£?¨??????????
				int[] track = new int[carNum];
				int count = 0;
				//System.out.println(weight + "????????????");
				for (int i = 0; i < track.length; i++) {
					for (int j = count; j < loadList.length; j++) {
						// ?????¨??????????????¨?¬??????????????????????????????£?????????????¶???????????????°????¬????????????????????????????
						// ?????¶?????????????????´?????????count????????°j??????(??????????????????????´???????)?????£??\?????????????????§???????????????????????????????????????break????¬????????????????????????????
						if (weight >= track[i] + loadList[j]) {
							track[i] += loadList[j];
							flag = true;
							//System.out.println("??????" + track[i] + " " + (i + 1) + "??????");
						} else {
							if (i == track.length -1 && weight < track[i] + loadList[j]) {
								weight = weight + 1;
								//System.out.println(weight + "????????´");
								flag = false;
								break roop;
							}
							//System.out.println("shori");
							count = j;
							break;
						}
					}
				}
			}
			if (flag == true) {
				break;
			}
		}
		//System.out.println("??????????????????" + weight);
		System.out.println(weight);
	}
}

	

Measured memory_bytes: 70616
#include <stdio.h>

int main(void){

	long long int a, b;
	
	scanf("%lld", &a);
	scanf("%lld", &b);

	if(a <= 0 && b >= 0){
	
		printf("Zero\n");
		return 0;

	}else if(a < 0 && b <0){

		if((b - a)%2 == 0){
			printf("Negative\n");
			return 0;
		}else{
			printf("Positive\n");
			return 0;
		}
	}else if(a > 0 && b > 0){
	
		printf("Positive\n");
		return 0;

	}	

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

string N;
int g[11] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1 };
int memo[1000010][2];
int f(int i, int j) {
    if (i < 0) {
        if(j == 0) return 0;
        else return 1;
    }
    if (0 <= memo[i][j]) return memo[i][j];

    int res = inf;
    rep(d, 0, 10) {
        int n = N[i] - '0' + j;

        int sm = g[d];
        if (d < n) sm += f(i - 1, 1) + g[10 + d - n];
        else sm += f(i - 1, 0) + g[d - n];

        chmin(res, sm);
    }

    return memo[i][j] = res;
}
void _main() {
    cin >> N;
    rep(i, 0, 1000010) rep(j, 0, 2) memo[i][j] = -1;
    cout << f(N.length()-1, 0) << endl;
}

Measured memory_bytes: 87324
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep2(i,n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
template <class T>
using Grid = vector<vector<T>>;

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

Measured memory_bytes: 4824
#include <bits/stdc++.h>
#define N 10050
using namespace std;
clock_t st;
int n, m, K, e = 2, head[N], dfn[N], low[N], tot, tim, bo[N * 20], ok[N * 20], be[N], Dp[N];
int fa[N][18], rt[N], dep[N], pp[N], a[N], b[N], dta[N], dtb[N];
struct edge{int u, v, next;}ed[N * 20];
void add(int u, int v){ed[e].u = u; ed[e].v = v; ed[e].next = head[u]; head[u] = e++;}
vector<pair<int, int> > V[N];
vector<int> vr;
int cnt = 0;
void tarjan(int x, int fa){
	++cnt;
	if(cnt > 100000) assert(0);
	dfn[x] = low[x] = ++tim;
	for(int i = head[x]; i; i = ed[i].next){
		int v = ed[i].v;
		if(!dfn[v]){
			tarjan(v, x);
			low[x] = min(low[x], low[v]);
			if(low[v] > dfn[x]) bo[i] = bo[i ^ 1] = 1;
		}
		else if(dfn[v] < dfn[x] && v != fa)
			low[x] = min(low[x], dfn[v]);
	}
}
void dfs(int x, int d, int fa){
	be[x] = tot; Dp[x] = d;
	for(int i = head[x]; i; i = ed[i].next){
		if(bo[i]) continue;
		int v = ed[i].v;
		if(!be[v]) {ok[i] = 1; dfs(v, d + 1, x);}
		else if(v != fa && Dp[v] < Dp[x]) {ok[i] = 1;}
	}
}
void dfs(int x, int root){
	rt[x] = root;
	for(int i = 1; (1 << i) <= dep[x]; i++)
		fa[x][i] = fa[fa[x][i - 1]][i - 1];
	for(int i = 0; i < (int)V[x].size(); i++){
		int v = V[x][i].first;
		if(v == fa[x][0]) continue;
		pp[v] = V[x][i].second;
		fa[v][0] = x;
		dep[v] = dep[x] + 1;
		dfs(v, root);
	}
}
int getlca(int x, int y){
	if(dep[x] < dep[y]) swap(x, y);
	for(int i = 14; ~i; i--)
		if(dep[fa[x][i]] >= dep[y]) x = fa[x][i];
	if(x == y) return x;
	for(int i = 14; ~i; i--)
		if(fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
	return fa[x][0];
}
void dfs(int x){
	a[x] = dta[x];
	b[x] = dtb[x];
	for(int i = 0; i < (int)V[x].size(); i++){
		int v = V[x][i].first;
		if(v == fa[x][0]) continue;
		dfs(v);
		a[x] += a[v];
		b[x] += b[v];
	}
	if(a[x] && b[x]){puts("No"); exit(0);}
	else if(a[x]) ok[pp[x] ^ 1] = 1;
	else ok[pp[x]] = 1;
}
int main(){
	st = clock();
	scanf("%d%d", &n, &m);
	for(int i = 1, u, v; i <= m; i++){
		scanf("%d%d", &u, &v);
		add(u, v); add(v, u);
	}
	for(int i = 1; i <= n; i++)
		if(!dfn[i]) tarjan(i, 0);
	for(int i = 1; i <= n; i++){
		if(!be[i]){
			++tot;
			dfs(i, 1, 0);
		}
	}
	for(int i = 2; i < e; i++) if(bo[i])
		V[be[ed[i].u]].push_back(make_pair(be[ed[i].v], i));
	for(int i = 1; i <= tot; i++){
		if(!rt[i]){
			fa[i][0] = 0;
			dep[i] = 1;
			dfs(i, i);
			vr.push_back(i);
		}
	}
	scanf("%d", &K);
	for(int i = 1, s, t, lca; i <= K; i++){
		scanf("%d%d", &s, &t);
		s = be[s]; t = be[t];
		if(rt[s] != rt[t]) {puts("No"); return 0;}
		lca = getlca(s, t);
		dta[s]++; dta[lca]--;
		dtb[t]++; dtb[lca]--;
	}
	for(int i = 0; i < (int)vr.size(); i++)
		dfs(vr[i]);
	puts("Yes");
	for(int i = 2; i < e; i++) if(ok[i])
		printf("%d %d\n", ed[i].u, ed[i].v);
	return 0;
}


Measured memory_bytes: 6896
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=200010,O=1000000007;
inline int fpow(int x,int n){
	lint ret=1;
	for(;n;n>>=1,x=(lint)x*x%O){
		if(n&1){
			(ret*=x)%=O;
		}
	}
	return ret;
}
inline int inv(int x){
	return fpow(x,O-2);
}
vector<int>wei[N];
int main(){
	int n=ni,x=ni,y=ni;
	for(int i=1,c;i<=n;i++,c=ni,wei[c].push_back(ni));
	int mn1=0,mn2=0;
	for(int i=1;i<=n;i++){
		sort(wei[i].begin(),wei[i].end());
		if(!wei[i].empty()){
			if(mn1==0||wei[i][0]<wei[mn1][0]){
				mn2=mn1,mn1=i;
			}else if(mn2==0||wei[i][0]<wei[mn2][0]){
				mn2=i;
			}
		}
	}
	lint ans=1;
	int totcnt=0;
	for(int i=1;i<=n;i++){
		if(!wei[i].empty()){
			int mn=i!=mn1?mn1:mn2,n=wei[i].size();
			int p1=1,p2=0;
			lint fac1=1,fac2=1;
			for(int tp=x-wei[i][0];p1<n&&wei[i][p1]<=tp;(fac1*=++p1)%=O);
			if(mn==0){//only one color
				assert(ans==1);
				assert(totcnt==0);
				break;
			}
			for(int tp=y-wei[mn][0];p2<n&&wei[i][p2]<=tp;(fac2*=++p2)%=O);
			if(p2){
				totcnt+=max(p1,p2);
				(ans*=inv(p1>p2?fac1:fac2))%=O;
			}
		}
	}
	for(;totcnt;(ans*=totcnt--)%=O);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
ll dp[105][N],sum[N];
int n,k,x;
int main()
{
	cin>>n>>k;
	for(int i=0;i<=k;i++)sum[i]=1;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		for(int j=k;j>=0;j--)
		{
			dp[i][j]=(sum[j]+mod-(j>x?sum[j-x-1]:0))%mod;
		}
		sum[0]=dp[i][0];
		for(int j=1;j<=k;j++)
		{
			sum[j]=sum[j-1]+dp[i][j];
			sum[j]%=mod;
		}
	}
	cout<<dp[n-1][k]<<endl;
	return 0;
}

Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
int year,month,day;
char a,b;
int main(){
	cin>>year>>a>>month>>b>>day;
	if(year<=2019)
		if(month<=4)
			if(day<=30){
				cout<<"Heisei";
				return 0;
			}
	cout<<"TBD";
	return 0;
}


Measured memory_bytes: 256