akhauriyash/Code-Regression huggingface dataset:
/**
*    author:  y_takano
*    created: 19.06.2020 08:51:06
**/

#include <bits/stdc++.h>

using namespace std;

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

  int n, a, tmp;
  cin >> n >> a;
  long min = a, max = a, sum = a;

  for (int i = 0; i < n - 1; i++)
  {
      cin >> tmp;
      if (min > tmp)
      {
          min = tmp;
      }
      if (max < tmp)
      {
          max = tmp;
      }
      sum += tmp; 
  }

  cout << min << ' ' << max << ' ' << sum << endl;

  return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<in6> data(n);
  rep(i,n) cin >> data[i];
  rep(i,n) data[i]--;
  in6 sum = 0;
  rep(i,n) sum += data[i];
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 510000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A=INF,B=0,C=INF,D=INF,E,F,N,M,K,sum=0,num=0,cnt=1,next=0;
  string S,T;cin >> S >> T;
  rep(i,0,3)if(S[i]==T[i])sum++;
  Out(sum);
}

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

pls = 0
for i in reversed(range(N)):
    a, b = AB[i]
    temp = (math.ceil((a + pls) / b))
    pls += b*temp - (a + pls)
print(pls)

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

int main() {
  int N,sum,min;
  cin >> N;

  vector<int> math(N); 
  int mathmin,mathmax;

  // 座標データを受け取る
  for (int i = 0; i < N; i++) {
    cin >> math.at(i);
    if(i==0){
    	mathmin = math.at(i);
    	mathmax = math.at(i);
    }else{
    	if(math.at(i) < mathmin) mathmin = math.at(i);
    	if(math.at(i) > mathmax) mathmax = math.at(i);
    }
  }
  
  //cout << mathmin << endl;
  //cout << mathmax << endl;

  // 集会を開く座標
  for (int i = mathmin; i <= mathmax; i++) {
    sum = 0;
    for(int j = 0; j < N; j++){ //体力計算
      sum = sum + (math.at(j) - i)*(math.at(j) - i);
    }
    if(i == mathmin){
    	min = sum;
    }else{
    	if(sum < min)min = sum;
    }
  }
  
  cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(ll, q, h, s, d, n);
  s = min({4 * q, 2 * h, s});
  if (2 * s > d) {
    cout << ((n / 2) * d + (n % 2) * s) << endl;
  } else {
    cout << n * s << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <fstream>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;



int main(){
	int N;
	while(cin >> N && N){
		deque<int> a(N),b(N);
		for(int i = 0 ; i < N ; i++) cin >> a[i];
		for(int i = 0 ; i < N ; i++) cin >> b[i];
		sort(a.rbegin(),a.rend());
		sort(b.rbegin(),b.rend());
		int win = 0;
		int ans = -1;
		
		for(int i = 0 ; i < N-1 ; i++){
			if( a.front() > b.front() ){
				b.pop_back();
				a.pop_front();
				win++;
			}else{
				a.pop_front();
				b.pop_front();
			}
			if( win > (i+1) / 2 ){
				ans = i+1;
				break;
			}
		}
		if(ans==-1)puts("NA");
		else cout << ans << endl;
		
		
	}
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

bool ok[100005];
int pena[100005];


int main(){
  int N, M;
  cin >> N >> M;
  rep(i,M){
    int p;
    string s;
    cin >> p >> s;

    if(!ok[p]){
      if(s == "AC"){
        ok[p] = true;
      }else{
        pena[p]++;
      }
    }
  }

  int seitou = 0;
  int penalty = 0;
  REP(i,1,N+1){
    if(ok[i]){
      seitou++;
      penalty+=pena[i];
    }
  }
  
  cout << seitou << " " << penalty << endl;
  
  return 0;
}


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

const int mod = 1e9 + 7;

void add_self(int &a, int b) {
    a += b;
    if (a >= mod) a -= mod;
}

int  main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string k; 
    int D;
    cin >> k >> D;

    // dp[sum][tight] - no of digits chosen such that the sum of digits modulo D is 'sum'
    // and tight indicates whether we have chosen some digit less than in K
    vector<vector<int>> dp(D, vector<int> (2));
    dp[0][0] = 1;
    int len = k.length();

    for (int where = 0; where < len; ++where) {
        vector<vector<int>> new_dp(D, vector<int> (2));

        for (int sum = 0; sum < D; ++sum) {
            for (int tight : {0, 1}) {
                for (int digit = 0; digit <= 9; ++digit) {
                    if (digit > k[where] - '0' and !tight) break;
                    add_self(new_dp[(sum + digit) % D][tight || (digit < k[where] - '0')], dp[sum][tight]);
                }
            }
        }
        dp = new_dp;
    }
    int ans = (dp[0][true] + dp[0][false]) % mod;
    --ans;
    if (ans < 0) ans += mod;

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

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int a,c,b=1,d;
    cin>>a;
    cin>>c;
    if(c!=a){
        b++;
    }
    cin>>d;
    if(d!=a&&d!=c){
        b++;
    }
    
    cout<<b<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string A,B;
  cin>>A>>B;
  int a=A.size(),b=B.size();
  if(a-b==1){
    for(int i=0;i<b;i++){
      cout<<A.at(i)<<B.at(i);
    }
    cout<<A.at(a-1)<<endl;
  }
  else{
    for(int i=0;i<a;i++){
      cout<<A.at(i)<<B.at(i);
    }
  cout<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int a,k,d=0,i;
    cin >> a;
    cin >> k;
    int s[a];
    for(i=0;i<a;i++){
      cin >> s[i];
      if(k<=s[i]){
        d++;
      }
    }
    cout << d << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int N;

double dp[310][310][310];

double rec(int i, int j, int k){
    if (dp[i][j][k] >= 0) return dp[i][j][k];
    if( i == 0 && j == 0 && k == 0 ) return 0.0;

    double res = 0.0;

    if(i > 0) res += rec(i-1, j, k) * i;
    if(j > 0) res += rec(i+1, j-1, k) * j;
    if(k > 0) res += rec(i, j+1, k-1) * k;
    res += N;
    res *= 1.0 / (i + j + k);

    return dp[i][j][k] = res;

}

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

    cin >> N;
    int one = 0, two = 0, three = 0;

    for(int i = 0; i < N; ++i){
        int a; cin >> a;
        if(a == 1) ++ one;
        else if(a == 2) ++two;
        else ++three;
    }

    memset(dp, -1, sizeof(dp));

    cout << fixed << setprecision(10) << rec(one, two, three) << endl;


    return 0;
}


Measured memory_bytes: 233088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define put(n) cout<<(n)<<endl
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);++(i))
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()


int main(){
    int H,R;
    cin>>H>>R;
    if(H+R == 0) cout<<0<<endl;
    else if(H+R > 0) cout<<1<<endl;
    else cout<<-1<<endl;   
}


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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) cin >> a[i];

  int b[N];
  for (int i = 0; i < N; i++) {
    b[i] = a[i] - (i + 1);
  }
  sort(b, b + N);

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += abs(a[i] - (b[N/2] + i + 1));
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader( new InputStreamReader( System.in) );
		System.out.println( (int)Math.pow( Integer.parseInt( in.readLine() ), 3 ) );
	}

}

Measured memory_bytes: 24024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			int N, L;
			N = Integer.parseInt(sc.next());
			L = Integer.parseInt(sc.next());
			int[] aji = new int[N];

			int sum = 0;
			for (int i = 0; i < N; i++) {
				aji[i] = L + i;
				sum += aji[i];
			}
			
			int difMin = Integer.MAX_VALUE;
			int ans = 0;
			
			for (int i = 0; i < N; i++) {
				
				int dif = Math.abs(sum - (sum - aji[i]) );
				
				if (difMin > dif) {
					ans = sum - aji[i];
					difMin = dif;
				}
			}
			
			System.out.println(ans);
			
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
}


Measured memory_bytes: 21972
def convolve(A, B):
    # 畳み込み  # 要素は整数
    # 3 つ以上の場合は一度にやった方がいい
    import numpy as np
    dtype = np.int64  # np.float128 は windows では動かない？
    fft, ifft = np.fft.rfft, np.fft.irfft
    a, b = len(A), len(B)
    if a==b==1:
        return np.array([A[0]*B[0]])
    n = a + b - 1  # 返り値のリストの長さ
    k = 1 << (n-1).bit_length()  # n 以上の最小の 2 冪
    AB = np.zeros((2, k), dtype=dtype)
    AB[0, :a] = A
    AB[1, :b] = B
    return np.rint(ifft(fft(AB[0]) * fft(AB[1]))).astype(np.int64)[:n]


import sys
import numpy as np
input = sys.stdin.readline

P = 200003
N = int(input())
A = sorted(map(int, input().split()))
A = [a for a in A if a]
Bucket = [0] * P
for a in A:
    Bucket[a] += 1

Perm = []
Perm_inv = [0] * (P)
p = 1
for i in range(P):
    Perm.append(p)
    p = p*2 % P
for i, p in enumerate(Perm):
    Perm_inv[p] = i
#
# print(Perm[:9])
# print(Perm_inv[:9])

def perm(arr, P):
    res = [0] * len(arr)
    for a, p in zip(arr, P):
        res[p] = a
    return res

B = perm(Bucket, Perm_inv)
C = convolve(B, B)
C_ = C[:P].copy()
C_[:len(C)-P+1] += C[P-1:]
C_ = perm(C_, Perm)
# for i, c in enumerate(C_):
#     if c:
#         print(i%P)
Ans = C_ * np.arange(P)
an = Ans.sum()
diag = sum(a*a%P for a in A)

ans = (an-diag) // 2
print(ans)


Measured memory_bytes: 78608
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
int dp[200010];
signed main(){
  int n,k;
  cin>>n>>k;
  cout<<n-k+1<<endl;
  return 0;
}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	bool turn = 0;
	while (a > 0 && c > 0) {
		if (turn) {
			a -= d;
		}
		else {
			c -= b;
		}
		turn ^= 1;
	}
	if (a <= 0)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}

//!

Measured memory_bytes: 3648
n = int(input())
a = list(map(int, input().split()))

ans = []
for i in range(n):
    if i < n//2:
        ans.append(0)
    else:
        ans.append(a[i])

for i in range(n//2-1, -1, -1):
    ans[i] = (a[i] + sum(ans[i::i+1])) % 2

print(ans.count(1))
for i in range(n):
    if ans[i] != 0:
        print(i+1, "", end="")


Measured memory_bytes: 9808
n,m = map(int, input().split())
l = []
for _ in range(n):
    l.append([int(x) for x in input().split()])

ans = 0
for i in range(2):
    for j in range(2):
        for k in range(2):
            a,b,c = (-1)**i, (-1)**j, (-1)**k
            tmp = [x[0]*a+x[1]*b+x[2]*c for x in l]
            tmp.sort(reverse=True)
            ans = max(ans, sum(tmp[:m]))

print(ans)

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

typedef long long int ll;
typedef long double ld;         
#define f(var,start,end) for(ll var = start; var <end ; ++var)
#define rf(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define nl cout<<"\n"
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
	ll n;
	cin>>n;
	ll arr[n];
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]==0)
		{
			cout<<"0";
			nl;
			return 0;
		}
	}
	ll mul=1;
	for(ll i=0;i<n;i++)
	{
		mul=mul*arr[i];
		if(mul>1000000000000000000 || mul<=0)
		{
			cout<<"-1";
			nl;
			return 0;
		}
	}
	cout<<mul;
	nl;



}

Measured memory_bytes: 4400
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        int cnt = 0;

        if(a == b && b == c){
            System.out.println(1);
        }else if(a == b || a ==c || b ==c){
            System.out.println(2);
        }else{
            System.out.println(3);
        }

    }
}


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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void) {

	long long X, K, D;

	cin >> X >> K >> D;

	long long count = 0;

    X=llabs(X);


    long long tmp = min(K,X/D);
    X=X-tmp*D;
    K=K-tmp;

    if(K>0 && K%2 ==1){
        X=X-D;
    }

	cout << llabs(X) << endl;


	return 0;
}



Measured memory_bytes: 3600
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

def bit(S, j):
    # Sの右からj bit目(0-indexed)
    return (S>>j)&1

N = int(input())
A = list(map(int, input().split()))

B = [0 for i in range(61)]
for i in range(61):
    for j in range(N):
        B[i] += bit(A[j], i)

for i in range(61):
    B[i] = B[i]*(N-B[i]) % mod

ans = 0
for i in range(61):
    ans = (ans + 2**i*B[i]) % mod

print(ans % mod)

Measured memory_bytes: 129708
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

bool is_prime(ll N)
{
    for (ll i = 2; i * i <= N; ++i)
    {
        if (N % i == 0)
            return false;
    }
    return true;
}
int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll mx = pow(10, 6);
    vector<int> vec(n), div(mx + 1);
    rep(i, 0, n) cin >> vec[i], div[vec[i]]++;
    int ans = 0;
    rep(i, 0, mx + 1)
    {
        if (div[i] == 0)
            continue;
        if (div[i] == 1)
            ans++;
        for (int j = 2; i * j < mx + 1; ++j)
            div[i * j] = 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 7960
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=n-2;i>=0;i--){
    if(a[i+1]+1<a[i]){
      cout << "No";
      return 0;
    }
    if(a[i+1]+1==a[i])a[i]--;
  }
  cout << "Yes";
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll h,w;cin >>h>>w;
    vector<vector<char>>a(h,vector<char>(w));
    vector<bool>hmemo(h,true);
    vector<bool>wmemo(w,true);
    for (int i = 0; i < h; ++i) {
        bool wflag=true;
        for (int j = 0; j < w; ++j) {
            cin >>a[i][j];
            if(a[i][j]=='#')wflag=false;
        }
        if(wflag)hmemo[i]=false;
    }
    for (int j = 0; j < w; ++j) {
        bool hflg=true;
        for (int i = 0; i < h; ++i) {
            if(a[i][j]=='#')hflg=false;
        }
        if(hflg)wmemo[j]=false;
    }
    for (int i = 0; i < h; ++i) {
        bool flg=true;
        for (int j = 0; j < w; ++j) {
            if(hmemo[i]&&wmemo[j]){
                cout <<a[i][j];
            }
            if(!hmemo[i]){
                flg=false;
            }
        }
        if(flg)cout <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
// Starting with the name of Allah

#include <bits/stdc++.h>
#define ll long long
#define nl endl
#define flash_all ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define gcd(a,b)         __gcd(a,b)
#define lcm(a,b)         (a/gcd(a,b))*b


using namespace std;



int main()
{
	flash_all;
	ll n,a=1000,sum=0;
	cin>>n;
	while(n>sum){
		sum=sum+a;
	}
	cout<<sum-n<<nl;
}
//Happy Coding.....

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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

#define N_MAX 1001010
ll f[N_MAX],rf[N_MAX];

ll pow(ll x,ll n){  // xのn乗 (mod m)
    ll res = 1;
    if(n > 0){
        res = pow(x,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }else{
            res = (((res * res) % mod) * x) % mod;
        }
    }
    return res;
}

void init(){
    f[0] = 1;
    for(ll i = 1; i < N_MAX; i++){
        f[i] = (i * f[i-1]) % mod;
    }
    for(ll i = 0; i < N_MAX; i++){
        rf[i] = pow(f[i],mod-2);
    }
}

int main()
{
    init();
    int n; cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i];
    ll tmp = 1;
    map<int,int> mp;
    rep(i,n){
        int x = a[i];
        for(int i = 2; i * i <= x; i++){
            int cnt = 0;
            while(x % i == 0){
                cnt++;
                x /= i;
            }
            if(cnt > 0) mp[i] = max(mp[i],cnt);
        }
        if(x != 1){
            mp[x] = max(mp[x],1);
        }
    }
    ll lcm = 1, ans = 0;
    for(auto i : mp){
        lcm *= pow(i.first,i.second);
        lcm %= mod;
    }
    rep(i,n){
        ans += (lcm * pow(a[i],mod-2));
        ans %= mod;
    }
    cout << ans << endl;
}

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

int main(){
  char a, c[26];
  cin >> a;
  int k = 0;
  int l = 0;
  for(char i = 'a'; i <= 'z'; ++i) {
    c[k] = i;
    if(i == a) l = k;
    k++;
  }
  
  cout << c[l+1] << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque


def main():
    # 幅優先探索
    def bfs():
        q = deque([0])
        while q:
            u = q.popleft()
            # 接続頂点を精査
            for v, w in g[u]:
                # まだチェックしていない頂点をチェック
                if color[v] == -1:
                    q.append(v)
                    # 偶数なら同じ色で塗る
                    if w == 0:
                        color[v] = color[u]
                    else:
                        color[v] = color[u] ^ 1

    n = int(input())
    g = [[] for _ in range(n)]
    # 塗りつぶし結果
    color = [-1] * n
    # スタートは黒で塗っておく
    color[0] = 1
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        w %= 2
        g[u].append((v, w))
        g[v].append((u, w))
    bfs()
    print(*color)


if __name__ == "__main__":
    main()

Measured memory_bytes: 37516
n = gets.to_i
input = Array.new
sum = 0
n.times do |i|
  ngo = gets.to_i
  sum += ngo
  input << ngo
end

table = Array.new(n).map{Array.new(sum + 1,false)}
table[0][0] = true
table[0][input[0]] = true

(1..(n-1)).each do |i|
  (sum + 1).times do |j|
    if table[i-1][j] then
      table[i][j + input[i]] = true if j + input[i] <= sum
      table[i][j] = true
    end
  end
end

sum.downto(0) do |i|
  n.times do |j|
    if table[j][i] && i % 10 != 0 then
      puts i
      exit
    end
  end
end
puts 0

Measured memory_bytes: 9596
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (long long i = (a); i <= (b); i++)
#define FORD(i,a,b) for (long long i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(long long)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define all(x) x.begin(), x.end()
#define uni(x) x.erase(unique(all(x)), x.end());
#define BUG(x) cout << #x << " = " << x << endl
#define BUGP(x) cout << #x << " = " << x._1 << ", " << x._2 << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto _i:x) cout << _i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 1e-8
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

long long a, b;

int main() {
  ios::sync_with_stdio(false);
  cin >> a >> b;
  long long h = b - a;
  cout << h * (h - 1) / 2 - a;
}


Measured memory_bytes: 256
x= int(input())
s=0
for i in range(100):
	if s==0:
		for j in range(100):
			if i**5+j**5==x:
				print(j,-i)
				s+=1	
				break
	else:
		break

for i in range(400):
	if s==0:
		for j in range(i,500):
			if j**5-i**5==x:
				print(j,i)
				s+=1	
				break
	else:
		break

Measured memory_bytes: 9028
def lcs_fast(x, y):
    len_x = len(x)
    len_y = len(y)

    c = [0] * (len_y + 1)
    for i in range(len_x):
        c_prev = c[:]
        for j in range(len_y):
            if x[i] == y[j]:
                c[j+1] = c_prev[j] + 1
            elif c[j+1] < c[j]:
                c[j+1] = c[j]
    return c[-1]


if __name__ == "__main__":
    n = int(input())
    for i in range(n):
        x = input()
        y = input()
        # print(lcs(x, y))
        print(lcs_fast(x, y))


Measured memory_bytes: 5624
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3010;
int n,mod,s[N][N],c[N][N],ans=0;
int poww(int x,int y,int mo){
	int ans=1;
	while(y){
		if(y&1){
			ans=ans*x%mo;
		}
		x=x*x%mo;
		y>>=1;
	}
	return ans;
}
signed main(){
	scanf("%lld%lld",&n,&mod);
	s[0][0]=1;
	for(int i=0;i<=n+1;i++){
		c[i][0]=1;
		for(int j=1;j<=i;j++){
			s[i][j]=(s[i-1][j-1]+j*s[i-1][j])%mod;
			c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
		}
	}
	for(int i=0;i<=n;i++){
		int sum=0;
		for(int j=0;j<=i;j++){
			(sum+=s[i+1][j+1]*poww(2,j*(n-i),mod)%mod)%=mod;
		}
		sum=sum*poww(2,poww(2,n-i,mod-1),mod)%mod*c[n][i]%mod;
		(ans+=(i&1)?mod-sum:sum)%=mod;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 96148
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,a[200005],ans=0;
map<ll,ll>m;
int32_t main(){
CODE_START;
cin>>n;
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
}
m[a[1]+1]=1;
for(ll i=2;i<=n;i++)
{
    ll val=i-a[i];
ans=ans+m[val];
m[i+a[i]]++;
}
cout<<ans<<endl;
}



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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
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++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


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

void solve() {
    int N; cin >> N;
    vector<ll> v(N);
    rep(i, N) cin >> v[i];
    vector<ll> L(N+1), R(N+1);
    L[0] = 0; R[N]=0;
    rep(i, N){
        L[i+1] = gcd(L[i], v[i]);
    }
    per(i, N){
        R[i] = gcd(R[i+1], v[i]);
    }

    ll res = 0;
    rep(i, N){
        if(R[i+1] == 0){
            res = max(res, L[i]);
            continue;
        }
        res = max(res, gcd(L[i], R[i+1]));
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vi as(n);
	trav(x,as) cin >> x;
	ll sum = 0;
	trav(x, as) sum += x;
	ll ans = 1e18;
	ll pre = 0;
	rep(i,0,n-1){
		pre += as[i];
		ans = min(ans, abs(sum-pre-pre));
	}
	cout << ans << endl;
}

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

using namespace std;

int main(){
    int N, len;
    cin>>N;
    string s;
    cin>>s;
    len = s.size();
    if (len > N){
        for (int i = len; i > N; i--){
            s.pop_back();
        }
        for (int j = 0; j < 3; j++){
            s.push_back('.');
        }
        cout<<s;
    }
    else {
        cout<<s;
    }

    return 0;
}


Measured memory_bytes: 3612
io = DATA.eof? ? STDIN : DATA
n=io.gets.to_i
xs=io.gets.chomp
x=xs.to_i(2)
def popcount(x)
  b = 0
  while x > 0
    x &= x - 1
    b += 1
  end
  b
end
def f(n)
  cnt=1
  while (n>0)
    n=n%popcount(n)
    cnt+=1
  end
  cnt
end
pcx=popcount(x)
pc0,pc1= pcx+1,pcx-1
xmod0=x%pc0
xmod1=x%pc1 if pc1>0
n.times do |i|
  if (xs[i])=="0"
    pci,xmodi,powi = [pc0,xmod0,(2.pow(n-1-i,pc0))]
  elsif pc1>0
    pci,xmodi,powi = [pc1,xmod1,-(2.pow(n-1-i,pc1))]
  else
    pci=pc1
  end
  if pci==0
    puts 0
  else
    pc=(xmodi+powi)%pci
    puts f(pc)
  end
end
__END__


Measured memory_bytes: 147368
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cstdint>
#include <cmath>
#include <algorithm>
using namespace std;

#define N 100000

int n;
long long c;
long long  x[N];
int v[N];

long long rsum[N+1];
long long lsum[N+1];

int main()
{
	long long ans = 0;

	cin >> n >> c;
	for( int i = 0; i < n; i++ ) {
		cin >> x[i] >> v[i];
	}

	rsum[0] = 0;
	lsum[0] = 0;
	long long vr = 0;
	long long vl = 0;
	for( int i = 0; i < n; i++ ) {
		vr += v[i];
		rsum[i + 1] = max(rsum[i], vr - x[i]);
		vl += v[n - (i + 1)];
		lsum[i + 1] = max(lsum[i], vl - (c - x[n - (i + 1)]));
	}

	for( int i = 0; i < n + 1; i++ ) {
		long long sum = rsum[i] + lsum[n - i];
		long long turn = x[i - 1];
		if( i == 0 ) {
			turn = 0;
		}
		long long rans = sum - turn;
		turn = c - x[i];
		if( i == n ) {
			turn = 0;
		}
		long long lans = sum - turn;
		ans = max(ans, max(rans, lans));
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2944
import java.util.Scanner;
import java.lang.Math;

public class Main {
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    while(true){
      int a = scan.nextInt();
      String s = scan.next();
      int b = scan.nextInt(); 


      if (s.equals("?")) break;

      switch (s) {
        case "+":
          System.out.println(a+b);
          break;
        case "-":
          System.out.println(a-b);
          break;
        case "*":
          System.out.println(a*b);
          break;
        case "/":
          System.out.println(a/b);
          break;
        default:
          break;
      }
    }
    scan.close();
  }
}



Measured memory_bytes: 26188
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int k,a,b,sum=0;
    cin>>k>>a>>b;
    long long int tmp=k+1;
    if (a<b) {
        if (k-(a-1)>=0) {
            k-=a-1;
            if (k>=2) {
                sum+=a+((b-a)*(k/2));
                if (k%2!=0) {
                    sum+=k%2;
                }
            } else {
                sum+=k;
            }
        } else {
            sum+=k+1;
        }
    } else {
        sum+=k+1;
    }
    cout<<max(sum,tmp)<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  long N;
  cin >> N;
  unordered_set<long> st;
  rep(i, N) {
    long tmp;
    cin >> tmp;
    st.insert(tmp);
  }
  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#define MAX 10001
#define INF 100000001

#define forall(i,a,b) for(int i = a; i < b; ++i)
#define ll long long
#define pb push_back
#define sd(s) scanf("%d", &s);
#define sll(s) scanf("%lld", &s);
using namespace std;

int H, W, N;
ll A[MAX];
ll ans[101][101];
int main()
{
	int k = 0;
	sd(H);
	sd(W);
	sd(N);
	forall(i, 0, N) sd(A[i]);


	forall(i, 0, H) {
		forall(j, 0, W) {
			while (A[k] <= 0) ++k;

			if (i % 2 == 0) ans[i][j] = k + 1;
			else ans[i][W - 1 - j] = k + 1;

			--A[k];
		}
	}

	forall(i, 0, H) {
		forall(j, 0, W) printf("%d ", ans[i][j]);
		printf("\n");
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll a, b, c, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> a >> b >> c >> k;

  ll kk = k;
  ll ans = 0;

  ans += min(a, kk);
  kk -= min(a, kk);
  kk -= min(b, kk);
  ans -= min(c, kk);

  cout << ans << endl;
}


Measured memory_bytes: 3652
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

ll dp[88];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	dp[0]=2; dp[1]=1;
	int n; cin >> n;
	for(int i=2; i<=n; i++){
		dp[i] = dp[i-1]+dp[i-2];
	}
	cout << dp[n] << endl;
}	


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

int main() {
	while (true) {
		int n, d; std::cin >> n >> d;
		if (n == 0 && d == 0) return 0;
		std::vector<std::vector<int>> countries(n);
		int sum = 0;
		for (auto& country : countries) {
			int m; std::cin >> m; sum += m;
			country.push_back(0);
			for (auto i = 0; i < m; ++i) {
				int c; std::cin >> c; country.push_back(c + country.back());
			}
		}
		auto can_reduce = true;
		for (auto rest = 0; rest < sum && can_reduce; ++rest) {
			int max = 0;
			for (auto i = 0; i < n; ++i) {
				if (countries[i].back() > countries[max].back()) {
					max = i;
				}
			}
			int second_max = 0;
			for (auto i = 0; i < n; ++i) {
				if (max != i) {
					for (auto c = countries[i].size() - 1; c > 0 && countries[i][c - 1] + d >= countries[max].back(); --c) {
						countries[i].pop_back();
						rest += 1;
					}
					if (second_max < countries[i].back()) second_max = countries[i].back();
				}
			}
			countries[max].pop_back();
			if (countries[max].back() + d < second_max) {
				can_reduce = false;
			}
		}
		if (can_reduce) std::cout << "Yes\n";
		else std::cout << "No\n";
	}
}


Measured memory_bytes: 3144
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[list(map(int,input().split())) for _ in range(m)]
g=[[]for _ in range(n)]
for a,b in ab:
  g[a-1].append(b-1)
  g[b-1].append(a-1)
ans=0
for i in range(n):
  c=h[i]
  t=True
  for j in g[i]:
    if c<=h[j]:
      t=False
      break
  ans+=1 if t else 0
print(ans)

Measured memory_bytes: 47612
#include <iostream>
#include <algorithm>
#include <array>
#include <numeric>

using namespace std;
const int maxn = 3e5 + 1e2;
using ll = long long;
array<int, maxn> a;
array<ll, maxn> p;
int n, m;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll tot = 0;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i < n; ++i) {
        int l = a[i - 1], r = a[i];
        r += (l > r) * m;
        tot += r - l;
        if (r - l > 1) {
            ++p[l + 2];
            p[r + 1] -= (r - (l + 2) + 1) + 1;
            p[r + 2] += (r - (l + 2) + 1);
        }
    }
    partial_sum(p.begin() + 1, p.begin() + 2 * m + 1, p.begin() + 1);
    partial_sum(p.begin() + 1, p.begin() + 2 * m + 1, p.begin() + 1);

    ll ans = 0;
    for (int i = 1; i <= m; ++i) ans = max(ans, p[i] + p[i + m]);
    cout << tot - ans << endl;

}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N, M;
    cin >> N >> M;
    vector<vector<ll>> v(M);
    REP(i, N) {
        int a, b;
        cin >> a >> b;
        if (M < a)
            continue;
        v[M - a].emplace_back(b);
    }
    priority_queue<int> que;
    ll ans = 0;
    RREP(i, M) {
        for (auto &&j : v[i]) {
            que.push(j);
        }
        if (!que.empty()) {
            ans += que.top();
            que.pop();
        }
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
long long int s,t,num[50],n;
int main()
{
	scanf("%lld",&s);
	while(s)
	{
		t=(s-1)%26;
		num[n]=t;
		s=(s-1)/26;
		n++;
	}
	for(int i=n-1;i>=0;i--)
		printf("%c",num[i]+'a');
} 

Measured memory_bytes: 3796
#include<stdio.h>

int main(){

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

if (N>1000)
{
  if (N%1000==0)
  {
    puts("0");
  }else
  {
    printf("%d",1000-(N%1000));
  }
}else
{
  printf("%d",1000-N);
}

return 0;

}

Measured memory_bytes: 1684
#include<stdio.h>
int main(void){
	int n,p[101],i,m=0,j,c;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&p[i]);
		if(p[i]>m){
			m=p[i];
		}
	}
	if(n<m){
		m=n;
	}
	for(;;m--){
		c=0;
		for(j=1;j<=n;j++){
			if(p[j]>=m){
				c++;
			}
		}
		if(c>=m){
			break;
		}
	}
	printf("%d\n",m);
	return 0;
}



Measured memory_bytes: 2112
from sys import stdin
S=(stdin.readline().rstrip())
if int(S[0:2]) == 0 and int(S[2:]) ==0:
    print("NA")
elif int(S[0:2]) > 12 and int(S[2:]) > 12:
    print("NA")
elif int(S[0:2]) > 12 and int(S[2:]) ==0:
    print("NA")
elif int(S[0:2]) == 0 and int(S[2:]) > 12:
    print("NA")
    
else :
    mae=0
    usiro=0
    if int(S[0:2]) > 12 or int(S[0:2]) == 0:
        mae = 1
    if int(S[2:]) > 12 or int(S[2:]) == 0:
        usiro = 1
    
    if mae == 0 and usiro == 0:
        print("AMBIGUOUS")
    elif mae == 0 and usiro ==1:
        print("MMYY")
    elif mae == 1 and usiro ==0:
        print("YYMM")

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  while(A>0 && C>0) {
    C-=B;
    if(C<=0) {
      cout << "Yes" << endl;break;
    }
    A-=D;
    if(A<=0) {
      cout << "No" << endl;break;
    }
  }
}

Measured memory_bytes: 3632
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define BigInt      __int128
#define endl        '\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define sim         template < class c
#define ris         return * this
#define dor         > debug & operator <<
#define eni(x)      sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

using namespace std;

sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug 
{
	~debug() 
	{ 
		cerr<<endl; 
	}
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) 
	{
		ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) 
	{
	  	*this << "[";
	  	for (auto it = d.b; it != d.e; ++it)
	    	*this << ", " + 2 * (it == d.b) << *it;
	  	ris << "]";
	}
};
#define fuck(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define N  100005

ll int n,m,q;

ll int a[100],b[100],c[100],d[100];

ll int arr[15];

ll int maxi=0;

void fun(ll int idx)
{
	if(idx==n+1)
	{
		// debug() << fuck(vi(arr+1,arr+1+n)) ;
		ll int sm=0;
		for(ll int i=1;i<=q;i++)
		{
			if(arr[a[i]]-arr[b[i]]==-c[i])
			{	
				sm+=d[i];
			}
		}
		maxi=max(maxi,sm);
	}
	else
	{
		for(ll int i=arr[idx-1];i<=m;i++)
		{
			arr[idx]=i;
			fun(idx+1);
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		arr[0]=1;
		cin>>n>>m>>q;
		for(ll int i=1;i<=q;i++)
		{
			cin>>a[i]>>b[i]>>c[i]>>d[i];
		}
		fun(1);
		cout<<maxi<<endl;
	}
	return 0;
}

Measured memory_bytes: 3648
import sys
import numpy as np

#%% Smart Solution

input = sys.stdin.readline

H, W = map(int, input().split())

status = np.full((H, W), H*W, dtype=int)
for i in range(H):
    for j, c in enumerate(input()):
        if c == "#":
            status[i,j] = 0


for h in range(1, H):
    status[h, :] = np.minimum(status[h, :], status[h-1, :] + 1)
for h in range(0, H-1)[::-1]:
    status[h, :] = np.minimum(status[h, :], status[h+1, :] + 1)
for w in range(1, W):
    status[:, w] = np.minimum(status[:, w], status[:, w-1] + 1)
for w in range(0, W-1)[::-1]:
    status[:, w] = np.minimum(status[:, w], status[:, w+1] + 1)

print(np.max(status))

Measured memory_bytes: 20184
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main(){
  typedef long long int ll;
int A, B, C;
cin >> A >> B;
bool ans = false;
if(A + B >= 10)ans = true;
if(ans)cout << "error" << endl;
else cout << A + B << endl;
        return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    int a, b, c, tmp = 0;
    scanf("%d%d%d", &a, &b, &c);

    if(a >= b){
        tmp = a;
        a = b;
        b = tmp;
    }

    if(b >= c){
        tmp = b;
        b = c;
        c = tmp;
    }

    if(a >= b){
        tmp = a;
        a = b;
        b = tmp;
    }

    printf("%d\n", c - a);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

int main(){
    int n, i;
    cin>>n;
    int t[n+1], x[n+1], y[n+1];
    for(i = 0; i<n; i++)
        cin>>t[i]>>x[i]>>y[i];
    int X = 0, Y = 0, T = 0;
    bool heCan = true;
    for(i = 0; i<n; i++){
        int d = abs(x[i] - X) + abs(y[i] - Y);
        T = t[i] - T;
        if(d > T || (T-d)%2){
            heCan = false;
            break;
        }
        T = t[i];
        X = x[i];
        Y = y[i];
    }
    if(heCan)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
A=[[int(i)-1 for i in input().split()] for i in range(N)]
L=set()
#print(A)
def f(L):
    K=[0]*M
    for i in range(N):
        for j in range(M):
            if A[i][j] not in L:
                K[A[i][j]]+=1
                break
    a=0
    b=0
    for i in range(M):
        if a<K[i]:
            a=K[i]
            b=i
    return a,b
ans=10**9
for i in range(M):
    a,b =f(L)
    ans=min(ans,a)
    L.add(b)
    #print(ans,a,b)
print(ans)

Measured memory_bytes: 43356
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;


int main()
{
    string s;
    cin>>s;
    
    cout<<s.substr(0,3)<<endl;
    return 0;

}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void){
	int i,n;
	double s,x[22][2];

	for(n=0;scanf("%lf,%lf",&x[n][0],&x[n][1])!=EOF;n++);

	for(i=s=0;i<n;i++){
		if(i == n - 1){
			s += x[i][0] * x[0][1] - x[i][1] * x[0][0];
		}
		else{
			s += x[i][0] * x[i+1][1] - x[i][1] * x[i+1][0];
		}
	}
	if(s < 0) s = -s;
	printf("%.6lf\n",s/2);

	return 0;
}

Measured memory_bytes: 0