akhauriyash/Code-Regression huggingface dataset:
def main():
    n = int(input())

    As = list(map(int, input().split()))
    nums = [0] * (10**5+1)
    ans = 0
    for a in As:
        ans += a
        nums[a] += 1

    q = int(input())
    for i in range(q):
        b, c = map(int, input().split())
        ans += (c-b) * nums[b]
        nums[c] += nums[b]
        nums[b] = 0
        print(ans)


if __name__ == "__main__":
    main()


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

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const LL A_MAX = 1e9;

int main() {

    LL N, counter = 0;
    cin >> N;
    set<LL> A;
    LL input;

    for (int i=0;i<N;i++)
    {
        set<LL>::iterator it;
        cin >> input;
        it = A.find(input);
        if (it!=A.end())
        {
            A.erase(it);
            counter --;
        } else{
            A.insert(input);
            counter++;
        }
    }
    cout << counter;
    return 0;
}


Measured memory_bytes: 4864
#include<stdio.h>

int main(){
  int a,b,c;
  int i;
  int count=0;

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

  for(i=a;i<b+1;i++){
    if(c%i==0){
      count+=1;
    }
  }

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

  return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int A = sc.nextInt();
        int B = sc.nextInt();

        int ans = (A + B - 3) / (A - 1);

        System.out.println(ans);
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define dep(i,a,b) for(register int i=(a);i>=(b);i--)
using namespace std;
#define maxn 200005
#define mod 1000000007
ll a,b,x,y,n,z;
int main()
{
    scanf("%lld",&n);
    a=0;b=0;
    while(n--)
    {
        scanf("%lld%lld",&x,&y);
        if(x>=a&&y>=b)
        {
            z=1;
        }
        else if(x>=a)
        {
            z=b/y+(b%y!=0);

        }
        else if(y>=b)
        {
            z=a/x+(a%x!=0);
        }
        else
        {
            z=max(a/x+(a%x!=0),b/y+(b%y!=0));
        }
        a=x*z;
        b=y*z;
        //cout<<a<<" "<<b<<" "<<x<<" "<<y<<endl;
    }
    printf("%lld\n",a+b);
}


Measured memory_bytes: 256
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


//変数
int N;
map<int, int> a, b;






//サブ関数
//入力
void input()
{
	cin >> N;
	REP(i, N) {
		int tmp;
		cin >> tmp;
		if (i % 2 == 0)a[tmp]++;
		else b[tmp]++;
	}
}


//計算
void calc()
{
	vector<pair<int, int>> va, vb;
	for (auto k : a) {
		va.push_back({ k.second,k.first });
	}
	for (auto k : b) {
		vb.push_back({ k.second,k.first });
	}
	sort(va.begin(), va.end());
	reverse(va.begin(), va.end());
	sort(vb.begin(), vb.end());
	reverse(vb.begin(), vb.end());
	
	if (va[0].second != vb[0].second) {
		cout << N - va[0].first - vb[0].first << endl;
	}
	else {

		if (va.size() == 1 && vb.size() == 1) {
			cout << N - va[0].first << endl;
		}
		else if (va.size() == 1) {
			cout << N - va[0].first - vb[1].first << endl;
		}
		else if (vb.size() == 1) {
			cout << N - vb[0].first - va[1].first << endl;
		}
		else {
			int a1 = va[0].first;
			int a2 = va[1].first;
			int b1 = vb[0].first;
			int b2 = vb[1].first;

			int res = max(a1 + b2, a2 + b1);
			cout << N - res << endl;

		}
	}
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	//debug();
	
	return 0;
}


Measured memory_bytes: 6136
Imports System
Imports System.IO

Module Module1

    Sub Main(ByVal args As String())

        Dim s As String() = Console.ReadLine().Split(" ")
        Dim ans As String

        If CInt(s(0)) <= CInt(s(1)) Then
            ans = "unsafe"
        Else
            ans = "safe"
        End If

        Console.Write(ans)

    End Sub

End Module


Measured memory_bytes: 28348
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import floor
from decimal import Decimal

def main():
    x = int(input())
    n = Decimal(100)
    r = 0
    while n < x:
        n = Decimal(floor((n * 101 / 100)))
        r += 1
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9904
#include<bits/stdc++.h>
#define maxn 450
using namespace std;
typedef long long LL;
LL a[maxn];
LL f[maxn][maxn];
int main(){
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	for(int i = 1; i <= N; i += 1) cin >> a[i];
	for(int L = 2; L <= N; L += 1)
		for(int i = 1; i + L <= N + 1; i += 1){
			f[i][L] = 1E18;
			for(int j = 1; j < L; j += 1) f[i][L] = min(f[i][L], f[i][j] + f[i + j][L - j]);
			for(int j = i; j < i + L; j += 1) f[i][L] += a[j];
		}
	cout << f[1][N];
}

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

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n, m, k; cin >> n >> m >> k;
	for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) {
		if (i * m + j * n - 2 * i * j == k) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	
	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define ssd ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)
#define MOD 1000000009
typedef long long int ll;
using namespace std;
using namespace __gnu_pbds;


int main()
{
	ssd
	#define task "TASK"
	 //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    int n;
    cin>>n;
    if(n==1)
        cout<<"0"<<endl;
    else
        cout<<"1"<<endl;

	return 0;
}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
  ll n,k;
  cin >> n >> k;
  map<ll,ll> mp;
  rep(i,k){
    ll d;
    cin >> d;
    rep(j,d){
      ll a; cin >> a;
      mp[a]++;
    }
  }

  ll ans = distance(mp.begin(), mp.end());
  cout << n - ans << endl;

  return 0;
}

Measured memory_bytes: 3632
inputText = input().split()
a = int(inputText[0])
b = int(inputText[1])
c = int(inputText[2])
week = a*7+b
weeks = int(c /week)
remain = c % week
totalday = weeks * 7
totalday += int(remain/a)
totalday2 = (int(c/week)+1)*7
if remain%a != 0:
    totalday +=1
print(min(totalday,totalday2))



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int ans,st,mi;

int main(){
	int h;
	cin>>h;
	bool bou=false;
	vector<int>vec(h);
	for(int i=0;i<h;i++){
		cin>>vec[i];
	}
	ans+=vec[0];
	for(int i=1;i<h;i++){
		if(vec[i-1]<vec[i]){
			ans+=vec[i]-vec[i-1];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T& t)
{T f=1;char ch=getchar();t=0;
while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0'&&ch<='9')t=t*10+ch-'0',ch=getchar();t*=f;}
template <typename T,typename... Args>
inline void read(T& t, Args&... args)
{read(t);read(args...);}
int n,m,L,R;
int sum[100005];
int main()
{
    read(n,m);
//    printf("-- %d %d --",n,m);
    for(int i=1;i<=n;i++)
    {
        read(L,R);
        L--;
//        printf("ok\n");
        for(int l=1,r;l<=L;l=r+1)
        {
            r=min(L/(L/l),R/(R/l));
//            printf("--- %d %d ---\n",l,r);
            if(L/l<R/l)
            {
                sum[l]++;
                sum[r+1]--;
            }
        }
        sum[L+1]++;
        sum[R+1]--;
    }
    for(int i=1;i<=m;i++)printf("%d\n",sum[i]+=sum[i-1]);
}

Measured memory_bytes: 1280
import java.util.Scanner;

//AtCoder Beginner Contest 158
//A Station and Bus
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		if (S.equals("AAA") || S.equals("BBB") ) {
			System.out.print("No");
		} else {
			System.out.print("Yes");
		}
	}
}


Measured memory_bytes: 21716
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int X = Integer.parseInt(sc.get());
		for (long i = 0; i < 1000; i++) {
			for (long j = 0; j < 1000; j++) {
				var a5 = BigInteger.valueOf(i).pow(5);
				var b5 = BigInteger.valueOf(j).pow(5);
				if (a5.subtract(b5).intValue() == X) {
					System.out.printf("%d %d\n", i, j);
					return;
				}
				if (a5.add(b5).intValue() == X) {
					System.out.printf("%d %d\n", i, -j);
					return;
				}
			}
		}
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

Measured memory_bytes: 54732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)

int main() {
  int h,w,k,ans = 0;
  cin >> h >> w >> k;
  vector<string>data(h);
  rep(i,0,h) cin >> data[i];
  for (int x = 0; x < (1<<h); ++x){
    for (int y = 0; y < (1<<w); ++y){
      int c = 0;
      rep(i,0,h) rep(j,0,w) if(data[i][j] == '#' && x & (1<<i) && y & (1<<j)) c++;
      if(c == k) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
x1, y1, x2, y2 = map(int, input().split())

a = x2 - x1
b = y2 - y1

x3 = x2 + (-b)
y3 = y2 + a

a = x3 - x2
b = y3 - y2

x4 = x3 + (-b)
y4 = y3 + a

print(x3, y3, x4, y4)


Measured memory_bytes: 8944
from copy import *
from sys import *
from math import *
import queue
from collections import defaultdict,Counter,deque

setrecursionlimit(1000000)

def main():
	n, m = map(int,input().split())
	s=set()
	t=set()
	for _ in range(m):
		a, b = map(int, input().split())
		if a == 1:
			s.add(b)
		elif b == n:
			t.add(a)
	for i in s:
		if(i in t):
			print('POSSIBLE')
			exit()
	print('IMPOSSIBLE')

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	#競プロ用のQueue
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)

class Stack():
	#怯プロ用のStack
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)

main()

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

constexpr long lim = 1e6+1;
vector<vector<int>> pr(lim), id(lim);
vector<bool> is_pr(lim, true);

void all_fac() {
  is_pr.at(0) = 0;
  is_pr.at(1) = 0;
  for (int i = 2; i < lim; i++) {
    if (is_pr.at(i)) {
      pr.at(i).push_back(i);
      id.at(i).push_back(1);
      for (int j = 2 * i; j < lim; j += i) {
        is_pr.at(j) = false;
        int cnt = 0;
        int nw = j;
        while (nw % i == 0) {
          nw /= i;
          cnt++;
        }
        pr.at(j).push_back(i);
        id.at(j).push_back(cnt);
      }
    }
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  all_fac();
  long N;
  cin >> N;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);

  bool B = 1;
  vector<long> cnt(1e6+1);
  for (int i = 0; i < N; i++) {
    for (auto p : pr.at(A.at(i))) {
      if (cnt.at(p)) B = 0;
      cnt.at(p)++;
    }
  }
  if (B) return cout << "pairwise coprime" << "\n", 0;

  long G = 0;
  for (long i = 0; i < N; i++) {
    G = gcd(G, A.at(i));
  }

  if (G == 1) return cout << "setwise coprime" << "\n", 0;

  cout << "not coprime" << "\n";
}

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

template<typename T>
struct Parser {
	using itr = string::const_iterator;
	itr now;
	T ans;
	const struct ex {
		vector<char> _012;
		ex() {
			_012.resize(10);
			for(int i = 0; i < 10; ++i) {
				_012[i] = (char)('0' + i);
			}
		}
	} ex;
	Parser(const string &s) {
		now = s.begin();
		ans = expr(now);
	}
	T expr(itr &now) {
		T ret = term(now);
		while(true) {
			if(*now == '+') {
				next(now, '+');
				ret += term(now);
			}else if(*now == '-') {
				next(now, '-');
				ret -= term(now);
			} else {
				return ret;
			}
		}
	}
	T term(itr &now) {
		T ret = fact(now);
		while(true) {
			if(*now == '*') {
				next(now, '*');
				ret *= fact(now);
			}else if(*now == '/') {
				next(now, '/');
				ret /= fact(now);
			} else {
				return ret;
			}
		}
	}
	T fact(itr &now) {
		if(*now == '(') {
			next(now, '(');
			T ret = expr(now);
			next(now, ')');
			return ret;
		} else {
			return numb(now);
		}
	}
	T numb(itr &now) {
		T ret = 0;
		while('0' <= *now and *now <= '9') {
			ret *= 10;
			ret += (T)(*now - '0');
			next(now, ex._012);
		}
		return ret;
	}
	void next(itr &now, const char expected) {
		vector<char> req = {expected};
		next(now, req);
	}
	void next(itr &now, const vector<char> &expected) {
		for(char c : expected) {
			if(*now == c) {
				now++;
				return;
			}
		}
		cerr << *now << "\n";
		for(char c : expected) cerr << c << "\n";
	}
};

int main() {
	int n; cin >> n;
	while(n--) {
		string s; cin >> s;
		Parser<int> parse(s);
		cout << parse.ans << "\n";
	}
	return 0;
}


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

int main() {
    int N, L;
    cin >> N >> L;

    string S[10000];
    for(int i = 0; i < N; i++) {
        cin >> S[i];
    }

    sort(S, S+N);
    for(int i = 0; i < N; i++) {
        cout << S[i];
    }
    cout << endl;
}

Measured memory_bytes: 3892
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

ll GCD(ll a, ll b){
    return b ? GCD(b, a % b) : a;
}

//約数を求める
vector<ll > divisor(ll n){
    vector<ll > ans;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            ans.push_back(i);
            //重複を防ぐ
            if(i * i != n){
                ans.push_back(n / i);
            }
        }
    }
    sort(ans.begin(), ans.end());
    return ans;
}

int main(){

    ll N, M;
    cin >> N >> M;

    //ll ans = GCD(M / N, M / N + M % N);
    ll ans = 0;
    vector<ll > ret = divisor(M);

    for(ll i = 0; i < ret.size(); i++){
        if(M - N * ret[i] >= 0){
            ans = max(ans, ret[i]);
        }
    }

    cout << ans << endl; 

} 


Measured memory_bytes: 256
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

A.sort()

arr = []
arr.append(A[0])
arr.append(A[-1])
Atop = 1
Abtm = len(A) - 2
ans = arr[-1]-arr[0]
for i in range(len(A)-2):
    (Ai, ai) = (Atop, 0)
    if abs(A[Atop]-arr[-1]) > abs(A[Ai]-arr[ai]):
        (Ai, ai) = (Atop, -1)
    if abs(A[Abtm]-arr[0]) > abs(A[Ai]-arr[ai]):
        (Ai, ai) = (Abtm, 0)
    if abs(A[Abtm]-arr[-1]) > abs(A[Ai]-arr[ai]):
        (Ai, ai) = (Abtm, -1)

    #print('A[Ai]: ', A[Ai])
    #print(arr)
    ans += abs(A[Ai]-arr[ai])
    if ai == -1:
        arr[-1] = A[Ai]
    else:
        arr[0] = A[Ai]

    if Ai == Atop:
        Atop += 1
    else:
        Abtm -= 1


print(ans)


Measured memory_bytes: 7504
//by tzupengwang™
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<iostream>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;

int n;
int s[100005];
vector<int> v;

void init() {
  scanf("%d", &n);
  for (int i = 0; i < n; i ++) {
    scanf("%d", &s[i]);
    v.push_back(s[i]);
  }

  sort(v.begin(), v.end());
}

void process() {
  int a2 = v[n - 1];
  int a1 = v[0];
  for (int i = 1; i < n - 1; i ++) {
    int t1 = a1, t2 = v[i];
    if (t1 + t1 > a2) t1 = a2 - t1;
    if (t2 + t2 > a2) t2 = a2 - t2;

    if (t2 > t1) a1 = v[i];
  }
  printf("%d %d\n", a2, a1);
}

int main() {
/*
#ifdef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  int Cases;
  scanf("%d", &Cases);
  for (int cs = 1; cs <= Cases; cs ++) {
*/
    init();
    process();
/*
  }
*/
  return 0;
}


Measured memory_bytes: 1148
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n; cin >> n;
	if (n == 1)cout << "Hello World\n";
	else {
		int a, b; cin >> a >> b;
		cout << a + b << endl;
	}
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import Counter
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    a=list(map(int,input().split()))
    c=Counter(a)
    ans=0
    for k,v in c.items():
        if k<v:
            ans+=v-k
        elif k>v:
            ans+=v
    print(ans)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 64416
def D_Derangement():
    try:
        LOCAL_FLAG
        N = 5
        raw_p = "1 2 3 4 5"
        
        p = list(map(int, raw_p.split()))

    except NameError:
        N = int(input())
        p = list(map(int, input().split()))

    bad = []
    for i in range(N):
        if(p[i] == i+1):
            bad.append(i+1)

    n_bad = len(bad)

    n_ope = n_bad
    while n_bad > 0:
        if(bad[n_bad-2] == (bad[n_bad-1]-1)):
            n_ope -= 1
            n_bad -= 2
        else:
            n_bad -= 1

    print(n_ope)

D_Derangement()

Measured memory_bytes: 14008
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    vector<ll> d(n);
    for(ll i=0;i<n;++i){
        cin>>d[i];
    }
    sort(d.begin(), d.end());
    ll ans = d[n/2] - d[n/2-1];
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{char x,y;
 cin>>x>>y;
 if(x==y)
   cout<<'='<<endl;
 else
   {if(x<y)
      cout<<'<'<<endl;
    else
      cout<<'>'<<endl;
   }
} 

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

public class Program
{
	public static void Main()
	{
		int N = int.Parse(Console.ReadLine());
		int[] T = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int M = int.Parse(Console.ReadLine());
		var drinks = new Drink[M];
		for (int i = 0; i < M; i++)
		{
			int[] PX = Console.ReadLine().Split().Select(int.Parse).ToArray();
			drinks[i] = new Drink { ProblemId = PX[0] - 1, Shortened = PX[1] };
		}
		foreach (var item in drinks)
		{
			int ans = 0;
			for (int i = 0; i < N; i++)
			{
				ans += (i == item.ProblemId) ? item.Shortened : T[i];
			}
			Console.WriteLine(ans);
		}
	}
}

public class Drink
{
	public int ProblemId { get; set; }
	public int Shortened { get; set; }
}

Measured memory_bytes: 2904
Scanf.scanf "%d %d" (fun n m ->
    let nei = Array.make n [] in
    for i = 1 to m do
        Scanf.scanf " %d %d" (fun a b ->
            let a = a - 1 in
            let b = b - 1 in
            nei.(a) <- b :: nei.(a);
            nei.(b) <- a :: nei.(b)
        )
    done;

    let full = 1 lsl n - 1 in
    let rec loop cur set =
        if set = full then 1 else
            List.fold_left (fun acc v ->
                if (1 lsl v) land set = 0 then acc + loop v ((1 lsl v) lor set) else acc) 0 nei.(cur)
    in
    loop 0 1 |> Printf.printf "%d\n"
)

Measured memory_bytes: 4152
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  const [, ...nums] = content
    .trim()
    .split('\n')
    .map(n => +n);

  let max = null;
  let min = nums[0];
  for (let i = 1; i < nums.length; i++) {
    const bNum = nums[i];
    min = min > nums[i - 1] ? nums[i - 1] : min;
    const d = bNum - min;
    if (max === null || d > max) {
      max = d;
    }
  }

  console.log(max);
});


Measured memory_bytes: 49960
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=200005;
const int mod=1e9+7;
int n;
int a[maxn],dp[maxn],sum[maxn];

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d",&n);
	REP(i,n)scanf("%d",&a[i]);
	dp[0]=sum[a[1]]=1;
	REP(i,n){
		dp[i]=sum[a[i]];
		if(a[i]!=a[i+1])sum[a[i+1]]=(sum[a[i+1]]+dp[i])%mod; 
	}
	printf("%d\n",dp[n]);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	int c, s, f, t[n - 1];
	for(int i = 0; i < n - 1; i++)
	{
		scanf("%d %d %d", &c, &s, &f);
		t[i] = c + s;
		for(int j = 0; j < i; j++)
		{
			if(t[j] <= s)
			{
				t[j] = c + s;
			}
			else
			{
				t[j] += (f - ((t[j] - s) % f)) % f + c;
			}
		}
	}
	for(int i = 0; i < n - 1; i++)
	{
		printf("%d\n", t[i]);
	}
	printf("0\n");	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
  int H,W,i,j;

  while(1){

    scanf("%d %d",&H,&W);

    if(H == 0 && W == 0){
      break;
    }

    for(i = 0;i < H;i++){
      if(i % 2 == 0){
	for(j = 0;j < W;j++){
	  if(j % 2 == 0){
	    printf("#");
	  }
	  else{
	    printf(".");
	  }
	}
      }

      else{
	for(j = 0;j < W;j++){
	  if(j % 2 == 0){
	    printf(".");
	  }
	  else{
	    printf("#");
	  }
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
# -*- coding: utf-8 -*-
# Input
list = []
for _ in range(5):
    list += [int(input())]

list.sort(key = lambda x: (x - 1) % 10)

for ii in range(1, 5):
    list[ii] = (list[ii] // 10 + (list[ii] % 10 > 0)) * 10

print(sum(list))


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

int main()
{
    int N;
    string S[305];

    cin >> N;
    for ( int i = 0; i < N; i++ ) {
        S[i] = string(N, '\0');
        for ( int j = 0; j < N; j++ ) {
            cin >> S[i][j];
        }
    }
    int ans = 0;
    for ( int p = 0; p < N; p++ ) {
        int cnt = N;
        for ( int i = 0; i < N; i++ ) {
            for ( int j = i + 1; j < N; j++ ) {
                if ( S[i][(j + p) % N] != S[j][(i + p) % N] ) {
                    cnt = 0;
                }
            }
        }
        ans += cnt;
    }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
int main() {
	int n; ll p,q; cin >> n >> p >> q;
	vector<ll> v; ll c; ll sum = 0;
	rep(i, n) {
		cin >> c;
		sum += c;
		v.push_back(c-p*(q-(ll)i));
	}
	sort(v.begin(), v.end());
	ll ma = sum;
	rep1(i, n) {
		sum -= v[i-1];
		sum += p * (ll)(i - 1)*(ll)2;
		ma = max(ma, sum);
	}
	cout << ma << endl;
	return 0;
}


Measured memory_bytes: 7044
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int Q = int.Parse(Console.ReadLine());
		long[]NA = new long[1000010];
		long[]INA = new long[1000010];
		long mod = 1000003;
		NA[0] = 1;
		INA[0] = 1;
		for(var i=1;i<1000010;i++){
			NA[i] = NA[i-1] * i % mod;
			INA[i] = INA[i-1] * Mpow(i,mod-2,mod) % mod;
		}
		for(var i=0;i<Q;i++){
			string[] str = Console.ReadLine().Split();
			long X = long.Parse(str[0]);
			long D = long.Parse(str[1]);
			long N = long.Parse(str[2]);
			long ans;
			if(D==0){
				ans = Mpow(X,N,mod);
			} else {
              	long x1 = X*Mpow(D,mod-2,mod)%mod;
              	if(x1+N-1>=1000003){
                  	ans = 0;
                } else {
					ans = NA[(x1+N-1)%mod] * INA[(x1+mod-1)%mod] % mod;
					ans = ans * Mpow(D,N,mod) % mod;
				}
			}
			Console.WriteLine(ans);
		}
	}
	
	public static long Mpow(long x,long n,long m)
	{
		long ans = 1;
		while(n > 0){
			if(n % 2 == 1){
				ans = ans * x % m;
				n -= 1;
			}
			x = x * x % m;
			n /= 2;
		}
		return ans;
	}
}

Measured memory_bytes: 33088
S = input()
n = len(S)
ans = 0
s = 0
t = 0
for i in range(n):
    x = S[i]
    if x == 'S':
        s += 1
    else:
        if s > 0:
            s -= 1
        else:
            ans += 1
ans += s
print(ans)

Measured memory_bytes: 3500
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
#include <string.h>
using namespace std;

const int N = 205,inf = 2e7;

#define source 0
#define sink N-1

struct Edge{
	int v,cap,rev;
	Edge(){}
	Edge(int v,int cap,int rev):v(v),cap(cap),rev(rev){}
};

vector<Edge> vt[N];

void addEdge(int s,int e,int c){
	vt[s].push_back(Edge(e,c,(int)vt[e].size()));
	vt[e].push_back(Edge(s,0,(int)vt[s].size()-1));

	assert(vt[s].back().v ==e);
	assert(vt[e].back().v==s);
}

int level[N];
int work[N];

bool bfs(){
	memset(level,-1,sizeof(level));
	queue<int> q;
	q.push(source);
	level[source] = 0;
	int here,there,i;
	Edge x;
	while(!q.empty()){
		here= q.front();
		q.pop();

		for(i=0;i<vt[here].size();++i){
			x = vt[here][i];
			there= x.v;
			int cap = x.cap;
			if(level[there]==-1 && cap>0){
				level[there] = level[here]+1;
				q.push(there);
			}
		}
	}
	return level[sink]!=-1;
}

int dfs(int here,int mcap){

	if(here==sink)return mcap;

	for(int &i = work[here];i<vt[here].size();++i){
		Edge x = vt[here][i];
		int there =x.v;
		int cap = x.cap;
		if(level[there]==level[here]+1 && cap>0){
			int flow = dfs(there,min(mcap,cap));
			if(flow>0){
				vt[here][i].cap-=flow;
				vt[there][x.rev].cap+= flow;
				return flow;
			}
		}
	}
	return 0;

}

int maxFlow(){
	int ret=0;
	while(bfs()){//levle graph가 생성되는 경우에만
		memset(work,0,sizeof(work));
		while(1){
			int flow = dfs(source,inf);

			if(!flow)break;

			ret+=flow;
		}
	}
	return ret;
}
char in[N][N];
void solve() {
  int h,w;scanf("%d %d ", &h,&w);
  for(int i=1;i<=h;++i) {
    scanf(" %s ",in[i]+1);
    for(int j=1;j<=w;++j) {
      if(in[i][j]=='o') {
        addEdge(i,h+j,1);
        addEdge(h+j,i,1);
      }
      else if(in[i][j]=='S') {
        addEdge(source,i,inf);
        addEdge(source,h+j,inf);
      }
      else if(in[i][j]=='T') {
        addEdge(i,sink,inf);
        addEdge(j+h,sink,inf);
      }
    }
  }
  int ret = maxFlow();
  if(ret>=inf) {
    ret = -1;
  }
  printf("%d\n", ret);
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main(){
    int R;
    cin >> R;
    if(R < 1200){
        cout << "ABC" << endl;
    }
    else if(R < 2800){
        cout << "ARC" << endl;
    }
    else {
        cout << "AGC" << endl;
    }
    return 0;
}

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

int main(void){
  int N, s, i, c=0;

  scanf("%d",&s);
  for(i=0;i<6;i++){
    if(s%10==1){
      c++;
      s=(s-1)/10;
    }else s/=10;
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



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

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


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

  ll k=0;
  while(h>0){h/=2;k++;}
  cout<<(1ll<<k)-1<<endl;

  return 0;

}


Measured memory_bytes: 256
from collections import deque
INFTY = 10**14
N = int(input())
G = {}
for _ in range(N-1):
    a,b,c = map(int,input().split())
    if a not in G:
        G[a] = []
    G[a].append((b,c))
    if b not in G:
        G[b] = []
    G[b].append((a,c))
Q,K = map(int,input().split())
d = [INFTY for _ in range(N+1)]
d[K] = 0
hist = [0 for _ in range(N+1)]
heap = deque([K])
hist[K] = 1
while heap:
    cur = heap.popleft()
    for x in G[cur]:
        if hist[x[0]]==0:
            d[x[0]] = d[cur]+x[1]
            heap.append(x[0])
            hist[x[0]] = 1
for _ in range(Q):
    x,y = map(int,input().split())
    print(d[x]+d[y])
            

Measured memory_bytes: 49820
import java.util.*;

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

        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();

            if(h == 0 && w == 0){
                break;
            }else{
                for(int i=0;i<h;i++){
                    for(int j=0;j<w;j++){
                        if(i%2 == 0){
                            if(j%2 == 0){
                                System.out.print("#");
                            }else{
                                System.out.print(".");
                            }
                        }else{
                            if(j%2 == 0){
                                System.out.print(".");
                            }else{
                                System.out.print("#");
                            } 
                        }
                    }
                    System.out.println();
                }
            }
            System.out.println();

        }

    }
}


Measured memory_bytes: 35676
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

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

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


int main()
{	
	int N;
	cin >> N;
	vector<string> vec(N);
	rep(i, N) cin >> vec.at(i);

	map<string, int> s_map;

	for (auto elem : vec)
	{
		if (s_map.count(elem) == 0)
		{
			s_map.insert(make_pair(elem, 1));
		}
		else
		{
			s_map[elem]++;
		}
	}

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

	return 0;
}

Measured memory_bytes: 25016
import java.util.*;

public class Main {
    static long combination(long n,long r)
    {
        long ans=1;
        for(long i=0;i<r;i++)
        {
            ans=(ans*(n-i))/(i+1);
        }
        return ans;
    }
    
    public static void main(String[] args){
    	Scanner sc=new Scanner(System.in);
    	long e=sc.nextLong();
      	long o=sc.nextLong();
      	long ans=0;
      	if(e>=2){
          ans+=combination(e,2);
        }
      	if(o>=2){
          ans+=combination(o,2);
        }
      System.out.println(ans);
    }
}


Measured memory_bytes: 23380
/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;



#define err(x) cerr << #x  << " = "<<  x << '\n'
#define out(x) cout << x << '\n'
#define forp(i, r, l) for(int i = int(r); i < int(l); i++)
#define forn(i, r, l) for(int i = int(r); i > int(l); i--)
#define FAST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll ,ll> pll;
const int maxn = 5e5 + 120;


int d, g, s, p[15], c[15], dp[1005];
int main(){FAST;    
    cin >> d >> g;

    forp(i ,1 ,d + 1)
        cin >> p[i] >> c[i];

    register int  i ,j ,k;
    for(i = 1;i < d + 1; i++){
            s += p[i];

            for(j = s; j > 0; j--)
                for(k = 1; k <= p[i] && k <= j; k++)
                    dp[j] = max(dp[j] ,dp[j - k] + k * 100 * i + (k == p[i]) * c[i]);
    }
        for(i = 1; dp[i] < g; i++);
            cout << i;

        return 0;
    


    return 0;

}
 










Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
dp = [0]*(n+1)
for i in range(n):
  dp[i+1] += dp[i] + (1 if s[i:i+2] == 'AC' else 0)
for j in range(q):
  l, r = map(int,input().split())
  print(dp[r-1]-dp[l-1])

Measured memory_bytes: 9716
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main() {
    val (h, w, k) = readIs()
    val cc = Array(h) {
        readLine()!!.map {
            it == '#'
        }
    }
    var ans = 0
    for (i in 0 until (1 shl h)) {
        val rri = (0 until h).filter {
            i and (1 shl it) != 0
        }
        for (j in 0 until (1 shl w)) {
            val rrj = (0 until w).filter {
                j and (1 shl it) != 0
            }
            var cnt = 0
            for (ri in rri) {
                for (rj in rrj) {
                    if (cc[ri][rj]) cnt++
                }
            }
            if (cnt == k) ans++
        }
    }
    println(ans)
}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define OUT(a) cout << (a) << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll n;
    set<string > st;

    cin >> n;

    string tmp;
    REP(i, n){
        cin >> tmp;
        st.insert(tmp);
    }

    cout << st.size() << endl;
    
    return 0;
}

Measured memory_bytes: 19064
#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=1001001001;

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int ans=0;
	if(a<b){
		ans += a;
	}else ans += b;
	if(c<d){
		ans += c;
	}else ans += d;
	cout << ans << endl;

	return 0;

}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, a, b, c, d);
    Cout(min(c, b/a));
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll R, G, B, N;

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

  cin >> R >> G >> B >> N;

  ll ans = 0;
  for (ll r = 0; r*R <= N; ++r) {
      for (ll b = 0; r*R+b*B <= N; ++b) {
          ll t = N-(r*R+b*B);
          if (t%G == 0) ++ ans;
      }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 888
import sys
import re
sys.setrecursionlimit(1000000) # 再帰上限を増やす

def main():
    input = sys.stdin.readline  # 文字列に対してinputした場合は、rstripするのを忘れずに！
    S = input().rstrip()
    T = input().rstrip()

    word_size_s = len(S)
    word_size_t = len(T)
    for i in range(word_size_s - word_size_t, -1, -1):
        part_s = S[i:i+word_size_t]
        part_s = part_s.replace("?", ".")
        m = re.match(part_s, T)
        if m:
            S = (S[:i] + T + S[i+word_size_t:]).replace("?", "a")
            print(S)
            exit()
    print("UNRESTORABLE")


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long x;cin >> x;
  int time=0;
  long long iti=0;
  for(long long i=1;i<=x;i++){
    iti+=i;
    time++;
    if(iti>=x){
      break;
    }
  }
  cout << time << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int N,i,a,MAX=0,MIN=1000;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&a);
        if(a<MIN) MIN=a;
        if(a>MAX) MAX=a;
    }
    printf("%d\n",MAX-MIN);
    return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const long long MOD = 1e9 + 7;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int N,K; cin >> N >> K;
    vector<int> a(N+1);
    int ans = 0;
    REP(i,K){
        int d;
        cin >> d;
        REP(j,d){
            int A; cin >> A;
            a[A]++;
        }
    }

    FORq(i,1,N){
        if (a[i] == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
inline int gi() {
	register int x; register char c, op = 0;
	while(c = getchar(), c < '0' || c > '9') if(c == '-') op = !op;
	x = c ^ 48;
	while(c = getchar(), c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48);
	return op ? -x : x;
}
#define mod 1000000007
long long dp[301][301][301] = {0};
vector<pair<int, int> > v[301];
int main() {
	int n = gi(), m = gi();
	for(int i = 1; i <= m; i ++) {
		int x = gi(), y = gi(), z = gi();
		v[y].push_back(make_pair(x, z));
	}
	dp[1][0][0] = 1;
	for(int i = 1; i <= n; i ++) {
		for(int j = 0; j < i; j ++)
			for(int k = 0; k < max(1, j); k ++)
				for(auto &p : v[i]) {
					if(p.second == 1 && p.first <= j) dp[i][j][k] = 0;
					if(p.second == 2 && (p.first <= k || p.first > j)) dp[i][j][k] = 0;
					if(p.second == 3 && p.first > k) dp[i][j][k] = 0;
				}
		if(i == n) break;
		for(int j = 0; j < i; j ++)
			for(int k = 0; k < max(1, j); k ++) {
				(dp[i + 1][j][k] += dp[i][j][k]) %= mod;
				(dp[i + 1][i][k] += dp[i][j][k]) %= mod;
				(dp[i + 1][i][j] += dp[i][j][k]) %= mod;
			}
	}
	long long ans = 0;
	for(int i = 0; i < n; i ++)
		for(int j = 0; j < max(1, i); j ++) (ans += dp[n][i][j]) %= mod;
	ans *= 3, ans %= mod; 
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 211328
s = list(input())
law = 10 ** 9 + 7
l = len(s)
dp = [[0 for _ in range(4)] for _ in range(l+1)]
dp[0][0] = 1
for i in range(l):
    dp[i+1][0] = (1 + 2 * int(s[i] == '?')) * dp[i][0]
    dp[i+1][1] = int(s[i] in ('A', '?')) * dp[i][0] + dp[i][1] * (1 + 2 * int(s[i] == '?'))
    dp[i+1][2] = int(s[i] in ('B', '?')) * dp[i][1] + dp[i][2] * (1 + 2 * int(s[i] == '?'))
    dp[i+1][3] = int(s[i] in ('C', '?')) * dp[i][2] + dp[i][3] * (1 + 2 * int(s[i] == '?'))
    dp[i+1][0] %= law
    dp[i+1][1] %= law
    dp[i+1][2] %= law
    dp[i+1][3] %= law
print(dp[l][3])


Measured memory_bytes: 28320
#include <stdio.h>
int main(){
    int n,input,i,max=0,min=0;
    long sum=0;
    scanf("%d",&n);
    
    if(n==0){
        printf("yokuwakaranaidesu\n");
    }
    
    else for(i=1;i<=n;i++){
        scanf("%d",&input);
        
        if(i==1){
            min=input;
            max=input;
            sum=input;
        }
        else{
            if(max<input){
                max=input;
            }
            if(min>input){
                min=input;
            }
            sum+=input;
        }
    }
    printf("%d %d %ld\n",min,max,sum); 
    return 0;
}

Measured memory_bytes: 600
# -*- coding:utf8 -*-

import copy

n = int(input())
l1 = list(map(str, input().split()))
l2 = copy.deepcopy(l1)

flag = 1
while flag:
    flag = 0
    for i in reversed(range(1, n)):
        if l1[i][-1] < l1[i - 1][-1]:
            l1[i], l1[i - 1] = l1[i - 1], l1[i]
            flag = 1
print(' '.join(map(str, l1)))
print('Stable')

for i in range(n):
    minj = i + l2[i:].index(min(l2[i:], key = lambda x : x[-1]))
    if minj != i:
        l2[i], l2[minj] = l2[minj], l2[i]
print(' '.join(map(str, l2)))
print('Stable' if l1 == l2 else 'Not stable')


Measured memory_bytes: 6348