akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<long long>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

ll C[51][51];

void comb (int N) {
    rep(i, 0, N + 1) rep(j, 0, i + 1) {
        if(j == 0 || i == j) C[i][j] = 1ll;
        else C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }
}

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

    int N, A, B;
    cin >> N >> A >> B;
    vector<ll> v(N);
    rep(i, 0, N) cin >> v[i];
    comb(N);
    vsort_r(v);

    long double rsl = 0.0;
    rep(i, 0, A) rsl += v[i];
    rsl /= A;


    int X = 0, Y = 0;
    rep(i, 0, N) {
        if(v[i] == v[A - 1]) {
            if(i < A) Y++;
            X++;
        }
    }

    ll count = 0;
    if(Y != A) {
        count = C[X][Y];
    } else {
        rep(i, A, B + 1) {
            count += C[X][i];
        }
    }

    cout.precision(20);
    cout << fixed << rsl << endl;
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
        
int main() {
  double A,B,X;
  cin >> A >> B >> X;
  X /= A;
  double S = A*B;
  
  if(X <= S/2){
    cout << setprecision(10) << atan(B/(X*2/B))*(180.0/M_PI) << endl;
  }
  else{
    X = S-X;
    cout << setprecision(10) << atan((X*2/A)/A)*(180.0/M_PI) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
from math import atan2, degrees

a, b, x = [int(x) for x in input().split()]

temp = 2 * b - 2 * x / a ** 2
if temp < b:
    s = a
    t = temp
else:
    s = 2 * x / a / b
    t = b

theta = degrees(atan2(t, s))
print(theta)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		while (n-- > 0) {
			int a = scanner.nextInt();
			boolean[][] map = new boolean[a + 4][a + 4];
			for (int i = 0; i < a + 4; i++) {
				for (int j = 0; j < a + 4; j++) {
					if (i == 0 || j == 0 || i == a + 3 || j == a + 3) {
						map[i][j] = true;
					}
				}
			}
			int x = 2;
			int y = a + 1;
			int h = 0;
			int[][] dxy = { { 1, 0 }, { 0, -1 }, { -1, 0 }, { 0, 1 } };
			loop: while (true) {
				for (int i = 0; i < 4; i++) {
					if (i == h) {
						continue;
					}
					int py = y + dxy[i][0];
					int px = x + dxy[i][1];
					if (map[py][px]) {
						break loop;
					}
				}
				map[y][x] = true;
				if (h == 0) {
					if (map[y - 2][x]) {
						x++;
						h = 1;
					} else {
						y--;
					}
				} else if (h == 1) {
					if (map[y][x + 2]) {
						y++;
						h = 2;
					} else {
						x++;
					}
				} else if (h == 2) {
					if (map[y + 2][x]) {
						x--;
						h = 3;
					} else {
						y++;
					}
				} else {
					if (map[y][x - 2]) {
						y--;
						h = 0;
					} else {
						x--;
					}
				}
			}
			for (int i = 2; i < a + 2; i++) {
				for (int j = 2; j < a + 2; j++) {
					System.out.print(map[i][j] ? "#" : " ");
				}
				System.out.println();
			}
			if (n != 0) {
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 26400
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;

void dfs(int pos, vector<vector<int> > &graph, vector<bool> &arrived_flag, vector<int> &arrived_num) {
	if(arrived_flag[pos]) return;
	arrived_flag[pos] = true;
	for(int i = 0; i < graph[pos].size(); i++) dfs(graph[pos][i],graph,arrived_flag,arrived_num);
	arrived_num.push_back(pos);
}

vector<int>& rdfs(int pos, vector<vector<int> > &graph, vector<bool> &arrived_flag, vector<int> &group) {
	if(arrived_flag[pos]) return group;
	arrived_flag[pos] = true;
	for(int i = 0; i < graph[pos].size(); i++) rdfs(graph[pos][i],graph,arrived_flag,group);
	group.push_back(pos);
	return group;
}

int main() {
	int n;
	scanf("%d",&n);
	while(n>0) {
		vector<vector<int> > graph(n);
		vector<vector<int> > r_graph(n);
		vector<double> ps(n);
		for(int i = 0; i < n; i++) {
			graph[i] = vector<int>();
			r_graph[i] = vector<int>();
		}
		for(int i = 0; i < n; i++) {
			double p;
			int m;
			scanf("%lf%d",&p,&m);
			for(int j = 0; j < m; j++) {
				int a; scanf("%d",&a);
				a--;
				graph[i].push_back(a);
				r_graph[a].push_back(i);
			}
			ps[i] = p;
		}
		vector<bool> arrived_flag(n);
		vector<int> arrived_num(0);
		for(int i = 0; i < n; i++) dfs(i,graph,arrived_flag,arrived_num);
		fill(arrived_flag.begin(),arrived_flag.end(),false);
		double ans = 1.0;
		for(int i = n-1; i >= 0; i--) {
			vector<int> group = rdfs(arrived_num[i],r_graph,arrived_flag, *(new vector<int>(0)));
			if(group.size()>0) {
				map<int,bool> group_nums;
				for(int j = 0; j < group.size(); j++) {
					group_nums[group[j]] = true;
				}
				bool is_final = true;
				for(int j = 0; j < group.size(); j++) {
					int next = group[j];
					for(int k = 0; k < r_graph[next].size(); k++) {
						is_final &= group_nums[r_graph[next][k]];
					}
				}
				if(is_final) {
					double all_p = 1.0;
					for(int j = 0; j < group.size(); j++) {
						all_p *= ps[group[j]];
					}
					ans *= (1-all_p);
				};
			}
		}
		printf("%.9lf\n",ans);
		scanf("%d",&n);
	}
}



Measured memory_bytes: 3080
#include<iostream>

using namespace std;

int num,count,data[4];

void function(int n){

	if(n == 4){
		int sum = 0;
		for(int i=0;i<4;i++){
			sum += data[i];
		}
		if(sum == num){
			count++;
		}
	}

	else{
		for(int i=0;i<10;i++){
			data[n] = i;
			int tmpSum = 0;
			for(int j=0;j<n;j++){
				tmpSum += data[j];
			}
			if(tmpSum>35){
				break;
			}
			function(n+1);
		}
	}

}

int main(){

	int sum = 0;

	while(cin >> num){
		count = 0;

		function(0);

		cout<<count<<endl;
	}

	return 0;
}

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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  int counta,countb,countc;
  counta = countb = countc;
  string mae = "a";
  for(int i = 0;;i++){
    if(mae == "a"){
      if(counta == a.size()){
      	cout << "A" << endl;
      	break;
      }
      mae = a.at(counta);
      counta++;
    }else if(mae == "b"){
       if(countb == b.size()){
      	cout << "B" << endl;
      	break;
      }
      mae = b.at(countb);
      countb++;
    }else if(mae == "c"){
       if(countc == c.size()){
      	cout << "C" << endl;
      	break;
      }
      mae = c.at(countc);
      countc++;
    }
  }
}


      
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}

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

  int n, k;
  cin >> n >> k;
  vt<int> h(n);
  rep(i, 0, n) cin >> h[i];
  sort(rall(h));

  int ans = INF;
  rep(i, 0, n - k + 1) ans = min(ans, h[i] - h[i + k - 1]);
  cout << ans << endl;
}


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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  ans=0
  ind=1
  for x in l:
    if x==ind:
      ind+=1
    else:
      ans+=1

  if ans==n:
    return -1
  return ans

# main()
print(main())


Measured memory_bytes: 27384
#input : 整数の数 n と１から n までを並び替えた整数 p_1 から p_n まで
#output : ３つの並びを取り出したとき真ん中の数が二番目に小さい並びの個数

n = int(input())
P = list(map(int,input().split()))
N = 0

for i in range(n-2):
    s = []
    s.append(P[i])
    s.append(P[i+1])
    s.append(P[i+2])
    if s[1] != max(s) and s[1] != min(s):
        N += 1

print(N)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
const int M=1e9+7;// M=1e9+7;//M=300000;//
const int N=2e6+5;
typedef long long int ll;
using namespace std;
 
ll cnt(0),sum(0),n,x,y,t,i,j,temp,k,ans(0),mn(M),mx(-9e9);
map<ll,ll> m;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>x>>n;
	for(i=0;i<n;i++)
	{
		cin>>y;
		m[y]++;
	}
	i=x;
	while(1)
	{
		if(m[i]==0)
		{
			ans=i;
			break;
		}
		i++;
	}
	i=x;
	while(1)
	{
		if(m[i]==0)
		{
			if(abs(x-i)<=abs(ans-x))
			{
				ans=i;
			}
			break;
		}
		i--;
	}
	cout<<ans;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl = vector<ll>; using vvl = vector<vl>;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
    int n;cin >> n;
    vector<int> num(100005,0);
    rep(i,n){
        int s;cin >> s;
        num[s]++;
    }
    ll ans = 0;
    rep(i,100005){
        ans += num[i]*i;
    }
    int Q;cin >> Q;
    rep(i,Q){
        int a,b;cin >> a >> b;
        ans += (b-a)*num[a];
        num[b] += num[a];
        num[a] = 0;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3792
#include <iostream>
using namespace std;
typedef long long ll;

const ll M=3005,mod=998244353;
ll n,m,res=0,C[M][M];

int main(){
	cin>>n>>m;
	C[0][0]++;
	for(int i=0;i<M-1;i++) for(int j=0;j<=i;j++){
		(C[i+1][j]+=C[i][j])%=mod;
		(C[i+1][j+1]+=C[i][j])%=mod;
	}
	for(int i=0;i<m;i++) for(int j=0;j<=i/2;j++) if(i-j<=n) (res+=C[n][j]*C[n-j][i-2*j])%=mod;
	for(int i=m+1;i<=2*m-2;i+=2){
		int t=(i-m+1)/2*2,x=i-2*t;
		for(int j=0;j<=x/2;j++) if(t+x-j<=n) (res+=C[x-j][j]*C[n][t+x-j])%=mod;
	}
	if(m%2==1) for(int i=m;i<=n;i++) (res+=C[n][i])%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 69120
N=int(input())
A,B=map(int,input().split())
P=list(map(int,input().split()))
check=[0]*3
for x in P:
  if x<=A:
    check[0]+=1
  elif A<x<=B:
    check[1]+=1
  else:
    check[2]+=1
print(min(check))


Measured memory_bytes: 8984
N = input().replace("\n", "")
L = len(N)
dp = [[0 for _ in range(2)] for i in range(L+1)]
dp[0][1] = 1
for i in range(L):
    n = int(N[i])
    dp[i+1][0] = min(dp[i][0]+n, dp[i][1]+(10-n))
    dp[i+1][1] = min(dp[i][0]+n+1, dp[i][1]+(9-n))
print(dp[L][0])


Measured memory_bytes: 157768
#include <bits/stdc++.h>
using namespace std;
int L[200005];
int R[200005];

int main(){
    int n;
    string s;
    cin>>n>>s;
    memset(L,0,sizeof(L));
    memset(R,0,sizeof(R));
    for(int i=0;i<n;i++) {
        if(s[i]=='#') L[i]=L[i-1]+1;
        else L[i]=L[i-1];
    }
    for(int i=n-1;i>=0;i--) {
        if(s[i]=='.') R[i]=R[i+1]+1;
        else R[i]=R[i+1];
    }
    int ans = 10000000;
    for(int i=0;i<n;i++) {
//        cout<<L[i-1]<<"  "<<R[i+1]<<endl;
        ans = min(ans,L[i-1]+R[i+1]);
//        cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2180
#include <iostream>

using namespace std;

int main(void) {
	int H, W;
	cin >> H >> W;
	while (H || W)
	{
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;
	}
}


Measured memory_bytes: 3028
#include<cstdio>
#include<map>
using namespace std;

const int MAX_N = 1e5;
int n, m, k, sum[100000];
map<int, int> ma;

int par[MAX_N], r[MAX_N];

void init(int x) {
    for (int i = 0; i < x; i++) par[i] = i;
}

int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (r[x] < r[y]) par[x] = y;
    else {
        if (r[x] == r[y]) r[x]++;
        par[y] = x;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    scanf("%d %d %d", &n, &m, &k);
    init(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        unite(a - 1, b - 1);
        sum[a - 1]++;
        sum[b - 1]++;
    }
    for (int i = 0; i < k; i++) {
        int c, d;
        scanf("%d %d", &c, &d);
        if (same(c - 1, d - 1)) {
            sum[c - 1]++;
            sum[d - 1]++;
        }
    }
    for (int i = 0; i < n; i++) ma[find(i)]++;
    for (int i = 0; i < n; i++) {
        printf("%d%c", ma[find(i)] - sum[i] - 1, i == n - 1 ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 6144
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 100010;

int a[Maxn];
bool b[Maxn];

int n, m;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    fill(a, a + n, 1);
    b[0] = true;
    while(m--){
        int x, y;
        cin >> x >> y;
        x--, y--;
        a[x]--, a[y]++;
        if (b[x]){
            b[y] = true;
            if (a[x] == 0) b[x] = false;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += b[i];
    }
    cout << ans << endl;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

long long int gcd(long long int a,long long int b){
    if(a<b){
        long long int tmp=a;
        a=b;
        b=tmp;
    }

    long long int r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

long long int lcm(long long int a,long long int b){
    long long int g = gcd(a,b);
    return (a/g)*b;
}


int main() {
    ll A,B,C,K;
    cin >> A >> B >> C >> K;

    if(K%2==0){
        pl(A-B)
    } else {
        pl(B-A)
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*

data class NodeValue(
  var x: Long = 0L,
  var v: Long = 0L
)

class Node {
  val value = NodeValue()
  val edges = mutableListOf<Int>()

  fun addEdge(to: Int) {
    edges.add(to)
  }
}

class Graph(N: Int) {
  private val nodes = Array(N) { Node() }

  fun addEdge(a: Int, b: Int) {
    nodes[a - 1].addEdge(b)
    nodes[b - 1].addEdge(a)
  }

  fun getNode(i: Int) = nodes[i - 1]
}

fun main() {
  val (N, Q) = readInts()
  val ab = (1 until N).map { readInts() }
  val px = (1..Q).map { readInts() }

  val g = Graph(N)
  ab.forEach { g.addEdge(it[0], it[1]) }
  px.forEach { g.getNode(it[0]).value.x += it[1] }

  val result = Array(N) { 0L }
  val queue = ArrayDeque<Triple<Int, Int, Long>>()
  queue.add(Triple(0, 1, 0L))
  while (queue.isNotEmpty()) {
    val (from, to, sum) = queue.pop()
    val node = g.getNode(to)
    node.value.v = sum + node.value.x
    result[to - 1] = node.value.v
    node.edges.filter { it != from }.forEach { queue.add(Triple(to, it, node.value.v)) }
  }

  println(result.joinToString(" "))
}

fun gcd(a: Int, b: Int): Int = if (a < b) gcd(b, a) else if (b == 0) a else gcd(b, a % b)
fun gcd(a: Long, b: Long): Long = if (a < b) gcd(b, a) else if (b == 0L) a else gcd(b, a % b)
fun lcm(a: Int, b: Int): Int = (a * b) / gcd(a, b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)

fun readString() = readLine()!!
fun readStrings() = readLine()!!.split(" ")
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readInts() = readLine()!!.split(" ").map { it.toInt() }
fun readLongs() = readLine()!!.split(" ").map { it.toLong() }


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

int main() {
  int N;
  cin >> N;
  
  vector<int> card(N);
  for (int i=0; i<N; i++) cin >> card.at(i);
  /*
  for (int i=0; i<N-1; i++){
    for (int j=N-1; j>i; j--){
      int tmp;
      if (card.at(j-1)<card.at(j)){
        tmp=card.at(j-1);
        card.at(j-1)=card.at(j);
        card.at(j)=tmp;
      }
    }
  }
  */
  sort (card.begin(),card.end(),greater<int>());
  int a=0,b=0;
  
  for (int i=0; i<N; i+=2) a+=card.at(i);
  for (int i=1; i<N; i+=2) b+=card.at(i);
  
  cout << a-b << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>

using namespace std;

#define LL long long
#define FOR(i,l,r) for(int i = l; i <= r; ++i)
#define REP(i,l,r) for(int i = l; i < r; ++i)

const int maxV = 1e6 + 1;
const int maxN = 2e5 + 123;
const LL MOD = 998244353;

int N;
LL w[maxV];
int A[maxN],D[maxV];
LL res = 0;

LL ABC(LL x){
    x %= MOD;
    return x < 0 ? x + MOD : x;
}
LL pow(LL x, LL y){
    if(y == 0) return 1;
    if(y == 1) return x;
    LL a = pow(x,y/2);
    a = (a * a) % MOD;
    return y % 2 == 0 ? a : (a * x) % MOD;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    //
    //freopen("L.INP","r",stdin);
    //freopen("L.OUT","w",stdout);

    cin >> N;
    int z = -1;
    FOR(i,1,N){
        cin >> A[i];
        ++D[A[i]];
        z = max(z,A[i]);
    }
    FOR(i,1,z) w[i] = pow(i,MOD - 2);
    
    FOR(i,1,z){
        for(int j = i * 2; j <= z; j += i) w[j] = ABC(w[j] - w[i]);
    }

    FOR(i,1,z){
        LL cur = 0,sum = 0;
        int t = 0;
        for(int j = i; j <= z; j += i){
            for(int k = 1; k <= D[j]; ++k){
                ++t;
                if(t > 1){
                    sum += ABC(cur * j);
                    sum %= MOD;
                }
                cur += j;
                cur %= MOD;
            }
        }
        res += ABC(sum * w[i]);
        res %= MOD;
    }

    cout << res;

    return 0;
}

Measured memory_bytes: 12800
NAB = input()
n_a_b = NAB.split(" ")
N = int(n_a_b[0])
A = int(n_a_b[1])#青
B = int(n_a_b[2])#赤
numOfAB = N//(A+B)
n = N - numOfAB*(A+B)#残りのボールの数
if (n - A) >= 0:
    print(numOfAB*A + A)
else:
    print(numOfAB*A + n)

Measured memory_bytes: 3060
import math
n,m = map(int, input().split())
factors = []
comp = m//n
for i in range(int(math.sqrt(m)),0,-1):
    if(m%i==0):
        factors.insert(0,i)
        factors.append(m//i)
for item in factors[::-1]:
    if (item <= comp):
        print(item)
        exit(0)

Measured memory_bytes: 3064
#include<iostream>
struct D{int a,b,c;};main(){int a,b,c,N,i,w,x,y,z,m[301];D t[1001];for(;std::cin>>a>>b>>c>>N,a;){for(i=301;i>0;)m[--i]=2;for(;N-->0;){std::cin>>w>>x>>y>>z;D d={w,x,y};if(z)m[w]=m[x]=m[y]=1;else t[i++]=d;}for(;i>0;){if((m[t[--i].a]&1)+(m[t[i].b]&1)+(m[t[i].c]&1)==2){m[t[i].a]&=1;m[t[i].b]&=1;m[t[i].c]&=1;}}for(;i++<a+b+c;)printf("%d\n",m[i]);}}

Measured memory_bytes: 0
#include <stdio.h>

int main()
{
    int n,query,p,x=0;
    int *A;
    scanf("%d",&n);
    A = malloc(sizeof(int)*n);
    
    for(int i=0;i<n;i++){
        scanf("%d",&query);
        switch(query){
            case 0:
                scanf("%d",&A[x]);
                x++;
                break;
            case 1:
                scanf("%d",&p);
                printf("%d\n",A[p]);
                break;
            case 2:
                A[x]=0;
                x--;
                break;
        }
    }
    
    free(A);
    return 0;
}



Measured memory_bytes: 2276
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
int main() {


	int n;
	std::cin >>n;
	if (n == 1) {
		std::cout << "Hello World" << std::endl;
	}
	else {
	int a;
	std::cin >> a;
	int b;
	std::cin >> b;

		std::cout << a + b << std::endl;

	}

return 0;
}

Measured memory_bytes: 256
N,M=list(map(int,input().split()))
H=[0]*N
H=list(map(int,input().split()))
A=[0]*M
B=[0]*M
road=[[0 for i in range(1)] for j in range(N)]
good=[0]*N
count=0

for i in range(M):
    A[i],B[i]=list(map(int,input().split()))
    road[A[i]-1].append(B[i]-1)
    road[B[i]-1].append(A[i]-1)
    if H[A[i]-1]<H[B[i]-1]:
        good[B[i]-1]+=1
        good[A[i]-1]+=-10000000
    elif H[B[i]-1]<H[A[i]-1]:
        good[B[i]-1]+=-10000000
        good[A[i]-1]+=1
    else:
        good[B[i]-1]+=-10000000
        good[A[i]-1]+=-10000000

for i in range(N):
    if 0<=good[i]:
        count+=1

print(count)

Measured memory_bytes: 40916
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    int i=0;
    while(1){
        if(N<pow(K,i)){
            cout << i << endl;
            return 0;
        }
        else{
            i++;
        }
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

int path[101][101];
int used[101][11];

void bfs(int s,int d,int n,int c){
	priority_queue<PP,vector<PP>,greater<PP> > que;
	que.push(PP(0,P(s,c)));
	used[s][c] = 0;

	while(!que.empty()){
		int cost = que.top().first;
		int src = que.top().second.first;
		int ticket = que.top().second.second;
		que.pop();

		for(int dst=1;dst<=n;dst++){
			if(used[dst][ticket] > cost + path[src][dst]){
				used[dst][ticket] = cost + path[src][dst];
				que.push(PP(cost + path[src][dst],P(dst,ticket)));
			}

			if(ticket > 0 && used[dst][ticket-1] > cost + path[src][dst]/2){
				used[dst][ticket-1] = cost + path[src][dst]/2;
				que.push(PP(cost + path[src][dst]/2,P(dst,ticket-1)));
			}
		}
	}
}

int main(){
	//c:number of tickets
	//n:number of towns
	//m:number of buses
	//s:source
	//d:destination
	int c,n,m,s,d;
	while(~scanf("%d %d %d %d %d",&c,&n,&m,&s,&d)){
		if(c==n && n==m && m==s && s==d && d==0) break;
		memset(path,0x3,sizeof(path));
		memset(used,0x3,sizeof(used));

		for(int i=0;i<m;i++){
			int a,b,f;
			scanf("%d %d %d",&a,&b,&f);
			path[a][b] = path[b][a] = min(path[a][b],f);
		}

		bfs(s,d,n,c);
		int res=numeric_limits<int>::max();
		for(int i=c;i>=0;i--) res = min(res,used[d][i]);
		printf("%d\n",res);
	}
}

Measured memory_bytes: 3200
#include <stdio.h>

bool vyymm(int a, int b) {
  return 1 <= b && b <= 12;
}

bool vmmyy(int a, int b) {
  return 1 <= a && a <= 12;
}

int main() {
  char t[10];
  int tt[10];
  scanf("%s", t);
  for (int i = 0; i < 4; i++) {
    tt[i] = t[i] - '0';
  }
  int a = tt[0] * 10 + tt[1];
  int b = tt[2] * 10 + tt[3];
  if (vyymm(a, b) && vmmyy(a, b)) {
    puts("AMBIGUOUS");
  } else if (vyymm(a, b)) {
    puts("YYMM");
  } else if (vmmyy(a, b)) {
    puts("MMYY");
  } else {
    puts("NA");
  }
  return 0;
}

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

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int main() {
  int N; scanf("%d", &N);
  int count[2]{0}, temp;
  for (int i{0}; i < N; ++i) {
    scanf("%d", &temp);
    ++count[temp & 1];
  }
  printf("%s\n", count[1] & 1 ? "NO" : "YES");
  return 0;
}


Measured memory_bytes: 256
a,b,c = map(int,input().split())
if a > b:
    tmp = a
    a = b
    b = tmp
if a > c:
    tmp = a
    a = c
    c = tmp
if b > c:
    tmp = b
    b = c
    c = tmp
print(int(str(c)+str(b))+int(a))

Measured memory_bytes: 3064
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
using namespace std;
typedef long long ll;
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	int r = 0;
	r += 100000 * max(0, 4 - a);
	r += 100000 * max(0, 4 - b);
	if (a == 1 && b == 1)r = 1000000;
	printf("%d\n", r);
}

Measured memory_bytes: 256
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#include <unordered_map>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
int n;
LL a[100005][3], dp[100005][3];
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	for (int i = 0; i < n; i++)
	{
		for(int j=0;j<3;j++)
			for (int b = 0; b < 3; b++)
			{
				if (j == b)
					continue;
				dp[i + 1][b] = max(dp[i + 1][b], dp[i][j] + a[i + 1][b]);
			}
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
	return 0;
}

/*



*/

Measured memory_bytes: 4992
#include<iostream>
#include<vector>

using LL = long long;

int N, A;
int x[51];
LL dp[51][51][2501];
LL ans;

int main() {
	for(int i=0;i<51;i++)dp[i][0][0] = 1;
	std::cin >> N >> A;
	for (int i = 1; i <= N; i++) {
		std::cin >> x[i];
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			for (int k = 0; k <= N * 50; k++) {
				if (x[i] > k) {
					dp[i][j][k] = dp[i - 1][j][k];
					continue;
				}
				if (x[i] <= k) {
					dp[i][j][k] = dp[i - 1][j - 1][k - x[i]] + dp[i - 1][j][k];
					continue;
				}
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		ans += dp[N][i][i*A];
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 50048
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
#define int long long
using ll = long long;
const ll mod = LLONG_MAX;


int x,y;
signed main(){

  cin>>x>>y;
  if(x>=y){
    if(x%y==0){
      cout<<-1<<endl;
    }else{
      cout<<x*(y-1)<<endl;
    }
  }else{
    if(y%x==0){
      cout<<(x)*(y-1)<<endl;
    }else{
      if(y%2!=0)cout<<x*2<<endl;
      else cout<<x*(y-1)<<endl;
    }
  }


}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
#include<cmath>
#define INF 

typedef long long ll;

int main() {
	std::string str;
	std::vector<int> ans;
	std::cin >> str;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] == '0') {
			ans.push_back(0);
		}
		else if (str[i] == '1') {
			ans.push_back(1);
		}
		else if (str[i] == 'B'&&ans.size()>0) {
			ans.pop_back();
		}
	}
	for (int i = 0; i < ans.size(); i++) {
		std::cout << ans[i];
	}
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 256
#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 ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
ll power(ll a,ll n)
{
    ll p;
    if(n==0)
    {
        return 1;
    }
    p=power(a,n/2);
    p=((p%mod)*(p%mod))%mod;
    if(n%2==1)
    {
        p=(p%mod)*(a%mod);
    }
    return p;
}
int main()
{
    fastIO;
    ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll x;
    cin>>x;
    cout<<a[x-1]<<endl;
}


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

using namespace std;
int main()
{
    int n,i;
    cin>>n;
    set<string> ar;
    string s;
    
    for(i=0; i<n; i++)
    {
        cin>>s;
        ar.insert(s);
    }
    cout<<ar.size();
    
}

Measured memory_bytes: 19236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,ans=0,x[100005],s,a,b;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>x[i];
    for(int i=1;i<n;i++){
		s=0,a=0,b=n-1;
		while(a<n-i){
			if(a==b||a-i==b)break;
			s+=x[a];
			s+=x[b];
			ans=max(ans,s);
			a+=i;
			b-=i;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
S = input()
T = input()

def canMake(left):
    for s, t in zip(S[left:], T):
        if s == '?':
            continue
        if s != t:
            return False
    return True

ans = []
for left in range(len(S) - len(T) + 1):
    if canMake(left):
        Z = S[: left] + T + S[left + len(T):]
        ans.append(Z.replace('?', 'a'))

if len(ans) == 0:
    ans.append('UNRESTORABLE')
ans.sort()
print(ans[0])

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include "atcoder/dsu"
using namespace std;
using namespace atcoder;
#define newl '\n'
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
typedef long long ll;
#define int ll

int32_t main() {
    int n,q; cin >> n >> q;
    dsu d(n);
    while(q--) {
        int t, u, v; cin >> t >> u >> v;
        if(t == 0 ) {
            d.merge(u, v);
        } else if(t == 1) {
            cout << d.same(u, v) << newl;
        }
    }
    return 0;
}




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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX = 100000;

int n, k;
ll T[MAX];

// 最大積載量Pのk台のトラックで何個の荷物を積めるか
int check(ll P){
    int i = 0;
    rep(j,k){
        ll s = 0;
        while(s + T[i] <= P){
            s += T[i];
            i++;    // iは積めた荷物の個数をカウントする変数
            if(i == n) return n;
        }
    }
    return i;
}

// 二分探索のアルゴリズムを用いて、
ll solve(){
    ll left = 0;
    ll right = 100000 * 10000;  // 荷物の個数　×　1個あたりの最大重量
    ll mid;
    while(right - left > 1){
        mid = (left + right) / 2;
        int v = check(mid);
        if(v >= n) right = mid;
        else left = mid;
    }
    return right;
}

int main()
{
    cin >> n >> k;    // 荷物の数n、トラックの数k
    rep(i,n) cin >> T[i];
    ll ans = solve();   // 写経するときはmain関数から、使用する関数が出現したときにその関数に移るというように実行順に書くと理解しやすい
    cout << ans << endl;
}


Measured memory_bytes: 3896
from functools import reduce
N = int(input())
T = []
for _ in range(N):
    T.append(int(input()))


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


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


x = reduce(lcm, T)
print(x)


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define LL long long
#define LD long double
#define VI vector<int>
#define VPII vector<PII>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define FOR(a,s,d) for (int a = (s); a <= (int)(d); ++a)
#define FORD(a,s,d) for (int a = (s); a >= (int)(d); --a)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(x) x.begin(), x.end()
#define siz(x) ((int)x.size())
#define Sim template <class s
Sim, class d> ostream & operator<<(ostream &os, pair<s,d> x){return os << "<" << x.f << ", " <<
  x.s << "> ";}
Sim> auto operator<<(ostream &os, s x) -> typename enable_if<!is_same<s,string>::value,
  decltype(x.begin(), os)>::type
{ int o = 0; os << "{"; for (auto c : x) {if(o++) os << ", "; os << c;}return os << "} ";}
void dor() {cerr << endl;}
Sim, class ...t> void dor(s x, t...y) {cerr << x << " "; dor(y...);}
#ifdef DEB
#define debug(c...) dor(__FUNCTION__, ":", __LINE__, ": ", c)
#else
#define debug(...)
#endif
const int M = 200;

struct qwe
{
  int x, y, z;
  qwe(int a, int b, int c) : x(a), y(b), z(c) {}
};

int dist[M][M][M];
bool vis[M][M][M];
int x[] = {1, 1, 0, 2, 0, 0};
int y[] = {1, 0, 1, 0, 2, 0};
int z[] = {0, 1, 1, 0, 0, 2};
queue<qwe> Q;

int main()
{
  //ios_base::sync_with_stdio(0);
  //cin.tie(0);
  for (int i = 0; i < M; i++)
  {
    for (int j = 0; j < M; j++)
    {
      for (int k = 0; k < M; k++)
      {
        dist[i][j][k] = 1000000;
      }
    }
  }
  for (int i = 0; i < M; i++)
  {
    dist[i][i][i] = 0;
    Q.push(qwe(i, i, i));
    vis[i][i][i] = true;
  }
  while (!Q.empty())
  {
    qwe a = Q.front();
    Q.pop();
    for (int i = 0; i < 6; i++)
    {
      qwe aa = qwe(a.x - x[i], a.y - y[i], a.z - z[i]);
      if (aa.x < 0 || aa.y < 0 || aa. z < 0)
      {
        continue;
      }
      if (!vis[aa.x][aa.y][aa.z])
      {
        dist[aa.x][aa.y][aa.z] = dist[a.x][a.y][a.z] + 1;
        vis[aa.x][aa.y][aa.z] = true;
        Q.push(aa);
      }
    }
  }
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  printf("%d\n", dist[a][b][c]);
  return 0;
}

Measured memory_bytes: 40320
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h, w;
		while(true){
			h = sc.nextInt();
			w = sc.nextInt();
			if(h==0 && w==0)break;
			if(h<=300 && w<=300){
				for(int i=0; i<h; i++){
					for(int j=0; j<w; j++){
						if(((i%2)==0 && (j%2)==0) || ((i%2)==1 && (j%2)==1)){
							System.out.print("#");
						} else{
							System.out.print(".");
						}
					}
					System.out.println();
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 26872
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(b/a,c) << endl;
    return 0;
    
}

Measured memory_bytes: 256
// ABC067 B - Snake Toy
#include <stdio.h>
#include <stdlib.h>

int comp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

// void printarray(int *arr, int n) {
//     for (int i = 0; i < n; i++) {
//         printf("%d, ", arr[i]);
//     }
//     printf("\n");
//     return;
// }


int main(void)
{
    int N, K;
    scanf("%d %d", &N, &K);
    int l[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &l[i]);
    }
    qsort(l, N, sizeof(int), comp);
    // printarray(l, N);
    int result = 0;
    for (int i = N - 1; i > N - K - 1; i--) {
        result += l[i];
    }
    printf("%d\n", result);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void) {
  int H,W;
  while(cin >> H >> W && H && W) {
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N;
  cin>>N;
  int x=N*800;
  int y=N/15*200;
  cout<<x-y<<endl;
  return 0;
}

Measured memory_bytes: 3600
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		boolean ans;

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int height = in.nextInt();
			int width = in.nextInt();
			char[][] s = new char[height][];
			for (int r = 0; r < height; r++) {
				s[r] = in.next().toCharArray();
			}
			ans = true;
			dfs(0, 0, s, height, width);
			for (int r = 0; r < height; r++) {
				for (int c = 0; c < width; c++) {
					if (s[r][c] == '#') {
						ans = false;
					}
				}
			}
			out.println(ans ? "Possible" : "Impossible");
		}

		private void dfs(int r, int c, char[][] s, int height, int width) {
			if (r >= height || c >= width) {
				return;
			}
			if (s[r][c] == '.') {
				return;
			}
			int x = 0;
			if (r + 1 < height && s[r + 1][c] == '#') {
				++x;
			}
			if (c + 1 < width && s[r][c + 1] == '#') {
				++x;
			}
			if (x > 1) {
				ans = false;
				return;
			}
			s[r][c] = '.';
			dfs(r + 1, c, s, height, width);
			dfs(r, c + 1, s, height, width);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



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

int main()
{
    int n, value, info[4][13];
    cin >> n;
    char suit;
    
    for(int i=0; i<4; ++i){
        for(int j=0; j<13; ++j){
            info[i][j] = 0;
        }
    }
    
    for(int i=0; i<n; ++i){
        cin >> suit >> value;
        if(suit=='S') info[0][value-1] = 1;
        else if(suit=='H') info[1][value-1] = 1;
        else if(suit=='C') info[2][value-1] = 1;
        else if(suit=='D') info[3][value-1] = 1;
    }
    
    for(int i=0; i<4; ++i){
        for(int j=0; j<13; ++j){
            if(info[i][j] == false){
                if(i == 0) cout << "S" << " " << j+1 << endl;
                else if(i == 1) cout << "H" << " " << j+1 << endl;
                else if(i == 2) cout << "C" << " " << j+1 << endl;
                else if(i == 3) cout << "D" << " " << j+1 << endl;
            }
        }
    }
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int counter1 = 0;
  int counter0 = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '0') {
      counter0 += 1;
    } else if (S.at(i) == '1') {
      counter1 += 1;
    }
  }

  cout << min(counter1, counter0) * 2 << endl;
};

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define in insert
#define sort(v) sort(v.begin(),v.end())
int main()
{ 
ll a,b,c,d,e,f,i,j,k,l=0;
string s,t;
    cin>>s>>t;
    for(i=0;i<s.size();i++)
   {if(s[i]!=t[i])l++;
  }
cout<<l<<endl;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  int N;
  cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  int n=0;
  int ans=0;
  for(int i=0;i<N-1;i++){
    n+=v[i];
    if(n*2<v[i+1])ans=i+1;
  }
  cout<<N-ans<<endl;
}


Measured memory_bytes: 1024
from collections import deque
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
p = sum(1 for a in A if a > 0)
if A[-1] > 0:
    print(sum(A[:-1]) - A[-1])
    k = A[-1]
    for a in A[:-2]:
        print(k, a)
        k -= a
    print(A[-2], k)

elif A[0] < 0:
    print(A[0] - sum(A[1:]))
    k = A[0]
    for a in A[1:]:
        print(k, a)
        k -= a
else:
    print(sum(abs(a) for a in A))
    A = deque(A)
    k = A.pop()
    for _ in range(p-1):
        t = A.popleft()
        print(k, t)
        k -= t
    t = A.popleft()
    print(t, k)
    t -= k
    for a in A:
        print(t, a)
        t -= a


Measured memory_bytes: 65692
#include "bits/stdc++.h"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define SIZE(a) int((a).size())

int main(){
  int n;cin>>n;double ans=0;
  rep(i,0,n){
    double x;string u;
    cin>>x>>u;
    if(u=="JPY"){ans+=x;}
    else{ans+=x*380000;}
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
S=input()

if S=="SUN":
    print(7)
if S=="MON":
    print(6)
if S=="TUE":
    print(5)
if S=="WED":
    print(4)
if S=="THU":
    print(3)
if S=="FRI":
    print(2)
if S=="SAT":
    print(1)


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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()

ll gcd(ll a, ll b);

ll sum(int n);

void go(){
   int a,b,c;cin>>a>>b>>c;
   int ans=c-(a-b);
   if(ans<0) cout << 0;
   else cout << ans;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

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

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()

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

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



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

    int n, m;
    cin >> n >> m;

    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));

    ll ans = 0;
    vector<P> d;
    rep(i, m){
        int b, c;
        cin >> b >> c;

        d.push_back(make_pair(c, b));
    }
    sort(d.rbegin(), d.rend());

    int j = 0;
    rep(i, n){
        if(d[j].second <= 0) j++;
        if(j >= m) break;
        if(a[i] < d[j].first){
            a[i] = d[j].first;
            d[j].second--;
        }
        //cout << a[i] << "\n";
    }

    rep(i, n){
        ans += a[i];
    }

    cout << ans << "\n";


    return 0;
}


Measured memory_bytes: 1784
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

typedef pair<ll, int> P;
#define fs first
#define sc second

ll INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    P p[N];
    for(int i = 0; i < N; i++){
        cin >> p[i].fs;
        p[i].sc = i;
    }

    sort(p, p + N, greater<P>());

    //大きい方からi個つかって、左に詰めたのがjこのときのスコアmax
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, -INF));
    dp[0][0] = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= i; j++) {
            //右に詰めた数
            int k = i - j;

            //左に詰める
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + p[i].fs * (p[i].sc - j));

            //右に詰める
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + p[i].fs * (N - k - 1 - p[i].sc));
        }
    }

    ll ans = 0;
    for(int j = 0; j <= N; j++) {
        ans = max(ans, dp[N][j]);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 34628
#include<stdio.h>
#define MAX 100000

int parent(int i){ return i/2; }
int left(int i){ return 2*i; }
int right(int i){ return (2*i)+1; }

int main(){
  int H, i, A[MAX+1];

  scanf("%d", &H);
  for( i = 1 ; i <= H ; i++ ){
    scanf("%d", &A[i]);
  }

  for( i = 1 ; i <= H ; i++ ){
    printf("node %d: key = %d, ", i, A[i]);
    if( A[parent(i)] != 0  ) printf("parent key = %d, ", A[parent(i)]);
    if( A[left(i)] != 0 ) printf("left key = %d, ", A[left(i)]);
    if( A[right(i)] != 0 ) printf("right key = %d, ", A[right(i)]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2104