akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>

using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

#define rep(i,s,n)for(int i = s;i<n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=s;i--)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define repe_r(i,s,n)for(int i = n;i>=s;i--)

ll l[100001] = {};
ll r[100001] = {};
ll x[100001] = {};

int main() {
	ll n, m; cin >> n >> m;
	rep(i, 0, m) {
		ll L; cin >> L;
		ll R; cin >> R;
		x[L]++; x[R + 1]--;
	}

	repe(i, 1, n) {
		x[i] += x[i - 1];
	}

	ll ans = 0;
	repe(i, 1, n) {
		if (x[i] == m)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
# 累積和(2次元)
N, M, Q = map(int, input().split())

t = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    t[L][R] += 1

for i in range(N + 1):
    for j in range(N):
        t[i][j + 1] += t[i][j]

for i in range(N):
    for j in range(N + 1):
        t[i + 1][j] += t[i][j]

result = []
for _ in range(Q):
    p, q = map(int, input().split())
    result.append(t[q][q] + t[p - 1][p - 1] - t[p - 1][q] - t[q][p - 1])
print('\n'.join(str(v) for v in result))
#print(*result, sep='\n')


Measured memory_bytes: 30484
S = str(input())
s = list(S)

s0 = s[0]
s1 = s[1]
s2 = s[2]
s3 = s[3]

c0 = S.count(s0)
c1 = S.count(s1)
c2 = S.count(s2)
c3 = S.count(s3)
ct = c0 + c1 + c2 + c3
ct

if ct == 8:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3188
from sys import stdin

def main():
    S = input()

    S_ = S.replace('BC', 'D')
    ans, cnt = 0, 0
    for s in S_[::-1]:
        if s == 'D':
            cnt += 1
        elif s == 'A':
            ans += cnt
        else:
            cnt = 0
    print(ans)

input = lambda: stdin.readline().rstrip()
main()


Measured memory_bytes: 3560
macro_rules! read_line_to_tuple {
    ( $( $t:ty ),* ) => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        let mut iter = input.split_whitespace();
        ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )
    }};
}

struct Scc {
    n: usize,
    graph: Vec<Vec<usize>>,
    rev_graph: Vec<Vec<usize>>,
    post_order: Vec<usize>,
    component: Vec<usize>,
    ans: Vec<Vec<usize>>,
}

impl Scc {
    fn new(n: usize) -> Scc {
        Scc {
            n,
            graph: vec![Vec::new(); n],
            rev_graph: vec![Vec::new(); n],
            component: vec![n; n],
            post_order: Vec::with_capacity(n),
            ans: Vec::new(),
        }
    }

    fn add_edge(&mut self, from: usize, to: usize) {
        self.graph[from].push(to);
        self.rev_graph[to].push(from);
    }

    fn dfs(&mut self, from: usize) {
        self.component[from] = self.n + 1;
        for to in self.graph[from].clone() {
            if self.component[to] == self.n {
                self.dfs(to);
            }
        }
        self.post_order.push(from);
    }
    
    fn rev_dfs(&mut self, from: usize, k: usize) {
        self.component[from] = k;
        for to in self.rev_graph[from].clone() {
            if self.component[to] > self.n {
                self.rev_dfs(to, k);
            }
        }
        self.ans[k].push(from);
    }

    fn solve(&mut self) -> usize {
        for i in 0..self.n {
            if self.component[i] == self.n {
                self.dfs(i);
            }
        }

        let mut k: usize = 0;
        for i in (0..self.n).rev() {
            if self.component[self.post_order[i]] > self.n {
                self.ans.push(Vec::new());
                self.rev_dfs(self.post_order[i], k);
                k += 1;
            }
        }

        k
    }
}

fn main() {
    let (n, m) = read_line_to_tuple!(usize, usize);

    let mut scc = Scc::new(n);
    for _ in 0..m {
        let (a, b) = read_line_to_tuple!(usize, usize);
        scc.add_edge(a, b);
    }
    let k = scc.solve();

    let mut ans = Vec::with_capacity(k + 1);
    ans.push(k.to_string());
    for i in 0..k {
        ans.push(
            [scc.ans[i].len()].iter().chain(scc.ans[i].iter())
                .map(|x| x.to_string())
                .collect::<Vec<_>>()
                .join(" ")
        );
    }
    println!("{}", ans.join("\n"));
}

Measured memory_bytes: 116364
bingo = []
for i in range(3):
    bingo.append(list(map(int, input().split())))

n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == b:
                bingo[i][j] = "o"

for i in range(3):
    flag = 0
    for j in range(3):
        if bingo[i][j] == "o":
            flag += 1
    if flag == 3:
        print("Yes")
        exit()
    flag = 0
    for j in range(3):
        if bingo[j][i] == "o":
            flag += 1
    if flag == 3:
        print("Yes")
        exit()
# 斜め
if (
    bingo[0][0] == bingo[1][1] == bingo[2][2] == "o"
    or bingo[0][2] == bingo[1][1] == bingo[2][0] == "o"
):
    print("Yes")
    exit()
print("No")


Measured memory_bytes: 3064
a = list(map(int, input()))
for bs in range(8):
    sm = a[0]
    ret = str(a[0])
    for i in range(3):
        num = a[i + 1]
        if bs & 1 << i:
            sm += num
            ret += str("+")
        else:
            sm -= num
            ret += str("-")
        ret += str(num)
    if sm == 7:
        ret += "=7"
        break
print(ret)


Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    int K, X;
    read(K, X);
    vector<int> ans;
    for(int i = max(-1000000, X - K + 1); i <= min(1000000, X + K - 1); i++){
        ans.push_back(i);
    }
    write_vec(ans, ' ');
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL LMAX = 100;

LL ec = 1,to[2000005],cap[2000005],w[2000005],nxt[2000005],hed[1000005] = {0};
void add_edge(LL f,LL t,LL c,LL d){
	++ ec; to[ec] = t; cap[ec] = c; w[ec] = d; nxt[ec] = hed[f]; hed[f] = ec;
	++ ec; to[ec] = f; cap[ec] = 0; w[ec] = -d; nxt[ec] = hed[t]; hed[t] = ec;
}

LL dis[4005],inq[4005],flw[4005];
LL pre[4005],prv[4005];

queue <LL> q;
LL spfa(LL s,LL t){
	memset(dis,INF,sizeof(dis));
	memset(inq,0,sizeof(inq));
	memset(flw,0,sizeof(flw)); prv[t] = -1;
	q.push(s); inq[s] = 1; dis[s] = 0; flw[s] = INF;
	while(!q.empty()){
		LL u = q.front(); q.pop();
		inq[u] = 0;
		for(LL i = hed[u];i;i = nxt[i]){
			LL v = to[i];
			if(dis[v] > dis[u] + w[i] && cap[i]){
				dis[v] = dis[u] + w[i];
				prv[v] = u; pre[v] = i;
				flw[v] = min(flw[u],cap[i]);
				if(!inq[v]){
					inq[v] = 1;
					q.push(v);
				}
			}
		}
	}
	return prv[t] != -1;
}

LL mxf = 0,mcf = 0;
void mcmf(LL s,LL t){
	while(spfa(s,t)){
		mxf += flw[t];
		mcf += flw[t] * dis[t];
		LL now = t;
		while(now != s){
			cap[pre[now]] -= flw[t];
			cap[pre[now] ^ 1] += flw[t];
			now = prv[now];
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	LL n,x,y,w,S,T;
	cin >> n;
	S = n + n + 5; T = S + 1;
	for(LL i = 1;i <= n;i ++){
		cin >> x >> y >> w;
		add_edge(S,i,w,0);
		add_edge(i,n + n + 1,INF,+ x + y);
		add_edge(i,n + n + 2,INF,+ x - y);
		add_edge(i,n + n + 3,INF,- x + y);
		add_edge(i,n + n + 4,INF,- x - y);
	}
	for(LL i = 1;i <= n;i ++){
		cin >> x >> y >> w;
		add_edge(i + n,T,w,0);
		add_edge(n + n + 1,i + n,INF,- x - y);
		add_edge(n + n + 2,i + n,INF,- x + y);
		add_edge(n + n + 3,i + n,INF,+ x - y);
		add_edge(n + n + 4,i + n,INF,+ x + y);
	}
	mcmf(S,T);
	cout << -mcf << endl;
	return 0;
}

Measured memory_bytes: 8704
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, a, b;
int main() {
  cin >> n >> a >> b;
  cout << (min(a, b)) << ' '
    << (max(a+b-n, 0ll)) << endl;
  return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main() {
	int X, Y, N, M, x[100], y[100];
	cin >> N >> M >> X >> Y;

	int a = X, b = Y;
	REP(i, N) {
		cin >> x[i];
		a = max(a, x[i]);
	}
	REP(i, M) {
		cin >> y[i];
		b = min(b, y[i]);
	}

	if (a < b) {
		cout << "No War" << endl;
	}
	else {
		cout << "War" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
import sys

def ispalindrome(str):return 1 if str == str[::-1] else 0

S=str(input())
len_s = len(S)
len_h = int((len_s-1)/2)


if ispalindrome(S)==0:
	print('No')
	sys.exit()
else:
	if ispalindrome(S[:len_h])==0:
		print('No')
		sys.exit()
	elif ispalindrome(S[-1:len_h])==0:
		print('No')
		sys.exit()
print('Yes')

Measured memory_bytes: 3064
n = int(input())
arr = list(map(int,input().split()))
dicta={}
ans=0
for i in arr:
    dicta[i] = dicta.get(i,0)+1

for key,value in dicta.items():
    if key == value:
        continue
    elif key > value:
        ans+=value
    else:
        diff = abs(value-key)
        ans += diff

print(ans)






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

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

using namespace std;
typedef long long ll;

int main() {
  ll n, x, ans = 0, t, ans2 = 0;
  cin >> n >> x;
  vector<ll> a(n), acp(n);
  rep(i, n) cin >> a[i];

  for (int i = 1; i < n; ++i)
    if (a[i - 1] + a[i] > x) {
      ans += a[i] + a[i - 1] - x;
      a[i] = x - a[i - 1];
      if (a[i] < 0) a[i - 1] += a[i], a[i] = 0;
    }


  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
import sys
sys.setrecursionlimit(10**8)

def main():
    n,m = map(int,input().split())
    UF = UnionFind(n+m)
    for i in range(n):
        kl = list(map(int, input().split()))
        for j in range(1,len(kl)):
            UF.union(i,n+kl[j]-1)
    for i in range(n-1):
        if not UF.same(i,i+1):
            print('NO')
            return
    print('YES')
if __name__ == "__main__":
    main()

Measured memory_bytes: 9660
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>
//#include "atcoder/all"

using namespace std;
//using namespace atcoder;

#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define P pair<int,int>

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;


int main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.rbegin(),a.rend());
    ll ans = 0;
    rep(i,n) {
        ans += a[i/2];
    }
    cout << ans - a[0] << endl;
}



Measured memory_bytes: 4672
using System;
using System.Collections.Generic;
 
namespace ALDS1_3
{
    class Program
    {
        public struct Process
        {
            public readonly string n;
            public readonly int t;
            public Process(string n, int t)
            {
                this.n = n;
                this.t = t;
            }
        }
 
        static void Main()
        {
            var s = Console.ReadLine().Split();
            var a = int.Parse(s[1]);
            var b = new Queue<Process>();
            string w;

            while ((w = Console.ReadLine()) != null)
            {
                var c = w.Split();
                var d = c[0]; var e = int.Parse(c[1]);
                b.Enqueue(new Process(d, e));
            }
 
            var f = 0;
 
            while (b.Count > 0)
            {
               var g = b.Dequeue();
               var k = g.n;
               var v = g.t;
               f += v < a ? v : a;
               v -= a;
               if (v <= 0)
                   Console.WriteLine("{0} {1}", k, f);
               else
                   b.Enqueue(new Process(k, v));
            }
        }
    }
}

Measured memory_bytes: 15800
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    vi A(N), B(N); F0R(i, N) cin >> A[i] >> B[i];
    sort(all(A));
    sort(all(B));
    ll X, Y; 
    if (N % 2 == 1) {
        X = A[N/2];
        Y = B[N/2];
    } else {
        X = A[N/2 - 1] + A[N/2];
        Y = B[N/2 - 1] + B[N/2];
    }

    cout << Y-X+1 << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 4784
n = input()
a,b = "",""
for i in range(len(n)//2):
    a += "01"
    b += "10"
if len(n) != len(a):
    a += "0"
    b += "1"

acount,bcount = 0,0
for i in range(len(n)):
    if n[i] != a[i]:
        acount += 1
    if n[i] != b[i]:
        bcount += 1
print(min(acount,bcount))

Measured memory_bytes: 9432
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

int v[20], c[20];

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

	int N; cin >> N;
	int ans = 0;
	for (int i = 0; i < N; i++) cin >> v[i];
	for (int i = 0; i < N; i++) cin >> c[i];
	for (int i = 0; i < N; i++) {
		if (v[i] >= c[i]) ans += (v[i] - c[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/*
    Author: Jerry Yang C.H. (tico88612)
    Date: 2019/12/12
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN = 

/********** Good Luck :) **********/
int main()
{
    IOS();
    string enter;
    while(cin >> enter){
        vector<bool> alpha(26, 0);
        REP(i, SZ(enter)){
            alpha[enter[i] - 'a'] = 1;
        }
        bool ju = 1;
        REP(i, 26){
            if(!alpha[i]){
                cout << (char)(i + 'a') << '\n';
                ju = 0;
                break;
            }
        }
        if(ju)
            cout << "None" << '\n';
    }
    return 0;
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define pii pair<int,int>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define nl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main()
{   fastio;

    int n;
    cin>>n;
    map<string , int>mp;
    for(int i=0; i<n; i++)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}


Measured memory_bytes: 3652
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P) :
 P = sorted(P)
 phU = []
 phU.append(P[0])
 phU.append(P[1])
 for p in P[2:] :
  phU.append(p)
  if isCLKWISE(phU) : continue
  while(True):
   del phU[-2]
   try:
    if isCLKWISE(phU) : break
   except IndexError : break
 phL = []
 phL.append(P[-1])
 phL.append(P[-2])
 for p in P[-3::-1] :
  phL.append(p)
  if isCLKWISE(phL) : continue
  while(True) :
   del phL[-2]
   try:
    if isCLKWISE(phL) : break
   except IndexError : break
 ph = phU + phL[1:-1]
 return ph
  
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
P = ConvexHullScan(P)
P.reverse()
print(len(P))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2]
for p in P[idx:] + P[:idx] : print(p[0],p[1])

Measured memory_bytes: 33180
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> inline bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct tree{
    size_t n,r,md;
    vector<vector<int>> e;
    vector<int> pa,d,sz,x;
    explicit tree(int n):n(n),e(n),x(n){}
    explicit tree(string&s):n(s.length()/2+1),e(n),pa(n),d(n),sz(n,1){
        pa[0]=-1;
        int i{};
        stack<int> p;
        p.push(0);
        for(auto c:s){
            if(c=='('){
                pa[++i]=p.top();
                d[i]=p.size();
                e[p.top()].push_back(i);
                p.push(i);
            }
            else{
                sz[pa[p.top()]]+=sz[p.top()];
                p.pop();
            }
        }
        assert(i==n-1);
    }
    void built(bool f=true){
        static int a,b;
        fr(i,n-1){
            cin>>a>>b;
            if(f) --a,--b;
            add(a,b);
        }
    }
    void pbuilt(bool f=true){
        static int a;
        Fr(i,n-1){
            cin>>a;
            if(f) --a;
            add(a,i,false);
        }
        for(auto&i:x) cin>>i;
    }
    void add(int a,int b,bool f=true){
        e[a].emplace_back(b);
        if(f) e[b].emplace_back(a);
    }
    template<class T>
    vector<T> rec(int i){
        vector<T> ans(3,1);
        ans[1]=2;
        for(auto j:e[i]){
            auto a=move(rec<T>(j));
            auto m0=ans.size(),m1=a.size();
            ans.resize(m0+m1-1,0);
            ifr(i0,m0){
                iFr(i1,m1-1) ans[i0+i1]+=ans[i0]*a[i1];
                ans[i0]*=a[0];
            }
        }
        return ans;
    }
    void r_dfs(int i,int p=-1,int D=0){
        pa[i]=p;d[i]=D;md=max(md,(size_t)D);++D;
        for(auto j:e[i]) if(j!=p) r_dfs(j,i,D),sz[i]+=sz[j];
    }
    void r_i(int r_){
        pa.resize(n);d.resize(n);sz.resize(n,1),r=r_;md=0;
        r_dfs(r);
    }
    int r2(){
        r_i(0);
        int m=0,M=0;
        fr(i,n) m=max(m,d[i]);
        fr(i,n) if(d[i]==m) M=i;
        pa.clear(),d.clear();
        r_i(M);
        m=0;
        fr(i,n) m=max(m,d[i]);
        return m;
    }
    int solve(int i){
        int s{};
        bitset<5001> a;
        a[0]=true;
        for(auto&j:e[i]){
            int y=solve(j);
            if(y<0) return -1;
            s += x[j] + y;
            a = a << x[j] | a << y;
        }
        ifr(l,x[i]+1) if(a[l]) return s - l;
        return -1;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    tree tr(n);
    tr.pbuilt();
    puts(tr.solve(0)>=0?"POSSIBLE":"IMPOSSIBLE");
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int q;
  int flag=1;
  cin>>s>>q;
  for(int i=0;i<q;i++){
    int t;
    cin>>t;
    if(t==1){
      flag*=-1;
    }else{
      int f;
      string c;
      cin>>f>>c;
      if(flag>0){
        if(f==2){
          s+=c;
        }else if(f==1){
          s.insert(0,c);
        }
      }else{
        if(f==1){
          s+=c;
        }else if(f==2){
          s.insert(0,c);
        }
      }
    }

  }
  if(flag<0){
    reverse(s.begin(),s.end());
  }
  cout<<s<<endl;
}


Measured memory_bytes: 900
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner reader = new Scanner(System.in);
    int N = reader.nextInt();
    int M = reader.nextInt();
    int X = reader.nextInt();
    int Y = reader.nextInt();
    int[] xn = new int[N];
    int[] ym = new int[M];
    for (int i= 0; i < N; i++) {
    	xn[i] = reader.nextInt();
    }
    for (int i= 0; i < M; i++) {
    	ym[i] = reader.nextInt();
    }
    
    int Z = X + 1;
    while (Z < Y) {
    boolean isWar = false;
    	for (int i= 0; i < N; i++) {
            if (xn[i] >= Z) {
              isWar = true;
            }
        }
        for (int i= 0; i < M; i++) {
            if (ym[i] < Z) {
              	isWar = true;
            }
        }
      if (!isWar) {
         System.out.print("No War");
      	return;
      }
      	Z++;
      
    }
        System.out.print("War");
  
  }


}

Measured memory_bytes: 23636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;


public class Main {
	static int[][] grid = new int[14][14];

	static void dropL(int x, int y) {
		grid[x][y-2]++;
		grid[x-1][y-1]++;grid[x][y-1]++;grid[x+1][y-1]++;
		grid[x-2][y]++;grid[x-1][y]++;grid[x][y]++;grid[x+1][y]++;grid[x+2][y]++;
		grid[x-1][y+1]++;grid[x][y+1]++;grid[x+1][y+1]++;
		grid[x][y+2]++;
	}

	static void dropM(int x, int y) {
		grid[x-1][y-1]++;grid[x][y-1]++;grid[x+1][y-1]++;
		grid[x-1][y]++;grid[x][y]++;grid[x+1][y]++;
		grid[x-1][y+1]++;grid[x][y+1]++;grid[x+1][y+1]++;
	}

	static void dropS(int x, int y) {
		grid[x][y-1]++;
		grid[x-1][y]++;grid[x][y]++;grid[x+1][y]++;
		grid[x][y+1]++;
	}

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

		int i = 1;
		while (sc.hasNext()) {
			String[] terms = sc.next().split(",");
			int x = Integer.parseInt(terms[0])+2;
			int y = Integer.parseInt(terms[1])+2;
			int s = Integer.parseInt(terms[2]);

			switch (s) {
			case 1: dropS(x, y); break;
			case 2: dropM(x, y); break;
			case 3: dropL(x, y); break;
			}
			//if (i == 6) break; else i++;
		}

		int W = 100, T = 0;
		for (int x = 2 ; x < 12 ; x++) {
			for (int y = 2 ; y < 12 ; y++) { //System.out.print(grid[x][y]);
				if (grid[x][y] > 0) {
					W--;
					T = Math.max(T, grid[x][y]);
				}
			} //System.out.print("\n");
		}
		System.out.println(W+"\n"+T);
	}
}

Measured memory_bytes: 17168
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=list(map(lambda x:x-1 ,a))

s=[0]
for i in range(n):
    s.append(s[-1]+a[i])
s=list(map(lambda x:x%k,s))
from collections import defaultdict
d=defaultdict(int)
d[0]=1
ans=0

for i in range(1,n+1):
    if i>=k:
        d[s[i-k]]-=1
    ans+=d[s[i]]
    d[s[i]]+=1
print(ans)


Measured memory_bytes: 116040
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        Integer r = sc.nextInt(); // 2 < 5
        Integer D = sc.nextInt(); // 1 <= 1000
        Integer x = sc.nextInt(); // D <= 200

        List<Integer> results = new ArrayList<>(10);
        for (int i = 0; i < 10; i++) {
            int tmp = r * x - D;
            results.add(tmp);
            x = tmp;
        }

        results.stream().peek(System.out::println).count();
    }

}


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

int main(){

 
  ll N;
  ll A,B;
  cin>>N>>A>>B;
  
  if(A==0 && B==0){cout<<0<<endl;return 0;}
  
  ll count=0;
  count+=A*(N/(A+B));
  
  if(N%(A+B)<A)count+=N%(A+B);
  else count+=A;
  
  cout<<count<<endl;
  
}

Measured memory_bytes: 256
package main

import "fmt"

func main(){
  var a, b int
  fmt.Scan(&a, &b)
  if a%3 == 0 || b%3 == 0 || (a+b)%3 == 0{
    fmt.Println("Possible")
  }else{
    fmt.Println("Impossible")
  }
}


Measured memory_bytes: 512
// https://atcoder.jp/contests/abc179/tasks/abc179_b

#include <bits/stdc++.h>
using namespace std;

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

    int cont = 0;
    for (int i = 0; i < n; i++)
    {
        int d1, d2;
        cin >> d1 >> d2;
        if (d1 == d2)
        {
            cont++;
            if (cont == 3)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
        else
        {
            cont = 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int n;
vector<vi> a;
vi now;
void dfs(int d) {
    if (d == n) {
        a.pb(now);
        return;
    }
    rep1(i, n) {
        bool used = false;
        rep(j, d) if (now[j] == i) used = true;
        if (used) continue;
        now[d] = i;
        dfs(d+1);
    }
}

int main(){
    cin >> n;
    vi p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    now = vi(n);
    dfs(0);
    int pnum = 0, qnum = 0;
    rep(i, sz(a)) {
        if (a[i] == p) pnum = i;
        if (a[i] == q) qnum = i;
    }
    cout << abs(pnum-qnum) << endl;
    return 0;
}


Measured memory_bytes: 6356
import java.util.*;
import java.io.*;
 
public class Main {
    static int ans = 0;
    static long n = 0;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        n = sc.nextInt();
        int[] checked = new int[3];
        dfs("", checked);
        System.out.println(ans);
    }
    
    public static void dfs(String now, int[] chk){
        if(!now.isEmpty() && Long.parseLong(now) <= n && chk[0] >= 1 && chk[1] >= 1 && chk[2] >= 1){
            ans++;
        }else if(!now.isEmpty() && Long.parseLong(now) > n){
            return;
        }
        chk[0]++;
        dfs(now+"3",chk);
        chk[0]--;
        chk[1]++;
        dfs(now+"5",chk);
        chk[1]--;
        chk[2]++;
        dfs(now+"7",chk);
        chk[2]--;
        return;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
    
    public void close() throws Exception{
        this.reader.close();
        return;
    }

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

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

Measured memory_bytes: 41468
n = gets.to_i
s = gets.chomp.chars

ans = 0
(1..n-2).each do |i|
  cnt = 0
  ('a'..'z').to_a.each do |str|
    cnt += 1 if s[0..i].include?(str) && s[(i+1)..(n-1)].include?(str)
  end
  ans = cnt if cnt > ans
end

puts ans

Measured memory_bytes: 1788
#include<cstdio>
typedef long long ll;
ll s[210000],t[210000];
ll mergesort(int l,int r)
{
	if(l==r) return 0;
	int mid=(l+r)>>1;
	ll ret=mergesort(l,mid)+mergesort(mid+1,r);
	int i=l,j=mid+1,k=l;
	while(i<=mid&&j<=r)
		if(s[i]>s[j]) t[k++]=s[i++];
		else {t[k++]=s[j++];ret+=(mid-i+1);}
	while(i<=mid) t[k++]=s[i++];
	while(j<=r) t[k++]=s[j++];
	for(int i=l;i<=r;i++) s[i]=t[i];
	return ret;
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		ll x;scanf("%lld",&x);
		x-=k;
		s[i]=s[i-1]+x;
	}
	ll ans=mergesort(0,n);
	printf("%lld\n",ans);
	return 0;
}

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

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795

ll f(ll a)
{
  ll cnt=0,i;
  for(i=1;i*i<a;i++)
  {
if(a%i==0)cnt+=2;
  }
  if(i*i==a)cnt++;
  return cnt;
}
ll ans(ll x)
{
ll l=1, r=(ll)4000;
ll m;
while(l<=r)
{
  m=(l+r)/2;
  ll temp=ll(100*pow(1.01,m));
  if(temp>x)r=m-1;
  else if(temp<x)l=m+1;
  else return m;
}
return m;
}

ll powM(ll a,ll b, ll m)
{ 
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
return ans%m;
}


int main()
{
ll a,b,n;
cin>>a>>b>>n;
ll val=min(n,b-1);
ll ans=(ll)(a*val/b);
cout<<ans<<"\n";
  return 0;
}





Measured memory_bytes: 3584
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
ans = 0
abs_min = 1 << 40
minus_count = 0
is_zero = false
a.each do |i|
    minus_count += 1 if i < 0
    is_zero = true if i == 0
    element_abs = i.abs
    ans += element_abs
    abs_min = abs_min > element_abs ? element_abs : abs_min
end

if minus_count % 2 != 0 && !is_zero then
    ans -= abs_min * 2
end
puts ans

Measured memory_bytes: 9980
#include<cstdio>
#include<algorithm>

int digit(long long int l) {
    int res = 0;
    while(l > 0) l/=10, res++;
    return res;
}

int main(void) {
    long long int n;
    scanf("%lld",&n);

    int res = 10000;
    for(long long int i=1; i*i<=n; i++) {
        if(i * (n/i) != n) continue;
        int a = digit(i);
        int b = digit(n/i);
        if(res > a && res > b)
            res = std::max(a, b);
    }
    printf("%d\n", res);
}

Measured memory_bytes: 128
N=int(input())
X=[[0]*2 for i in range(N)]
for i in range(N):
  X[i]=list(map(int,input().split()))

r2max=0
for i in range(N):
  for j in range(i+1):
    for k in range(j+1):
      if i>j and j>k:
        x=(X[i])
        y=(X[j])
        z=(X[k])
        M=[x[0]-y[0],y[0]-z[0],x[1]-y[1],y[1]-z[1],z[0]-x[0],z[1]-x[1]]
        a=M[0]*M[3]-M[1]*M[2]
        b=-M[0]*M[1]-M[2]*M[3]
        c=-M[0]*M[4]-M[2]*M[5]
        d=-M[4]*M[1]-M[5]*M[3]
        if a!=0 and b>0 and c>0 and d>0:
          xyl=x[0]**2+x[1]**2-(y[0]**2+y[1]**2)
          yzl=y[0]**2+y[1]**2-(z[0]**2+z[1]**2)
          A=(M[3]*xyl-M[2]*yzl)/(2*a)
          B=(-M[1]*xyl+M[0]*yzl)/(2*a)
          r2=(x[0]-A)**2+(x[1]-B)**2
          if r2>r2max:
            r2max=r2
for i in range(N):
  for j in range(i+1):
    r2=(X[i][0]-X[j][0])**2+(X[i][1]-X[j][1])**2
    r2=r2/4
    if r2>r2max:
      r2max=r2
import math
print(math.sqrt(r2max))

Measured memory_bytes: 43884
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int n, r;
    cin >> n >> r;

    if(n < 10){
        cout << r + (100 * (10 - n)) << endl;
    }
    else{
        cout << r << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,n) for(int i=1;i<(n),i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define Rrep(i,n) for(int i=n-1;i>0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define P pair<int,int>
#define Pll pair<ll,ll>
using namespace std;
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 ll INF = 1e18;

struct Edge{
    int to,a,b;
    Edge(int to,int a,int b):to(to),a(a),b(b) {}
};
struct Data{
    int v,s;
    ll x;
    Data(int v,int s,ll x):v(v),s(s),x(x) {}
    bool operator<(const Data& a)const{ return x>a.x; } //pqに返す
};
vector<Edge> G[50];
ll dp[50][2600];
signed main(){
    int n,m,s;
    cin >> n >> m >> s;
    chmin(s,2525);
    rep(i,m){
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--; v--;
        G[u].pb({v,a,b});
        G[v].pb({u,a,b});
    }
    vector<int> c(n),d(n);
    rep(i,n) cin >> c[i] >> d[i];
    rep(i,n)rep(j,2600)dp[i][j]=INF;
    priority_queue<Data> pq;
    auto push=[&](int v,int s,ll x){ // to>v ¥s dist=x
        if(s<0) return;
        if(dp[v][s]<=x) return;
        dp[v][s]=x;
        pq.push({v,s,x});
    };
    push(0,s,0);
    while(!pq.empty()){
        Data tp=pq.top(); pq.pop();
        int v=tp.v,ss=tp.s;
        ll x=tp.x;
        if(dp[v][ss]!=x) continue;
        int gets=min(ss+c[v],2525);
        push(v,gets,x+d[v]);
        for(auto u:G[v]) push(u.to,ss-u.a,x+u.b);
    }
    for(int i=1;i<n;i++){
        ll ans=INF;
        rep(j,2600) chmin(ans,dp[i][j]);
        cout << ans << endl;
    }
}




Measured memory_bytes: 6288
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    const int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    sort(a.rbegin(), a.rend());
    const int inf = 1001001001;
    vector<int> dp(n+1, -inf);
    dp[0] = 0;
    rep(i, m) rep(j, n+1) if (j - cost[a[i]] >= 0) chmax(dp[j], dp[j - cost[a[i]]] + 1);

    string ans;
    int match = n;
    int remain = dp[n];
    while (match > 0) {
        rep(i, m) {
            if ((remain != 1 && match - cost[a[i]] >= 0 && dp[match - cost[a[i]]] == remain - 1) || (remain == 1 && match - cost[a[i]] == 0)) {
                match -= cost[a[i]];
                ans += '0' + a[i];
                remain--;
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		
		int ans = 0;
		if(n == 0) {
			System.out.println(x);
		}else {
			int[] p = new int[n];
			for(int i = 0; i < n; i++) {
				p[i] = sc.nextInt();
			}
			
			int min = 100;
			for(int i = 0; i <= 101; i++) {
				boolean flag = false;
				
				for(int j = 0; j < n; j++) {
					if(i == p[j]) {
						flag = true;
						break;
					}
				}
				
				if(flag) continue;
				
				if(Math.abs(x - i) < min) {
					min = Math.abs(x - i);
					ans = i;
				}
			}
		
			System.out.println(ans);
		}
		
	}

}


Measured memory_bytes: 36004
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
#define adiii \                               
  ios_base::sync_with_stdio(false); \                                      
  cin.tie(NULL);  \
  cout.tie(NULL);									
 
ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
ll gcd(ll a,ll b) {if (b == 0) return a;return gcd(b, a % b);}

int main(){
	adiii
	ll a,b,n;cin>>a>>b>>n;
	ll mi  = min(n,b-1);
	ll ans = (a*mi)/b;
	cout<<ans<<endl;




}


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

bool n,w,s,e;

int main() {
  string S;
  cin>>S;
  for (int i=0; i<S.size(); i++) {
    if (S[i]=='N') n=true;
    else if (S[i]=='W') w=true;
    else if (S[i]=='S') s=true;
    else e=true;
  }
  if ((n&&s||!n&&!s)&&(e&&w||!e&&!w)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl; 
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
long long x,y,u,v,ans;
inline long long read()
{
	long long 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<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	x=read(),y=read(),u=read(),v=read();
	ans=max(y*v,x*u);
	ans=max(ans,max(x*v,y*u));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define N 200007
using namespace std;
typedef long long ll;

inline ll rd() {
  ll x = 0;
  char c = getchar();
  while(!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return x;
}

ll n, x, m, p, ans, cnt[N];

inline int phi(int x) {
  int res = x;
  for (int i = 2; i <= x; ++i)
    if (x % i == 0) {
      res = res / i * (i - 1);
      while (x % i == 0) x /= i;
      if (x == 1) break;
    }
  return res;
}

inline void work1() {
  for (int i = 1; i <= n; ++i) {
    ans += x; x = x * x % m;
  }
  printf("%lld\n", ans);
}

inline ll fpow(ll x, ll t) {
  ll res = 1;
  while (t) {
    if (t & 1) res = res * x % m;
    x = x * x % m; t >>= 1;
  }
  return res;
}

int main() {
  n = rd(); x = rd();
  m = rd(); p = phi(m);
  if (n <= 1000000) {work1(); return 0;}
  ll index = 0;
  ll xx = x;
  while ((1ll << index) < p) {
    ans += x; x = x * x % m; ++index;
  }
  ll tmp = index;
  ll nw = (1ll << index) % p;
  while (cnt[nw] == 0) {
    ++cnt[nw];
    nw = (nw << 1) % p;
    ++tmp;
  }
  ll t = (n - index) / (tmp - index);
  for (int i = 0; i < p; ++i) cnt[i] *= t;
  n = (n - index) % (tmp - index);
  for (int i = 1; i <= n; ++i) {
    ++cnt[nw]; nw = (nw << 1) % p;
  }
  nw = fpow(xx, p);
  for (int i = 0; i < p; ++i) {
    ans += nw * cnt[i];
    nw = nw * xx % m;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, D;
  while(cin >> N >> D, N) {
    vector< stack< int > > st(N);
    multiset< int > sss;
    vector< int > sum(N, 0);
    for(int i = 0; i < N; i++) {
      int M;
      cin >> M;
      while(M--) {
        int c;
        cin >> c;
        sum[i] += c;
        st[i].push(c);
      }
      sss.insert(sum[i]);
    }
    bool update = *--sss.end() - *sss.begin() <= D;
    while(update) {
      update = false;
      for(int i = 0; i < N; i++) {
        if(!st[i].empty()) {
          int p = st[i].top();
          sss.erase(sss.find(sum[i]));
          sss.insert(sum[i] - p);
          if(sss.empty() || *--sss.end() - *sss.begin() <= D) {
            st[i].pop();
            sum[i] -= p;
            update = true;
          } else {
            sss.erase(sss.find(sum[i] - p));
            sss.insert(sum[i]);
          }
        }
      }
    }
    if(*--sss.end() == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

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

int main(){
    ll X, K, D;
    cin >> X >> K >> D;
    ll ans;
    ll n = abs(X) / D;


    if (X < 0){
        if (n >= K){
            ans = X + K * D;
        }else if( (K - n) % 2 == 0 ){
            ans = X + n * D;
        }else{
            ans = X + (n + 1) * D;
        }
    }else{
        if (n >= K){
            ans = X - K * D;
        }else if( (K - n) % 2 == 0 ){
            ans = X - n * D;
        }else{
            ans = X - (n + 1) * D;
        }
    }

    cout << abs(ans) << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<algorithm>
int a,b;
template<class T>
inline void read(T&a){
	char c=getchar();
	for(a=0;c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-'0';
}
int main(){
	read(a),read(b);
	if(a%3==0||b%3==0||(a+b)%3==0)puts("Possible");
	else puts("Impossible");
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


const int INF = 1e9 + 7;
int _;

int main() {
	INIT
	int n, m;
	cin >> n >> m;
	_ = (n * (n - 1) / 2) + (m * (m - 1)/ 2);
	cout << _;

	return 0;
}
/*
rep (i, 0, n) {
		if (i) cout << ' ';
		cout << A[i];
	}
*/

Measured memory_bytes: 256