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

const int N = 100;
int a[N], cnt[N], n;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i], ++cnt[a[i]];
    int len = *max_element(a, a + n);
    for (int i = 0; i <= len; ++i) {
        if (cnt[max(i, len - i)]-- == 0) {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    for (int i = 1; i <= (len + 1) / 2; ++i) if (cnt[i] > 0) {
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    return 0;
}


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

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

  int n1 = 0, n2 = 0;
  char f = s.front();
  for (auto iter = s.begin(); iter != s.end(); ++iter)
  {
    if (*iter != f) n1++;
    f = *iter;
  }

  char b = s.back();
  for (auto iter = s.rbegin(); iter != s.rend(); ++iter)
  {
    if (*iter != b) n2++;
    b = *iter;
  }

  cout << min(n1, n2) << endl;
  return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  if(-1000<=a && b<=1000){
    if(a>b)printf("a > b\n");
    if(a<b)printf("a < b\n");
    if(a==b)printf("a == b\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

void sieve(vector<bool> &primes) {
	for (int i = 2; i * i <= (int) primes.size(); ++i) {
		if (primes[i]) {
			for (int j = 2 * i; j < (int) primes.size(); j += i) {
				primes[j] = false;
			}
		}
	}
}

int main() {

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

	int q;
	cin >> q;

	vector<bool> primes(1e5 + 1000, true);
	primes[1] = false;
	sieve(primes);

	vector<int> pre_sum(1e5 + 1);
	for (int i = 2; i <= 1e5; ++i) {
		pre_sum[i] = pre_sum[i - 1];
		if (primes[i] && primes[(i + 1) / 2]) {
			++pre_sum[i];
		}
	}

	int l, r;
	while (q--) {
		cin >> l >> r;
		cout << pre_sum[r] - pre_sum[l - 1] << "\n";
	}

	return 0;

}

Measured memory_bytes: 3708
#include <iostream>
#include <string>
using namespace std;
int main(){
  int N;
  string ans = "No";
  cin >> N;
  if( N % 10 == 9){
    ans = "Yes";
  } else {
    if (N / 10 == 9){
      ans = "Yes";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int n, m;
  cin >> n >> m;
  vi x(m);
  rep(i,m) cin >> x[i];
  sort(x.begin(), x.end());
  vector<int> v(m-1);
  rep(i, m-1) v[i] = x[i+1] - x[i];
  sort(ALL(v));
  if (n == m) cout << 0 << endl;
  else {
    int ans = 0;
    rep(i, m-n) {
      ans += v[i];
    }
    cout << ans << endl;
  }

}

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

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int n, k, ans = 0;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
        if(h[i] >= k) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define PI 3.1415926536
typedef long long ll;
typedef pair<int, int> P;

int main() {
	int n, ans = 0;
	string s;
	cin >> n >> s;
	n = 0;
	rep(i, s.length()) {
		if (s[i] == 'I') {
			n++;
		}
		else {
			n--;
		}
		ans = max(ans, n);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    char[] array = sc.nextLine().toCharArray();
    
    try{
      for(int i = array.length-1;i>=0;i--){
        if(i>=6){
          if(array[i-6] == 'd'&&array[i-5] == 'r'&&array[i-4] == 'e'&&
             array[i-3] == 'a'&&array[i-2] == 'm'&&array[i-1] == 'e'&&
             array[i] == 'r'){
            i -= 6;
            continue;
          }
        }
        if(i >=5){
          if(array[i-5] == 'e'&&array[i-4] == 'r'&&array[i-3] == 'a'&&
             array[i-2] == 's'&&array[i-1] == 'e'&&array[i] == 'r'){
            i -= 5;
            continue;
          }
        }
        if((array[i-4] == 'd'&&array[i-3] == 'r'&&array[i-2] == 'e'&&
           array[i-1] == 'a'&&array[i] == 'm')||(array[i-4] == 'e'&&
           array[i-3] == 'r'&&array[i-2] == 'a'&&
           array[i-1] == 's'&&array[i] == 'e')){
          i-=4;
        }else{
          System.out.println("NO");
          return;
        }
      }
    }catch(ArrayIndexOutOfBoundsException e){
      System.out.println("NO");
      return;
    }
    System.out.println("YES");
  }
}

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

      
      
 
int main() {
  int sum=0;
  int max;
  int a,b;
  cin>>a>>b;
  max = a+b;
  if(max<a*b)
  {
      max = a*b;
  }
  if(max<a-b)
  {
      max = a-b;
  }
  cout<<max<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}



int N;
vector<long long> d, c;

long long solve() {
    long long ketasuu = 0;
    long long sum = 0;
    for (int i = 0; i < N; ++i) ketasuu += c[i], sum += d[i] * c[i];
    return (sum - 1) / 9 + (ketasuu - 1);
}

int main() {
    while (cin >> N) {
        d.resize(N); c.resize(N);
        for (int i = 0; i < N; ++i) cin >> d[i] >> c[i];
        cout << solve() << endl;
    }
}


Measured memory_bytes: 3328
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long int64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5, P = 1e9+7;
struct Matrix
{
	int64 __[3][3];
	Matrix() { memset(__, 0, sizeof(__)); }
	int64* operator [] (int i) { return __[i]; }
	Matrix operator * (const Matrix &_) const
	{
		Matrix ret;
		for(int i = 0; i < 3; ++i)
			for(int j = 0; j < 3; ++j)
				for(int k = 0; k < 3; ++k)
					ret[i][j] = (ret[i][j]+__[i][k]*_.__[k][j]%P)%P;
		return ret;
	}
	void set() { for(int i = 0; i < 4; ++i) __[i][i] = 1; }
}f, g, h;
int n, m, s[N];
Matrix qpow(Matrix a, int b)
{
	Matrix ret; ret.set();
	for( ; b; b >>= 1, a = a*a) if(b&1) ret = ret*a;
	return ret;
}
int main()
{
    n = read(), m = read();
    for(int i = 1; i <= m; ++i) s[i] = read();
	f[0][0] = f[0][1] = f[0][2] = 1;
	h[0][0] = 1;
	h[1][0] = 2, h[1][1] = 1;
	h[2][0] = h[2][1] = h[2][2] = 1;
	g = h, g[0][0] = 2, g[0][1] = g[0][2] = 1;
	for(int i = 1; i <= m; ++i) f = f*qpow(g, s[i]-s[i-1]-1)*h;
	f = f*qpow(g, n-1-s[m]);
	printf("%lld\n", f[0][0]);
    return 0;
}

Measured memory_bytes: 512
n = int(input())
L = []
for _ in range(n):
    x, l = map(int, input().split())
    left = x - l
    right = x + l
    L.append((left, right))
L = sorted(L, key=lambda x: x[1])
ans = 0
prev = -float('inf')
for r in L:
    if r[0] >= prev:
        ans += 1
        prev = r[1]
print(ans)


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

using namespace std;

typedef long long int64;
const int64 INF = 1LL << 58;
typedef pair< int64, pair< int, int > > Pi;

struct edge
{
  int vv, time, cost, nxt_ptr;

  bool operator<(const edge &e) const
  {
    return (time < e.time);
  }

  bool operator<(int t) const
  {
    return (time < t);
  }
};

int main()
{
  int N, M, S, G;
  vector< edge > g[100000];

  cin >> N >> M >> S >> G;
  --S, --G;

  for(int i = 0; i < M; i++) {
    int u, v, t, c;
    cin >> u >> v >> t >> c;
    --u, --v;
    g[u].push_back((edge) {v, t, c});
  }

  for(int i = 0; i < N; i++) {
    sort(begin(g[i]), end(g[i]));
  }

  for(int i = 0; i < N; i++) {
    for(auto &e : g[i]) {
      e.nxt_ptr = lower_bound(begin(g[e.vv]), end(g[e.vv]), e.time + e.cost) - begin(g[e.vv]);
    }
  }


  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  map< pair< int, int >, int64 > vv;
  que.emplace(g[S][0].time, make_pair(S, 0));
  vv[{S, 0}] = g[S][0].time;

  while(!que.empty()) {
    auto p = que.top();
    que.pop();

    int idx, now;
    tie(idx, now) = p.second;

    if(p.first > vv[{idx, now}]) continue;

    if(idx == G) {
      cout << p.first << endl;
      return (0);
    }

    if(now + 1 < g[idx].size()) {
      int64 nt = p.first + g[idx][now + 1].time - g[idx][now].time;
      if(!vv.count({idx, now + 1}) || nt < vv[{idx, now + 1}]) {
        vv[{idx, now + 1}] = nt;
        que.emplace(nt, make_pair(idx, now + 1));
      }
    }

    if(now < g[idx].size()) {
      auto &ee = g[idx][now];
      int64 nt = p.first;
      if(ee.vv != G) {
        if(ee.nxt_ptr >= g[ee.vv].size()) continue;
        nt += g[ee.vv][ee.nxt_ptr].time - (ee.time + ee.cost);
      }
      if(!vv.count({ee.vv, ee.nxt_ptr}) || nt < vv[{ee.vv, ee.nxt_ptr}]) {
        vv[{ee.vv, ee.nxt_ptr}] = nt;
        que.emplace(nt, make_pair(ee.vv, ee.nxt_ptr));
      }
    }
  }

}

Measured memory_bytes: 13552
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,x,y,z,l,n,m,a,r,f,c;
  long long min,max,sum;
  string s;

    cin >> r >> c;
    //vector<vector<int>> A(r, vector<int>(c, 0));
    vector<int> A(c, 0);
      
    for(int i=0;i<r+1;i++){
      sum = 0;
      for(int j=0;j<c;j++){
        if(i != r){
          cin >> x;
          A.at(j) += x;
        }else x = A.at(j);
        sum += x;
        cout << x << " ";
      }
      cout << sum << endl;
    }
  

  
}


Measured memory_bytes: 3080
/**
 *    author: gxfireball       
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
using namespace std;

void solve(){
   int n;
   cin>>n;
   if(n>=30) cout<<"Yes";
   else cout<<"No";

}

int main(){
    fastio;
    int t;
    t = 1;
    //cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int x,y;
int ans=0;
int cnt=0;
int main()
{
	cin>>x>>y;
	int a[x];
	for(int i=0;i<x;i++)
	{
		cin>>a[i];
		cnt=cnt+a[i];
	}
	sort(a,a+x);
	for(int j=0;j<x-y;j++)
	{
		ans=ans+a[j];
	}
	cout<<cnt-ans<<endl;
	return 0;	
}

Measured memory_bytes: 256
// Next Mayor
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1159&lang=jp

#include<iostream>
#include<vector>

using namespace std;

const int NONE = -1;

int N, P;
vector<int> player;
int bowl;
int winner;

inline bool is_win(int i) {
    for (int nth = 0; nth < N; ++nth) {
        if (nth == i) continue;
        if (player[nth] != 0) return false;
    }
    return true;
}

inline void pick_up(int i) {
    if (bowl == 0) {
        bowl += player[i];
        player[i] = 0;
        return;
    }
    else if (bowl == 1) {
        bowl--;
        player[i]++;
        if (is_win(i)) winner = i;
        return;
    }
    bowl--;
    player[i]++;
    return;
}

int main() {
    while(cin >> N >> P && N) {
        player.assign(N, 0); 
        bowl = P;
        winner = NONE;
        int i = 0;
        while (true) {
            if (winner != NONE) break;
            pick_up(i);
            i = (i + 1) % N;
        }
        cout << winner << endl;
    }
    return 0;
}

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

int main() {

  int S,b;
  b = 0;
  cin >> S;
  for(int i=0;i < S;i++){
  	char a;
    cin >> a;
    if(a == 'Y'){
      b++;
    }
  }
  if(b != 0){
    cout << "Four" << endl;
  }
  else{
    cout << "Three" << endl;
  }
}


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

int explorer(vector<string> *map,int i, int j){
	if(map->at(i)[j]=='#') return 0;
	
	int cnt=1;
	vector<int>vi;
    vi.reserve(4);
	vector<int>vj;
    vj.reserve(4);
	
	map->at(i)[j]='#';
	
	if(i!=0&&map->at(i-1)[j]=='.'){
		vi.push_back(i-1);
		vj.push_back(j);
	}if(i+1!=map->size()&&map->at(i+1)[j]=='.'){
		vi.push_back(i+1);
		vj.push_back(j);		
	}if(j!=0&&map->at(i)[j-1]=='.'){
		vi.push_back(i);
		vj.push_back(j-1);		
	}if(j+1!=map->at(i).size()&&map->at(i)[j+1]=='.'){
		vi.push_back(i);
		vj.push_back(j+1);		
	}

	while(!vi.empty()){
		cnt += explorer(map,vi.back(),vj.back());
		vi.pop_back();
		vj.pop_back();
	}

	return cnt;
}

int main() {
	int w,h;
	
	while(cin >> w >> h,w){
	vector<string> map;
	int psx=0,psy=0;
	map.resize(h);
	for(int i=0;i<h;i++){
		cin >> map[i];
		
		if(psx==0){
			if(map[i].find('@')!=-1){
				psx=map[i].find('@');
				psy=i;
			}
		}
	}
	
	cout << explorer(&map,psy,psx) << endl;
	}
	return 0;
}

Measured memory_bytes: 1260
import sys
input = sys.stdin.buffer.readline

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N - 1)]
M = int(input())
UV = [list(map(int, input().split())) for _ in range(M)]

def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff)
    return c
    
graph = [[] for _ in range(N + 1)]
for a, b in AB:
  graph[a].append(b)
  graph[b].append(a)
  
def make_tree(graph, root) -> (list, list):
  INF = 10 ** 15
  dist = [INF] * len(graph)
  parent = [-1] * len(graph)
  stack = [root]
  dist[root] = 0
  parent[root] = root
  while stack:
    s = stack.pop()
    for g in graph[s]:
      if dist[g] > dist[s] + 1:
        dist[g] = dist[s] + 1
        parent[g] = s
        stack.append(g)
  return dist, parent
 
def lca(u, v, dist, parent):
  distu, distv = dist[u], dist[v]
  if distu > distv:
    for _ in range(distu - distv):
      u = parent[u]
  if distv > distu:
    for _ in range(distv - distu):
      v = parent[v]
  while u != v:
    u, v = parent[u], parent[v]
  return u

dist, parent = make_tree(graph, 1)

tree_lca = []
for i in range(M):
    tmp = 0
    u, v = UV[i]
    l = lca(u, v, dist, parent)
    while u != l:
        tmp |= 1 << u
        u = parent[u]
    while v != l:
        tmp |= 1 << v
        v = parent[v]
    tree_lca.append(tmp)

answer = 2 ** (N - 1)
for i in range(1, 2 ** M):
    tmp = 0
    for j in range(M):
        if (i >> j) & 1:
            tmp |= tree_lca[j]
    cnt = popcnt(tmp)

    if popcnt(i) % 2 == 1:
        answer -= 2 ** (N - 1 - cnt) 
    else:
        answer += 2 ** (N - 1 - cnt) 
        
print(answer)

Measured memory_bytes: 41964
#include <iostream>
#define MOD 1000000007

using namespace std;
long long modtable[100001][13];
int main() {
    char S[100000];
    cin >> S;
    
    int m = 0;
    int N = 0;
    for (int i=0; S[i] != 0; i++, N++) {
        m = (m * 10) % 13;
        if (S[i] == '?') m += 0;
        else {
            m += (int)(S[i] - '0');
            m = m % 13;
        }
    }
    modtable[0][m]++;
    for (int mul=1, i=0; i<N; i++, mul=(mul*10)%13) {
        for (int k = 0; k < 13; k++) {
            if (S[N-i-1] == '?') {
                for (int l = 0; l < 10; l++) {
                    modtable[i+1][(k+l*mul)%13] += modtable[i][k];
                    modtable[i+1][(k+l*mul)%13] %= MOD;
                }
            } else {
                modtable[i+1][k] = modtable[i][k];
            }
        }
    }
    cout << modtable[N][5] << endl;
    return 0;
}



Measured memory_bytes: 10496
numbers = input().split()
A = int(numbers[0])
B = int(numbers[1])
C = int(numbers[2])

K = int(input())

for i in range(K):
    M = max(A,B,C)
    if A == M:
        A = 2 * A
    elif B == M:
        B = 2 * B
    else:
        C = 2 * C

print(A + B + C)

Measured memory_bytes: 3060
import java.util.*;


public class Main {
    static void solve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashSet<Integer> set = new HashSet<Integer>();
        for(int i=0; i<n; i++){
            set.add(sc.nextInt());
        }
        System.out.println(set.size());
    }

    public static void main(String[] args) {
        solve();
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
#define repd(i,a,b) for (int i=a;i<int(b);i++)
#define rep(i,n) repd(i,0,n)
#define VARNAME(v) #v
using P = pair<int,int>;


int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int BEAM = 900;
  int d;vector<int> c(26);cin>>d;rep(i,26)cin>>c[i];
  vector<array<int, 26>> s(d);
  rep(i,d)rep(j,26)cin>>s[i][j];
  vector<int> curs = {0};
  vector<array<int, 26>> curl(1);
  vector<vector<int>> cura(1);
  rep(i,d){
    int len = int(curs.size()) * 26, ind = 0;
    vector<P> nxs(len);
    vector<array<int, 26>> nxl(len);
    vector<vector<int>> nxa(len);
    rep(j, curs.size()){
      rep(t, 26){
        int score = curs[j];
        array<int, 26> last = curl[j];
        vector<int> ans = cura[j];
        score += s[i][t];
        last[t] = i+1;
        rep(k,26)score -= c[k]*(i+1 - last[k]);
        ans.emplace_back(t);
        nxs[ind] = P(score, ind);
        nxl[ind] = last;
        nxa[ind] = ans;
        ind++;
      }
    }
    sort(nxs.rbegin(), nxs.rend());
    len = min(len, BEAM);
    curs.resize(len);curl.resize(len);cura.resize(len);
    rep(j,len){
      curs[j] = nxs[j].first;
      curl[j] = nxl[nxs[j].second];
      cura[j] = nxa[nxs[j].second];
    }
    if(i % 73 == 0)BEAM -= 150;
  }
  int ans = 0;
  rep(i,min(int(curs.size()), BEAM)){
    if(curs[ans] < curs[i])ans = i;
  }

  for(auto x : cura[ans]){
    cout << x+1 << endl;
  }
}


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

int main(){
    map<long long ,long long> h;
    long long N;
    cin >> N;
    long long sum = 0;
    for(int i = 0; i < N; i++){
        long long a;
        cin >> a;
        sum += a;
        h[a] ++;
    }
    int Q;
    cin >> Q;
    long long BC[Q][2];    
    for(int i = 0; i < Q; i++){
        cin >> BC[i][0] >> BC[i][1];
    }
    for(int i = 0; i < Q; i++){
        long long B, C;
        B = BC[i][0];
        C = BC[i][1];
        // cout << h[B] << endl;
        // cout << h[C] << endl;
        sum += C*h[B] - B*h[B];
        h[C] += h[B];
        h[B] = 0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 10996
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

LL mod_pow(LL x, LL n){
    LL ans = 1;
    while(n>0){
        if((n&1)==1){
            ans = (ans * x) % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return ans;
}

int main(){
    LL n;
    cin >> n;
    LL ans=0;
    ans+=mod_pow(10,n);
    ans-=mod_pow(9,n);
    ans-=mod_pow(9,n);
    ans+=mod_pow(8,n);
    while(ans<0){
        ans+=MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *v = (i32 *) calloc (2 * n, sizeof (i32));
  i32 *c = v + n;
  for (i32 i = 0; i < 2 * n; ++i) {
    scanf ("%" SCNi32, v + i);
  }
  i32 ans = 0;
  for (i32 i = 0; i < n; ++i) {
    if (v[i] >= c[i]) {
      ans += v[i] - c[i];
    }
  }
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cout << fixed << setprecision(10);
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n,vector<int>(m));

  rep(i,n){
    cin >> c.at(i);
    rep(j,m){
      cin >> a.at(i).at(j);
    }
  }
  int ans = INF;
  for(int bit = 0; bit<(1<<n); bit++){
    vector<int> b(m,0);
    int cost = 0;
    rep(i,n){
      if(bit&(1<<i)){
        cost+=c.at(i);
        rep(j,m){
          b.at(j)+=a.at(i).at(j);
        }
      }
    }
    bool is = true;
    rep(i,m){
      if(b.at(i)<x){
        is = false;
      }
    }
    if(is){
      ans = min(ans,cost);
    }
  }
  if(ans==INF){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }
}


Measured memory_bytes: 3636
import kotlin.math.*
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*


private var fs = BufferedReader(InputStreamReader(System.`in`))
private fun readLn() = fs.readLine()!! // string line
private fun readStrings() = readLn().split(" ") // list of strings
private fun readLong() = readLn().toLong()
private fun readLongs() = readStrings().map { it.toLong() } // list of ints
private fun readInt() = readLn().toInt() // single int
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    solveAtc()
}
fun solveAtc() {
    var(a,b) = readStrings()
    var c = b.substringBeforeLast(".").toLong()
    var d = b.toString().substringAfterLast(".").toLong()
    println((d*a.toLong())/100L + c*a.toLong())
}


Measured memory_bytes: 35708
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bfs(nodes, src):
    from collections import deque

    N = len(nodes)
    que = deque([src])
    res = [-1] * N
    res[src] = 0
    while que:
        u = que.popleft()
        for v in nodes[u]:
            if res[v] != -1:
                continue
            res[v] = u
            que.append((v))
    return res

N, M = MAP()
nodes = [[] for i in range(N)]
for i in range(M):
    a, b = MAP()
    a -= 1; b -= 1
    nodes[a].append(b)
    nodes[b].append(a)

res = bfs(nodes, 0)
Yes()
for a in res[1:]:
    print(a+1)


Measured memory_bytes: 35052
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

signed main(){
  int N;
  cin >> N;

  vector<int> A(N);
  map<int, int> fac;
  for( int i = 0; i < N; i++ ){
    cin >> A.at(i);
    int M = A.at(i);
    for( int j = 2; j*j <= A.at(i); j++ ){
      if( M%j != 0 ) continue;
      int cnt = 0;
      while( M%j == 0 ){
        cnt++;
        M /= j;
      }
      if( fac.count(j) ) fac[j] = max(fac[j], cnt);
      else fac[j] = cnt;
    }
    if( fac.count(M) ) continue;
    else fac[M] = 1;
  }

  int L = 1;
  for( auto p : fac ){
    L *= modpow(p.first, p.second, MOD);
    L %= MOD;
  }

  int ans = 0;
  for( int i = 0; i < N; i++ ){
    int num = L * modinv(A.at(i), MOD) % MOD;
    ans += num;
    ans %= MOD;
  }
  cout << ans << endl;
 }


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define forna(i,a,n) for(int i=a;i<n;i++)
typedef long long int lli;
using namespace std;
int min(int x, int y)
{
    return (x < y)? x: y;

}
double my_sqrt(double num)
{
    double start = 0.00000000;
    double end = num;
    double sqrt = 0.0000000000;
    double epsil = 0.00000100000;

    while (start <= end)
    {
        double mid = ((start + end) / 2);

        sqrt = mid;
        // printf("sqrt = %f\n", sqrt);
        if (fabs(mid * mid -num) <= epsil)
        {
            break;
        }
        else if (mid * mid < num)
        {
            start = mid;
        }
        else
        {
            end = mid;
        }
    }
    return sqrt;
}
int findAngle(int hour, int min)
{
	int h = (hour * 360) / 12 + (min * 360) / (12 * 60);

	// find position of minute's hand
	int m = (min * 360) / (60);

	// calculate the angle difference
	int angle = abs(h - m);

	// consider shorter angle and return it
	if (angle > 180)
		angle = 360 - angle;

	return angle;
}
double calcAngle(double h, double m)
{
    if (h <0 || m < 0 || h >12 || m > 60)
    if (h == 12) h = 0;
    if (m == 60) m = 0;
    double hour_angle = 0.5 * (h * 60 + m);
    double minute_angle = 6 * m;
    double angle = minute_angle>hour_angle?  -hour_angle + minute_angle: hour_angle - minute_angle;
    // double angle = abs(hour_angle - minute_angle);
    angle = min(360 - angle, angle);
    return angle;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
double a,b,h,m;
cin>>a>>b>>h>>m;
double pi = 3.141592653589793238;
double angle=calcAngle(h,m)*pi/double(180);
// cout<<angle<<setprecision(25);
double c=sqrtl(a*a+b*b-double(2)*b*a*double(cos(angle)));
cout<<fixed<<setprecision(25)<<c;
}


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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N;

int main(){
	cin >> N;
	p(N*(N+1)/2-N);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL M;
LL dp[7001][7001];//1..iの要素で2以上をj回使った場合
int main(){
	cin>>N>>M;
	dp[0][0]=1;
	REP(i,3*N){
		REP(j,3*N){
			dp[i+1][j]+=dp[i][j];
			dp[i+1][j]%=M;
			dp[i+2][j+1]+=dp[i][j]*(i+1);
			dp[i+2][j+1]%=M;
			dp[i+3][j+1]+=dp[i][j]*(i+2)*(i+1);
			dp[i+3][j+1]%=M;
		}
	}
	/*REP(i,4){
		REP(j,3){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}*/
	LL ans=0;
	REP(i,N+1){
		ans+=dp[3*N][i];
		ans%=M;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 327552
using System;

namespace abc161_c
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long N = long.Parse(input[0]);
            long K = long.Parse(input[1]);

            int x = 0; //ループ用
            while(x == 0)
            {
                N = N % K;

                if(Math.Abs(N-K) > N)
                {
                    Console.WriteLine(N);
                    break;
                }
                N = System.Math.Abs(N-K);
            }
            Console.Read();
        }
    }
}

Measured memory_bytes: 27540
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;
int a[100000], b[100000];
int g[100001],cnt[100001];

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}
int dfs(int i) {
	if (g[i] != i) {
		int r = dfs(g[i]);
		cnt[r] += cnt[i];
		cnt[i] = 0;
		return g[i] = r;
	}
	else {
		return i;
	}
}


int main() {
	int n, m;
	scanf("%d%d", &n, &m);

	REP(i, m) {
		scanf("%d%d", &a[i], &b[i]);
	}
	REPS(i, n) {
		g[i] = i;
		cnt[i] = 1;
	}
	ll ans[100001];
	ans[m]= (ll)n*(n - 1) / 2;
	RREPS(i, m-1) {
		//puts("a");
		int g1 = dfs(a[i]);
		int g2 = dfs(b[i]);
		if (g1 != g2) {
			//puts("b");
			g[g2] = a[i];
			int bcnt = cnt[g1];
			dfs(b[i]);
			int acnt = cnt[g1];
			ans[i] = ans[i + 1] - (ll)bcnt*(acnt - bcnt);
			//printf("bc=%d ac=%d ans[%d]=%d\n", bcnt, acnt,i,ans[i]);
		}
		else {
			ans[i] = ans[i + 1];
		}
	}

	REPS(i, m) {
		PRINTL(ans[i]);
	}

}

Measured memory_bytes: 3584
sa = gets.chomp.chars
sb = gets.chomp.chars
sc = gets.chomp.chars

ans = ""
n = sa.shift
loop do
  if n == "a" && sa.empty?
    ans = "A"
    break
  elsif n == "b" && sb.empty?
    ans = "B"
    break
  elsif n == "c" && sc.empty?
    ans = "C"
    break
  end

  if n == "a"
    n = sa.shift 
  elsif n == "b"
    n = sb.shift if n == "b"
  else
    n = sc.shift
  end
end

puts ans

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    cout << a[n-1]-a[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

int c[51][51];
void f(){
    rep(i, 0, 51) c[i][0] = 1;
    rep(i, 1, 51){
        rep(j, 1, 51){
            c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
        }
    }
}

signed main(){
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> v(n);
    map<int, int> mp;
    rep(i, 0, n){
        cin >> v[i];
        mp[v[i]]++;
    }
    sort(all(v));
    reverse(all(v));
    double sum = 0;
    int end = v[a - 1], cnt = 0;
    rep(i, 0, a){
        sum += v[i];
        if(v[i] == end) cnt++;
    }
    int ans = 0;
    f();
    if(cnt != a){
        ans = c[mp[end]][cnt];
    }else{
        int MAX = min(mp[end], cnt + b - a);
        // cout << MAX << endl;
        rep(i, cnt, MAX + 1){
            ans += c[mp[end]][i];
        }
    }
    double ave = sum / (double)a;
    printf("%.10lf\n", ave);
    cout << ans << endl;
}

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

int main() {
  ll n, ans=0, a, b;  cin >> n >> a >> b;	vector<ll> v(n);
  for (int i = 0; i < n; i++){ 
  	cin >> v[i];
  }
  for (int i = 0; i < n - 1; i++)
    ans += min((v[i + 1] - v[i]) * a, b);
  cout << ans;
}


Measured memory_bytes: 1024
#include <stdio.h>
typedef struct return_home{
	int cost;
	int time;
}Ret;

int main(void) {
	int n, t;
	Ret ret[100];
	Ret ans = { 0, 0 };

	scanf("%d %d", &n, &t);
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &ret[i].cost, &ret[i].time);
		if (t >= ret[i].time) {
			if (ans.cost == 0) {
				ans = ret[i];
			}
			else {
				if (ret[i].cost < ans.cost) {
					ans = ret[i];
				}
			}
		}
	}
	if (ans.cost != 0) {
		printf("%d", ans.cost);
	}
	else {
		printf("TLE");
	}

	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
		// 1行目数字、2行目文字
		int iCount = Integer.parseInt(br.readLine());
		String ans = "ARC";
		
		if ( iCount < 1200 ) {
			ans = "ABC";
		}
		


        System.out.println(ans);
        return;
    }
    // Debug.Print
    static void dp(String s) {
		System.out.println(s);
	}
    static void dp(StringBuilder s) { dp(s.toString()); }
    static void dp(int i) { dp(String.valueOf(i)); }
    static void dp(long i) { dp(String.valueOf(i)); }

}

Measured memory_bytes: 8148
#include <bits/stdc++.h>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int n,h[105],ans;
signed main() {
	cin>>n;
	for(int i=1;i<=n;i++)cin>>h[i];
	for(int i=1;i<=100;i++){
		for(int j=1;j<=n;j++){
			if(h[j]>=i&&h[j-1]<i)ans++;
		}
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) cin >> d.at(i);

	ll res = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i == j) continue;
			res += d.at(i) * d.at(j);
		}
	}

	cout << res / 2 << endl;

	return 0;
}

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

if N <= 1 or M <= 1:
    if N*M <= 1:
        print(1)
    elif N*M <= 2:
        print(0)
    else:
        print(max(N, M) - 2)
elif N <= 2 or M <= 2:
    print(0)
else:
    print((N-2)*(M-2))


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

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

	vector<int> v;

	for( int i = 0; i < N; ++i ) {
		int a;
		cin >> a;

		v.push_back( a );
	}

	int count = 0;
	bool even = true;

	for( ;; ) {
		for( int i = 0; i < N; ++i ) {
			if( v[i] % 2 ) {
				even = false;
				break;
			}
		}

		if( !even ) {
			break;
		}

		for( int i = 0; i < N; ++i ) {
			v[i] /= 2;
		}

		count += 1;
	}

	cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int cnt,di;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<1000000000;i++){
		di=0;
		for(int j=0;j<n;j++){
			if(a[j]%2==0){
				di++;
			}
			else{
				break;
			}
		}
		if(di==n){
			for(int j=0;j<n;j++){
				a[j]=a[j]/2;
			}
			cnt++;
		}
		else{
			break;
		}
	}
	cout<<cnt<<endl;
}

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

int main()
{
    int a,b;
    cin >> a >> b;
    if(a == 1) a = 14;
    if(b == 1) b = 14;
    if(a == b){
        cout << "Draw";
    }else if(a > b){
        cout << "Alice";
    }else{
        cout << "Bob";
    }
}

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

int main()
{
    int A[3],i,cost[6];
    for(i=0;i<3;i++){
        scanf("%d",&A[i]);
    }

    cost[0] = abs(A[1]-A[0]) + abs(A[2]-A[1]);
    cost[1] = abs(A[2]-A[0]) + abs(A[1]-A[2]);
    cost[2] = abs(A[2]-A[1]) + abs(A[0]-A[2]);
    cost[3] = abs(A[0]-A[1]) + abs(A[2]-A[0]);
    cost[4] = abs(A[1]-A[2]) + abs(A[0]-A[1]);
    cost[5] = abs(A[0]-A[2]) + abs(A[1]-A[0]);

    int min=10000;
    for(i=0;i<6;i++){
        if( min > cost[i]){
            min = cost[i];
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int make(int i, int j){
    return pow(10, i) * j;
}

int main(){

    int N;
    cin >> N;

    int P=0;
    int Q=0;
    int A[N];
    for(int i=N; i>=1; i--){
        int t;
        cin >> t;
        P += make(i-1, t);
    }

    for(int i=N; i>=1; i--){
        int t;
        cin >> t;
        Q += make(i-1, t);
    }

    for(int i=0; i<N; i++){
        A[i] = i+1;
    }

    vector<int> L;
    do {

        int num = 0;
        for(int i=0; i<N; i++){
            num += make(i, A[i]);
        }

        L.push_back(num);

    }while(next_permutation(A, A+N));

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

    int i=0, a=0, b=0;
    do{
        if(P==L[i]) a = i;
        if(Q==L[i]) b = i;
        if(a!=0 && b!= 0) break;
        i++;
    }while(next_permutation(A, A+N));
    
    if(a >= b){
        cout << a-b;
    }else{
        cout << b-a;
    }    

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    long long ai=0;
    int a1;
    for(int i=0;i<m;i++){
        cin>>a1;
        ai+=a1;
    }
    if(n-ai>=0){
        cout<<n-ai<<"\n";
    }else{
        cout<<-1<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

#define rep(i,n) for (int i = 0; i < (n); ++i)

int main()
{
  ll n;
  cin >> n;

  vector<ll> hurui(n+1, 0);

  for (ll i = 2; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      hurui[j]++;
    }
  }

  ll total = 0;
  for (int i = 1; i <= n; i++) {
    total += i * (hurui[i] + 1);
  }

  cout << total << endl;
}


Measured memory_bytes: 81380
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    ll ans = 0;
    char pre = '!';
    REP(j,K){
        char pre = '!';
        for(int i=j;i<N;i+=K){
            if(pre == '!'){
                if(T[i] == 'r'){
                    ans += P;
                    pre = 'r';
                }
                else if(T[i] == 's'){
                    ans += R;
                    pre = 's';
                }
                else if(T[i] == 'p'){
                    ans += S;
                    pre = 'p';
                }
            }
            else{
                if(pre == T[i]){
                    pre = '!';
                    continue;
                }
                if(T[i] == 'r'){
                    ans += P;
                    pre = 'r';
                }
                else if(T[i] == 's'){
                    ans += R;
                    pre = 's';
                }
                else if(T[i] == 'p'){
                    ans += S;
                    pre = 'p';
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int N;
  cin >> N;
  ll ans = 1;
  for (int i = 1; i <= N; i++) {
    ans *= i;
    ans %= MOD;
  }
  cout << ans << endl;
}

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;

#define int long long
#define deb(x) cout << #x << " " << x << endl;
#define pb push_back
#define pp pop_back
#define F first
#define S second
#define all(x) x.begin(),x.end()

#define MOD 1000000007
#define MAX 50000

typedef long double ld;
const int N = 1e5 + 10;
const long double Pie = acos(-1);

signed main() {
	
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	
	int positiveOnes = min(a, k);
	k = k - positiveOnes;
	
	int zeroes = min(b, k);
	k = k - zeroes;
	
	int negativeOnes = min(c, k);
	
	cout << positiveOnes +  (-1 * negativeOnes);
	
	return 0;
}


Measured memory_bytes: 3552
#include<iostream>
using namespace std;
int main(){
	int sx, sy, tx,ty;
	cin >> sx >> sy >> tx >> ty;
	for(int i = 0; i<(ty- sy); i++){
		cout << 'U';
	} 
	for(int i = 0; i<(tx- sx); i++){
		cout << 'R';
	} 
	for(int i = 0; i<(ty- sy); i++){
		cout << 'D';
	} 
	for(int i = 0; i<(tx- sx); i++){
		cout << 'L';
	}
	 
	int csx = sx, csy =sy, ctx = tx,cty = ty;
	csx -= 1;
	cty += 1;
	cout << 'L'; 
	for(int i = 0; i<(cty- csy); i++){
		cout << 'U';
	}
	for(int i = 0; i<(ctx- csx); i++){
		cout << 'R';
	} 
	 cout << 'D';
	 
	ctx = tx +1;
	csy = sy -1; 
	csx = sx, cty = ty; 
	cout << 'R';  
	for(int i = 0; i<(cty- csy); i++){
		cout << 'D';
	} 
	for(int i = 0; i<(ctx- csx); i++){
		cout << 'L';
	} 
	cout << 'U';
	
	return 0;
}

Measured memory_bytes: 3604
d,g=map(int,input().split())
pc=[]
for _ in range(d):
  pc.append([int(i) for i in input().split()])

def solve(g,i):
  if i==-1:
    return 100000
  n=min(g//(100*(i+1)),pc[i][0])
  s=n*(i+1)*100
  if n==pc[i][0]:
    s+=pc[i][1]
  if g-s>0:
    n+=solve(g-s,i-1)
  return min(n,solve(g,i-1))

print(solve(g,d-1))

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        if(n==0&&m==0) continue;
        printf(((n&1)&&(m&1))?"no\n":"yes\n");
    }
    return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
vector<list<int>> v(100005);
vector<int> dp(100005,-1);
// vector<int> isvisited(100005);
int n,m;
int dfs(int i)
{
    int ans = 0;
    for(auto nbr:v[i])
    {
        if(dp[nbr]==-1)
        {
            ans = max(ans,1+dfs(nbr));
        }
        else{
            ans = max(ans,dp[nbr]+1);
        }
    }
    return dp[i] = ans;
}
int main() {
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
    }
    for(int i=1;i<=n;i++)
    {
        if(dp[i]==-1)
        {
            dp[i] = dfs(i);
        }
    }
    int res=0;
    for(int i=1;i<=n;i++)
    res = max(res,dp[i]);
    cout<<res;
}


Measured memory_bytes: 11100
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

int main() {
	int N, K, d;
	int A[100] = { 0 };
	int cnt = 0;

	scanf("%d %d", &N, &K);

	for (int i = 0; i < K; i++) {
		scanf("%d", &d);

		for (int j = 0; j < d; j++) {
			int num;
			scanf("%d", &num);
			A[num - 1]++;
		}
	}

	for (int i = 0; i < N; i++) if (A[i] == 0) cnt++;

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

	return 0;
}

Measured memory_bytes: 1736
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N[] = new int[5];
        for(int i = 0; i < 5; i++){
            N[i] = sc.nextInt();
            if(N[i] == 0){
                System.out.println(i+1);
            }
        }
    }
}


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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    map<string, int> mp;

    int n; cin >> n;
    for(int i = 0;i < n; ++i){
        string s; cin >> s;
        ++mp[s];
    }

    int m; cin >> m;
    for(int i = 0;i < m; ++i){
        string s; cin >> s;
        --mp[s];
    }

    int ans = 0;
    for(auto itr : mp){
        ans = max(ans, itr.second);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256