akhauriyash/Code-Regression huggingface dataset:
n = int(input())
t = []
for i in range(n):
    t.append(int(input()))
    
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

def lcm(a, b):
    return a*b//gcd(a, b)

result = 1
for i in range(n):
    result = lcm(result, t[i])
    
print(result)
            

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int32_t main() {
	int m,n;
	cin>>m>>n;
	set<int> s;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		s.insert(x);
	}
	ll dp[m+1];
	fill(dp,dp+m+1,0);
	dp[0]=1;
	if(s.find(1)!=s.end()) dp[1]=0;
	else dp[1]=1;
	for(int i=2;i<=m;i++){
		if(s.find(i)!=s.end()) dp[i]=0;
		
		else dp[i]=(dp[i-1]+dp[i-2])%1000000007;
	//	cout<<dp[i-1]<<' '<<dp[i-2]<<'\n';
	}
	cout<<dp[m];
}

Measured memory_bytes: 5760
def STR(): return input()

mod = 1000000007

s = STR()
l = len(s)
dp = [[0] * 13 for _ in range(l + 1)] #dp[i]i桁目まで決めた時の13で割ったあまりが[j]の個数
dp[0][0] = 1


for i in range(l + 1): #i桁目まで決める
    if s[i-1] == '?':
        for j in range(13): #i-1桁目のあまりがj
            a = dp[i-1][j]
            b = j * 10
            for k in range(10): #i桁目の値
                dp[i][(b + k) % 13] += a
        for j in range(13):
            dp[i][j] %= mod
    else:
        a = int(s[i-1])
        for j in range(13): #i-1桁目のあまりがj
            num = (j * 10 + a) % 13
            dp[i][num] += dp[i-1][j]
            dp[i][num] %= mod
#print(dp)
print(dp[l][5])


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

#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pq priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define inf LLONG_MAX


signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin>>n;
	inp(a,n,0);
	map<int,int> m;
	for(int i=0;i<n;i++)
	{
		set<int> s;
		int temp=a[i];
		while(temp%2==0)
		{
			temp/=2;
			s.insert(2);
		}
		for(int j=3;j*j<=temp;j+=2)
		{
			while(temp%j==0)
			{
				temp/=j;
				s.insert(j);
			}
		}
		if(temp>2)
			s.insert(temp);
		for(int x:s)
			m[x]++;
	}
	bool ok=1;
	for(auto x:m)
		if(x.se!=1)
			ok=0;
	if(ok)
		cout<<"pairwise coprime";
	else
	{
		int gc=a[0];
		for(int i=1;i<n;i++)
			gc=__gcd(gc,a[i]);
		if(gc==1)
			cout<<"setwise coprime";
		else
			cout<<"not coprime";
	}
	return 0;
}


Measured memory_bytes: 16292
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

int64_t solve(const int N, string c) {
  char RED = 'R';
  char WHITE = 'W';
  int r = N - 1;
  int count = 0;

  REP(l, N) {
    if (c.at(l) == RED)
      continue;

    while (c.at(r) == WHITE && r > 0)
      --r;

    if (l >= r)
      break;

    c.at(l) = RED;
    c.at(r) = WHITE;
    ++count;
  }

  return count;
}

// generated by online-judge-template-generator v4.4.0
// (https://github.com/kmyk/online-judge-template-generator)
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  constexpr char endl = '\n';
  int N;
  cin >> N;
  string c;
  cin >> c;
  auto ans = solve(N, c);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3864
mod = 10**9+7

# modを取りながらべき乗する
def power_func(a,n,mod=mod):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %mod
        if bi[i]=="1":
            res=(res*a) %mod
    return res

N = input()
up = True
M = ''
for l in range(len(N)):
    if up:
        if N[len(N)-l-1] == '0':
            M += '1'
            up = False
        else:
            M += '0'
    else:
        M += N[len(N)-l-1]
if up:
    M += '1'
M = M[::-1]
L = len(M)

c = 0
ans = 0
for l in range(L):
    if int(M[l]) == 1:
        ans += power_func(3, L-l-1) * power_func(2, c) % mod
        c += 1
        ans %= mod

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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

void solve(ll N, vector<ll> A) {
  sort(A.rbegin(), A.rend());

  ll ans(A[0]);
  FOR(i, 2, N)
    ans += A[i / 2];
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) {
    cin >> A[i];
  }

  solve(N, move(A));

  return 0;
}


Measured memory_bytes: 4776
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()
#define pb push_back

typedef long long ll;
const int inf = 1e9+7;
const ll infll = 1 << 60LL;
const ll mod = 1e9 + 7;
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

// 型による変数のオーバーフローに気をつけろ！！
// 悩んだら図やグラフを書け！！悩む前から書け！！

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

	int n;
	cin >> n;

	vector<char> s;

	//cout << 3 % (-2) << endl;
	if (n == 0) s.push_back('0');
	while (n != 0) {
		if(n & 1){ // 奇数ってこと？
			s.push_back('1');
			n--;
		}
		else {
			s.push_back('0');
		}
		n /= -2;
	}

	//cout << ((5) & 1) << endl;
	reverse(allof(s));
	rep(i,s.size()) cout << s[i];

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n;
  cin>>n;
  long long int i,sum;
  sum=0;
  for(i=1;i<=n;i++)
  {
    if(i%5==0||i%3==0)
    {continue;}
    sum=sum+i;
  }
  cout<<sum;
  
  return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

long long N;
long long A[50];

bool f(long long X) {
  long long sum = 0;
  rep(i, N) {
    long long x = A[i] + X;
    if (x <= N-1) continue;
    sum += (x-(N-1)+N)/(N+1);
  }
  //cout<<"f("<<X<<") = "<<(sum<=X)<<"\n";
  return sum <= X;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> A[i];
  long long m = (1LL<<60);
  rep(d, N) {
    long long lo = -1, hi = 100000000000000000;
    while (hi - lo > 1) {
      long long mid = (lo + hi) / 2LL;
      if (f(mid*N+d)) hi = mid;
      else lo = mid;
    }
    m = min(m, hi*N+d);
  }
  cout << m << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
long long N, M, K;
int c[3][3];
int checkdigit(long long a, long long b) {
	int cnt_a = 0, cnt_b = 0;
	while (a > 0) {
		a /= 10;
		cnt_a++;
	}
	while (b > 0) {
		b /= 10;
		cnt_b++;
	}
	return max(cnt_a, cnt_b);
}
int main() {
	cin >> N;
	int ans = 100000;
	for (long long i = 1; i*i <= N; ++i) {
		if (N%i != 0) continue;
		ans = min(ans, checkdigit(i, N / i));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
using namespace std;
int g[100010];
vector<int> to[100010];

class UnionFind {
  public:
    // 親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> Parent;

    // 作る時はParentの値を全て-1にする
    // こうすると全てバラバラが表現できる。
    UnionFind(int N) {
      Parent = vector<int>(N, -1);
    }

    // Aがどのグループに属しているか調べる
    int root(int A) {
      if(Parent[A] < 0) return A;
      return Parent[A] = root(Parent[A]);
    }

    int size(int A) {
      return -Parent[root(A)]; // 親を取ってきたい
    }

    bool connect(int A, int B) {
      // AとBを直接繋ぐのではなく、root(A)をroot(B)をくっつける
      A = root(A);
      B = root(B);
      if(A == B) {
        //すでにくっついているからくっつけない
        return false;
      }

      // 大きい方に小さい方をくっつけたい
      // 代償が逆だったらひっくり返す
      if(size(A) < size(B)) swap(A, B);
      // Aのsizeを更新
      Parent[A] += Parent[B];
      // Bの親をAに変更する
      Parent[B] = A;

      return true;
    }

    bool same(int A, int B) {
      return root(A) == root(B);
    }
};

int main() {
  int N, M, K; cin >> N >> M >> K;
  UnionFind uni(N);
  for(int i = 0; i < M; i++) {
    int A, B; cin >> A >> B;
    A--, B--;
    uni.connect(A, B);
    g[A]++, g[B]++;
  }

  for(int i = 0; i < K; i++) {
    int C, D; cin >> C >> D; C--, D--;
    to[C].push_back(D);
    to[D].push_back(C);
  }

  for(int i = 0; i < N; i++) {
    int ans = uni.size(i) - g[i] - 1;
    for(int u: to[i]) {
      if(uni.same(i, u)) ans--;
    }
    if(i) cout << " ";
    cout << ans;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 6784
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
    int h, w, d, q;
    cin >> h >> w >> d;
    map<int, pair<int, int>> grid; //数字と位置の対応
    map<int, int> cost; //そこに至るまでのコスト
    vector<int> nums;
    for(int i = 1; i <= h; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            int a;
            cin >> a;
            nums.push_back(a);
            grid[a] = {i, j};
        }
    }
    cin >> q;
    vector<pair<int, int>> exams(q);
    for(int i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;
        exams[i] = {l, r};
    }
    //書いてある番号をソート
    sort(nums.begin(), nums.end());
    //コストの計算
    for(int i = 0; i < nums.size(); i++)
    {
        if(!cost.count(nums[i]))
        {
            int back = nums[i] - d;
            if(cost.count(back))
            {
                int dist = abs(grid[nums[i]].first - grid[back].first) + abs(grid[nums[i]].second - grid[back].second);
                cost[nums[i]] = cost[back] + dist;
            }else{
                cost[nums[i]] = 0;
            }
        }
    }
    for(auto exam : exams)
    {
        cout << cost[exam.second] - cost[exam.first] << endl;
    }
    return 0;
}


Measured memory_bytes: 12152
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;

#define same2(a,b) (c[a]==c[b])
#define same3(a,b,c) (same2(a,b)&&same2(b,c))
#define same4(a,b,c,d) (same3(a,b,c)&&same2(c,d))
int c[5];

bool four_card(){
	if(same4(0,1,2,3)||same4(1,2,3,4)){
		return 1;
	}
	return 0;
}

bool full_house(){
	if((same3(0,1,2)&&same2(3,4)) || (same2(0,1)&&same3(2,3,4))){
		return 1;
	}else{
		return 0;
	}
}

bool straight(){
	bool res=1;
	for(int i=0;i<4;i++){
		if((c[i]+1)!=c[i+1])res=0;
	}
	if((res==0) && (c[0]==1) && (c[1]==10)){
		res=1;
		for(int i=1;i<4;i++){
			if((c[i]+1)!=c[i+1])res=0;
		}
	}
	return res;
}

bool three_card(){
	if(same3(0,1,2)||same3(1,2,3)||same3(2,3,4)){
		return 1;
	}else{
		return 0;
	}
}

bool two_pair(){
	int p=0;
	for(int i=0;i<4;i++){
		if(same2(i,i+1)){
			p++;
		}
	}
	if(p==2){
		return 1;
	}else{
		return 0;
	}
}

bool one_pair(){
	if(same2(0,1)||same2(1,2)||same2(2,3)||same2(3,4)){
		return 1;
	}else{
		return 0;
	}
}

int main(){
	while(scanf("%d,%d,%d,%d,%d",&c[0],&c[1],&c[2],&c[3],&c[4])!=EOF){
		sort(c,c+5);
		if(four_card()){
			cout<<"four card"<<endl;
		}else if(full_house()){
			cout<<"full house"<<endl;
		}else if(straight()){
			cout<<"straight"<<endl;
		}else if(three_card()){
			cout<<"three card"<<endl;
		}else if(two_pair()){
			cout<<"two pair"<<endl;
		}else if(one_pair()){
			cout<<"one pair"<<endl;
		}else{
			cout<<"null"<<endl;
		}
	}
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vi dp(n + 1);
    dp[1] = 1;
    for (int i = 2; i <= n; i++) {
        int mn = dp[i - 1];
        int r = 1;
        while (i - r * 6 >= 0) {
            r *= 6;
            mn = min(mn, dp[i - r]);
        }
        r = 1;
        while (i - r * 9 >= 0) {
            r *= 9;
            mn = min(mn, dp[i - r]);
        }
        dp[i] = mn + 1;
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
	int x1,x2,x3,x4,x5;cin>>x1>>x2>>x3>>x4>>x5;
	if(x1==0)
	cout<<"1";
	else if(x2==0)
	cout<<"2";
	else if(x3==0)
	cout<<"3";
	else if(x4==0)
	cout<<"4";
	else
	cout<<"5";
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	int N;
	int ans;
	
	cin >> N;

	int n;
	int cnt = 0;
	for (int ni = 1; ni <= N; ni++){
		cin >> n;
		if (ni != n){
			cnt++;
		}
	}

	if (cnt <= 2){
		printf("YES");
	}else{
		printf("NO");
	}


	//printf("No");


	return 0;
}



Measured memory_bytes: 256
x=list(input().split())
stack=[]

for i in range(len(x)):
	if(x[i]=='+'):
		b=stack.pop()
		a=stack.pop()
		stack.append(a+b)
	elif(x[i]=='-'):
		b=stack.pop()
		a=stack.pop()
		stack.append(a-b)	
	elif(x[i]=='*'):
		b=stack.pop()
		a=stack.pop()
		stack.append(a*b)
	else:
		stack.append(int(x[i]))

print(stack.pop())	
	
	


Measured memory_bytes: 5600
import heapq
push, pop = heapq.heappush, heapq.heappop

n,m = list(map(int, input().split()))
a = list(map(int, input().split()))

def modify():
    heapq.heapify(a)
    
    bc = [list(map(int, input().split())) for _ in range(m)]
    bc.sort(key=lambda x:x[1], reverse=True)
    
    for b,c in bc:
        for _ in range(b):
            p = pop(a)
            if p < c:
                push(a, c)
            else:
                # キューに戻す
                push(a, p)
                return

modify()            
print(sum(a))

Measured memory_bytes: 33152
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n)  for(int i=0;i<n;i++)
#define per(i,n)  for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int A[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k; cin >> k;
    cout << A[k - 1];
    
    return 0;
}


Measured memory_bytes: 256
object Main{
  def main(args : Array[String]): Unit ={
    val sr = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    val n = sr(0)
    val m = sr(1)
    print("a ")
    if(n > m){
      print(">")
    }
    else if(n == m){
      print("==")
    }
    else{
      print("<")
    }
    println(" b")
  }
}


Measured memory_bytes: 43600
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
    
#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)
    
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void){
    
    int drugnumber;
    int drugcounter;
    /* x????¨????,y?????´????????? */
    double drugeffect[120][120] = {0};
    int i,j,k,l;
    double max = 0;
    double answer[100] = {0};
    
    while(cin >> drugnumber >> drugcounter,drugnumber+drugnumber)
    {
        double combination[120][120] = {0};
        /*??£??\*/
        FOR(j, 1, drugnumber+1)
        FOR(i, 1, drugnumber+1)
        cin >> drugeffect[j][i];
        
        //cout << drugeffect[2][1];
        
        for(k = 1;k <= drugnumber; k++)
            combination[1][k] = 1.0;
        //cout << combination[1][2] << endl;
        
        /* j?????¬?????°,i????????°*/
        
        for(i = 1; i< drugcounter;i++)
            for(j = 1; j<= drugnumber;j++)
            {
                for(k = 1; k<=drugnumber;k++)
                {
                    if((combination[i][j] * drugeffect[j][k]) >= combination[i+1][k])
                        combination[i+1][k] = combination[i][j]*drugeffect[j][k];
                     //cout << combination[i+1][j] << " ";
                    /*
                     if((combination[j][i] * drugeffect[j][i]) >= combination[j][i])
                     combination[j][i+1] = combination[j][i] * drugeffect[j][i];
                     */
                }
            }
        
    
    for(i = 1 ; i<= drugnumber;i++)
        if(max <  combination[drugcounter][i])
            max = combination[drugcounter][i];
    
        answer[l] = max;
        max = 0;
        l++;
        
    }
    REP(i,l)
    printf("%.2f\n",answer[i]);
    return 0;
    
}

Measured memory_bytes: 1472
#include <cstdio>

int main() {
  int i, j;
  for (i = 0; i < 9; ++i) {
    for (j = 0; j < 9; ++j) {
      std::printf("%dx%d=%d\n", i + 1, j + 1, (i + 1) * (j + 1));
    }
  }

  return 0;
}

Measured memory_bytes: 2588
#include <iostream>

using namespace std;

int main()
{
	string original;
	cin >> original;
	for (const char &target : original)
	{
		if (target == '1')
		{
			cout << '9';
		}
		else if (target == '9')
		{
			cout << '1';
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    ll n;
    cin >> n;
    vector<ll> A(n), B(n);
    ll ans = 0;
    rep(i, n) {
        cin >> A[i] >> B[i];
    }
    for(int i = n - 1; i >= 0; i--) {
        A[i] += ans;
        B[i] *= ceil((double)A[i] / B[i]);
        ans += B[i] - A[i];
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  cout << (k == 1 ? 0 : n - k) << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main(){
	var N, A, B int64
	fmt.Scanf("%v",&N)
	if N == 1 {
		fmt.Printf("%s\n","Hello World")
	} else {
		fmt.Scanf("%v",&A)
		fmt.Scanf("%v",&B)
		fmt.Printf("%v\n",A+B)
	}
}

Measured memory_bytes: 512
// Problem : D - Flat Subsequence
// Contest : AtCoder - ACL Beginner Contest
// URL : https://atcoder.jp/contests/abl/tasks/abl_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// Macros

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(x) (int) x.size()
#define mod 1000000007
#define EPS 1e-9
#define inf 1e10
#define PI acos(-1.0)
#define int long long
#define N 300005

// Solution

class SegTree {
  int tl, tr, sum;
  SegTree *left, *right;

 public:
  SegTree(int l, int r) {
    sum = 0;
    tl = l;
    tr = r;
    left = nullptr;
    right = nullptr;
  }

  void makeChildren() {
    int tm = (tl + tr) / 2;
    left = new SegTree(tl, tm);
    right = new SegTree(tm + 1, tr);
  }

  void update(int pos, int val) {
    sum = max(sum, val);
    if (tl == tr) return;
    if (left == nullptr) makeChildren();
    if (pos <= left->tr)
      left->update(pos, val);
    else
      right->update(pos, val);
  }

  int get(int l, int r) {
    if (l > tr || r < tl) return 0;
    if (tl >= l && tr <= r) return sum;
    if (left == nullptr) return 0;
    return max(left->get(l, r), right->get(l, r));
  }
};

void solve() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  for (int &x : a) cin >> x;
  SegTree *st = new SegTree(0, N);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int cur = st->get(max(0ll, a[i] - k), min((ll)N, a[i] + k));
    cur++;
    ans = max(ans, cur);
    st->update(a[i], cur);
  }
  cout << ans << '\n';
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  int tests;
  tests = 1;
  // cin>>tests;

  for (int test = 1; test <= tests; test++) {
    // cout<<"Case #"<<test<<": ";
    solve();
  }

  return 0;
}

Measured memory_bytes: 31720
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 105
#define HP 100010


void calc(int n){
  int hp[SIZE],m,mp[SIZE],damage[SIZE],target[SIZE];
  int max_hp = 0;
  
  for(int i=0;i<n;i++){
    scanf("%d",hp+i);
    max_hp = max(max_hp,hp[i]);
  }

  scanf("%d",&m);

  for(int i=0;i<m;i++){
    char target_c[SIZE];
    scanf("%*s%d%s%d",mp+i,target_c,damage+i);

    target[i] = target_c[0] == 'A';
  }

  int dp_a[HP],dp_s[HP];
  
  for(int i=0;i<HP;i++){
    dp_a[i] = dp_s[i] = INF;
  }

  dp_a[0] = dp_s[0] = 0;

  for(int i=0;i<max_hp;i++){
    for(int j=0;j<m;j++){
      int p = min(i+damage[j],max_hp);
      if(target[j]){ //ALL
        dp_a[p] = min(dp_a[p], dp_a[i]+mp[j]);
      }else{
        dp_s[p] = min(dp_s[p], dp_s[i]+mp[j]);
      }   
    }
  }

  for(int i=max_hp;i>0;i--){
    dp_a[i-1] = min(dp_a[i-1],dp_a[i]);
    dp_s[i-1] = min(dp_s[i-1],dp_s[i]);
  }

  ll ans = LLINF;
  
  for(int i=0;i<=max_hp;i++){
    ll sum = dp_a[i];

    for(int j=0;j<n;j++){
      sum += dp_s[max(0,hp[j]-i)];
    }

    ans = min(ans, sum);
  }

  printf("%lld\n",ans);
}

int main(){

  int x;
  
  while(1){
    scanf("%d",&x);

    if(x == 0) break;

    calc(x);
  }
  
  return 0;
}

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

using namespace std;

typedef long long ll;

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

	int A, B, T;
	cin >> A >> B >> T;

	int ans = 0;
	int t = 0;
	while(t <= T){
		if(t + A <= T){
			ans += B;
			t += A;
		}else{
			break;
		}
	}

	cout << ans << endl;
}


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

int main() {
	int A,B,C;
	cin >> A >> B >> C;
	int ans = B;
	if(A+B>=C){
	     ans+=C;
	}
	else{
	    // if(C-A+B)
	     ans+=(A+B)+1;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3576
using System;

namespace ABC061
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');
            var a = int.Parse(s[0]);
            var b = int.Parse(s[1]);
            var c = int.Parse(s[2]);

            Console.WriteLine(
                c >= a && c <= b
                    ? "Yes"
                    : "No"
            );
        }
    }
}


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

int N, M, X;
int A[15][15], C[15];

int coba(int mask) {
  for(int i = 1; i <= M; i++) {
    int sum = 0;
    for(int j = 1; j <= N; j++) {
      if(!(mask & (1 << (j - 1)))) continue;
      sum += A[j][i];
    }
    if(sum < X) return 1000000000;
  }
  int pay = 0;
  for(int i = 1; i <= N; i++) {
    if(!(mask & (1 << (i - 1)))) continue;
    pay += C[i];
  }
  return pay;
}

int main() {
  cin >> N >> M >> X;
  for(int i = 1; i <= N; i++) {
    cin >> C[i];
    for(int j = 1; j <= M; j++) {
      cin >> A[i][j];
    }
  }
  int ans = 1000000000;
  for(int i = 1; i < (1 << N); i++) {
    ans = min(ans, coba(i));
  }
  cout << (ans == 1000000000 ? -1 : ans) << "\n";
}

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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

bool color[100005];
unordered_map<int, vector<P>> graph;
void dfs(int tar, int prev, bool bw){
    color[tar] = bw;
    for(P v: graph[tar]){
        if(v.first != prev){
            if(v.second % 2 != 0) {
                dfs(v.first, tar, !bw);
            }else{
                dfs(v.first, tar, bw);
            }
        }
    }
}

void Main() {
    int N;
    cin >> N;
    rep(i, N-1){
        int u, v, w;
        cin >> u >> v >> w;
        graph[u-1].push_back({v-1, w});
        graph[v-1].push_back({u-1, w});
    }
    dfs(0, -1, true);
    rep(i, N){
        cout << color[i] << endl;
    }
}

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


Measured memory_bytes: 12708
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

ll n, m;

int main() {
    fastio();

    cin >> n >> m;

    if (n == 1 && m == 1) {
        cout << 1 << endl;
    } else if (n == 1) {
        cout << m - 2 << endl;
    } else if (m == 1) {
        cout << n - 2 << endl;
    } else {
        cout << (n - 2) * (m - 2) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            switch( n % 10)
            {
                case 2:
                case 4:
                case 5:
                case 7:
                case 9:
                    Console.WriteLine("hon");
                    break;
                case 0:
                case 1:
                case 6:
                case 8:
                    Console.WriteLine("pon");
                    break;
                case 3:
                    Console.WriteLine("bon");
                    break;
            }
        }

    }
}


Measured memory_bytes: 27392
n=int(input())
xy=[tuple(map(int, input().split())) for _ in range(n)]

fn=[lambda x:x[0]+x[1],lambda x:x[0]-x[1]]
ans=0
for f in fn:
    xy.sort(key = f)
    ans=max(ans,abs(f(xy[0])-f(xy[-1])))
print(ans)

Measured memory_bytes: 45352
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
using namespace std;


int main()
{
	int H,W;
	cin>>H>>W;
	char masu[100][100];
	bool compColumnList[100];
	bool compRawList[100];
	for(int i = 0; i < 100; i++){
		compColumnList[i] = true;
	}

	for(int i = 0; i < H; i++){
		bool thisRawIsAllWhite = true;
		for(int j = 0; j < W; j++){
			cin>>masu[i][j];
			if( masu[i][j] == '#'){
				thisRawIsAllWhite = false;
				compColumnList[j] = false;
			}
		}
		if( thisRawIsAllWhite == true){	//compress this raw
			i--;
			H--;
		}
	}

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(compColumnList[j] != true){
				cout<<masu[i][j];
			}
		}
		cout<<endl;
	}
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <math.h>
#include <time.h>
using namespace std;
int main() {
	long long int a, b, cnt[26] = {}, c;
	long long int iti = 0, ni = 0, yon = 0;
	char k[100][100];
	cin >> a >> b;
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			cin >> k[a][b];
			c = 25 - 'z' + k[a][b];
			cnt[c]++;
		}
	}
	for (int i = 0; i < 26; i++) {
		yon += cnt[i] / 4;
		cnt[i] -= (cnt[i] / 4) * 4;
		ni += cnt[i] / 2;
		cnt[i] -= (cnt[i] / 2) * 2;
		iti += cnt[i];
	}
	if (a % 2 == 0 && b % 2 == 0) {
		if (a*b == 4 * yon&&ni==0&&iti==0) {
			cout << "Yes" << endl;
			return 0;
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}

	if (a % 2 == 1 && b % 2 == 1) {
		long long int d = yon - ((a - 1)*(b - 1)) / 4;
		if (d >= 0 && (d * 2 + ni) * 2 == a + b - 2 && iti == 1) {
			cout << "Yes" << endl;
			return 0;
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	if (a % 2 == 0 && b % 2 == 1) {
		long long int e = yon - a*(b - 1) / 4;
		if (e >= 0 && 2 * (2 * e + ni) == a && iti == 0) {
			cout << "Yes" << endl;
			return 0;
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	if (b % 2 == 0 && a % 2 == 1) {
		long long int f = yon - b*(a - 1) / 4;
		if (f >= 0 && 2 * (2 * f + ni) == b && iti == 0) {
			cout << "Yes" << endl;
			return 0;
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


mod = 10 ** 9 + 7
f = [1]
for i in range(1, 10000): f.append(f[-1] * i % mod)
def comb(a, b): return f[a] * pow(f[b], mod - 2, mod) * pow(f[a - b], mod - 2, mod) % mod


def main():
	n, k = map(int, input().split())
	b, r = k, n - k
	for i in range(1, k + 1):
		a = 1
		if r < i - 1: print(0);continue
		a *= comb(k - 1, i - 1)
		a *= comb(n - k + 1, i)
		print(a % mod)





if __name__ == '__main__':
	main()


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

int main() {

  int A, B, K;

  cin >> A >> B >> K;

  for (int i = A; i <= B; i++) {
    if (i < (A + K) || (B - K) < i) {
      cout << i << endl;
    }
  }

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main()
{
	string S;
	int ans = 0;
	cin >> S;
	for (int i = 0; i < 4; i++) {
		if (S[i] == '+') ans++;
		else ans--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# ref: https://atcoder.jp/contests/abc154/submissions/9991364

from functools import lru_cache

#0以上N以下の整数で、0でない数字がちょうどK個あるものの個数
@lru_cache(None)
def F(N, K):
    assert N >= 0
    if N < 10:
        if K == 0:
            return 1
        if K == 1:
            return N
        else:
            return 0
    
    q,r = divmod(N,10)

    ans = 0
    if K >= 1:
        # 1の位が0ではない
        ans += F(q, K-1) * r
        ans += F(q-1, K-1) * (9-r)
    # 1の位が0
    ans += F(q, K)
    
    return ans

def main():
    N = int(input())
    K = int(input())

    print(F(N,K))

if __name__ == "__main__":
    main()

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

C = []
A = [ [] for _ in range(N)]
for i in range(N):
    A[i] = [int(x) for x in input().split()]

cost = 10**5 * N
f = False
for i in range(2**N):
    BAG = [0]*(1+M)
    for j in range(N):
        if bin(i>>j)[-1] == '1':
            for k in range(1+M):
                BAG[k] += A[j][k]

    for k in range(1,1+M):
        if BAG[k] < X:
            break
    else:
        f = True
        cost = min(cost,BAG[0])

if f:
    print(cost)
else:
    print(-1)

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define INF 1000000000
#define MOD 1000000007
int dp[3001][3001];

void solve() {
    string a, b, ans;
    cin >> a >> b;
    a = ' ' + a;
    b = ' ' + b;
    //map<int, map<int, ii>> tr;
    rep(i, 1, sz(a)) {
        rep(j, 1, sz(b)) {
            if (a[i] == b[j]) {
                dp[i][j] = dp[i-1][j-1] + 1;
                //tr[i][j] = {i-1,j-1};
            }
            else {
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
                //if (dp[i][j-1] > dp[i-1][j]) tr[i][j] = {i,j-1};
                //else tr[i][j] = {i-1,j};
            }
        }
    }
    int x = sz(a) - 1, y = sz(b) - 1;
    while (x >= 1 && y >= 1) {
        if (a[x] == b[y]) {
            ans.pb(a[x]);
            --x;--y;
            continue;
        }
        if (dp[x-1][y] > dp[x][y-1]) {
            --x;
        }
        else --y;
    }
    reverse(all(ans));
    cout << ans << "\n";
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 38744
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n;
  cin>>n;
  vector<int> b(n-1);
  rep(i,n-1) cin>>b.at(i);
  int s=b.at(0)+b.at(n-2);
  rep(i,n-2) s+=min(b.at(i),b.at(i+1));
  cout<<s<<endl;
}


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

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

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,m = LI()
    a = []
    c = []
    for i in range(m):
        d,b = LI()
        e = LI_()
        a.append(d)
        t = 0
        for u in e:
            t |= 2**u
        c.append(t)

    d = collections.defaultdict(lambda: inf)
    d[0] = 0
    for i in range(m):
        ai = a[i]
        ci = c[i]
        for k,v in list(d.items()):
            nk = k | ci
            nv = v + ai
            if d[nk] > nv:
                d[nk] = nv
    if d[2**n-1] == inf:
        return -1

    return d[2**n-1]


print(main())





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

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for(int i = 0; i < N; i++) cin >> H[i];
  sort(H.begin(), H.end());
  long long a = 0;
  for(int i = 0; i < N - min(N, K); i++){
    a += H[i];
  }
  
  cout << a << endl;
  
  return 0;
}

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

using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

const int mod = 1e9 + 7;

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    int n, k;
    cin >> n >> k;
    vi a(n);
    for (int& i : a) cin >> i;
    sort(all(a));

    int fpos = n, f0 = n;
    rep(i, n) if (a[i] == 0) {
        f0 = i;
        break;
    }
    rep(i, n) if (a[i] > 0) {
        fpos = i;
        if (f0 == n) f0 = i;
        break;
    }

    if (n - fpos + f0 < k || fpos == n && f0 != n && k & 1)
        return cout << 0, 0;

    ll ans = 1;
    if ((n - fpos + f0 == k && f0 & 1) || (fpos == n && k & 1)) {
        for (int& i : a) if (i < 0) i *= -1;
        sort(all(a));
        rep(i, k) ans = ans * a[i] % mod;
        return cout << (mod - ans) % mod, 0;
    }

    int l = min(f0, k) / 2 * 2, r = n - k + l;
    while (l > 1 && r > fpos + 1 &&
           (ll)a[l - 2] * a[l - 1] < (ll)a[r - 2] * a[r - 1]) {
        l -= 2, r -= 2;
    }

    rep(i, l) ans = ans * -a[i] % mod;
    for (int i = r; i < n; i++) ans = ans * a[i] % mod;
    cout << ans;
}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define AB_BHI_NI_DEGI                \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
//int mod = 1e9 + 7;
int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double

#define ordered_set tree<P, null_type, less<P>, rb_tree_tag, tree_order_statistics_node_update>

int32_t main()
{
	AB_BHI_NI_DEGI
	map<int, int> mp;
	int sum = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		mp[x]++;
		sum += x;
	}
	int q;
	cin >> q;
	while (q--)
	{
		int x, y;
		cin >> x >> y;
		sum -= mp[x] * x;
		mp[y] += mp[x];
		sum += mp[x] * y;
		mp[x] = 0;
		cout << sum << "\n";
	}
	return 0;
}

Measured memory_bytes: 9544
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int a,p;

        cin >> a >> p;
        int ans = (a * 3 + p) / 2;
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
a = int(input())
b = list(map(int,input().split()))
tairyoku_sum = 0
sel1 = 0
sel2 = 0
for val in range(a):
    sel1 = val
    sel2 = val+1
    for val2 in range(a-val-1):
        tairyoku_sum += b[sel1]*b[sel2]
        sel2 += 1
print(tairyoku_sum)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int BLACK=1;

int n,M[MAX][MAX];

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

    d[0]=0;
    while(true){
    int minv=INFTY,u=-1;

    for(int i=0;i<n;i++){
        if(color[i]==WHITE&&minv>d[i]){minv=d[i];u=i;}
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(int i=0;i<n;i++){
        if(color[i]==WHITE&&M[u][i]!=INFTY){
            if(d[i]>M[u][i]){
                d[i]=M[u][i];
                p[i]=u;
            }
        }
    }
    }
    int sum=0;
    for(int i=0;i<n;i++){
        if(p[i]!=-1)sum+=M[i][p[i]];
    }
    return sum;
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int e;scanf("%d",&e);
            M[i][j]=(e==-1)?INFTY:e;
        }
    }

    cout<<prim()<<endl;
    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007;
#define pi 3.14159265358979323846
#define Endl endl
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int x;
	cin>>x;
	int ans = 0;
	ans += ( x / 500 ) * 1000;
	x = x % 500;
	ans += ( x / 5 ) * 5;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int s ;
  cin >> s;
  int s1 = s /100;
  int s2 = ( s - s1 * 100 ) / 10;
  int s3 = s - s1 * 100 - s2 * 10;
  cout << s1 + s2 + s3  << endl;
}

Measured memory_bytes: 256
def make_divs(n):
    divs = []
    
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            divs.append(i)
            
            if i!=n//i:
                divs.append(n//i)
    
    return divs

N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
divs = make_divs(S)
ans = 0

for d in divs:
    B = [Ai%d for Ai in A]
    B.sort()
    l, r = 0, N-1
    cnt = 0
    
    while l!=r:
        t = min(B[l], d-B[r])
        B[l] -= t
        B[r] += t
        cnt += t
        
        if B[l]==0:
            l += 1
        else:
            r -= 1
    
    if cnt<=K:
        ans = max(ans, d)

print(ans)

Measured memory_bytes: 42604
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int dp[310][310][310];


int rec(int l, int r, int k, string &S){
    if(dp[l][r][k] >= 0) 
        return dp[l][r][k];
    int res = 0;
    if(l == r){
        res = 1;
    }
    else if(l > r){
        res = 0;
    }
    else{
        if(S[l] == S[r]){
            res = max(res, rec(l + 1, r - 1, k, S) + 2);
        }
        else{
            if(k - 1 >= 0){
                res = max(res, rec(l + 1, r - 1, k - 1, S) + 2);
                res = max(res, rec(l + 1, r - 1, k - 1, S) + 2);
            }
        }
        res = max(res, rec(l + 1, r, k, S));
        res = max(res, rec(l, r - 1, k, S));
    }
    return dp[l][r][k] = res;
}


int main(){

    string S;
    int K;
    cin >> S;
    cin >> K;
    memset(dp, -1, sizeof(dp));
    cout << rec(0, (int)S.size() - 1, K, S) << endl;
    

    return 0;
}


Measured memory_bytes: 116608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    vector<int> even(100005,0), odd(100005,0);
    int tmp,n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> tmp;
        if(i % 2 == 1){
            odd.at(tmp)++;
        }
        else{
            even.at(tmp)++;
        }
    }

    int maxeven,secondeven,eveni,maxodd,secondodd,oddi;
    maxeven = 0; secondeven = 0; maxodd = 0; secondodd = 0;
    eveni = 0; oddi = 0;

    for(int i = 0; i < 100005; i++){
        if(even.at(i) > maxeven){
            secondeven = maxeven;
            maxeven = even.at(i);
            eveni = i;
        }
        else if(even.at(i) > secondeven){
            secondeven = even.at(i);
        }
        if(odd.at(i) > maxodd){
            secondodd = maxodd;
            maxodd = odd.at(i);
            oddi = i;
        }
        else if(odd.at(i) > secondodd){
            secondodd = odd.at(i);
        }
    }
    if(eveni != oddi){
        printf("%d\n", n - maxeven - maxodd);
    }
    else{
        printf("%d\n", min(n - maxeven - secondodd, n - secondeven - maxodd));
    }

}


Measured memory_bytes: 1024
import java.util.*;
class Main {
	public static void main(String...args) {
		Scanner in = new Scanner(System.in);
		String str = "";
		while(true) {
			List<Integer> l = new ArrayList<Integer>();
			int from = in.nextInt(), to = in.nextInt();
			if((from|to) == 0) break;
			System.out.print(str);
			for(int i = from; i <= to; i++)
				if(i%400==0 || i%100!=0&&i%4==0) l.add(i);
			if(l.isEmpty()) System.out.println("NA");
			else for(int i = 0; i < l.size(); i++) System.out.println(l.get(i));
			str = "\n";
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
#define pb push_back

/*int pare(int en,int start,int par[])
{
	if(par[en]==start)
	{
		return en;
	}
	pare(par[en],start,par);
}*/

int main()
{
    int tst=1;
    //scanf("%d",&tst);
    while(tst--)
    {
		char c;
		cin >> c;
		map<char,char>mp;
		mp['A']='T';
		mp['T']='A';
		mp['C']='G';
		mp['G']='C';
		cout << mp[c] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		String sep = System.getProperty("line.separator");
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter(sep);
		String str = sc.next();
		char[] charArray = str.toCharArray();
		for (int i = 0; i < charArray.length; i++) {
			if (Character.isUpperCase(charArray[i])) {
				charArray[i] = Character.toLowerCase(charArray[i]);
			} else {
				charArray[i] = Character.toUpperCase(charArray[i]);
			}
		}
		for (char ch : charArray) {
			System.out.print(ch);
		}
		System.out.println();

	}

}

Measured memory_bytes: 27184