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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

template<typename T>
T gcd(T a, T b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

template<typename T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b)) * b;
}


signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VL t(n);
  rep(i, n) cin >> t[i];
  ll ans = 1LL;
  rep(i, n) {
    ans = lcm<ll>(ans, t[i]);
  }
  out(ans);
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, q) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!

    val t = IntArray(n) { 0 }

    for (i in (1 until n)) {
        if (s[i - 1] == 'A' && s[i] == 'C') {
            t[i] = t[i - 1] + 1
        } else {
            t[i] = t[i - 1]
        }
    }

    (0 until q).map {
        val (l, r) = readLine()!!.split(' ').map { it.toInt() - 1 }
        t[r] - t[l]
    }.forEach {
        println(it)
    }

}

Measured memory_bytes: 66896
N = gets.to_i
ABC = Array.new(N-1) { gets.split.map(&:to_i) }
Q,K = gets.split.map(&:to_i)
XY = Array.new(Q) { gets.split.map(&:to_i) }

tree = Array.new(N+1) { [] }
ABC.each do |a,b,c|
  tree[a] << b << c
  tree[b] << a << c
end

dist = []
q = [K,0]
until q.empty?
  a,d = q.shift(2)
  unless dist[a]
    dist[a] = d
    tree[a].each_slice(2) do |b,c|
      q << b << d + c
    end
  end
end

XY.each do |x,y|
  puts dist[x] + dist[y]
end


Measured memory_bytes: 69976
N, M , X = map(int, input().split())
C = [0 for i in range(N)]
A = [[]for i in range(N)]


for i in range(N):
    temp = list(map(lambda x:int(x), input().split()))
    C[i] = temp[0]
    A[i] = temp[1:]

def solve():
    ans = float('inf')
    # Total: O(2^N*N*M)
    total = 1 << N
    for mask in range(total):  #O(2^N)
        L = [0 for i in range(M)]
        cost = 0
        
        for i in range(N):  #O(N)
            if (mask >> i) & 1:
                cost += C[i]
                for j in range(M): #O(M)
                    L[j] += A[i][j]
            
        ok = True
        for i in range(M):
            if L[i] < X: 
                ok = False
        #print(L, cost, ok)
        if ok:
            ans = min(ans,cost)

    if ans == float('inf'):
        print(-1)
    else:
        print(ans)
solve()


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

int main(void){
  string A, B;
  cin >> A >> B;
  int count = 0;
  for (int i = 0; i < A.size(); i++){
   if(A.at(i) == B.at(i)) count++; 
  }
  cout << count <<endl;
 return 0;
  
}

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

int main()
{
    long long h;
    cin >> h;

    long long addCount = 1;
    long long output = 0;
    while (h > 0)
    {
        h /= 2;
        output += addCount;
        addCount *= 2;
    }

    cout << output << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
int n,c=0;
cin>>n;
int arr[n];
for(int i=1;i<=n;i++){
    cin>>arr[i];
    if(i%2==1&&arr[i]%2==1){
        c++;
    }
}
cout<<c;
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int n;
	cin >> n;
	vector<pii> coor(n);
	vector<int> t(n);
	rep(i,n) {
		cin >> t[i] >> coor[i].fi >> coor[i].se;
	}
	rep(i,n) {
		if(i==0) {
			if (coor[i].fi + coor[i].se > t[0]) {
				cout << "No" << endl;
				return 0;
			}
			else if ((t[0] - (coor[i].fi + coor[i].se)) % 2 == 1) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			int d = abs(coor[i].fi - coor[i-1].fi) + abs(coor[i].se - coor[i-1].se);
			int tt = t[i] - t[i-1];
			if(d > tt || (tt - d) % 2 != 0) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	
	

  return 0;
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();

  vector<int> ans(n,1);
  for (int j = 0; j < 2; j++)
  {
    for (int i = 0; i < n; i++)
    {
      if(s[i]=='R' && s[i+1]=='R'){
        ans[i+2]+=ans[i];
        ans[i]=0;
      }
    }
    reverse(s.begin(),s.end());
    reverse(ans.begin(),ans.end());
    for (int i = 0; i < n; i++)
    {
      if(s[i]=='L') s[i]='R';
      else s[i]='L';
    }
  }
  
  for (int i = 0; i < n; i++)
  {
    cout << ans[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1024
lines = $stdin.read
array = lines.split("\n")
N,A,B = array[0].split(" ").map(&:to_i)

sum = 1.upto(N).map do |n|
  s = n.to_s.split("").map(&:to_i).inject(&:+)
  [n,s]
end.select do |e|
  A <= e.last and e.last <= B
end.map do |m|
  m.first
end

puts sum.inject(&:+)

Measured memory_bytes: 3708
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         fozubaoyou    pass System Test!
*/


//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#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 SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    LL x;
    cin >> x;
    LL n = 100;
    LL y = 0;
    while(n < x){
        n = n * 1.01;
        y++;
    }
    cout << y << endl;
    return 0;
}


Measured memory_bytes: 3636
S = str(input())
N = len(S)

A = '01' * (N//2) + '01'[(N-1)%2]
B = '10' * (N//2) + '10'[(N-1)%2]
ans_A = 0
for i in range(N):
    if S[i] != A[i]:
        ans_A += 1

ans_B = 0
for i in range(N):
    if S[i] != B[i]:
        ans_B += 1

print(min(ans_A, ans_B))

Measured memory_bytes: 41072
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 

using namespace std;

int main() {
	int i, j;
	string str;

	cin >> str;

	if (str[0] == str[1] && str[1] == str[2]) {
		cout << "Yes" << endl;
	}
	else if (str[3] == str[2] && str[2] == str[1]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}






	return 0;
}


Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
using namespace std;
int main(){
	
	map<int,int> r;
	
	r[1]=6000;
	r[2]=4000;
	r[3]=3000;
	r[4]=2000;
	
	int s[4];
	
	int t,n;
	
	for(int i=0;i<4;i++){
		cin>>t>>n;
		s[i]=r[t]*n;
	}
	
	for(int i=0;i<4;i++)
		cout<<s[i]<<endl;

}

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

int main() {
  int n; cin>>n;
  int ans = 0;
  map<pair<int, int>, int> ma;

  for (int i = 1; i <= n; i++) {
    int head = to_string(i)[0] - '0';
    int tail = i % 10;
    ++ma[make_pair(head, tail)];
  }

  for (auto x: ma) {
    int head = x.first.first;
    int tail = x.first.second;
    int a = x.second;
    int b = ma[make_pair(tail, head)];
    ans += a*b;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

// https://atcoder.jp/contests/abc137/tasks/abc137_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();


		int[] max = new int[3];
		//Integer[] max = new Integer[3];
		max[0] = A * B;
		max[1] = A - B;
		max[2] = A + B;

		Arrays.sort(max);
		System.out.println(max[2]);
	}

}


Measured memory_bytes: 23252
#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;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//head

bool isPr(int i){
	if(i == 1) return false;
	if(i == 2) return true;
	if(i % 2 == 0) return false;
	for(int j = 3; j*j <= i; j+=2){
		if(i % j == 0) return false;
	}
	return true;
}
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);

  	ll ans = 1;
  	int n;
  	cin >> n;
  	for(int i = 2; i <= n; i++){
  		if(isPr(i)){
  			ll t = i;
  			ll sum = 0;
  			while(n / t != 0){
  				sum += n / t;
  				t*=i;
  				sum %= mod;
  			}
  			ans *= ((sum+1) % mod);
  			ans %= mod;
  		}
  	}
  	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
    ifstream t("/proc/self/status");
    cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = 18, MAXL = 1 << MAXN;

int n;

int a[MAXL];

inline void input()
{
	n = read<int>();
	for(int i = 0; i < 1 << n; ++i) a[i] = read<int>();
}

pii f[MAXL];

inline void solve()
{
	for(int i = 0; i < 1 << n; ++i) f[i] = mp(0, 0);
	for(int S = 0; S < 1 << n; ++S)
		for(int T = S; T < 1 << n; T = (T + 1) | S)
			if(f[T].fst < a[S]) f[T].snd = f[T].fst, f[T].fst = a[S];
			else chkmax(f[T].snd, a[S]);

	static int ans[MAXL];
	for(int i = 1; i < 1 << n; ++i) ans[i] = max(ans[i - 1], f[i].fst + f[i].snd);
	for(int i = 1; i < 1 << n; ++i) printf("%d\n", ans[i]);
}

int main()
{
//#ifndef ONLINE_JUDGE
//	freopen("E.in", "r", stdin);
//	freopen("E.out", "w", stdout);
//#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 7168
def dfs(s,x):
    if len(s) == n:
        print(s)
    else:
        for c in range(ord('a'),ord(x) + 1):
            dfs(s + chr(c),chr(ord(x) + 1) if chr(c) == x  else x)

n = int(input())
dfs("",'a')

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	int N, L; cin >> N >> L;

	int S = 0;
	REP(i,N) S += L + i;

	int min_value = 1 << 30;
	int ans = 0;
	REP(i,N){
		int sum = 0;
		REP(j,N){
			if(i == j) continue;
			else sum += L + j;
		}
		if(abs(S-sum) < min_value){
			ans = sum;
			min_value = abs(S-sum);
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))

relations = {}

for i in range(N):
    relations[i+1] = P[i]

cnt = 0
for key, value in relations.items():
    if key != value:
        cnt += 1

if cnt <= 2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
	bool Is_found=false;
	int ans;
	char s[100];
	char t[100];
	scanf("%s",s);
	scanf("%s",t);
	for(int i=0;s[i];i++)
	{
		if(s[i]==t[0]||s[i]=='?')
		{
			int j;
			for(j=1;t[j]&&s[i+j];j++)
			{
				if(s[i+j]==t[j]||s[i+j]=='?')continue;
				else break;
			}
			if(t[j]==0){Is_found=true;ans=i;}
		}
	}
	for(int i=0;t[i];i++)s[ans+i]=t[i];
	for(int i=0;s[i];i++)if(s[i]=='?')s[i]='a';
	if(!Is_found)printf("UNRESTORABLE\n");
	else printf("%s",s);
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int N, S, A[3005];
ll DP[3005][3005];

int main(){

  scanf("%d%d", &N, &S);
  for (int i = 1; i <= N; i++) scanf("%d", &A[i]);

  DP[0][0] = 1;
  for (ll i = 1; i <= N; i++){
    for (int j = 0; j <= S; j++){
      DP[i][j] = DP[i-1][j];
    }
    
    if (A[i] > S) continue;
    if (A[i] == S){
      DP[i][S] += i * (N - i + 1);
      DP[i][S] %= Mod;
    }else{
      DP[i][A[i]] += i;
    }

    for (int j = 1; j + A[i] < S; j++){
      DP[i][j + A[i]] += DP[i-1][j];
    }
    if (A[i] < S) DP[i][S] += DP[i-1][S - A[i]] * (N - i + 1);

    for (int j = 0; j <= S; j++){
      DP[i][j] %= Mod;
    }
  }
  
  cout << DP[N][S] << endl;


  return 0;
}


Measured memory_bytes: 70656
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
using namespace std;
const int N=1e5+10;
int f[N],a[N];

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=2;i<=n;i++)
	{
		f[i]=f[i-1]+abs(a[i]-a[i-1]);
		for(int j=i-k;j<=i-2;j++)
		{
			if(j<=0)continue;
			f[i]=min(f[i],f[j]+abs(a[i]-a[j]));
		}
	}
	printf("%d\n",f[n]);
   return 0;
}


Measured memory_bytes: 4540
N,K = list(map(int,input().split()))
all_sunuke = set([i for i in range(1,N+1)])
d = [] # お菓子iを持っている人数
A = [] # お菓子iを持っている人のID列
for i in range(K):
    d = int(input())
    A += list(map(int,input().split()))

setA = set(A)
sub = list(all_sunuke - setA)

print(len(sub))


Measured memory_bytes: 9260
N = int(input())
A = [int(x) for x in input().split(' ')]

s = 0
mc = 0
mh = 1e10
for i in A:
  if i <= 0:
    mc += 1
  if abs(i) <= mh:
    mh = abs(i)
  s += abs(i)

if (mc % 2 == 1):
  mv = min(A[0],A[-1])
  #print('mv',mv)
  s -= mh*2
print(s)

Measured memory_bytes: 14284
PY = $<.map{|ln| ln.split.map(&:to_i) }
N,M = PY.shift

P = Array.new(N+1){ [] }
PY.each{|p,y|
	P[p] << y
}
P.each(&:sort!)

PY.each{|p,y|
	puts '%06d%06d'%[p,1+P[p].bsearch_index{|_| y<=_ }]
}


Measured memory_bytes: 18532
#include <cstdio>   
#include <algorithm>   
using namespace std;   
  
const int MAX_N = 100, MAX_M = MAX_N * MAX_N;   
  
int par[MAX_N]; // e   
int rank[MAX_N]; // ØÌ[³   
  
// nvfÅú»   
void init_union_find(int n)   
{   
    for (int i = 0; i < n; i++)   
    {   
        par[i] = i;   
        rank[i] = 0;   
    }   
}   
  
// ØÌªðßé   
int find_union_find(int x)   
{   
    if (par[x] == x)   
        return x;   
    else  
        return par[x] = find_union_find(par[x]);   
}   
  
// xÆyÌ®·éWð¹   
void unite_union_find(int x, int y)   
{   
    x = find_union_find(x);   
    y = find_union_find(y);   
    if (x == y) return ;   
  
    if (rank[x] < rank[y])   
        par[x] = y;   
    else  
    {   
        par[y] = x;   
        if (rank[x] == rank[y]) rank[x]++;   
    }   
}   
  
// xÆyª¯¶WÉ®·é©Û©   
bool same_union_find(int x, int y)   
{   
    return find_union_find(x) == find_union_find(y);   
}   
  
struct edge { int u, v, cost; };   
  
bool comp(const edge &e1, const edge &e2)   
{   
    return e1.cost < e2.cost;   
}   
  
// üÍ   
int n, m;   
edge es[MAX_M];   
  
int kruskal()   
{   
    std::sort(es, es + m, comp);   
    init_union_find(n);   
    int res = 0;   
    for (int i = 0; i < m; i++)   
    {   
        edge e = es[i];   
        if (!same_union_find(e.u, e.v))   
        {   
            unite_union_find(e.u, e.v);   
            res += e.cost;   
        }   
    }   
    return res;   
}   
  
void solve()   
{ 
    printf("%d\n", kruskal());   
}   
  
int main()   
{   
    while (scanf("%d", &n) && n)   
    {   
        scanf("%d", &m);   
        for (int i = 0; i < m; i++)   
        {   
            int a, b, d;   
            scanf("%d,%d,%d", &es[i].u, &es[i].v, &es[i].cost);   
            es[i].cost = es[i].cost / 100 - 1;   
        }   
  
        solve();   
    }   
  
    return 0;   
}  

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>

void QSort(int x[], int left, int right);
void Swap(int x[], int i, int j);

/* クイックソートを行う */
void QSort(int *x, int left, int right)
{
	int i, j;
	int pivot;

	i = left;                      /* ソートする配列の一番小さい要素の添字 */
	j = right;                     /* ソートする配列の一番大きい要素の添字 */

	pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */

	while (1) {                    /* 無限ループ */

		while (x[i] < pivot)       /* pivot より大きい値が */
			i++;                   /* 出るまで i を増加させる */

		while (pivot < x[j])       /* pivot より小さい値が */
			j--;                   /*  出るまで j を減少させる */
		if (i >= j)                /* i >= j なら */
			break;                 /* 無限ループから抜ける */

		Swap(x, i, j);             /* x[i] と x[j]を交換 */
		i++;                       /* 次のデータ */
		j--;
	}
	if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
		QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
	if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
		QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
}

/* 配列の要素を交換する */
void Swap(int *x, int i, int j) {
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

int main (void) {
	int N = -1, i, *x, *y, med;
	scanf("%d\n", &N);
	if (N % 2 != 0) return -1;
	i = 0;
	x = malloc(sizeof(int) * N);
	y = malloc(sizeof(int) * N);
	while (i < N) {
		scanf(" %d", &x[i]);
		y[i] = x[i];
		i++;
	}
	QSort(y, 0, N - 1);
	i = 0;
	int c = y[N / 2 - 1];
	while (i < N) {
		if (x[i] <= c)
			med = y[N / 2];
		else med = y[N / 2 - 1];
		printf("%d\n", med);
		i++;
	}
	free(x);
	free(y);
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define M 100010

int main(){
	IOS;
	tihs;

	string s,t;
	ll a,b;
	cin>>s>>t;
	cin>>a>>b;
	string u;
	cin>>u;
	if(u==s)cout<<a-1<<" "<<b;
	else if(u==t)cout<<a<<" "<<b-1;
	else cout<<a<<" "<<b;






	return 0;
}

Measured memory_bytes: 256
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

k = r()
val = 7%k
ans = False
for i in range(1,10**6+1):
    if val==0:
        ans = True
        print(i)
        break
    val = (val*10+7)%k
if not ans:
    print(-1)

Measured memory_bytes: 77436
import Control.Monad

choco ::Int -> Int -> Int
choco day a =
  length $ 1:[a+1,2*a+1..day]

solve ::Int -> [Int] -> Int -> Int
solve _ [] x = x
solve d (a:as) x =
  solve d as (x + choco d a)

main = do
  n <- read <$> getLine ::IO Int
  [d,x] <- map read . words <$> getLine ::IO [Int]
  al' <- replicateM n $ getLine 
  let al = map read al' :: [Int]
  print $ solve d al x


Measured memory_bytes: 892
import sys
input = sys.stdin.readline
from collections import *

N, K = map(int, input().split())
a = list(map(int, input().split()))
acc = [0]

for ai in a:
    acc.append(acc[-1]+ai)

l = []

for i in range(N):
    for j in range(i, N):
        l.append(acc[j+1]-acc[i])

ans = 0

for i in range(45):
    nl = []
    
    for li in l:
        if (li>>(44-i))&1:
            nl.append(li)
    
    if len(nl)>=K:
        ans += 2**(44-i)
        l = nl
    
print(ans)

Measured memory_bytes: 112392
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
const ll mod=1000000007;
const ll inf=(1LL<<60);
const double pi=acos(-1);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline void pcas(int ca) {printf("Case %d: ",ca);}
const int maxn=1e5+10;

int main()
{
    int a,x=0,y=0;
    for(int i = 0; i < 3; ++i) {
        scanf("%d",&a);
        if(a==5) x++;
        if(a==7) y++;
    }
    if(x==2&&y==1) puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

int main() {
	IN(int, n);
	int N = n * n;
	vector<int> p(N);
	cin >> p;
	RF(e, p) { e--; }
	
	vector<int> c(N, 1), d(N);
	inc(i, n) {
	inc(j, n) {
		d[n * i + j] = min(min(i, j), n - 1 - max(i, j));
	}
	}
	
	int ans = 0;
	RF(e, p) {
		ans += d[e];
		c[e] = 0;
		queue<pair<int, int>> q;
		q.emplace(e, d[e]);
		until(q.empty()) {
			auto [e, dd] = q.front(); q.pop();
			if(d[e] != dd) { continue; }
			vector<int> k = { e - 1, e + 1, e - n, e + n };
			RF(ee, k) {
				if_not(inID(ee, 0, N)) { continue; }
				if(setmin(d[ee], d[e] + c[e])) { q.emplace(ee, d[ee]); }
			}
		}
	}
	OUT(ans);
}


Measured memory_bytes: 6164
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <long long> vll;
typedef vector <vi> vvi;
typedef vector <vll> vvll;
 
#define all(v) v.begin(),v.end()
#define nl endl
#define bs(v,n) binary_search(v.begin(),v.end(),n)
#define sz() size()
#define pb push_back
#define mp make_pair
 
const ll mod=1e9+7;
const int MAX_CHAR = 26;

int main() {
	int N=0;
	cin>>N;
	vi V(N), C(N);
	int ans=0;
	for(int i=0;i<N;i++) cin>>V[i];
	for(int i=0;i<N;i++){
		cin>>C[i];
		if(V[i]-C[i] > 0) ans += V[i]-C[i];
	}
	cout<<ans<<nl;
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int M = max(max(a,b), c);
    int m = min(min(a,b), c);
    cout << M - m << endl;
}

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

int main() {
  
  int a,b,x;
  cin >> a >> b >> x;
  
  if ( x >= a && x <= a + b ){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  
}



Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n,d=MAP()
    x = [LIST() for _ in range(n)]
    comb=combinations(range(n),2)
    ct=0
    for r in comb:
        #print(r)
        dis=0
        for i in range(d):
            dis+=(x[r[0]][i]-x[r[1]][i])**2

        if int(sqrt(dis)) == sqrt(dis):
            ct+=1

    print(ct)






if  __name__=='__main__':
    main()


Measured memory_bytes: 5736
import java.util.*;
        import java.lang.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        long[] A = new long[N];
        int negElm = 0;
        long minAbs = Long.MAX_VALUE;
        long absSum = 0;
        for(int n=0; n<N; n++){
            A[n] = sc.nextLong();
            if(A[n]<0) negElm++;
            minAbs = Math.min(minAbs, Math.abs(A[n]));
            absSum += Math.abs(A[n]);
        }
        if(negElm%2==0) System.out.println(absSum);
        else System.out.println(absSum - minAbs*2);

    }
}

Measured memory_bytes: 50020
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a = 0;
	int b = 0;
	cin >> a;
	cin >> b;
	if (a == 1 && b != 1) {
		cout << "Alice" << "\n";
	}
	else if (a != 1 && b == 1) {
		cout << "Bob" << "\n";
	}
	else if (a < b) {
		cout << "Bob" << "\n";
	}
	else if (b < a) {
		cout << "Alice" << "\n";
	}
	else if (a == b) {
		cout << "Draw" << "\n";
	}

	cin >> a;
}

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

int main(){
  int n;
  cin >> n;
  
  int a[n];
  int sum=0;
  for(int i=0; i<n; i++){cin >> a[i]; sum += a[i];}
    
  for(int i=0; i<n; i++){a[i] = abs(n * a[i]-sum);}
  
  int min = 100 * n;
  int ans = 0;
  for(int i=0; i<n; i++){
    if (min > a[i]){
      min = a[i];
      ans = i;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int N=1e5+5;
vector<int> g[N];
ll dp[N];
int n,m;

ll f(int i){
	ll &r=dp[i];
	if(r!=-1)return r;
	r=0;
	for(int v:g[i])r=max(r,f(v));
	r++;
	return r;
}

int main(){FIN;mset(dp,-1);
	cin >> n >> m;
	fore(_,0,m){int u,v;cin>>u>>v;g[u].pb(v);}
	ll ans=0;
	fore(x,1,n+1)ans=max(ans,f(x));
	cout<<ans-1<<"\n";
}

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

int main(){
    int n,w1;
    cin>>n>>w1;
    std::vector<int>w(n+1) ;
    std::vector<int>v(n+1) ;
    for (int i=1;i<=n;i++) {
        cin>>w[i]>>v[i];
    }
    vector<vector<long> >f(n+1,vector<long>(w1+1,0));
    // for(int i=0;i<=w1;i++)f[0][i]=0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=w1;j++){
            if(w[i]+j<=w1)f[i][j+w[i]]=f[i-1][j]+v[i];
            f[i][j]=max(f[i-1][j],f[i][j]);
        }
    }
    long maxi=-8;
    for(int j=0;j<=w1;j++)maxi=max(maxi,f[n][j]);
    cout<<maxi;
}

Measured memory_bytes: 80256
#!/usr/bin/env python3

import itertools

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

max_x = max(max(x_list), A)
dp = [[[0 for s in range(N * max_x + 1)] for k in range(N + 1)] for j in range(N + 1)]
dp[0][0][0] = 1
ka_list = []

for j in range(N + 1):  # 何番目の数か
    x = x_list[j - 1]
    for k in range(N + 1):  # k枚選ぶとき
        for s in range(N * max_x + 1):
            if j == 0 and k == 0 and s == 0:
                dp[0][0][0] = 1
            elif j >= 1 and s < x:
                # オーバーするので選べない
                # ひとつ前と同じになる
                dp[j][k][s] = dp[j - 1][k][s]
            elif j >= 1 and k >= 1 and s >= x:
                dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x]
            else:
                dp[j][k][s] = 0

ans = sum([dp[N][k][k * A] for k in range(1, N + 1)])
print(ans)


Measured memory_bytes: 97116
#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/ 
using namespace std;

#define endl "\n"
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define re(i,a) for(ll i=0; i<a; ++i)
#define tr(i,v) for(auto &i: v)
#define mem(a,val) memset(a,val,sizeof(a))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define in(v,n) vll v(n);re(i,n) cin>>v[i]
#define printVec(v,s) cout << s; tr(i, v) cout << i << " ";
#define sz(v)	((ll)((v).size()))
#define dbgv(c, v) cout << c << " = " << v << endl;
#define P(x)				cout<<#x<<" = { "<<x<<" }\n"

typedef long long int ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<ll, ll> pll;
typedef vector< pll > vpll;
typedef vector< ll > vll;
typedef complex<double> point;

const long long MOD = 1000000007;
const long long inf = 1e18;
const double EPS = (1e-7);
inline ll dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

void solve(){
  ll n;
  cin>>n;
  in(a,n);
  sort(all(a), greater<ll>());
  ll left = n - 2;
  ll score = a[0];
  ll i = 1;
  while(left > 1) {
    score += 2 * a[i];
    i++;
    left -= 2;
  }
  if(left == 1) score += a[i];
  cout << score ;
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    	solve();
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 4764
#![allow(unused)]

use std::cmp::{min, max};
use std::io::Write;

macro_rules! dbg {
    ($($a:expr),*) => {
        writeln!(
            std::io::stderr(),
            concat!($(stringify!($a), " = {:?}, "),*),
            $($a),*);
    }
}

//
// Based on EbTech's Scanner https://stackoverflow.com/q/56449027
//
struct Scanner<'a, R: std::io::BufRead> {
    reader: R,
    buf: String,
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a, R: std::io::BufRead> Scanner<'a, R> {
    fn new(reader: R) -> Scanner<'a, R> {
        Scanner { reader: reader, buf: String::new(), iter: "".split_whitespace() }
    }

    fn get_str(&mut self) -> &str {
        if let Some(t) = self.iter.next() {
            return t;
        }
        self.buf.clear();
        self.reader.read_line(&mut self.buf).expect("I/O error");
        self.iter = unsafe { std::mem::transmute(self.buf.split_whitespace()) };
        self.get_str()
    }

    fn get<T: std::str::FromStr>(&mut self) -> T {
        self.get_str().parse().ok().expect("Parse error")
    }
}

fn main() {
    let stdin = std::io::stdin();
    solve(Scanner::new(stdin.lock()));
}

fn solve<R: std::io::BufRead>(mut sc: Scanner<R>) {
    let n: usize = sc.get();
    let nsushis: Vec<usize> = (0..n).map(|_| sc.get()).collect();

    // dp[d1][d2][d3] = 1貫皿 d1 枚, 2貫皿 d2 枚, 3貫皿 d3 枚 の状態から全貫
    //                  食べる手数の期待値
    let mut dp = vec![vec![vec![0.; n + 1]; n + 1]; n + 1];

    for d3 in 0..(n + 1) {
        for d2 in 0..(n - d3 + 1) {
            for d1 in 0..(n - d3 - d2 + 1) {
                if d1 + d2 + d3 == 0 {
                    continue;
                }

                // i 貫乘った皿を選ぶ確率
                let p0 = (n - d1 - d2 - d3) as f64 / n as f64;
                let p1 = d1 as f64 / n as f64;
                let p2 = d2 as f64 / n as f64;
                let p3 = d3 as f64 / n as f64;

                //
                // dp[d1][d2][d3] =
                //     1.
                //     + dp[d1 - 1][d2][d3] * p1
                //     + dp[d1][d2 - 1][d3] * p2
                //     + dp[d1][d2][d3 - 1] * p3
                //     + dp[d1][d2][d3] * p0;
                //
                // dp[d1][d2][d3] を左辺へ移項し，両辺 (1 - p0) で除算
                //
                dp[d1][d2][d3] =
                    (
                        1.
                        + if d1 > 0 { dp[d1 - 1][d2][d3] * p1 } else { 0. }
                        + if d2 > 0 { dp[d1 + 1][d2 - 1][d3] * p2 } else { 0. }
                        + if d3 > 0 { dp[d1][d2 + 1][d3 - 1] * p3 } else { 0. }
                    ) / (1. - p0);
            }
        }
    }

    let dinit = nsushis.iter().fold([0; 3], |mut a, x| { a[x - 1] += 1; a });
    println!("{}", dp[dinit[0]][dinit[1]][dinit[2]]);
}

Measured memory_bytes: 237948
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<cmath>
#include<deque>
#include<map>

using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF 1LL << 60
#define MAX 1000000000
const int MOD = 1000000007;
int main(void) {
	int N, M;
	ll l;
	scanf("%d%d", &N, &M);
	if (M == 1 || N >= M) {
		puts("0");
		return 0;
	}
	vector<int> X(M), D(M - 1);
	rep(i, 0, M) {
		scanf("%d", &X[i]);
	}
	sort(all(X));
	l = X.back() - X.front();
	rep(i, 0, M - 1)D[i] = X[i + 1] - X[i];
	r_sort(D);
	rep(i, 0, N - 1) {
		l -= D[i];
	}
	printf("%lld\n", l);
	return 0;
}
int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}

	return b ? gcd(b, a % b) : a;
}
long long modpow(long long a, long long n) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}/*
int main() {
	int N, K;
	ll s = 0;
	scanf("%d%d", &N, &K);
	rep(l, 1, K + 1) {
		s += (modpow(K - l + 1,N) - modpow(K - l, N)) % MOD + modpow(K / l, N - 1) * (l - 1);
		printf("%lld %lld \n",s, (modpow(K - l + 1, N) - modpow(K - l, N)) % MOD, N - 1);
		s %= MOD;
	}
	printf("%lld\n", s);
	return 0;
}*/

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Programming Education
            int n = int.Parse(Console.ReadLine());

            if (n == 1)
            {
                Console.WriteLine("Hello World");
            }
            else
            {
                int a = int.Parse(Console.ReadLine());
                int b = int.Parse(Console.ReadLine());

                Console.WriteLine(a + b);
            }
        }
    }
}

Measured memory_bytes: 11092
n,k=map(int,input().split())
sum = 0

for i in range(k, n+2):
	minunchi = (i*(i-1))//2
	maxunchi = (n*(n+1))//2 - ((n+1-i)*(n-i))//2
	sum += maxunchi - minunchi + 1

print(sum%(10**9+7))

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  vector<int>s;
  bool so[100000]={};
  so[0]=so[1]=1;
  for(int i=2;i*i<100000;i++)
    if(!so[i])for(int j=2;j*i<100000;j++)so[i*j]=1;
  for(int i=2;i<100000;i++)if(!so[i])s.push_back(i);
  while(cin>>n,n){
    int ans=0;
      for(int i=0;s[i]<=n/2;i++)
      if(!so[n-s[i]])ans++;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3300
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int main() {

    vector < ll > a(3);
    REP(i,3) cin >> a[i];

    sort(a.begin(), a.end());

    ll K; cin >> K;
    REP(i,K) {
        a.back() *= 2;
    }

    ll ans = 0;
    REP(i,3) ans += a[i];

    cout << ans << endl;

    return 0;
}

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

int main() {
    long long n,m,d;
    cin >> n >> m >> d;
    cout << fixed << setprecision(10);
    if(d == 0) cout << 1.0 * (m - 1) / n << endl;
    else cout << (m - 1) * 2.0 * (n - d) / (n * n) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
const int BUF = 100005;


int M;
string s;

void read() {
    int dummy;
    cin >> dummy >> M >> s;
}


void work() {
    int cost[BUF];
    memset(cost, -1, sizeof(cost));
    cost[s.size() - 1] = 0;

    for (int i = s.size() - 2, last = s.size() - 1; i >= 0; --i) {
        if (s[i] == '1') continue;
        while (last - i > M || (last > i && cost[last] == -1)) --last;

        if (last == i) {
            cout << -1 << endl;
            return;
        }

        cost[i] = cost[last] + 1;
    }

    int cur = 0;
    while (cur < s.size() - 1) {
        int nex = cur + 1;
        while (cost[nex] == -1 || cost[nex] == cost[cur]) ++nex;

        cout << nex - cur;
        if (nex != s.size() - 1) cout << ' ';

        cur = nex;
    }

    cout << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin >> n >> m;
    ll sum=0;
    for(int i=0;i<m;i++){
        ll a;cin >> a;
        sum+=a;
    }
    if(sum<=n){
        cout << n-sum << endl;
    }
    else{
        cout << -1 << endl;
    }
}

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

int main(){
  int n;
  cin >> n;
  set<string> st;
  rep(i,0,n){
    string s;
    cin >> s;
    st.insert(s);
  }
  int ans = st.size();
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 19228
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  int ans = 0;
  rep(i,n/2+n%2){
    if(!i)continue;
    if(n - i != i)ans++;
  }
  print(ans);
  return 0;
}



Measured memory_bytes: 256
N = int(raw_input())
X = map(int, raw_input().split())
memo = []
for i in range(0, N):
	memo.append(X[i])
memo.sort()
twomed = [memo[N/2-1], memo[N/2]]

for i in range(0, N):
	if X[i] <= twomed[0]: print twomed[1]
	else: print twomed[0]

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

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    if(k<=a){
        printf("%lld %lld",a-k,b);
    }
    else if(a+b-k>0){
        printf("%lld %lld",0,a+b-k);
    }
    else{
        printf("%lld %lld",0,0);
    }

    

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc122b()
}

fun abc122b() {
    val actg = listOf('A', 'C', 'T', 'G')

    val s = readLine()!!.toCharArray().toList()

    var maxLengthString = 0
    for (i in s.indices) {
        for (j in i + 1 .. s.size) {
            val subList = s.subList(i, j)
            if (actg.containsAll(subList)) {
                if (subList.size > maxLengthString) maxLengthString = subList.size
            }
        }
    }

    println(maxLengthString)
}


Measured memory_bytes: 35780
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char ss[10001],st[10001];
int main(){
	int i,j,k,n,m;
	cin>>ss>>st;
	n=strlen(ss);
	m=strlen(st);
	sort(ss,ss+n);
	sort(st,st+m);
	for(i=0;i<max(n,m);i++){
		if(ss[i]<st[m-i-1]){
			cout<<"Yes"<<endl;
			return 0;
		}
		if(ss[i]>st[m-i-1])break;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def partition(a,p,r):
    x=a[r]
    i=p-1
    for j in range(p,r):
        if(a[j]<=x):
            i+=1
            a[i],a[j]=a[j],a[i]
    a[i+1],a[r]=a[r],a[i+1]
    return i+1

def main(n,a):
    ans=partition(a,0,n-1)
    print(' '.join(map(str,a[:ans])),end='')
    print(' ['+str(a[ans])+'] ',end='')
    if(ans<n-1):
        print(' '.join(map(str,a[ans+1:])))

    return

if __name__=='__main__':
    n,a=readinput()
    main(n,a)


Measured memory_bytes: 16396