akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll h, n;
    cin >> h >> n;
    ll a[n], b[n];
    rep(i, n) { cin >> a[i] >> b[i]; }
    ll a_max = 0;
    rep(i, n) { a_max = max(a_max, a[i]); }
    ll size = h + a_max + 1;
    ll dp[size];

    rep(i, size) { dp[i] = mod; }
    dp[0] = 0;

    rep(i, size) {
        rep(j, n) {
            ll index = i - a[j];
            if (index >= 0) {
                dp[i] = min(dp[index] + b[j], dp[i]);
            }
        }
    }

    ll ans = mod;
    repd(i, h, size) { ans = min(ans, dp[i]); }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 384
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())

def make_divisors(n):
    result = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            result.append(i)
            if i != n // i:
                result.append(n//i)
    result.sort()
    return result

def main():
    N = i_input()
    A = i_list()
    ans = 0
    max_a = max(A)
    p = [0] * (max_a + 1)
    for i in A:
        for j in range(i , max_a + 1, i):
            p[j] += 1
    for i in A:
        if p[i] < 2:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 104032
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
Scanner kb=new Scanner(System.in);
int a=kb.nextInt(),b=kb.nextInt(),c=kb.nextInt();
int countc=0;

for(int i=a;i<=b;i++){
	if(c%i==0){
		countc++;
	}
}
System.out.println(countc);
	}

}

Measured memory_bytes: 26292
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define all(obj) obj.begin(), obj.end()
#define debug(x) cerr << #x << ":" << x << "\n"
#define vdebug(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
	int N; cin >> N;
	vi A(N); rep(i, N) cin >> A.at(i);
	int h = 0; ll ans = 0;
	for (int i = N - 1; i >= 0; i--) {
		h--;
		if (h < A.at(i)) {
			h = A.at(i);
			ans += h;			
		} else if (h > A.at(i)) {
			ans = -1;
			break;
		}
	}
	if (A.at(0) > 0) ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 1024
import sys
def main():
    input = sys.stdin.readline
    N,M=map(int, input().split())
    G=[[] for _ in range(N)]
    inn=[0]*N
    for _ in range(M):
        l,r,d=map(int, input().split())
        l,r=l-1,r-1
        G[l].append((r, d))
        inn[r] += 1

    ds = [-1] * N
    for i in range(N):
        if inn[i]: continue
        ds[i] = 0
        stk = [(i, 0)]
        while stk:
            v, d = stk.pop()
            for to, dt in G[v]:
                if ds[to] != -1:
                    if ds[to] != d+dt:
                        print('No')
                        return
                    continue
                ds[to] = d+dt
                stk.append((to, d+dt))

    if any([d == -1 for d in ds]):
        print('No')
        return
    print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 73172
program sample
    implicit none
    
    integer(8) :: a,b,c,i,j,m,n,k,a1,b1,c1
    integer(8), allocatable  ::x(:) 

    read(*,*) k,n
    allocate(x(n))
    read(*,*)x
    a=0
    do i=1,n-1
        b=x(i+1)-x(i)
        if (b>a)then
            a=b
        end if
    end do
    b=k-x(n)+x(1)
    if (b>a)then
        a=b
    end if
    write(*,*)k-a
    
    stop
end program sample
  



Measured memory_bytes: 2304
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ss := make([]int, n+1)
	var a int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		ss[i+1] = ss[i] + a
	}

	dp := [410][410]int{}
	var dfs func(l, r int) int
	dfs = func(l, r int) int {
		if l == r {
			return 0
		}
		if dp[l][r] != 0 {
			return dp[l][r]
		}

		res := int(1e18)
		s := ss[r+1] - ss[l]
		for i := l; i < r; i++ {
			res = min(res, dfs(l, i)+dfs(i+1, r)+s)
		}
		dp[l][r] = res
		return res
	}

	fmt.Println(dfs(0, n-1))
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

int h, w;
int ch, cw;
int dh, dw;
string s[1000];
int dp[1000][1000];
queue<pair<int, P> > que;

void f(int nh, int nw){

    // rep(i, h){
    //     rep(j, w){
    //         cout << dp[i][j];
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    int num = dp[nh][nw];
    int dx[] = {-1, 0, 1, 0};
    int dy[] = {0, 1, 0, -1};
    rep(i, 4){
        int ah = nh + dx[i];
        int aw = nw + dy[i];
        if(0 <= ah && ah < h && 0 <= aw && aw < w && s[ah][aw] == '.'){
            if(dp[ah][aw] < 0){
                dp[ah][aw] = num;
                f(ah, aw);
            }
        }
    }
    for(int i = -2; i <= 2; i++){
        for (int j = -2; j <= 2; j++){
            int ah = nh + i;
            int aw = nw + j;
            if(0 <= ah && ah < h && 0 <= aw && aw < w && s[ah][aw] == '.'){
                if(dp[ah][aw] < 0){
                    pair<int, P> p;
                    p.first = num + 1;
                    p.second.first = ah;
                    p.second.second = aw;
                    que.push(p);
                }
            }
        }
    }
}

int main(){
    cin >> h >> w;
    cin >> ch >> cw;
    ch--; cw--;
    cin >> dh >> dw;
    dh--; dw--;
    rep(i, h) cin >> s[i];
    rep(i, h)rep(j, w) dp[i][j] = -1;

    pair<int, P> p1;
    p1.first = 0;
    p1.second.first = ch;
    p1.second.second = cw;
    que.push(p1);

    while(que.size() > 0){
        pair<int, P> p;
        p = que.front();
        que.pop();
        int nh = p.second.first;
        int nw = p.second.second;
        if(dp[nh][nw] < 0){
            dp[nh][nw] = p.first;
            f(nh, nw);
        }
        
    }
    

    // rep(i, h){
    //     rep(j, w){
    //         cout << dp[i][j];
    //     }
    //     cout << endl;
    // }

    cout << dp[dh][dw] << endl;
}

Measured memory_bytes: 9712
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n=int(input())
    aa=list(map(int, input().split()))
    aa.sort()
    print(*aa)
main()



Measured memory_bytes: 224512
//Zory-2018
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;

namespace mine
{
	typedef long long ll;
	const int INF=0x3f3f3f3f;
	int qread()
	{
		int ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-') f=-1;;c=getchar();}
		while(c>='0' and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}

	const int MAX_N=1e6+10;
	ll bin[100];
	ll a[MAX_N],s[MAX_N];
	bool is[MAX_N];
	void main()
	{
		bin[0]=1;for(int i=1;i<=60;i++) bin[i]=bin[i-1]<<1;
		
		int n,k;scanf("%d%d",&n,&k);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		int tot=0;
		for(int l=1;l<=n;l++)
		{
			ll sum=0;
			for(int r=l;r<=n;r++)
			{
				sum+=a[r];
				s[++tot]=sum;
			}
		}
		
		ll ans=0;
		memset(is,1,sizeof is);
		for(int t=40;t>=0;t--)
		{
			int wt=0;for(int i=1;i<=tot;i++) if(is[i] and s[i]&bin[t]) wt++;
			if(wt>=k)
			{
				ans+=bin[t];
				for(int i=1;i<=tot;i++) if(is[i] and (s[i]&bin[t])==0) is[i]=0;
			}
		}
		printf("%lld",ans);
	}
};
int main()
{
	srand(time(0));
	mine::main();
}


Measured memory_bytes: 8448
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  int i = 0;
  bool match = false;
  while(i < s.size()){
    if(s == t){
      match = true;
      break;
      cout << "match!" << endl;
    }
    else{
      char tmp_char = s[s.size() -1];
      s.pop_back();
      s = tmp_char + s;
      i++;
    }
  }
  if(match) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main(){
  
  vector<int> T(5);
  for (int i=0;i<5;i++) cin >> T.at(i);
  
  vector<pair<int,int>> P(5);
  
  for (int i=0;i<5;i++){
    P.at(i) = make_pair((T.at(i)-1)%10,T.at(i));
  }
  
  sort(P.begin(),P.end());
  
  int ans = P[0].second;
  
  for (int i=1;i<5;i++){
    if (P[i].second % 10 > 0){
      P[i].second = P[i].second + 10 - P[i].second%10;
    }
    ans += P[i].second;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
class LoopSequenceSum(untilLoop: LongArray, inLoop: LongArray, private val mod: Long) {
    private val mUntilLoop: LongArray = LongArray(untilLoop.size + 1){0L}
    private val mInLoop: LongArray = LongArray(inLoop.size + 1) {0L}
    private val untilLoopSize = untilLoop.size
    private val loopSize = inLoop.size
    init {
        for (i in untilLoop.indices) {
            mUntilLoop[i + 1] = untilLoop[i] + mUntilLoop[i]
        }
        for (i in inLoop.indices) {
            mInLoop[i + 1] = inLoop[i] + mInLoop[i]
        }
    }
    operator fun get(length: Long): Long {
        if (length <= untilLoopSize) return mUntilLoop[length.toInt()]
        return mUntilLoop.last() + getInLoop(length - untilLoopSize)
    }
    private fun getInLoop(length: Long): Long {
        val loopCount = length / loopSize
        val rest = length % loopSize
        return loopCount * mInLoop.last() + mInLoop[rest.toInt()]
    }
    companion object {
        operator fun invoke(x: Int, m: Int): LoopSequenceSum {
            val prev = IntArray(m.toInt()){-1}
            var count = 0
            var current = x.toLong()
            while (prev[current.toInt()] == -1) {
                prev[current.toInt()] = count++
                current = (current * current) % m
            }
            val untilLoop = LongArray(prev[current.toInt()]){0}
            val inLoop = LongArray(count - untilLoop.size){0}
            current = x.toLong()
            for (i in untilLoop.indices) {
                untilLoop[i] = current
                current = (current * current) % m
            }
            for (i in inLoop.indices) {
                inLoop[i] = current
                current = (current * current) % m
            }
            return LoopSequenceSum(untilLoop, inLoop, m.toLong())
        }
    }
}

fun main() {
    val (n, x, m) = readLine()!!.trim().split(' ').map(String::toLong)
    val loopSum = LoopSequenceSum(x.toInt(), m.toInt())[n]
    println(loopSum)
}

Measured memory_bytes: 41448
from sys import stdin
input = stdin.readline
N = int(input())
S = {}
for n in range(N):
    s = input()
    if S.get(s) == None:
        S[s] = 1
    else:
        S[s] += 1
m = max(S.values())
A = [k for k,v in S.items() if v == m]
A = sorted(A)
for a in A:
    print(a.rstrip('\n'))

Measured memory_bytes: 33372
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
 
#define READ(x) (cin >> (x))
 
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
 
int main() {
    // get values from input
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    double R;
    READ(R);
    
    // main procedure
 
 
    // output
    WRITE(R*2.0d*M_PI);
    
 
    return 0;
}

Measured memory_bytes: 3808
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m;
    cin>>n>>m;
    vector<vector<int>> a(100004);
    for (int i = 0; i < n; i++) {
        int j, k;
        cin>>j>>k;
        a[j].push_back(k);
    }
    for (int i = 0; i < 100004; i++) {
        sort(a[i].begin(), a[i].end());
    }
    long ans = 0;
    priority_queue<pair<int, int>> pq;
    for (int i = 1; i <= m; i++) {
        if (a[i].size() > 0) pq.push({a[i][a[i].size()-1], i});
        if (pq.empty()) continue;
        pair<int, int> pa = pq.top();
        pq.pop();
        ans += pa.first;
        a[pa.second].pop_back();
        if (a[pa.second].size() > 0) pq.push({a[pa.second][a[pa.second].size()-1], pa.second});
    }
    cout<<ans<<endl;
}


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

int main() {

    int a,b;

    scanf("%d%d", &a,&b);

    if(a==b){
        puts("Draw");
    }else{
        if(a==1){
            puts("Alice");
        }else if(b==1){
            puts("Bob");
        }else{
            if(a>b){
                puts("Alice");
            }else{
                puts("Bob");
            }
        }
    }

    return 0;

}


Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;
ll c[100005];
const ll m=998244353;
int main()
{
    ll n,flag=0;
    cin>>n;
    for(ll i=0; i<n; i++)
        scanf("%lld",&c[i]);
    if(c[0]==0)
        flag=1;
    sort(c,c+n);
    ll s=0,cnt=1,bf=1;
    for(ll i=0; i<n; i++)
    {
        if(i==0)
        {
            if(c[i]==0)
                s=1;
        }
        else
        {
            if(c[i]==0)
            {
                s=0;
                break;
            }
            if(c[i]-c[i-1]==0)
            {
                s=(s*bf)%m;
                cnt++;
            }
            else if(c[i]-c[i-1]==1)
            {
                s=(s*cnt)%m;
                bf=cnt;
                cnt=1;
            }
            else
                s=0;
        }
        if(s==0)
            break;
    }
    if(flag)
    printf("%lld",s);
    else
        printf("0");
    return 0;
}
/*
5
5
1 5 4 2 3
1 2 5 4 3
*/



Measured memory_bytes: 1024
N = int(input())
hxy = []
for _ in range(N):
        x,y,h = map(int,input().split())
        hxy.append([h,x,y])
hxy.sort(reverse=True)
xy = [[x,y] for x in range(101) for y in range(101)]
for i in range(len(hxy) - 1):
        h1,x1,y1 = hxy[i]
        for j in range(i + 1,len(hxy)):
                h2,x2,y2 = hxy[j]
                xy_copy = xy.copy()
                if h1 == 0 and h2 == 0:
                        xy.remove([x1,y1])
                        xy.remove([x2,y2])
                        if len(xy) == 1:
                                x,y = xy[0]
                                print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                                exit()
                        continue
                elif h1 == 0:
                        for x,y in xy_copy:
                                if abs(x - x2) + abs(y - y2) - abs(x - x1) - abs(y - y1) + h2 > 0:
                                        xy.remove([x,y])
                        if len(xy) == 1:
                                x,y = xy[0]
                                print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                                exit()
                        continue
                elif h2 == 0:
                        for x,y in xy_copy:
                                if abs(x - x1) + abs(y - y1) - abs(x - x2) - abs(y - y2)  + h1 > 0:
                                        xy.remove([x,y])
                        if len(xy) == 1:
                                x,y = xy[0]
                                print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                                exit()
                        continue
                

                for x,y in xy_copy:
                        if abs(x - x1) + abs(y - y1) - abs(x - x2) - abs(y - y2) != h2 - h1:
                                xy.remove([x,y])
                if len(xy) == 1:
                        x,y = xy[0]
                        print(x,' ',y,' ',h1 + abs(x - x1) + abs(y - y1))
                        exit()

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

string S;
long long K;
int ans;
int main()
{
	cin >> S >> K;
	ans = '1';
	for( int i = 0; i < K; i++ ) {
		if( S[i] == '1' ) continue;
		ans = S[i];
		break;
	}
	cout << ans-'0' << endl;
}


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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	string n;
	cin >> n;
	int k{};
	for (char c : n) k += c - '0';
	cout << (k%9 == 0 ? "Yes" : "No");
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	int n; cin>>n;
	map<string,int> mp;
	rep(i,0,n){
		string s; cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;
	
	
	return 0;
}

Measured memory_bytes: 3600
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

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

signed main(){
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    vector<P> s(100001), t(100001);
    rep(i, 100001){
        s[i] = make_pair(0, i);
        t[i] = make_pair(0, i);
    }
    rep(i, n){
        if(i % 2 == 0){
            s[v[i]].first++;
        }else{
            t[v[i]].first++;
        }
    }
    sort(s.begin(), s.end(), greater<P>());
    sort(t.begin(), t.end(), greater<P>());
    int ans1 = s[0].first;
    if(s[0].second == t[0].second){
        ans1 += t[1].first;
    }else{
        ans1 += t[0].first;
    }
    int ans2 = t[0].first;
    if(s[0].second == t[0].second){
        ans2 += s[1].first;
    }else{
        ans2 += s[0].first;
    }

    cout << n - max(ans1, ans2) << endl;


    return 0;
}


Measured memory_bytes: 4736
#include<stdio.h>

int main(){
  int x,y,temp,gcd;

  scanf("%d%d",&x,&y);

  while(y!=0){
    temp=x;
    gcd=y;
    x=y;
    y=temp%gcd;
  }

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

  return 0;

}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N;
  cin >> N;
  vector<long long> a(3 * N);
  rep(i, 3 * N)
  {
    cin >> a[i];
  }
  priority_queue<long long, vector<long long>, greater<long long>> big;
  long long big_sum = 0;
  rep(i, N)
  {
    big.push(a[i]);
    big_sum += a[i];
  }

  vector<long long> small_sum(N + 1);
  priority_queue<long long> small;
  rep(i, N)
  {
    small_sum[0] += a[3 * N - 1 - i];
    small.push(a[3 * N - 1 - i]);
  }

  rep(i, N)
  {
    small.push(a[2 * N - 1 - i]);
    small_sum[i + 1] = small_sum[i] + a[2 * N - 1 - i] - small.top();
    small.pop();
  }
  reverse(small_sum.begin(), small_sum.end());
  long long ans = big_sum - small_sum[0];
  rep(i, N)
  {
    long long b = a[N + i];
    big.push(b);
    big_sum += b - big.top();
    big.pop();
    ans = max(ans, big_sum - small_sum[i + 1]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5748
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  (n, k) = InputLine.to_ia
  h = InputLine.to_ia

  h.sort!{|a, b| b <=> a}
  k.times{|i| h[i] = 0}
  s = h.reduce(:+)
  
  puts s.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

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

int n, m;

const int INF = 1e+9;
const int MAX_V = 100;
int cost[MAX_V][MAX_V];
int mincost[MAX_V];
bool used[MAX_V];

int prim(){
	for(int i=0 ; i < n ; i++ ){
		mincost[i] = INF;
		used[i] = false;
	}
	mincost[0] = 0;
	int res = 0;
	
	while( true ){
		int v = -1;
		for(int u=0 ; u < n ; u++ ){
			if( !used[u] && (v == -1 || mincost[u] < mincost[v]) ){
				v = u;
			}
		}
		
		if(v == -1) break;
		used[v] = true;
		res += mincost[v];
		
		for(int u=0 ; u < n ; u++ ){
			mincost[u] = min( mincost[u] , cost[v][u] );
		}
	}
	return res;
}

// ?????????s?????????c???????????§??????????????????
vector<string> split_string(string s, char c){
	string str;
	vector<string> vs;
	s.push_back( c );
	
	for(int i=0 ; i < s.size() ; i++ ){
		if( s[i] == c ){
			if( !str.empty() ){
				vs.push_back( str );
				str.clear();
			}
		}else{
			str.push_back( s[i] );
		}
	}
	return vs;
}

// string???int?????????
int s_to_i(string s){
	int n=0;
	for(int i=0 ; i < s.size() ; i++ ){
		n *= 10;
		n += s[i] - '0';
	}
	return n;
}

int main(){
	while( cin >> n , n ){
		for(int u=0 ; u < n ; u++ ){
			for(int v=0 ; v < n ; v++ ){
				cost[u][v] = cost[v][u] = INF;
			}
		}
		
		cin >> m;
		cin.ignore();
		for(int i=0 ; i < m ; i++ ){
			string s;
			getline(cin,s);
			vector<string> vs = split_string( s , ',' );
			int u = s_to_i( vs[0] );
			int v = s_to_i( vs[1] );
			int c = (s_to_i( vs[2] ) - 100) / 100;
			cost[u][v] = cost[v][u] = c;
		}
		int ans = prim();
		cout << ans << endl;
	}
}

Measured memory_bytes: 1252
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <map>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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

int main(){
	int R;
	cin >> R;
	if (R < 1200){
		cout << "ABC";
	}
	else if (R < 2800){
		cout << "ARC";
	}
	else{
		cout << "AGC";
	}
	cout << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
kyori = [0 for _ in range(n + 1)]
cum_k = [0 for _ in range(n + 1)]
for ni in range(1, n):
    si = int(input())
    kyori[ni] = si
    cum_k[ni + 1] = cum_k[ni] + si
# print(kyori)
# print(cum_k)
ans, pos = 0, 1
for mi in range(m):
    nex = pos + int(input())
    ans += abs(cum_k[nex] - cum_k[pos])
    pos = nex
print(ans % 100000)

Measured memory_bytes: 12500
function Main(input) {
    var input = input.split('\n');
    var s = input[0].split('')
    var t = input[1].split('')
    var ss = s.sort((a, b) => a < b ? -1 : 1).toString();
    var tt = t.sort((a, b) => a < b ? -1 : 1).reverse().toString();
   
         if (ss < tt) {
        console.log('Yes');
    } else {
        console.log('No');
    }

    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include<stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	int value[n], cost[n], sum=0;
	for(int i=0; i<n; i++){
		scanf("%d",&value[i]);
	}
	for(int i=0; i<n; i++){
		scanf("%d",&cost[i]);
	}
	for(int i=0; i<n; i++){
		if(value[i]-cost[i] > 0){
			sum += value[i]-cost[i];
		}
	}
	printf("%d", sum);
	
	return 0;
}

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

bool isPal(string s, int n){
	for(int i=0; i < n/2; i++){
		if(s[i]!=s[n-i-1])
			return false;
	}
	return true;
}

int main() {
	string s;
	cin >> s;
	int n = s.length();
	if(n == 1){
		cout << "Yes" << endl; return 0;
	}	
	string s1 = s.substr(0, n/2);
	string s2 = s.substr(n/2+1, n/2);
	if(isPal(s, n) && isPal(s1, n/2) && isPal(s2, n/2))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3620
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  printChessboard(sc.nextInt(), sc.nextInt())

  def printChessboard(h: Int, w: Int): Unit = {
    (h, w) match {
      case (0, 0) => sc.close()
      case _ =>
        for (i <- 1 to h) i match {
          case _ if i % 2 != 0 => printOddRow(w)
          case _ if i % 2 == 0 => printEvenRow(w)
        }
        println()
        printChessboard(sc.nextInt(), sc.nextInt())
    }
  }

  def printOddRow(w: Int): Unit = {
    for (i <- 1 to w) i match {
      case _ if i % 2 != 0 => print("#")
      case _ if i % 2 == 0 => print(".")
    }
    print("\n")
  }

  def printEvenRow(w: Int): Unit = {
    for (i <- 1 to w) i match {
      case _ if i % 2 != 0 => print(".")
      case _ if i % 2 == 0 => print("#")
    }
    print("\n")
  }
}

Measured memory_bytes: 53096
import numpy as np
n,m,x =map(int,input().split())
syo = []
for _ in range(n):
    temp =list(map(int,input().split()))
    syo.append(temp)

ans = []

for i in range(2 ** n):
    total = 0
    temp = [0]*m    
    for j in range(n):  
        if ((i >> j) & 1): 
            total += syo[j][0]
            for k in range(1,m+1):
                temp[k-1] += syo[j][k]
    if all(t >= x for t in temp):
        ans.append(total)

if ans:
    print(min(ans))
else:
    print("-1")


Measured memory_bytes: 27216
#include<stdio.h>

int main()
{
    int m[50],f[50],r[50];
    int count=0;
    while(1){
    scanf("%d %d %d",&m[count],&f[count],&r[count]);
    if(m[count]==-1&&f[count]==-1&&r[count]==-1){
        break;
    }
        count+=1;
    }
    for(int i=0;i<count;i++){
        if(m[i]==-1||f[i]==-1){
            printf("F\n");
        }else if(m[i]+f[i]>=80){
            printf("A\n");
        }else if(65<=m[i]+f[i]&&m[i]+f[i]<=79){
            printf("B\n");
        }else if(50<=m[i]+f[i]&&m[i]+f[i]<=64){
            printf("C\n");
        }else if(30<=m[i]+f[i]&&m[i]+f[i]<=49){
            if(r[i]>49){
                printf("C\n");
            }else{
                printf("D\n");
            }
        }else if(m[i]+f[i]<30){
            printf("F\n");
        }
    }
    return 0;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<int, int> p;


int main(){
  int n;
  cin >> n;
  map<string, vector<p>> mp;
  for (int i = 0; i < n; i++) {
    string s;
    int point;
    cin >> s >> point;
    if(mp[s].size() == 0) mp[s] = vector<p> ();
    mp[s].push_back({point, i+1});
  }

  for(auto a : mp){
    auto x = mp[a.first];
    sort(RALL(x));
    // print(x);
    for(auto b : x){
      cout << b.second << endl;
    }
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int A, B, C, K; cin >> A >> B >> C >> K;
  int cnt = 0;
  for(int i = 0; A >= B && i < K; i++) {
    B *= 2;
    cnt++;
  }
  C *= pow(2, K - cnt);
  if(A < B && B < C) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main()
{
    string n;
    int ans = 0;
    
    cin >> n;
    int len = n.size();
    
    for (size_t i = 0; i < len; i++)
    {
        ans += n[i] - '0';
    }

    if(stoi(n) % ans == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
a, b = map(int, input().split(' '))
x, y, z = 0, 0, 0
p = list(map(int, input().split(' ')))
for i in range(n):
    if p[i] <= a:
        x += 1
    elif p[i] <= b:
        y += 1
    else:
        z += 1
ans = min(x, y, z)
print(ans)

Measured memory_bytes: 3064
solve [] acc = if acc > (10^18) then -1 else acc
solve _ 0 = 0
solve (a:as) acc
    | acc > (10^18) = -1
    | otherwise = solve as (acc*a)


main = do
    n <- getLine
    an <- map read <$> (words <$> getLine) :: IO [Integer]
    print $ if elem 0 an then 0  else solve an 1


Measured memory_bytes: 64148
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
bool check1;
ld xpow(ld n, ll m){if(m==0){return 1;}else{ld x = xpow(n, m/2);if(m&1){ld res = x*x*n;if(res>1e7){check1=1;};return res;}else{ld res = x*x;if(res>1e7){check1=1;}return res;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
int main(){
    fast();
 
/* you get what you work for not what you wish for */
    
    inps(x, y);
    ll z = x+y;
    ll dp[1000005] = {0};
    dp[0] = 1;
    for(ll i=1; i<=1000000; i++){
        dp[i] = i*dp[i-1];
        dp[i] = xmod(dp[i], MOD);
    }
    if(z%3){
        cout << 0 << endl;
        return 0;
    }
    ll row = z/3;
    ll bound1 = max(row, z-row);
    ll bound2 = min(row, z-row);
    if(x<=bound1&&x>=bound2&&y<=bound1&&y>=bound2){
        ll col = abs(x-row);
        ll ans = dp[row];
        ll zz = xmodpow(dp[col], MOD-2, MOD);
        zz *= xmodpow(dp[row-col], MOD-2, MOD);
        zz%=MOD;
        ans*=zz;
        ans%=MOD;
        cout << ans << endl;
        return 0;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 8064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, K;
  while (cin >> N >> K) {
    double res = 0;
    for (ll i = 1; i <= N; i++) {
      if (i >= K) {
        res += 1.0 / N;
        continue;
      }
      ll v = i;
      double p = 1.0 / N;
      while (v < K) {
        v *= 2;
        p *= 0.5;
      }
      res += p;
    }
    printf("%.20f\n", res);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int r,g,b,n,ans=0;
  cin>>r>>g>>b>>n;
  for (int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      if((n-(i*r)-(j*g))/b>=0 && i*r+j*g+b*((n-(i*r)-(j*g))/b)==n){
          ans++;}
      }
    }
  cout<<ans;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n,m,d,ans=0,i,j,k;
  cin>>n>>m>>d;
  char c[1000][1000];
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      cin>>c[i][j];
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      bool bo=true;
      for(k=0;k<d;k++){
        if(c[i][j+k]!='.') {
          bo=false;
          break;
        }
      }
      if(bo) ans++;
    }
    //cout<<ans<<endl;
  }//??????
    for(j=0;j<m;j++){
      for(i=0;i<n;i++){
        bool bo=true;
        for(k=0;k<d;k++){
          if(c[i+k][j]!='.'){
            bo=false;
            break;
          }
        }
        if(bo) ans++;
      }
      //cout<<ans<<endl;
    }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;

int main() {
	long long a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	for (long long i = 0; i < a; ++i) {
		long long ma = b + i * e - (a - i - 1)*d, mi = b + i * d - (a - i - 1)*e;
		if (mi <= c && c <= ma) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
from collections import deque

s = input()
N = int(input())

S = []
for i in range(len(s)):
    S.append(s[i])

d = deque(S)
    
back_count = 0
for i in range(N):
    Q = list(map(str, input().split()))
    Q[0] = int(Q[0])
    if Q[0] == 1:
        if back_count == 0:
            back_count = 1
        else:
            back_count = 0
    else:
        Q[1] = int(Q[1])
        if back_count == 0:
            if Q[1] == 1:
                d.appendleft(Q[2])
            else:
                d.append(Q[2])
        else:
            if Q[1] == 1:
                d.append(Q[2])
            else:
                d.appendleft(Q[2])

S = list(d)
if back_count == 0:
    print("".join(S))
else:
    S = S[::-1]
    print("".join(S))

Measured memory_bytes: 10332
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, k = nm()

    ans = 0
    for i in range(k, n+2):
        mn = i * (i-1) // 2
        mx = i * (2 * n + 1 - i ) // 2
        ans += mx - mn + 1

    print(ans % mod)
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9736
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    ll l;
    cin >> l;
    printf("%.10f", pow(l/3.0,3));
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

#define VAL 1000000000+7



using namespace std;

int main(){
    long long int mod = 1;
    long long int n,k;

    long long int ans = 0;

    cin >> n >> k;
    for(long long int r=k;r<=n+1;r++){
        long long int val = r/2.0*(r-1);
        long long int val2 = r/2.0*(2*(n-r+1)+r-1);
        //cout << val << "," << val2 << endl;
        //cout << r << ","  << (val2-val)%(VAL)  << endl;
        ans = (ans + val2-val+1)%(VAL);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
n, m = map(int, input().split())
sugoroku = input()[::-1]

cnt = 0
pos = 0
tmp = 0
lst = []
while pos != n:
    pos += 1
    cnt += 1
    if cnt == m:
        if sugoroku[pos] == "0":
            lst.append(cnt)
            cnt = 0
        else:
            if tmp == 0:
                print(-1)
                exit()
            lst.append(tmp)
            cnt -= tmp
            tmp = 0
    else:
        if sugoroku[pos] == "0":
            tmp = cnt
if cnt != 0:
    lst.append(cnt)
for num in lst[::-1]:
    print(num, end = " ")


Measured memory_bytes: 5652
#include<iostream>
#include<sstream>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define each(i, c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

typedef pair<int, int> pi;
string s, t;
int p, val, iter;

int parse(){
	if(s[p] == '-'){
		p++;
		return !parse();
	}
	if(s[p] == 'T' || s[p] == 'F'){
		return s[p++] == 'T';
	}
	if(isalpha(s[p])){
		return val >> (s[p++] - 'a') & 1;
	}
	assert(s[p] == '(');
	p++;
	int a = parse();
	char c = s[p++];
	if(c == '-') p++;
	int b = parse();
	p++;
	if(c == '*') return a && b;
	if(c == '+') return a || b;
	return (!a) || b;
}


int main(){
	string in;
	while(getline(cin, in), in != "#"){
		int pos = in.find("=");
		s = in.substr(0, pos);
		t = in.substr(pos + 1);
		p = 0;
		
		bool ok = 1;
		rep(i, 1 << 12){
			val = i;
			p = 0;
			int a = parse();
			swap(s, t);
			p = 0;
			int b = parse();
			swap(s, t);
			
			if(a != b){
				ok = 0;
				break;
			}
		}
		cout << (ok ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 956
package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
)

var s = bufio.NewScanner(os.Stdin)

func getInt() int {
  s.Scan()
  i, _ := strconv.Atoi(s.Text())
  return i
}

func main() {
  s.Split(bufio.ScanWords)
  x := getInt()
  y := getInt()
  a := getInt()
  b := getInt()
  c := getInt()
  var p []int
  var q []int
  var r []int
  var s []int
  for i := 0; i < a; i++ {
    p = append(p, getInt())
  }
  for i := 0; i < b; i++ {
    q = append(q, getInt())
  }
  for i := 0; i < c; i++ {
    r = append(r, getInt())
  }
  sort.Sort(sort.Reverse(sort.IntSlice(p)))
  sort.Sort(sort.Reverse(sort.IntSlice(q)))
  sort.Sort(sort.Reverse(sort.IntSlice(r)))
  s = append(p[0:x], q[0:y]...)
  s = append(s, r...)
  sort.Sort(sort.Reverse(sort.IntSlice(s)))
  sum := 0
  for i := 0; i < x + y; i++ {
    sum += s[i]
  }
  fmt.Println(sum)
}


Measured memory_bytes: 10880
// A Naive recursive C++ program to find minimum of coins 
        // to make a given change V 
        #include<bits/stdc++.h> 
        using namespace std; 
        int main()
        {
            long int l,r;
            cin>>l>>r;
            int a[2019]={0};
            for(long int i=l;i<=min(r,l+2020);i++)
              a[i%2019]++;
            
            int min1=INT_MAX;
            // cout<<a[4]<<" "<<a[5]<<endl;
            if(a[0]!=0)
             cout<<0;
            else
            {
                for(int i=1;i<2019;i++)
                {
                    for(int j=i+1;j<2019;j++)
                    {
                        if(a[i]!=0 && a[j]!=0)
                        if(min1>((i*j)%2019))
                         min1=((i*j)%2019);
                    }
                }
                
                cout<<min1<<endl;
            }
            
        }

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int K;
  cin >> K;
  vector<int64_t> A(K);
  for (int i = 0; i < K; i++) {
    cin >> A[i];
  }
  reverse(A.begin(), A.end());
  int64_t lo = 2, hi = 2;
  for (int i = 0; i < K; i++) {
    if (lo % A[i] != 0 && lo - (lo % A[i]) + A[i] > hi) {
      cout << -1 << '\n';
      return 0;
    }
    lo = (lo + A[i] - 1) / A[i] * A[i], hi = hi / A[i] * A[i] + A[i] - 1;
  }
  cout << lo << ' ' << hi << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	stack<char> stc;
	int adf = 0, adr = 0;
	for(auto c : s){
		if(c == ')' && !stc.empty()){
			stc.pop();
		}else if(c == '('){
			stc.push('(');
		}else{
			adf++;
		}
	}
	adr = stc.size();
	rep(i, adf) cout << '(';
	cout << s;
	rep(i, adr) cout << ')';
	return 0;
}

Measured memory_bytes: 256
from collections import deque
N,K=map(int,input().split())
node=[0]*N
edge={}
G=[[] for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  edge[(a-1,b-1)]=0
  G[a-1].append(b-1)
  G[b-1].append(a-1)
if K%2:
  for a,b in edge.keys():
    visited=[False]*N
    stack=deque([(a,0),(b,0)])
    visited[a],visited[b]=True,True
    while stack:
      n,c=stack.popleft()
      if c>K//2:
        break
      edge[(a,b)]+=1
      for s in G[n]:
        if not visited[s]:
          stack.append((s,c+1))
          visited[s]=True
  print(N-max(edge.values()))
else:
  for a in range(N):
    visited=[False]*N
    stack=deque([(a,0)])
    visited[a]=True
    while stack:
      n,c=stack.popleft()
      if c>K//2:
        break
      node[a]+=1
      for s in G[n]:
        if not visited[s]:
          stack.append((s,c+1))
          visited[s]=True
  print(N-max(node))
      
      
  


Measured memory_bytes: 50904
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=0;i<n;i+=2)
#define ll long long
#define llc(n) ll n; cin >> n;
using namespace std;
int main() {
  int n,k;
  cin >> n >> k;
  vector<ll> h(n);
  ll a=0;
  r1(i, n) cin >> h.at(i);
  sort(h.begin(), h.end());
  if(n>k) {
    for(int i=0;i<n-k;i++) a+=h.at(i);
  }
  cout << a << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

double dist(int x1, int y1, int x2, int y2) {
    return sqrt((double)pow(abs(x2-x1), 2)+(double)pow(abs(y2-y1), 2));
}

int main() {
    int n;
    cin >> n;
    vint p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];

    vint v(n);
    rep(i, n) v[i] = i+1;
    int count = 0;
    int a, b;
    do {
        if (p == v) a = count;
        if (q == v) b = count;
        count++;
    } while( next_permutation(all(v)) );

    cout << abs(b-a) << endl;
    return 0;
}

Measured memory_bytes: 256
//daddy's back in town, back to rolling the damn hash yoooo babeeeeees//
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
const ll mod = 1000000007;
int n, a[200020], dp[200020], ans;

int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>a[i];
		dp[a[i]]=dp[a[i]-1]+1;
		ans=max(ans, dp[a[i]]);
	}
	cout<<n-ans;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s,a,b; cin>>s;
	a=s.substr(0,2); b=s.substr(2,2);
	cout<<("00"<a&&a<"13"?"00"<b&&b<"13"?"AMBIGUOUS":"MMYY":"00"<b&&b<"13"?"YYMM":"NA");
}

Measured memory_bytes: 3604