akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
const int dy[] = { -1, 1, 0, 0 };
const int dx[] = { 0, 0, 1, -1 };
struct point_t { int y, x; };
const int inf = 1e9+7;

int main() {
    // input
    int h, w, k; scanf("%d%d%d", &h, &w, &k);
    auto closed = vectors(h, w, bool());
    point_t start;
    repeat (y,h) repeat (x,w) {
        char c; scanf(" %c", &c);
        closed[y][x] = c == '#';
        if (c == 'S') {
            start.y = y;
            start.x = x;
        }
    }
    // solve
    point_t goal = { -1, -1 };
    auto is_on_field = [&](int y, int x) { return 0 <= y and y < h and 0 <= x and x < w; };
    auto is_goal = [&](int y, int x) { return y == 0 or y == h-1 or x == 0 or x == w-1; };
    auto dist = vectors(h, w, inf);
    { // // dfs
        queue<point_t> que;
        dist[start.y][start.x] = 0;
        que.push(start);
        while (not que.empty()) {
            point_t p = que.front(); que.pop();
            if (is_goal(p.y, p.x)) {
                goal = p;
                break;
            }
            if (dist[p.y][p.x] == k) continue;
            repeat (i,4) {
                point_t q = p;
                q.y += dy[i];
                q.x += dx[i];
                if (not is_on_field(q.y, q.x)) continue;
                if (closed[q.y][q.x]) continue;
                if (dist[q.y][q.x] <= dist[p.y][p.x] + 1) continue;
                dist[q.y][q.x] = dist[p.y][p.x] + 1;
                que.push(q);
            }
        }
    }
    // // dfs
    if (goal.y == -1) {
        queue<point_t> que;
        repeat (y,h) repeat (x,w) {
            if (dist[y][x] != inf) {
                dist[y][x] = k;
                que.push((point_t) { y, x });
            }
        }
        while (not que.empty()) {
            point_t p = que.front(); que.pop();
            if (is_goal(p.y, p.x)) {
                goal = p;
                break;
            }
            repeat (i,4) {
                point_t q = p;
                q.y += dy[i];
                q.x += dx[i];
                if (not is_on_field(q.y, q.x)) continue;
                if (dist[q.y][q.x] <= dist[p.y][p.x] + 1) continue;
                dist[q.y][q.x] = dist[p.y][p.x] + 1;
                que.push(q);
            }
        }
    }
    // output
    assert (goal.y != -1);
    int result = (dist[goal.y][goal.x] + k - 1) / k;
    printf("%d\n", result);
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
  }

  deque<int> m;
  rep(i, n) {
    auto ite = lower_bound(all(m), a[i]);
    if (ite == m.begin()) {
      m.push_front(a[i]);
    } else {
      *(ite-1) = a[i];
    }
  }

  cout << m.size() << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define int long long
# define mo 1000000000000007
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int dp[105][4][2][105],nn;
string s;
int k;
int help(int n,int k,int ch,int ex,int id)
{
   //cout<<n<<" "<<k<<endl;;
    //cout<<id<<" "<<nn<<endl;
    if(k<0 || n<0 || id==nn){
            if(n==0 && k==0)
            return 1;
        return 0;
    }
    if(n==0)
    {
        if(n==0 && k==0)
            return 1;
        return 0;
    }
    if(dp[n][k][ch][id]!=-1)
        return dp[n][k][ch][id];
    int an=0;
  if(ch==1)
  {
      for(int i=0;i<=s[id]-'0';i++){
             if(i==s[id]-'0'){
                    if(s[id]!='0'){
                an += help(n-1,k-1,1,i,id+1);
                    //an%=mo;
                    }
             else{
                an += help(n-1,k,1,i,id+1);
              //an%=mo;
             }
             }
                else if(i==0){
            an += help(n-1,k,0,i,id+1);
            //an%=mo;
                }
            else{

                an+=help(n-1,k-1,0,i,id+1);
             //an%=mo;
            }
      }
  }
  else
  {
      for(int i=0;i<=9;i++)
      {
          if(i==0){
            an+=help(n-1,k,0,i,id+1);
           //an%=mo;
          }
            else{

                an += help(n-1,k-1,0,i,id+1);
            // an %=mo;
            }
      }
  }
  dp[n][k][ch][id]=an;
  return an;
}
signed main(){
    gok

    //int k;
    cin>>s>>k;
    nn=s.size();
   // cout<<nn<<endl;
    memset(dp,-1,sizeof(dp));
    /*for(int i=0;i<100;i++)
        for(int j=0;j<4;j++)
        for(int k=0;k<2;k++)
        cout<<dp[i][j][k]<<" ";*/
    int an = help(nn,k,1,10,0);
    cout<<an;
     return 0;
}


Measured memory_bytes: 896
n=int(input())

nstr=str(n)
#print(n,nstr)

list=list(nstr)
#print(list)

a=0
for i in range(len(list)):
	a=a+int(list[i])
#print(a)
n=int(n)
a=int(a)
#print(n)
#print(a)
#print(n%a)

if n%a==0:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  bool f = true;
  if (N == 1) {
    int s, c;
    cin >> s >> c;
    for (int i = 0; i < M-1; i++) {
      int S, C;
      cin >> S >> C;
      if (c != C) {
        cout << -1 << endl;
        f = 0;
        break;
      }
    }
    if(f) {
    cout << c <<endl;
    }
  }
  else {
    vector<int> n(N, 10);
    for (int i = 0; i < M; i++) {
      int s, c;
      cin >> s >> c;
      if (s == 1 && c == 0) {
        f = 0;
        cout << -1 <<endl;
      }
      else if (n.at(s - 1) == 10) {
        n.at(s-1) = c;
      }
      else if (n.at(s-1) != 10 && n.at(s-1) != c) {
        cout << -1 <<endl;
        f = 0;
      }
    }
    if (f) {
    if (n.at(0) == 10) {
      cout << 1;
    }
    else {
      cout << n.at(0);
    }
    for (int i = 1; i < N; i++) {
      if (n.at(i) == 10) {
        cout << 0;
      }
      else {
        cout <<n.at(i);
      }
    }
    cout <<endl;
  }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n,s;
	cin>>n>>s;
	ll arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr+n,greater<ll>());
	ll res=0;
	for(int i=s;i<n;i++)
	{
		res+=arr[i];
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1792
A,B,C=map(int, input().split())
K=int(input())
count=0

ok1=False
while True:
    if count==K:
        if B>A:
            ok1=True
        break
    if B>A:
        ok1=True
        break
    B*=2
    count+=1
    
ok2=False
while True:
    if count==K:
        if C>B:
            ok2=True
        break
    if C>B:
        ok2=True
        break
    C*=2
    count+=1

if ok1 and ok2:
    print("Yes")
else:
    print("No")

#print(A,B,C, ok1, ok2)


Measured memory_bytes: 61712
N = int(input())

cnt = [0] * (N+1)
for i in range(1, N+1, 2):
    for j in range(1, N+1, 2):
        if i % j == 0:
            cnt[i] += 1
ans = 0
for i in cnt:
    if i == 8:
        ans += 1
print(ans)

Measured memory_bytes: 63696
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int,int>;
#define IOS cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);
LL cnt[10][10];

int findH(int x)
{
    while(x >= 10)
    {
        x /= 10;
    }
    return x;
}

int main()
{
    IOS;
    int n;
    LL ans1 = 0, ans2 = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        int h = findH(i), e = i % 10;
        ans1 += cnt[e][h];
        if(h == e)
        {
            ++ans2;
        }
        // cout << cnt[e][h] << ' ' << h << ' ' << e << '\n';
        ++cnt[h][e];
    }
    // cout << ans1 << ' ' << ans2 << '\n';
    cout << ans1 * 2 + ans2 << '\n';
}

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

int main() {
    string s; cin >> s;
    int ans = 0;
    if (s == "RRR") ans = 3;
    else if (s == "RRS" || s == "SRR") ans = 2;
    else if (s == "RSR" || s == "RSS" || s == "SRS" || s == "SSR") ans = 1;
    else ans = 0;
    cout << ans << endl;
}

Measured memory_bytes: 3624
N, M = map(int, input().split())
H = list(map(int, input().split()))
H.insert(0, 0)
edges = [list(map(int, input().split())) for _ in range(M)]

graph = [[] for _ in range(N+1)]

for a, b in edges:
  graph[a].append(b)
  graph[b].append(a)

cnt = 0
for i in range(1, N+1):
  if len(graph[i]) == 0:
    cnt += 1
    continue
  for a in graph[i]:
    if H[i] <= H[a]:
      break
  else:
    cnt += 1

print(cnt)


Measured memory_bytes: 41272
#include <iostream>
using namespace std;
#define MAX 100010
#define NIL -1
#define rep(i, n) for(int i=0;i<n;i++)

//???????????????????????????????????£????????????
//?????????????????¨???
struct Node {int parent, left, right;};
Node T[MAX];
int n, D[MAX];

void print(int u){
    cout << "node " << u <<": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "depth = " << D[u] << ", ";
    if(T[u].parent == NIL) cout << "root, ";
    else if(T[u].left == NIL) cout << "leaf, "; 
    else cout << "internal node, ";
    cout << "[";

    for(int i =0, c = T[u].left; c != NIL; i++, c = T[c].right){
        if(i) cout << ", ";
        cout << c; 
    }

    cout << "]" << endl;
}

//?????°??????????????¨??§???????????±???????±???????
//main??§depth(parent???null, 0)??¨????????°??¨??¨?????????????????±???????????????
void depth(int u, int p){
    D[u]=p;
    if(T[u].right != NIL) depth(T[u].right,p);
    if(T[u].left != NIL) depth(T[u].left,p+1);
}

int main(void){
    int v,d,c,l,r;
    cin >> n;
    rep(i, n) T[i].parent = T[i].left = T[i].right =NIL;
    rep(i, n){
        cin >> v >> d;
        rep(j, d){
            cin >> c;
            if(j == 0) T[v].left=c;
            else T[l].right = c;
            l = c;
            T[c].parent = v;
        }
    }
    rep(i, n){
        if(T[i].parent == NIL) r=i;
    }

    depth(r,0);
    rep(i, n) print(i);

    return 0;
}

Measured memory_bytes: 7728
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define for1(i, m, n) for (int i = m; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0) {
            break;
        }
        rep(i, h) {
            rep(j, w) {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;

  set<char> s1;
  set<string> s2;
  set<string> s3;
  for ( int i = 0; i < n; i++){
    for (auto ITR = s2.begin(); ITR != s2.end(); ++ITR) {
      string str = "";
      str += *ITR;
      str += s[i];
      s3.insert(str);
    }
    for (auto ITR = s1.begin(); ITR != s1.end(); ++ITR) {
      string str = "";
      str += *ITR;
      str += s[i];
      s2.insert(str);
    }
    s1.insert(s[i]);
  }
  cout << s3.size() << endl;

  return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
 
int n;
int p[100001];

int check() {
    imfor(i, n) {
        if (p[i + 1] == i + 1) {
            return 1;
        }
    }
    return 0;
}

int main() {
    
    cin >> n;
    imfor(i, n) {
        cin >> p[i + 1];
    }
    int ans = 0;
    while (check()) {
        imfor(i, n) {
            if (p[i + 1] == i + 1) {
                if (i + 1 == 1) {
                    swap(p[i + 1], p[i + 2]);
                }
                else if (i + 1 == n) {
                    swap(p[i], p[i + 1]);
                }
                else if (abs(p[i] - i - 1) > abs(p[i + 2] - (i + 2) + 1)) {
                    swap(p[i + 1], p[i + 2]);
                }
                else {
                    swap(p[i], p[i + 1]);
                }
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

int main()
{
	string O, E;
	cin >> O >> E;
	for (int i = 0; i < O.size(); i++) {
		cout << O[i];
		if (i < E.size()) cout << E[i];
	}
	cout << endl;
	return 0;
}


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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  if ( (a[a.size()-1] == b[0]) && (b[b.size()-1] == c[0]) ) {
    puts("YES")
  }else{
    puts("NO")
  }
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

char sc[255];
char tc[255];

int main(void)
{
  string s, t;
  cin >> s >> t;
  REP(i, 'z'+5) sc[i] = tc[i]= '@';

  bool ok = true;
  REP(i, s.size()) {
    if(sc[s[i]]!='@' && sc[s[i]] != t[i]) ok = false;
    if(tc[t[i]]!='@' && tc[t[i]] != s[i]) ok = false;
    if(sc[s[i]]=='@') sc[s[i]] = t[i];
    if(tc[t[i]]=='@') tc[t[i]] = s[i];
  }
  cout << (ok?"Yes":"No") << endl;
}


Measured memory_bytes: 776
P=998244353
MAX_N=3*10**5+1
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
def inv(x):
    return egcd(x,P)[0]
Fact=[0 for i in range(MAX_N+1)]
Finv=[0 for i in range(MAX_N+1)]
Fact[0]=1
Finv[0]=1
for i in range(MAX_N):
    Fact[i+1]=(Fact[i]*(i+1))%P
    Finv[i+1]=inv(Fact[i+1])%P
def C(n,k):
    return (Fact[n]*(Finv[k]*Finv[n-k])%P)%P
N,A,B,K=map(int,input().split())
L=[]
for i in range(K//A+1):
    if (K-A*i)%B==0:
        j=(K-A*i)//B
        if 0<=i<=N and 0<=j<=N:
            L.append((i,j))
ans=0
for x,y in L:
    ans+=C(N,x)*C(N,y)
    ans%=P
print(ans)



Measured memory_bytes: 67596
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <math.h>
#include <limits.h>

using namespace std;

int main() {
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int k;
		cin >> k;
		if (k % 2 == 0 && !(k % 3 == 0 || k % 5 == 0)) {
			cout << "DENIED" << endl;
			return 0;
		}
	}
	cout << "APPROVED" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;

    if(s == "MON")
    	cout << "6" << endl;
    if(s == "TUE")
    	cout << "5" << endl;
    if(s == "WED")
    	cout << "4" << endl;
    if(s == "THU")
    	cout << "3" << endl;
    if(s == "FRI")
    	cout << "2" << endl;
    if(s == "SAT")
    	cout << "1" << endl;
    if(s == "SUN")
    	cout << "7" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
typedef long long li;
#define MOD 1000000007
#define abs(n) max((n),-(n))
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
struct modint{
  li num;

  modint(li a=0){
    num=(a%MOD+MOD)%MOD;
  }
  modint operator+(modint a) {return{(num+a.num)%MOD};} 
  modint operator-(modint a) {return{((num-a.num)%MOD+MOD)%MOD};}
  modint operator*(modint a) {return{num*a.num%MOD};}
  modint inv(modint a);
  modint operator/(modint a) {return {*this*inv(a)};}
};
modint inv(modint a){
    // unordered_map 必須 O(1)
    static unordered_map<li,modint> f;
    f[1]=1;
    if(f.find(a.num)!=f.end())return f[a.num];
    modint m=MOD%a.num;
    return f[a.num]=(modint)(MOD/a.num*(-1))*inv(m);
}

std::ostream& operator<<(std::ostream& os, const modint& m){
  // ここでストリームに obj を書き込みます。
  li a=m.num;
  a%=MOD;
  a+=MOD;
  a%=MOD;
  cout << a;
  return os;
}

std::istream& operator>>(std::istream& os,modint& m){
  // ここでストリームに obj を書き込みます。
  li a; cin >>a;
  m=a;
  return os;
}

modint fact(int a){
  // vector 必須 O(1)
  static vector<modint> f(1,1);
  
  if(f.size()>a)return f[a];
  if(df)print(a,"!");
  int n=f.size();
  rep(i,a+1){
    if(i==0){
      i=n-1;
      continue;
    }
    f.push_back(f[i-1]*i);
    if(df)print(i,f[i]);
  }
  return f[a];
}

modint binom(int n,int k){
  if(k<0 or k>n) return 0;
  return fact(n)*inv(fact(k)*fact(n-k));
}

int main(){
  li n; cin >>n;
  vector<int> seen(n+1,-1);
  int m=0;
  rep(i,n+1){
    int a; cin >>a;
    if(seen[a]!=-1)m=abs(i-seen[a])-1;
    else seen[a]=i;
  }
  rep(i,n+1){
    int k=i+1;
    print(binom(n,k)+binom(n-1,k-1)-binom(n-m-1,k-1)+binom(n-1,k-2));
  }
}


Measured memory_bytes: 39260
N,W=map(int,input().split())
items=[(0,0)]
for _ in range(N):
    w,v=map(int,input().split())
    items.append((w,v))

dp=[[float("inf") for _ in range(10**5+1)] for _ in range(N+1)]

for i in range(N+1):
    w,v=items[i]
    dp[i][v]=w

for i in range(1,N+1):
    for v in range(1,10**5+1):
        if v-items[i][1]<0:
            dp[i][v]=min(dp[i][v],dp[i-1][v])
        else:
            dp[i][v]=min(dp[i][v],dp[i-1][v],dp[i-1][v-items[i][1]]+items[i][0])

for v in range(10**5,0,-1):
    if dp[N][v]<=W:
        print(v)
        break

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

int main() {

  int K, A, B;
  cin >> K >> A >> B;

  int current = 1;

  while(current * K <= B) {
    if (A <= current * K && current * K <= B) {
      cout << "OK" << endl;
      return 0;
    } else {
      current++;
    }
  }

  cout << "NG" << endl;

  return 0;

}

Measured memory_bytes: 3636
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
inline void write(int x)
{
    if(x<0)
	{
    	putchar('-');
		x=-x;
	}
    if(x>9)
		write(x/10);
    putchar(x%10+'0');
}
int a[51];
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	ios::sync_with_stdio(false);
	int n,m,s=0;
	n=read();
	m=read();
	for(register int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1,cmp);
	for(register int i=1;i<=m;i++) s+=a[i];
	write(s);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
					
public class my
{
	public static void Main()
	{
		var dict = new Dictionary<string, int>();
		string maxString = "";
		int maxLength = 0;
		
		foreach(var s in Console.ReadLine().Split(' ')) {
			if(!dict.ContainsKey(s)) {
				dict.Add(s, 1);
			} else {
				dict[s]++;
			}
			
			if(s.Length > maxLength) {
				maxLength = s.Length;
				maxString = s;
			}
		}
		
		int modeValue = 0;
		string modeString = "";
		
		foreach(var d in dict) {
			if(d.Value > modeValue) {
				modeValue = d.Value;
				modeString = d.Key;
			}
		}
		
		Console.WriteLine(modeString + " " + maxString);
	}
	
	private static void Swap(int[] A, int i, int j)
	{
		int tmp = A[i];
		A[i] = A[j];
		A[j] = tmp;
	}
	
	private static int GetInt()
	{
		return int.Parse(Console.ReadLine());
	}
	
	private static int[] GetIntArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
	}

	private static int[] GetIntArray(int n)
	{
		var A = new int[n];
		var s = Console.ReadLine().Split(' ');

		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}
	
	private static int[] GetIntArray(int n, string t)
	{
		var A = new int[n];
		var s = t.Split(' ');

		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}

	private static int[] GetIntArray(char c)
	{
		return Array.ConvertAll(Console.ReadLine().Split(c), int.Parse);
	}
	
	private static int[] GetIntArray(char c, string s)
	{
		return Array.ConvertAll(s.Split(c), int.Parse);
	}
	
	private static int[] GetIntArray(string s)
	{
		return Array.ConvertAll(s.Split(' '), int.Parse);
	}
	
	private static double[] GetDoubleArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
	}
	
	public static string Reverse(string s)
	{
		var c = s.ToCharArray();
		Array.Reverse(c);
		
		return new String(c);
	}
	
	private static void WriteArray(int[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}

	private static void WriteArray(long[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static void WriteVector(Vector v)
	{
		Console.WriteLine(string.Format("{0:f8} {1:f8}", v.X, v.Y));
	}
}

public struct Vector
{
	public double X,Y;
}

Measured memory_bytes: 8760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <climits>
#include<iomanip>
using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define in1(n) cin>>n;
#define in2(n, k) cin>>n>>k;
#define in3(n, k, s) cin>>n>>k>>s;
#define scn(t) scanf("%d", &t)
#define scnld(t) scanf("%ld", &t)
#define scnlld(t) scanf("%lld", &t)
#define scnc(t) scanf("%c", &t)
#define scns(t) scanf("%s", t)
#define scnf(t) scanf("%f", &t)
#define scnlf(t) scanf("%lf", &t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define nloop(i, j, k, in) for (int i = j; i < k; i += in)
#define rloop(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rep(i, j) nloop(i, 0, j, 1)
#define rrep(i, j) rloop(i, j, 0, 1)
#define inar(n, a) \
    rep(i, n)\
        cin>>a[i];
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define fast  \
    ios_base::sync_with_stdio(false);\
    cin.tie(NULL);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

double calcAngle(double h, double m)
{
    if (h == 0)
        h = 0;
    if (m == 0)
        m = 0;
    double hour_angle = 0.5 * (h * 60 + m);
    double minute_angle = 6 * m;

    // Find the difference between two angles
    double angle = abs(hour_angle - minute_angle); 

    // Return the smaller angle of two possible angles
    angle = min(360 - angle, angle);

    return angle;
}

int main()
{
    fast
    double a, b, hr, min;
    cin>>a>>b>>hr>>min;
    double deg = calcAngle(hr, min);
    double rad = deg*PI/180;
    double ans = sqrt(a*a+b*b - 2*a*b*cos(rad));
    cout<<fixed<<setprecision(24)<<ans;
    return 0;
}

Measured memory_bytes: 4208
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F0(i,n) for (int i = 0; i < n; i++)
#define F1(i,n) for (int i = 1; i <= n; i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define SZ(x) ((int)x.size())
const double eps = 1e-10;
const int inf = 1000000009;
int i, j, k, m, n, l;
int ans; int a[1000000];

int main() {
	//freopen("x.in", "r", stdin);
	cin >> n;
	F1(i, n) cin >> a[i];
	ans = 0; F1(i, n) if (a[a[i]] == i) ans++;
	cout << ans / 2 << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a[3];
  int k;
  REP(i,3) cin >> a[i];
  cin >> k;
  sort(a,a+3);
  REP(i,k) a[2] *= 2;
  cout << a[0]+a[1]+a[2] << endl;
  return 0;
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
char dna[4] = {'A', 'C' , 'G', 'T'};
int main(){
  char s;
  cin >> s;
  REP(i, 4){
      if(s == dna[i]){
          cout << dna[3 - i] << endl;
          return 0;
        }
    }
    cerr << "Not Found" << endl;
}

Measured memory_bytes: 256
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class Main {
    public static void main(String args[] ) throws IOException {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String line = br.readLine();
      int n = Integer.parseInt(line);
      int v = n;
      
      for(int i = 0; i < 2; i++){
        n *= v;
      }

      System.out.println(n);
    }
}

Measured memory_bytes: 24440
def is_harshad(x):
	X=x
	f=0
	while x > 0:
		f += x % 10
		x //= 10
#	print("X:", X, " f:", f)
	return X % f == 0

N=int(input())

res=is_harshad(N)

print("Yes" if res else "No")


Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#define inf 1e9

using namespace std;

int N;
int a[20];
vector<int> fact[200005];
double dp[20][200005];

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++) cin >> a[i];
	
	for(int i = 1; i <= 200000; i++){
		for(int j = i; j <= 200000; j += i){
			fact[j].push_back(i);
			
		}
	}
	
	for(int i = 1; i <= 200000; i++){
		dp[0][i] = fabs(a[0] - i) / a[0];
	}
	double r;
	for(int i = 1; i < N; i++){
		for(int j = 1; j <= 200000; j++){
			r = inf;
			for(int k = 0; k < fact[j].size(); k++) r = min(r, dp[i-1][fact[j][k]]);
			dp[i][j] = max( r, fabs(a[i]-j) / a[i] );
		}
	}
	
	int min_i; double min_val = inf;
	for(int i = 1; i <= 200000; i++){
		if(min_val > dp[N-1][i]){
			min_val = dp[N-1][i];
			min_i = i;
		}
	}
	
	double ans = inf;
	for(int i = 1; i <= 200000; i++) ans = min(ans, dp[N-1][i]);
	printf("%.10f\n", ans);
	
	return 0;
}
				

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

using namespace std;

int main(){
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0;i< n;i++){
        cin>>arr[i];
    }
    int min_till = arr[0];
    int count=0;
    for(int i= 0;i< n;i++){
        // if(arr[i] > max_till)max_till = arr[i];
        if(arr[i] <= min_till){
            count++;
            min_till = arr[i];
        }
    }
    cout<<count;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#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, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}


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

    for (;;) {
        int D, E; cin >> D >> E;
        if (D == 0) break;
        double ans = 1e9;
        REP(x, D+1) {
            int y = D - x;
            chmin(ans, abs(E - sqrt(x * x + y * y)));
        }
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main(){
  ll n,m;
  cin>>n>>m;
  string s,t;
  cin>>s>>t;
  ll o=min(n,m);
  while(true){
    if(n%o==0&&m%o==0){
      break;
    }
    o--;
  }
  ll lcm=n*m/o;
  ll x=lcm/n,y=lcm/m;
  ll z=min(x,y);
  if(s.at(0)!=t.at(0)){
    cout<<-1<<endl;
    return 0;
  }
  else {
    while(true){
    if(x%z==0&&y%z==0){
      break;
    }
    z--;
  }
  ll lcm2=x*y/z;
  ll i=1;
  ll ans=0;
  while(lcm2*i<lcm){
    if(s.at(lcm2*i/x)==t.at(lcm2*i/y)){
      i++;
    }
    else{
         ans++;
         break;
    }
  }

    if(ans==0){
         cout<<lcm<<endl;
       }
    else{
         cout<<-1<<endl;
       }
  }
    
    
  
    
  
}
  


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 3.14159265
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define endl '\n'
#define ff first
#define ss second
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / __gcd(a, b)
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define print(a) for(auto x : a) cout << x << " "; cout << endl;

using namespace std;

const ll inf = 1e18 + 42;

const ll M = 998244353;

ll power(ll x, ll y) {
	if (y == 0) return 1;
	if (y & 1) return (x * power(x, y - 1));
	ll t = power(x, y / 2);
	return (t * t);
}

const ll MAX = 1e3 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

// vector<ll> fact;

void primeFactors(ll n, map<ll, ll> &mp)  
{  
    // Prll the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        // cout << 2 << " "; 
        // fact.pb(2);
        mp[2]++; 
        n = n/2;  
    }  
  
    // n must be odd at this poll. So we can skip  
    // one element (Note i = i +2)  
    for (ll i = 3; i * i <= n; i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            // cout << i << " ";  
            // fact.pb(i);
            mp[i]++;
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        // cout << n << " ";  
        // fact.pb(n);
        mp[n]++;
}  


void ahShitHereWeGoAgain()
{
	ll n;
	cin >> n;
	if(n == 1)
	{
		cout << 0 << endl;
		return;
	}
	map<ll, ll> mp;
	// vector<ll> v;
	primeFactors(n, mp);
	// primeFactors(n, v);
	// print(v);
	if(mp.find(1) != mp.end())
		mp.erase(1);
	// for(auto x : mp)
	// {
	// 	cout << x.ff << " " << x.ss << endl;
	// }
	ll ans = 0;
	for(auto x : mp)
	{
		ll y = 0;
		for(ll i = 1; i * (i + 1) <= 2 * x.ss; i++)
		{
			y = i;
		}
		// deb(y);
		ans += y;
	}
	cout << ans << endl;
}

int main()
{
	DESYNC	
	ll t = 1;
	// cin >> t;
	while (t--)
		ahShitHereWeGoAgain();
	return 0;
}



Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
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; }

using namespace std;
int dp[31];
int main() {
  int n;
  int inf = 1 << 30;
  dp[0] = 1;
  for(int i = 1; i <= 30; i++){
    dp[i] += dp[i -1];
    if(i > 1) dp[i] += dp[i - 2];
    if(i > 2) dp[i] += dp[i - 3];
  }
  while(1){
    cin >> n;
    if(n == 0) break;
    cout << ceil(dp[n] / 10.0 / 365.0) << endl;
  }
}



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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class Key, class T> struct radix_heap {
  static_assert(is_integral<Key>::value, "");
  array<vector<pair<Key, T>>, sizeof(Key) * 8 + 1> v;
  Key last = 0;
  size_t sz = 0, ptr = 0;
  static int lg(Key a) { return a ? __lg(a) : -1; }
  void emplace(Key key, T val) {
    assert(key >= last);
    v[lg(key ^ last) + 1].emplace_back(key, val);
    ++sz;
  }
  void pull() {
    if (ptr < v[0].size()) return;
    v[0].clear(), ptr = 0;
    int i = 1;
    while (v[i].empty()) ++i;
    last = min_element(begin(v[i]), end(v[i]), [](auto a, auto b) {
      return a.first < b.first;
    })->first;
    for (auto e : v[i]) v[lg(e.first ^ last) + 1].push_back(e);
    v[i].clear();
  }
  pair<Key, T> top() { return pull(), v[0][ptr]; }
  void pop() { pull(), --sz, ++ptr; }
  bool empty() const { return sz == 0; }
};

template <class T> struct graph {
  struct edge {
    int to;
    T w;
    operator int() const { return to; }
  };
  template <class It> struct edge_list {
    const It bg, ed;
    It begin() const { return bg; }
    It end() const { return ed; }
    auto&& operator[](size_t i) const { return bg[i]; }
    size_t size() const { return ed - bg; }
  };
  vector<pair<int, edge>> pool;
  vector<int> head;
  vector<edge> edges;
  graph(int n) : head(n + 1) {}
  void add(int from, int to, T w = 1) {
    pool.push_back({from, {to, w}});
    ++head[from];
  }
  void build() {
    partial_sum(begin(head), end(head), begin(head));
    edges.resize(head.back());
    while (not empty(pool)) {
      edges[--head[pool.back().first]] = pool.back().second;
      pool.pop_back();
    }
  }
  edge_list<class vector<edge>::const_iterator> operator[](int v) const {
    return {begin(edges) + head[v], begin(edges) + head[v + 1]};
  }
  edge_list<class vector<edge>::iterator> operator[](int v) {
    return {begin(edges) + head[v], begin(edges) + head[v + 1]};
  }
  size_t size() const { return std::size(head) - 1; }
};

template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

auto chmin = [](auto&& a, auto b) { return b < a ? a = b, 1 : 0; };

template <class T, class G> auto dijkstra(const G& g, int s) {
  vector d(size(g), inf<T>);
  vector prv(size(g), -1);
  radix_heap<T, int> rh;
  rh.emplace(d[s] = 0, s);
  while (not empty(rh)) {
    auto [dv, v] = rh.top();
    rh.pop();
    if (dv != d[v]) continue;
    for (auto&& e : g[v])
      if (chmin(d[e.to], dv + e.w)) {
        rh.emplace(d[e.to], e.to);
        prv[e.to] = v;
      }
  }
  return make_pair(d, prv);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  graph<int> g(n);
  while (m--) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g.add(u, v);
    g.add(v, u);
  }
  g.build();
  auto res = dijkstra<int>(g, 0).second;
  cout << "Yes\n";
  for (int v = 1; v < n; ++v) {
    cout << res[v] + 1 << '\n';
  }
}


Measured memory_bytes: 14864
package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
  "strings"
)

func main() {
  var n,m int = NextInts()
  var x []int = NextIntArray()
  sort.Ints(x)
  var r []map[int]int = make([]map[int]int,m)
  for i:=0;i<m;i++ { r[i] = map[int]int{} }
  for i:=0;i<n;i++ { r[x[i]%m][x[i]]++ }
  var p int
  for _,v := range r[0] { p += v }
  p /= 2
  for i:=1;i<=m/2;i++ {
    var t0all,t0even,t1all,t1even int
    for _,v := range r[i] {
      t0all += v
      t0even += (v/2)*2
    }
    for _,v := range r[m-i] {
      t1all += v
      t1even += (v/2)*2
    }
    if i == m-i {
      p += t0all/2
      continue
    }
    if t0all == t1all {
      p += t0all
      continue
    }
    if t0all > t1all {
      t0all,t1all = t1all,t0all
      t0even,t1even = t1even,t0even
    }
    var t0 int = t0all
    if t1all-t0all <= t1even {
      t0 += (t1all-t0all)/2
    } else {
      t0 += t1even/2
    }
    var t1 int = t1all-t1even
    if t1 > t0all { t1 = t0all }
    t1 += t1even/2
    var t2 int = t0all-t0even
    if t2 > t1all-t1even { t2 = t1all-t1even }
    t2 += (t0even+t1even)/2
    p += max(t0,t1,t2)
  }
  fmt.Println(p)
}

func max(n ...int) int {
  m := n[0]
  for i:=1;i<len(n);i++ {
    if m < n[i] { m = n[i] }
  }
  return m
}

var reader = bufio.NewReaderSize(os.Stdin,1000000)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInts() (int,int) {
  var x,y int
  var s []string = strings.Split(NextLine()," ")
  x,_ = strconv.Atoi(s[0])
  y,_ = strconv.Atoi(s[1])
  return x,y
}
func NextIntArray() []int {
  var s []string = strings.Split(NextLine()," ")
  var n int = len(s)
  var a []int = make([]int,n)
  for i:=0;i<n;i++ {
    a[i],_ = strconv.Atoi(s[i])
  }
  return a
}

Measured memory_bytes: 27904
def modpow(a, n, mod):
    res = 1
    while n > 0:
        if (n & 1):
            res = res * a % mod
        a = a * a % mod
        n = n >> 1

    return res


def main():
    m, n = map(int, input().split())
    print(modpow(m, n, 1000000007))


if __name__ == "__main__":
    main()


Measured memory_bytes: 5600
#include <bits/stdc++.h>
template <typename T>
constexpr T INF() { return std::numeric_limits<T>::max() / 16; }
int main()
{
    int N, W;
    std::cin >> N >> W;
    std::vector<int> v(N), w(N);
    for (int i = 0; i < N; i++) { std::cin >> v[i] >> w[i]; }
    std::vector<int> dp(W + 1, 0);
    for (int i = 0; i < N; i++) {
        for (int j = W - w[i]; j >= 0; j--) { dp[j + w[i]] = std::max(dp[j + w[i]], dp[j] + v[i]); }
    }
    std::cout << *max_element(dp.begin(), dp.end()) << std::endl;
    return 0;
}


Measured memory_bytes: 3140
#include <stdio.h>
#include <ctype.h>

int main(){
    int count[26]={0};
    char ch;
    int i, num;

    while(scanf("%c", &ch)!=EOF){
        if(islower(ch)){
            num=ch-'a';
        }else if(isupper(ch)){
            num=ch-'A';
        }else{
            continue;
        }
        count[num]++;
    }
    for(i=0;i<26;i++){
        printf("%c : %d\n", 'a'+i, count[i]);
    }

    return 0;
}
//*/


Measured memory_bytes: 2704
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,l;
  cin >> n >> l;
  vector<int> list(n);
  int total=0,j=100000000,p,e;
  for(int i=0; i<n; i++) {
    list.at(i) = l+i;
    total += list.at(i);
    p = abs(list.at(i));
    if(j > p) {
      j = p;
      e = i;
    }
  }
  total -= list.at(e);
  cout << total << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define INF numeric_limits<int>::max()
#define st string
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

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

void solve(){
    int n, a, b, cnt = 0; cin >> n;
    while(n--){
        cin >> a >> b;
        if(a == b) cnt++;
        else cnt = 0;
        if(cnt == 3) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

int main(){
    fastio
    solve();
    return 0;
}


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

using namespace std;

int Prime[100000];

bool IsPrime(int n){
	if(n <= 1) return false;
	if(n == 2) return true;
	for (int i = 2; i <= sqrt(n); i++){
		if(n % i == 0) return false;
	}
	return true;
}

void solve(){
	int cnt = 0;	
	for(int i = 2; i < 110000; i++){
		if(IsPrime(i)) {
			Prime[cnt] = i;
			// cout << i << endl;
			cnt++;
		}
	}
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		int ans = 0;
		for(int i = 0; i < n; i++){
			ans = ans + Prime[i];
		}
		cout << ans << endl;
	}
}

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

Measured memory_bytes: 1232
#include<stdio.h>
#define MAX 100000
void rec(int x,int y);
typedef struct{
  int p;
  int l;
  int r;
}id;
   
id A[MAX];
int n,B[MAX];
 
   
void rec(int x,int y){
  B[x] = y;
  if(A[x].r != -1) rec(A[x].r,y);
  if(A[x].l != -1) rec(A[x].l,y + 1);
}


int main(){
  int c,d,i,j,v,l,r,n,op;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].p = A[i].l = A[i].r = -1;
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0) A[v].l=c;
      else A[l].r = c;
      l=c;
      A[c].p = v;
    }
  }
  for(i=0;i<n;i++){
    if(A[i].p == -1) r=i;
  }
 
  rec(r,0);
 
  for(i=0;i<n;i++){
    
    printf("node %d: parent = %d, depth = %d,",i,A[i].p,B[i]);
    if(A[i].p == -1) printf(" root,");
    else if(A[i].l == -1 ) printf(" leaf,");
    else printf(" internal node,");
    printf(" [");
    op=A[i].l;
    for(j=0;op!=-1;j++){
      if(j != 0) printf(", ");
      printf("%d",op);
      op = A[op].r;
    }
    printf("]\n");  
  }
 
  return 0;
}

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

namespace ABC112
{
    class Program
    {
        static void Main(string[] args)
        {
            // Console.WriteLine("Helo World!");
            if(int.Parse(Console.ReadLine()) == 1)
            {
                Console.WriteLine("Hello World");
            }
            else
            {
                var a = int.Parse(Console.ReadLine());
                var b = int.Parse(Console.ReadLine());

                Console.WriteLine(a+b);

            }
        }
    }
}


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

using namespace std;
int main()
{
	int N, X, min, ans;
  	vector<int> vec;
  	cin >> N >> X;
  	for (int i = 0; i < N; i++){
    	int v; cin >> v;
      	vec.push_back(v);
    }
  	min = vec[0];
  	for (int i = 0; i < N; i++){
    	X -= vec[i];
      	if (min > vec[i]){
        	min = vec[i];
        }
    }
  	ans = N + X / min;
  	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>v;
void print()
{
    int ans=0;
    for(auto it=v.begin();it!=v.end();it++,ans++)
    {
        if(ans!=0)cout<<" ";
        cout<<*it;
    }
    cout<<endl;
}

int main()
{
    int n,i,j;
    cin>>n;
    v.resize(n);
    for(i=0;i<n;i++)
    {
        v[i]=i+1;
    }
    do{
       print();
    }while(next_permutation(v.begin(),v.end()));
    return 0;
}



Measured memory_bytes: 3104