akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>

using namespace std;

bool IsPrime(int a)
{
    bool flag=true;
    double b=sqrt(a);
    for(int i=2;i<=b;i++)
    {
        if(a%i==0)
        {
            flag=false;
            break;
        }
    }
    return flag;
}

int main()
{
    int n;

    int a,cnt=0;

    cin>>n;

    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(IsPrime(a))
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}



Measured memory_bytes: 3000
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0 

using namespace std;
using ll = long long;

void testcase() {
    int x[6];
    rep (i, 1, 5) cin >> x[i];

    rep (i, 1, 5) {
        if (x[i] == 0) {
            cout << i;
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main() {

  while( 1 ) {
    string s[3];
    cin >> s[0];
    if( s[0] == "0" ) break;
    cin >> s[1] >> s[2];

    for(int i=0; i<3; i++) {
      int p[2] = {0};
      for(int j=1; j<s[i].size(); j++) {
	if( s[i][j] == 'A' ) p[0]++;
	else p[1]++;
      }
      if( p[0] > p[1] ) p[0]++;
      else p[1]++;
      cout << p[0] << ' ' << p[1] << endl;
    }
  }
}

Measured memory_bytes: 1192
#include <stdio.h>

int main(void){
	int a = 0,to = 0,i;
	for(i = 0; i < 5; i++){
		scanf("%d", &a);
		if(a < 40){
			a = 40;
		}
		to += a;
	}
	printf("%d\n", to/5);
	return 0;
}

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

vector<vector<int>> Node;
vector<int> vs;
int ans;
int N, M;

void dfs(int v, int cnt, vector<int> vs)
{
	if (vs[v]) return;
	if (cnt == N-1) ans++;
	vs[v] = 1;
	for (auto t : Node[v]) dfs(t, cnt+1, vs);
}

int main()
{
	cin >> N >> M;
	Node.resize(N);
	vs.resize(N, 0);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--;	b--;
		Node[a].push_back(b);
		Node[b].push_back(a);
	}
	dfs(0, 0, vs);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <cctype>
#include <complex>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <typeinfo>
#include <unordered_set>
#include <unordered_map>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REPD(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define PB(e) push_back(e)
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define BIT(n, m) (((n) >> (m)) & 1)

typedef long long ll;

template <typename S, typename T> ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}

int main(int argc, char *argv[])
{
  int n, m;
  cin >> n >> m;
  vector<vector<int>> G(n);
  vector<vector<ll>> S(n);
  REP(i, m) {
    int u, v, s;
    cin >> u >> v >> s; 
    u--, v--;
    G[u].push_back(v);
    S[u].push_back(s);
    G[v].push_back(u);
    S[v].push_back(s);
  }

  vector<ll> values(n);
  vector<int> positive(n, -1);
  queue<int> que;
  que.push(0);
  values[0] = 0;
  positive[0] = 1;
  while (!que.empty()) {
    int v = que.front(); que.pop();
    REP(i, G[v].size()) {
      int w = G[v][i];
      if (positive[w] == -1) {
        positive[w] = !positive[v];
        values[w] = S[v][i] - values[v];
        que.push(w);
      }
    }
  }

  set<ll> candidates;
  REP(u, n) {
    REP(i, G[u].size()) {
      int v = G[u][i];
      ll s = S[u][i];
      if (values[u] + values[v] != s && (positive[u] != positive[v])) {
        cout << 0 << endl;
        return 0;
      }

      if (positive[u] == positive[v]) {
        ll rest = s - (values[u] + values[v]);
        // cout << s << " " << rest << " " << u << " " << v << endl;
        if (rest % 2 != 0) {
          cout << 0 << endl;
          return 0;
        } else if (positive[u]) {
          candidates.insert(rest / 2);
        } else if(!positive[u]) {
          candidates.insert((-rest) / 2);
        } else {
          cout << 0 << endl;
          return 0;
        }
      }
    }
  }
  
  ll min0 = 1;
  ll max0 = 1e18;
  REP(v, n) {
    if (positive[v]) {
      min0 = max(min0, 1 - values[v]);
    } else {
      max0 = min(max0, values[v] - 1);
    }
  }
  if (candidates.size() > 1) {
    cout << 0 << endl;
  } else if (candidates.size() == 0) {
    cout << max(0LL, max0 - min0 + 1) << endl;
  } else {
    ll v = *candidates.begin();
    if (min0 <= v && v <= max0) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 14012
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	vector<int> c(30);
	cin >> n;
	REP(i, n){
		vector<int> nc(30);
		string s;
		cin >> s;
		for(char c : s) nc[c - 'a'] ++;
		REP(j, 30){
			int x = (i == 0) ? 50 : c[j];
			c[j] = min(x, nc[j]);
		}
	}
	string ans = "";
	REP(i, 30) ans += string(c[i], 'a' + i);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline

class list2D:
    def __init__(self, H, W, num):
        self.__H = H
        self.__W = W
        self.__dat = [num] * (H * W)

    def __getitem__(self, a):
        return self.__dat[a[0]*self.__W+a[1]]

    def __setitem__(self, a, b):
        self.__dat[a[0]*self.__W+a[1]] = b

    def debug(self):
        print(self.__dat)

class list3D:
    def __init__(self, H, W, D, num):
        self.__H = H
        self.__W = W
        self.__D = D
        self.__dat = [num] * (H * W * D)

    def __getitem__(self, a):
        return self.__dat[a[0]*self.__W*self.__D+a[1]*self.__D + a[2]]

    def __setitem__(self, a, b):
        self.__dat[a[0]*self.__W*self.__D+a[1]*self.__D + a[2]] = b

    def debug(self):
        print(self.__dat)

def main():
    r,c,k=map(int,input().split())
    v = list2D(r, c, 0)

    for _ in range(k):
        ri,ci,a=map(int,input().split())
        v[ri-1, ci-1] = a

    dp = list3D(r, c, 4, 0)
    #print(dp)
    if v[0, 0]>0: dp[0, 0, 1]=v[0, 0]

    for i in range(r):
        for j in range(c):
            val = v[i, j]
            if i>0:
                x = max(dp[i-1, j, 0], dp[i-1, j, 1], dp[i-1, j, 2], dp[i-1, j, 3])
                dp[i, j, 1]=max(dp[i, j, 1],x+val)
                dp[i, j, 0]=max(dp[i, j, 0],x)

            if j>0:
                X = dp[i, j-1, 0]
                Y = dp[i, j-1, 1]
                V = dp[i, j-1, 2]
                Z = dp[i, j-1, 3]
                dp[i, j, 0]=max(dp[i, j, 0],X)
                dp[i, j, 1]=max(dp[i, j, 1],X+val,Y)
                dp[i, j, 2]=max(dp[i, j, 2],Y+val,V)
                dp[i, j, 3]=max(dp[i, j, 3],V+val,Z)

    #print(dp)
    ans=0
    for i in range(4): ans=max(dp[r-1, c-1, i],ans)
    return print(ans)
if __name__=="__main__":
    main()


Measured memory_bytes: 431624
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int i=0,j=n-1;
	int count=0;
	while(i<j){

		while(i<n && s[i]=='R')
			i++;
		while(j>=0 && s[j]=='W')
			j--;
		if(i<n && j>=0 && i<j)
			count++;
		i++,j--;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 3752
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    d={'A':'T','T':'A','G':'C','C':'G'}
    print(d[input()])

if __name__ == '__main__':
    main()


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

using namespace std;

int n;
char x[20];
map<string, int> m;
long long ans;

int main() {
	scanf("%d", &n);
	while (n--) {
		scanf("%s", x);
		sort(x, x + 10);
		ans += m[string(x)];
		m[string(x)]++;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 11136
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	int ans = 0;
	vector<int> xs(n), ys(n);
	for (int i = 0; i < n; i++)
	{
		cin >> xs[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> ys[i];
	}
	for (int i = 0; i < n; i++)
	{
		ans += max(0, xs[i] - ys[i]);
	}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
cout<<fixed<<setprecision(10);
int N,K;
string S;
  cin >>N>>K;
  
  cin>>S;
  S.at(K-1)=S.at(K-1)+0x20;
  cout <<S<<endl;
	
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

def main(A):
    ans = 1
    if 0 in A:
        return 0
    for a in A:
        ans *= a
        if ans > 10**18:
            return -1
    return ans

print(main(A))

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

int N, A, B, C, D;
string S;

void solve()
{
	A--,B--,C--,D--;
	bool ok = true;
	for(int i=A+1; ok && i<=C;++i){
	    if(S[i]=='#' && S[i-1]=='#') ok = false;
	}
	for(int i=B+1; ok && i<=D;++i){
		if(S[i]=='#' && S[i-1]=='#') ok = false;
	}
	if(ok && C>D){ //must contain 3 spaces or both B-1 and B+1 are spaces
		if(!(S[B-1] == '.' && S[B+1] == '.')){
			bool f = false;
			for(int i=B; !f && i<=D; ++i){
				if(S[i]=='.'&&S[i-1]=='.'&&S[i+1]=='.'){
					f = true;
				}
			}
			ok = f;
		}			
	}
	if(ok) cout << "Yes\n";
	else cout << "No\n";
}

int main()
{
	cin >> N >> A >> B >> C >> D;
	cin >> S;
	solve();
	return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
N = int(input())
X = [[] for _ in range(N)]
P = [-1] * N
for i in range(N-1):
    a, b = map(int, input().split())
    X[a-1].append((i, b-1))
    #print(X)
    #P[b-1] = a-1
#print(X)

Q = [(0, -1)]
ANS = [-1] * (N-1)
maxc = 0
while Q:
    x, c0 = Q.pop()
    c = 1
    for i, y in X[x]:
        if c == c0: c += 1
        ANS[i] = c
        if c>maxc:maxc=c
        Q.append((y, c))
        c += 1

print(maxc)
for ans in ANS:
    print(ans)

Measured memory_bytes: 27732
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    if a[i]>=b[i]:
        ans+=b[i]
    elif a[i]<b[i]:
        if a[i+1]>=b[i]-a[i]:
            ans+=b[i]
            a[i+1]-=b[i]-a[i]
        elif a[i+1]<b[i]-a[i]:
            ans+=a[i]+a[i+1]
            a[i+1]=0

print(ans)


Measured memory_bytes: 82020
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    P ai[n];
    rep(i, n){
        int a; cin >> a;
        ai[i] = {a, i+1};
    }

    sort(ai, ai+n);

    rep(i, n){
        cout << ai[i].second << " ";
    }

    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
class Solve{
public:
  int numTriangles(vector<int>& v){
    sort(v.begin(), v.end());
    int res = 0, len = (int)v.size();
    for(int a = 0; a < len; ++a){
      for(int b = a + 1; b < len; ++b){
        res += lower_bound(v.begin(), v.end(), v[a] + v[b]) - (v.begin() + b + 1);
      }
    }
    return res;
  }
};
int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  for(auto& e : v) cin >> e;
  std::cout << Solve().numTriangles(v) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	deque<int> qu;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if(i % 2 == 0) qu.push_back(a);
		else qu.push_front(a);
	}
	if(n % 2 == 0){
		for(int i = 0; i < n; i++){
			cout << qu[i];
			if(i == n - 1) cout << endl;
			else cout << " ";
		}
	} else {
		for(int i = n - 1; i >= 0; i--){
			cout << qu[i];
			if(i == 0) cout << endl;
			else cout << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 2944
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

ans = 0
hist = []
for _t in t:
    h = ""
    if len(hist) >= k:
        h = hist.pop(0)

    if _t == "r" and h != "p":
        ans += p
        hist.append("p")
    elif _t == "s" and h != "r":
        ans += r
        hist.append("r")
    elif _t == "p" and h != "s":
        ans += s
        hist.append("s")
    else:
        hist.append("")

print(ans)


Measured memory_bytes: 3956
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#define inf 0x3f3f3f3f
#define LL long long

using namespace std;

int f(int n)
{
    if (n<2)
    {
        return 0;
    }
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            return 0;
        }
    }
    return 1;
}
int num[100005];

int main()
{
    num[1]=0;
    for(int i=2;i<=100001;i++)
    {
        if(f(i)&&f((i+1)/2)) num[i]+=num[i-1]+1;
        else num[i]=num[i-1];
    }
    int q;
    int l,r;
    scanf("%d",&q);
    while(q--)
    {
        scanf("%d%d",&l,&r);
        int ans=0;
        if(f(l)&&f((l+1)/2)) ans=1;
        printf("%d\n",ans+num[r]-num[l]);
    }
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	double f=0;
	int a,b,i,c=0,x[1000];
	scanf("%d %d",&a,&b);
	for(i=0;i<a;i++){
		scanf("%d",&x[i]);
		f=f+x[i];
	}
	for(i=0;i<a;i++){
		if(x[i]>=f/4/b){
			c++;
		}
	}
	if(c>=b){
		printf("Yes\n");
	}
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 1652
n,k = gets.split.map(&:to_i)
face = gets.chomp.split("")
happy = 0
count = 0
for i in 1..n-1
  if face[i] == face[i-1]
    happy += 1
  else face[i] == "L" && face[i-1] == "R"
    count += 1
  end
end
if k*2 < count
  happy += k*2
else
  happy += count
end

puts happy


Measured memory_bytes: 9468
import numpy as np

X,Y = map(int, input().split())

A = np.array([1, 1, 4, 2]).reshape(2, 2)
v = np.array([X, Y]).reshape(2, 1)

u = np.dot(np.linalg.inv(A),v)

if u[0] < 0 or u[1] < 0:
    print("No")
elif np.linalg.norm(u - (u//1)) > 0.1:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 27644
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[110];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	int ans=0;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			for(int k=j+1;k<N;k++){
				if(A[i]+A[j]>A[k]&&A[i]+A[k]>A[j]&&A[k]+A[j]>A[i]&&A[i]!=A[j]&&A[j]!=A[k]&&A[i]!=A[k]){
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<queue>
using namespace std;
const int inf=2147483647;
int abs(int x){return x>0?x:-x;}
int h[100010],nex[200010],to[200010],M;
void add(int a,int b){
	M++;
	to[M]=b;
	nex[M]=h[a];
	h[a]=M;
}
int v[100010];
struct cmp{
	bool operator()(int x,int y){return v[x]<v[y];}
};
priority_queue<int,vector<int>,cmp>q;
int main(){
	int n,m,i,x,y,head,tail;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	for(i=1;i<=n;i++)v[i]=inf;
	scanf("%d",&m);
	head=1;
	tail=0;
	while(m--){
		scanf("%d%d",&x,&y);
		v[x]=y;
		q.push(x);
	}
	while(!q.empty()){
		x=q.top();
		q.pop();
		for(i=h[x];i;i=nex[i]){
			if(v[to[i]]!=inf){
				if(abs(v[x]-v[to[i]])!=1){
					puts("No");
					return 0;
				}
			}else{
				v[to[i]]=v[x]-1;
				q.push(to[i]);
			}
		}
	}
	puts("Yes");
	for(i=1;i<=n;i++)printf("%d\n",v[i]);
}

Measured memory_bytes: 3832
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static long[] prime;
	static int n;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO ツ篠ゥツ督ョツ青カツ青ャツつウツづェツつスツδソツッツドツ・ツスツタツブ
		while(read()){
			slove();
		}
	}
	static boolean read(){
		if(!sc.hasNextInt())
			return false;
		n = sc.nextInt();
		return true;
	}
	static void Prime(int a){
		prime = new long[a+1];
		for(int i = 1; i < prime.length; i++)
			prime[i] = 1;
		
		for(long i = 2; i < prime.length; i++){
			if(prime[(int) i] == 1){
				for(long j = i; i*j < prime.length; j++)
				prime[(int) (i*j)] = 0;	
			}
		}
	}
	
	static void slove(){
		int count = 0;
		Prime(n);
		for(int i = 2; i < prime.length; i++){
			if(prime[i] == 1)
				count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 28000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int h, n;
  cin >> h >> n;
  vi a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  vi dp(h + 1, 1e9);
  dp[0] = 0;
  rep(i, n) rep(j, h) dp[min(h, j + a[i])] =
      min(dp[min(h, j + a[i])], dp[j] + b[i]);
  cout << dp[h] << endl;
}

Measured memory_bytes: 256
import math
a,b,h,m=map(int,input().split())
h=360*(h/12)+360*(1/12)*(m/60)
m=360*(m/60)
angle=abs(h-m)
if angle>=180:
  angle=360-angle
ans=math.sqrt(a**2+b**2-(2*a*b*math.cos(math.radians(angle))))
print(ans)

Measured memory_bytes: 9508
import numpy as np
from scipy import signal
H, W = list(map(int, input().split()))
com = np.full((1,W),'#')
Mat = np.zeros((H,W))
MAP = np.empty((H,W),int)
mask = [[1,1,1],
        [1,0,1],
        [1,1,1]]
for i in range(H):
    Mat[i] = list(input())==com

MAP = signal.convolve2d(Mat,mask,'same')
outMAP = np.where(Mat,'#',MAP.astype('int'))

for j in outMAP:print(*j,sep='')
# print(MAP)

Measured memory_bytes: 60420
#include<iostream>
#include<iostream>
#include <algorithm>
#include <cstdlib>
#include<string>
using namespace std;
int main(){
  int n[5];
  for(int i=0;i<5;i++){
    cin >> n[i];
  }
  if (n[0]>=n[2]+n[4] && 0<=n[2]-n[4] && n[1]>=n[3]+n[4] && 0<=n[3]-n[4]){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3096
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

double a[6];

void solve(){
	double x,y;
	double c[2];
	c[0]=(a[0]+a[2])/2.0;
	c[1]=(a[1]+a[3])/2.0;
	
	double l1[2], k1[2];
	k1[0]=-(a[3]-a[1]);
	k1[1]=(a[2]-a[0]);
	
	double d[2];
	d[0]=(a[4]+a[2])/2.0;
	d[1]=(a[5]+a[3])/2.0;
	
	double l2[2], k2[2];
	k2[0]=-(a[3]-a[5]);
	k2[1]=(a[2]-a[4]);
	
	if(k1[0]==0){
		x=c[0];
		l2[0]=k2[1]/k2[0];
		l2[1]=-l2[0]*d[0]+d[1];
		y=l2[0]*x+l2[1];
		
	}
	else if(k2[0]==0){
		x=d[0];
		l1[0]=k1[1]/k1[0];
		l1[1]=-l1[0]*c[0]+c[1];
		y=l1[0]*x+l1[1];
	}
	else{
		l1[0]=k1[1]/k1[0];
		l1[1]=-l1[0]*c[0]+c[1];
		
		l2[0]=k2[1]/k2[0];
		l2[1]=-l2[0]*d[0]+d[1];
		
		x=-(l2[1]-l1[1])/(l2[0]-l1[0]);
		y=l1[0]*x+l1[1];
	}
	double r=sqrt((x-a[0])*(x-a[0])+(y-a[1])*(y-a[1]));
	
	printf("%.3f %.3f %.3f\n",x,y,r);
}

int main(){
	li n;
	cin>>n;
	
	rin{
		rep(j,6)cin>>a[j];
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL L;
LL ans1(vector<LL> a){
	sort(a.begin(), a.end());
	int n = a.size();
	vector<LL> psums(n+1);
	psums[0] = 0;
	for(int i = 1; i <= n; i++){
		psums[i] = psums[i-1] + a[i-1];
	}
	LL best = 0;
	for(int q = 0; q < 2; q++){
		for(int cut = 0; cut <= n; cut++){
			int n1 = cut + 1;
			if(q == 0){
				n1 = min(n1, (n - (cut+1) ));
			} else {
				n1 = min(n1, 1 + (n - (cut+1) ));				
			}
			int n2 = n1;
			if(q) n2--;
			if(n1 <= 0) continue;
			//cout << cut << " " << q << " " << n1 << " " << n2 << endl;
			LL z = 0;
			z += (psums[cut+1] - psums[cut + 1 - n1]) * 2;
			z += (L * n2 - (psums[cut+1+n2] - psums[cut+1]) )* 2;
			if(n1 == n2){
				z -= (L - a[cut+1]);
				best = max(best, z);
			} else {
				z -= a[cut];
				best = max(best, z);
			}
			//cout << best << endl;
		}
	}
	return best;
}

int main(){
	cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> L;
	int n;
	cin >> n;
	vector<LL> a(n);
	vector<LL> b(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		b[i] = L - a[i];
	}
	LL ans = max(ans1(a), ans1(b));
	cout << ans << endl;
}

Measured memory_bytes: 8036
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

/**
 * The Number of Island
 */
public class Main {

	final static int LAND = 1;
	final static int VISITED = -1;

	final static int[] V = { 1, -1, 0, 0 };
	final static int[] H = { 0, 0, 1, -1 };

	static Queue<Integer> xs, ys;
	static int count;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (true) {

			// load map
			int[][] map = new int[14][14];
			xs = new ArrayDeque<Integer>();
			ys = new ArrayDeque<Integer>();

			for (int i = 1; i < 13; i++) {
				line = br.readLine();
				for (int j = 1; j < 13; j++) {
					map[i][j] = line.charAt(j - 1) - '0';
				}
			}

			// solve
			count = 0;
			for (int i = 1; i < 13; i++) {
				for (int j = 1; j < 13; j++) {
					if (map[i][j] == LAND) {
						xs.add(i);
						ys.add(j);
						while (!xs.isEmpty() && !ys.isEmpty()) {
							visit(map);
						}
						count++;
					}
				}
			}

			// output.
			System.out.println(count);

			// next map
			line = br.readLine();
			if (line == null) {
				break;
			} else {
				continue;
			}
		}
		//
	}

	public static void visit(int[][] map) {

		int x, y;
		x = xs.remove();
		y = ys.remove();

		map[x][y] = VISITED;

		// next choices
		for (int i = 0; i < 4; i++) {
			int xv, yh;
			xv = x + V[i];
			yh = y + H[i];
			// if (xv >= 0 && xv < 12 && yh >= 0 && yh < 12 && map[xv][yh] ==
			// LAND) {
			if (map[xv][yh] == LAND) {
				xs.add(xv);
				ys.add(yh);
			}
		}
	}
}

Measured memory_bytes: 37508
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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 h,w;
    cin>>h>>w;
    int a[h][w];
    rep(i,h){
        rep(j,w){
            cin>>a[i][j];
        }
    }
    /*
    →→→→↓
    →→→→↓
    って感じに、奇数なら動かす。偶数なら放置を繰り返せば？？
    こうすれば奇数になるの可能性があるのは最後のマスのみ
    0のやつから移動することもないし完璧じゃん
     */
    vector<pair<int,int>> ans1,ans2;
    for(int i=0;i<h;i++){
        for(int j=0;j<w-1;j++){
            if(a[i][j]%2==1){
                ans1.push_back(make_pair(i,j));
                ans2.push_back(make_pair(i,j+1));
                a[i][j+1]++;
            }
        }
    }
    for(int i=0;i<h-1;i++){
        if(a[i][w-1]%2==1){
            ans1.push_back(make_pair(i,w-1));
            ans2.push_back(make_pair(i+1,w-1));
            a[i+1][w-1]++;
        }
    }

    cout<<ans1.size()<<endl;
    rep(i,ans1.size()){
        cout<<ans1[i].first+1<<' '<<ans1[i].second+1<<' '<<ans2[i].first+1<<' '<<ans2[i].second+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 5228
n,m = list(map(int, input().split()))
wa = [0] * (n + 1)
ac = [0] * (n + 1)
for _ in range(m):
    p,s = input().split()
    p = int(p)
    if s == 'WA' and ac[p] == 0:
        wa[p] += 1
    elif s == 'AC':
        ac[p] = 1

for i,ok in enumerate(ac):
    if not ok:
        wa[i] = 0

print('{} {}'.format(sum(ac), sum(wa)))


Measured memory_bytes: 10452
#include <iostream>

int main()
{
    std::size_t n;
    std::cin >> n;
    unsigned long long curT = 1, curA = 1;
    for(std::size_t i = 0; i != n; i++)
    {
        unsigned long long t, a;
        std::cin >> t >> a;
        unsigned long long base = 1 + std::max((curT - 1) / t, (curA - 1) / a);
        curT = t * base;
        curA = a * base;
    }
    std::cout << curT + curA << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main() {
	int k, a, b;
	cin >> k >> a >> b;
	for (;a <= b;a++) {
		if (a % k == 0) {
			cout << "OK" << endl;goto t;
		}
	}
	cout << "NG" << endl;
	t:
	return 0;
}

Measured memory_bytes: 3568
#include <stdio.h>
#define NUM 100

//	最大値を探す関数
int max(int data[], int n) {
	int max = 0;
	for (int i = 0; i < n; i++) {
		if (max < data[i]) { max = data[i]; }
	}
	return max;
}

int min(int data[], int n) {
	int min = 1000;
	for (int i = 0; i < n; i++) {
		if (min > data[i]) { min = data[i]; }
	}
	return min;
}

int main() {

	int n;
	int s[NUM];
	int i;
	int sum;

	while (1) {
		
		//	合計値を初期化
		sum = 0;

		//	審判員の数を入力
		scanf("%d", &n);

		//	0が入力されたらbreak
		if (n == 0) { break; }

		//	審判員の数だけ得点を入力
		//	合計値を計算
		for (i = 0; i < n; i++) {
			scanf("%d", &s[i]);
			sum += s[i];

		}

		//	最大値と最小値を引く
//		sum -= max(data, n) + min(data, n);
		sum = sum - max(s, n);
		sum = sum - min(s, n);

		//	平均を出す
		sum = sum / (n-2);

		//	出力
		printf("%d\n", sum);
	}


}


Measured memory_bytes: 2032
#include<iostream>
#include<cmath>
#include<algorithm>

int main(){
  std::string s,t,result;
  std::cin >> s >> t;
  int DP[3001][3001];

  for(int i=0;i<(int)s.length();i++)
    DP[i][0]=0;
  for(int i=0;i<(int)t.length();i++)
    DP[0][i]=0;

  for(int i=1;i<=(int)s.length();i++){
    for(int j=1;j<=(int)t.length();j++){
      if(s[i-1]==t[j-1])
        DP[i][j]=DP[i-1][j-1]+1;
      else
        DP[i][j]=std::max(DP[i-1][j],DP[i][j-1]);
    }
  }
  int i=s.length(),j=t.length();
  while(i!=0&&j!=0){
    if(s[i-1]==t[j-1]){
      result = s[i-1] + result;
      i--;j--;
    }
    else
      if(DP[i][j]==DP[i-1][j])
        i=i-1;
      else
        j=j-1;

  }
  std::cout << result;
  return 0;
}


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

int n,a,b;

int main(){
  cin>>n>>a>>b;
  
  if( n*a > b){
    cout<<b<<endl;
  }
  
  else if ( n*a < b){
    cout<<n*a<<endl;
  }
  
  else{
    cout<<b<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

long long int series_sum(long long int n){
    return n*(n+1)/2;
}

int main(){
    ll n;
    in(n);
    ll i=0;
    for(i=0;series_sum(i)<n;i++){}
    out(i);
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  double r;
  cin >> r;
  cout << setprecision(20) << 2 * r * M_PI << endl;
  return 0;
}


Measured memory_bytes: 3784
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, accumulate
from operator import itemgetter, mul
from copy import deepcopy
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

x1, y1, x2, y2 = MAP()

a = x2 - x1
b = y2 - y1

x3, y3 = x2 - b, y2 + a
x4, y4 = x3 - a, y3 - b

print(x3, y3, x4, y4)


Measured memory_bytes: 5388
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

char ch;
LL a[55][55],b[55][55],cnt = 0;

int main(){
	LL h,w,k;
	cin >> h >> w >> k;
	for(LL i = 0;i < h;i ++){
		for(LL j = 0;j < w;j ++){
			cin >> ch;
			a[i][j] = (ch == '#' ? 1 : 0);
		}
	}
	for(LL si = 0;si < (1LL << h);si ++){
		for(LL sj = 0;sj < (1LL << w);sj ++){
			LL sum = 0;
			for(LL i = 0;i < h;i ++){
				for(LL j = 0;j < w;j ++){
					b[i][j] = a[i][j];
					if(((si >> i) & 1) || ((sj >> j) & 1)) b[i][j] = 0;
					sum += b[i][j];
				}
			}
			if(sum == k) cnt ++;
		}
	}
	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(void)
{
    int a,b,c,i,count=0;
    scanf("%d %d %d",&a,&b,&c);
    for(i=a;i<=b;i++){
        if((c%i)==0) count++;
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int X = scan.nextInt();
        int Y = scan.nextInt();
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        List<Long> p = new ArrayList<>();
        List<Long> q = new ArrayList<>();
        List<Long> r = new ArrayList<>();
        for (int i = 0; i < A; i++) {
            p.add(scan.nextLong());
        }
        for (int i = 0; i < B; i++) {
            q.add(scan.nextLong());
        }
        for (int i = 0; i < C; i++) {
            r.add(scan.nextLong());
        }
        p.sort(Comparator.naturalOrder());
        q.sort(Comparator.naturalOrder());
        r.sort(Comparator.reverseOrder());
        long[] one = new long[X+1];
        long[] two = new long[Y+1];
        for (int i = A - X; i < A; i++) {
            one[i - (A - X)] = p.get(i);
        }
        one[X] = Long.MAX_VALUE;
        for (int i = B - Y; i < B; i++) {
            two[i - (B - Y)] = q.get(i);
        }
        two[Y] = Long.MAX_VALUE;
        int one_l = 0;
        int two_l = 0;
        for (long target : r) {
            if (one[one_l] <= two[two_l]) {
                if (target <= one[one_l]) {
                    continue;
                }
                one[one_l] = target;
                one_l += 1;
                continue;
            }
            if (target <= two[two_l]) {
                continue;
            }
            two[two_l] = target;
            two_l += 1;
            continue;
        }
        one[X] = 0;
        two[Y] = 0;
        long ans = Arrays.stream(one).sum() + Arrays.stream(two).sum();

        System.out.println(ans);
    }
}


Measured memory_bytes: 102500
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define pb push_back
#define PI 3.14159265
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  vector<int> p;
  p.push_back(1);
  int sum = 1;
  int cnt = 2;
  while (sum < n)
  {
    p.push_back(cnt);
    sum += cnt;
  }
  int val = p.back();
  sum -= val;
  int max = n - 1;
  p.pop_back();
  p.push_back(max - sum);
  int ans = 0;
  for (int i = 0; i < p.size(); ++i)
  {
    ans += p[i] * a[i];
  }
  cout << ans;

}


Measured memory_bytes: 5848
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val s = sc.next()
    println(problem138a(a, s))
}

fun problem138a(a: Int, s: String): String {
    return if (a >= 3200) s else "red"
}

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


int main() {
    int a,b,ans=0,tap=1;
    cin>>a>>b;
    while(tap<b){
        tap+=a-1;
        ans++;
    }
    cout << ans <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
int n,temp,sum=0,m;
cin>>m>>n;
int k[m];
for(int i=1;i<=m ; i++){
    cin>>k[i];
}
for(int i=1;i<=m;i++){
    for(int j=1;j<=m;j++){
        if(k[i]<k[j]){
            temp=k[i];
            k[i]=k[j];
            k[j]=temp;

        }
    }
}
for(int i=1;i<=n ; i++){
    sum+=k[i];
}
cout<<sum;
}




Measured memory_bytes: 3152
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M 1000000007
#define rep(i,b)  for(int i=0;i<(int)(b);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
typedef long long ll;
typedef long double ld;

using namespace std;
ll power(ll a,ll b){
    ll t=1;
    while(b) {
        if(b&1) t=(t*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    return t;
}
int main(){
    cs
    ll n,k,ans=0;cin>>n>>k;
    vector<ll> v(k+1);
    Repp(i,k,1) {
        v[i]=power(k/i,n);
        for(int j=i*2;j<=k;j+=i) v[i]-=v[j];
    }
    repp(i,1,k) {ans+=v[i]*i;ans%=M;}
    cout<<ans;
}

Measured memory_bytes: 3980
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int A,B;
    cin >> A >> B;
    
    int cnt = 0,tap = 1;
    for(int i=0;i<=100;i++){
        if(tap>=B){
            cout << cnt << endl;
            return 0;
        }else{
            tap += A-1;
            cnt++;
        }
    }
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    while(1){
    int l,k;
    cin >> l >> k;
        if(l == 0, k == 0)break;
        for ( int i = 0; i < l; i++ ){
            for ( int j = 0; j < k; j++ ){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include <stdio.h>
int main(){
    int x,y,z,n,Y;
    scanf("%d %d",&n,&Y);
    for(x=0;x<=n;x++){
        for(y=0;y<=n-x;y++){
            for(z=0;z<=n-x-y;z++){
            if(((10*x+5*y+z)==(Y/1000))&&(x+y+z==n)){
          printf("%d %d %d",x,y,z);
          return 0;
        }
            }
        }
    }
    printf("-1 -1 -1");
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main(){
    int n,maxstep = 0,step = 0;
    cin>>n;
    vector<int> h(n);
    rep(i,n){
        cin>>h[i];
        if(i==0) continue;

        if(h[i] > h[i-1]){
            maxstep = max(step,maxstep);
            step=0;
        }
        else if(h[i] < h[i-1]){
            step++;
        }
        else if(h[i] == h[i-1]) step++;
    }
    maxstep = max(step,maxstep);
    cout<<maxstep<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    LL N, M;
    cin >> N >> M;
    if (N == 1 && M == 1) cout << 1 << endl;
    else if (N == 1) cout << M - 2 << endl;
    else if (M == 1) cout << N - 2 << endl;
    else {
        cout << (M - 2) * (N - 2) << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>

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

int main(){
    ll a, b;
    cin >> a >> b;
    set<ll> st;
    st.insert(1);
    map<ll, bool> mp; 
    ll a_tmp = a;
    ll b_tmp = b;
    for ( ll i = 2; i * i <= a_tmp; ++i ) {
        if ( a % i == 0 ) {
            mp[i] = true;
        }
        while(1) {
            if ( a % i != 0 ) {
                break;
            }
            a /= i;
        }
    }
    if ( a != 1 ) {
        mp[a] = true;
    }
    for ( ll i = 2; i * i <= b_tmp; ++i ) {
        if ( b % i == 0 && mp[i] ) {
            st.insert(i);
        }
        while(1) {
            if ( b % i != 0 ) {
                break;
            }
            b /= i;
        }
    }
    if ( b != 1 ) {
        if ( mp[b] ) {
            st.insert(b);
        }
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    string s;
    cin >> s;
    if(s=="ARC"){
        cout << "ABC" << endl;
    }else{
        cout << "ARC" << endl;
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define f1(a,b,c) for(int c=a;c<=b;c++)
#define f2(a,b,c) for(int c=a;c>=b;c--)
#define f3(a,b,c) for(int c=a;c;c=b)
#define so1(a,n) sort(a+1,a+n+1,mycmp);
#define so2(a,n) sort(a+1,a+n+1);
#define re(a,n) reverse(a+1,a+n+1);
#define ll long long
#define itn int
#define ubt int 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
const int twx=2e5+100;
const int inf=0x3f3f3f3f;
ll read()
{
    ll sum=0;
    ll flag=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            flag=-1;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        sum=((sum*10)+c-'0');
        c=getchar();
    }
    return sum*flag;
}
int n;
int a[twx];
int l[twx];
int r[twx];
ll ans=0;
int pos[twx];
void init()
{
	n=read();
    r[0]=1;
    l[n+1]=n;
    f1(1,n,i)
    {
        int x=read();
        l[i]=i-1;
        r[i]=i+1;
        pos[x]=i;
    }
}
void work()
{
    f2(n,1,i)
    {
        ans+=1LL*i*(pos[i]-l[pos[i]])*(r[pos[i]]-pos[i]);
        r[l[pos[i]]]=r[pos[i]];
		l[r[pos[i]]]=l[pos[i]];
    }
}
void print()
{
	printf("%lld\n",ans);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	init();
    work();
    print();
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    
    vector<int> ans(N);
    for (int i = 0; i < N; i++) ans[i] = 0;
    
    for (int i = N; i > 0; i--) {
        int sum = 0;
        for (int j = i; j <= N; j += i) {
            sum += ans[j-1];
        }
        if (sum % 2 != a[i-1]) ans[i-1] = 1;
    }
    
    int M = 0;
    for (int i = 0; i < N; i++) if (ans[i] == 1) M++;
    cout << M << endl;
    for (int i = 0; i < N; i++) if (ans[i] == 1) cout << i + 1 << " "; 
}


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> P(N), Q(N);
    for(auto& i : P)cin >> i;
    for(auto& i : Q)cin >> i;
    if(P > Q)swap(P, Q);
    unsigned long ans{0};
    while(!equal(P.begin(), P.end(), Q.begin())){
        next_permutation(P.begin(), P.end());
        ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (int argc, char * argv[])
{
    int m;//中間試験の点数
    int f;//期末試験の点数
    int r;//再試験の点数
    
    int sum;//中間試験と期末テストと再試験の合計
   
    while(1){
        scanf("%d %d %d",&m,&f,&r);
        if(m==-1&f==-1&&r==-1){
            break;
        }
        
          sum = m+f;
        if(m==-1||f==-1){
            printf("F\n");
        }else if(80<=sum){
            printf("A\n");
        }else if(65<=sum && sum<80){
            printf("B\n");
        }else if(50<=sum && sum<65){
            printf("C\n");
        }else if(30<=sum && sum<50){
            if(50<=r){
                printf("C\n");
            }else {
                printf("D\n");
            }
        }else if(sum<30){
            printf("F\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

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

int main() {
    int a, b;
    cin >> a >> b;

    cout << (a + b + 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256