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

int main() {
    stack<int> S;
    int a, b, x;
    string s;
    while (cin >> s) {
        if (s[0] == '+') {
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a + b);
        } else if (s[0] == '-') {
            b = S.top(); S.pop();
            a = S.top(); S.pop();
            S.push(a - b);
        } else if (s[0] == '*') {
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a * b);
        } else {
            S.push(atoi(s.c_str()));
        }
    }
        cout << S.top() << endl;

        return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll N;
  cin >> N;
  rep(i, N) {
    ll a;
    cin >> a;

    if (a % 2 == 0) {
      if (a % 3 == 0 || a % 5 == 0) {
        continue;
      }
      COUT("DENIED");
      return 0;
    }
  }

  COUT("APPROVED");

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX=1e6+5;

int main()
{
    int t;
    while(cin>>t)
    {
        if(t==22)puts("Christmas Eve Eve Eve");
        else if(t==23)puts("Christmas Eve Eve");
        else if(t==24)puts("Christmas Eve");
        else if(t==25)puts("Christmas");
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pi 3.1415926535
#define endl '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll inf=1e19;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  ll n,a,b,c;
  cin>>n;
  a=n/500;
  n=n-500*a;
  c=a*1000;
  n=n-(n%5);
  cout<<c+n<<endl;
}


Measured memory_bytes: 256
a, b, x = map(int, input().split())
if a // 2 < b:
    if x % 1000 == 0:
        print(a*(x//1000))
    else:
        if (x % 1000) / 500 > 1:
            print(min(a*(x//1000 + 1), a*(x//1000) + b*2))
        else:
            print(min(a*(x//1000 + 1), a*(x//1000) + b))
else:
    if x % 500 == 0:
        print(b*(x//500))
    else:
        print(b*(x//500 + 1))


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() 
{
	
	ll T=1;
	while(T--)
	{
		ll n;
		cin>>n;
		vector <ll> a(n);
		for(ll i=0;i<n;i++)
			cin>>a[i];
		ll index=0;
		ll ma=0;
		while(index<n)
		{
			ll low=index+1;
			while(low<n && a[low]<=a[low-1])
				low++;
			ll num=low-index;
			ma=max(num-1,ma);
			index=low;
		}
		cout<<ma<<endl;
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(){
	string s[3];
	for(int i = 0 ; i < 3 ; i++) cin >> s[i];
	
	
	int x = 0;
	while(true){
		if( s[x].size() == 0 ){
			cout << "ABC"[x] << endl;
			return 0;
		}else{
			int y = x;
			x = s[x].front() - 'a';
			s[y] = s[y].substr(1);
		}
	}
}

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

using namespace std;

int p[50];


int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	bool possible = true;
	for (int i = 1; i < n; ++i) {
		if (p[i] < p[i - 1]) {
			possible = false;
			break;
		}
		else if (p[i] > p[i - 1]) {
			continue;
		}
	}
	if (possible) {
		cout << "YES\n";
		return 0;
	}
	for (int i = 0; i < n - 1; ++i) {
		for (int j = i + 1; j < n; ++j) {
			swap(p[i], p[j]);
			possible = true;
			for (int i = 1; i < n; ++i) {
				if (p[i] < p[i - 1]) {
					possible = false;
					break;
				}
				else if (p[i] > p[i - 1]) {
					continue;
				}
			}
			if (possible) {
				cout << "YES\n";
				return 0;
			}
			else {
				swap(p[i], p[j]);
			}
		}
	}
	if (!possible) cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
#075-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
#UnionFindクラス
class UnionFind(object):
 
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
 
    def find(self, x):
  
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
  
    # xとyの根を結合させる
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
  
  # x,yの根が同じかどうかを返す（根が同じ:True、根が異なる:False）
    def same(self, x, y):
        return self.find(x) == self.find(y)
n,m=IL()
nl=[]
for i in range(m):
    f,t=IL()
    nl.append([f-1,t-1])
ans=0
for i in range(m):
    uf=UnionFind(n)
    flag=False
    for j in range(m):
        if i==j:
            continue
        uf.union(nl[j][0],nl[j][1])
    nl.append(t)
    for j in range(n):
        for k in range(n):
            if not uf.same(j,k):
                flag=True
    if flag:
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int score[20];
int n, m, x;
int ans = INF;
vector<int> C(n);
vector<vector<int> > A(n, vector<int>(m));
int ccc;

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f)
{
    if (rest == 0)
    {
        f(indexes);
    }
    else
    {
        if (s < 0)
            return;
        recursive_comb(indexes, s - 1, rest, f);
        indexes[rest - 1] = s;
        recursive_comb(indexes, s - 1, rest - 1, f);
    }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f)
{
    int indexes[k];
    recursive_comb(indexes, n - 1, k, f);
}

int main()
{
    
    
    cin >> n >> m >> x;
    C = vector<int>(n);
    A = vector<vector<int> >(n, vector<int>(m));
    rep(i, n)
    {
        cin >> C[i];
        rep(j,m){
            cin >> A[i][j];
        }
    }

    for (int i = 1; i <= n; i++){
        ccc = i;
        foreach_comb(n, i, [](int *indexes) {
            int tmp = 0;
            rep(j, ccc)
            {
                tmp += C[indexes[j]];
                rep(k, m)
                {
                    score[k] += A[indexes[j]][k];
                }
            }
            bool can = true;
            rep(j, m)
            {
                if (score[j] < x)
                    can = false;
                score[j] = 0;
            }
            if (can)
            {
                ans = min(ans, tmp);
            }
        });
    }
    cout <<  (ans==INF? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int n, k;
vector<int> a;

bool ok(double x) {
  ll sum = 0;
  REP(i, n) sum += (a[i] - 1) / x;
  if (k >= sum) return true;
  else
    return false;
}

void solve(istream& cin, ostream& cout) {
  cin >> n >> k;
  a.resize(n);
  REP(i, n) {
    cin >> a[i];
  }
  int l = 0, r = INF, mid;
  while (r - l > 1) {
    mid = (r + l) / 2;
    if (ok(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 3976
# https://atcoder.jp/contests/agc040/tasks/agc040_a
s = input()
A = [0] * (len(s) + 1)
B = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == '<':
        A[i + 1] = A[i] + 1

for i in range(len(s))[::-1]:
    if s[i] == '>':
        B[i] = B[i + 1] + 1

ans = 0
for i in range(len(s) + 1):
    ans += max(A[i], B[i])
print(ans)

Measured memory_bytes: 50888
N, M, K = map(int, input().split())
flag = True
for i in range(0, N+1):
    for j in range(0, M+1):
        if (i*(M-j)+j*(N-i)) == K:
            print("Yes")
            flag = False
            break
    if not(flag):
        break
if flag:
    print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 1000000007
#define INF 1000000000000000000
using Graph=vector<vector<int>>;

int main(){
  ll K,A,B;
  cin>>K>>A>>B;
  ll count=K-(A-1);
  if(K<A+1||B-A<=2){
    cout<<K+1<<endl;
  }else if(count%2==0){
    cout<<A+(B-A)*count/2<<endl;
  }else{
    cout<<A+(B-A)*(count/2)+1<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/indexed.hpp>
using namespace std;

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

template <typename T>
std::ostream &operator<<(std::ostream &ostr, const std::vector<T> &v) {
  for (const auto &i : v | boost::adaptors::indexed())
    ostr << (i.index() > 0 ? " " : "") << i.value();
  return ostr;
}

using P = pair<int, int>;
const int INF = 1e9;
const int NX[4] = {-1, 1, 0, 0};
const int NY[4] = {0, 0, -1, 1};

bool check(string &s, string &t) {
  if(s.size() < t.size()) return false;

  rep(i, s.size()-t.size()+1) {
    bool flag = true;
    rep(j, t.size()) {
      if(!(s.at(i+j) == t.at(j) || s.at(i+j) == '?')) {
        flag =  false;
      }
    }
    if(flag) {
      rep(j, t.size()) {
        if(s.at(i+j) == '?') {
        s.at(i+j) = t.at(j);
        }
      }
      return true;
    }
  }

  return false;
}

void create(string &s) {
  rep(i, s.size()) {
    if(s.at(i) == '?') {
      s.at(i) = 'a';
    }
  }
}

inline void Main() {
  // code
  string s, t;
  cin >> s >> t;
  reverse(all(s));
  reverse(all(t));
  if(!check(s, t)) {
    cout << "UNRESTORABLE" << endl;
    return;
  }
  reverse(all(s));
  create(s);
  cout << s << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


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


int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  ll ans = 0;


  if (k > a) {
    k -= a;
    ans += a;

    if (k > b) {
      k -= b;

      if (k > 0) {
        ans -= k;
        cout << ans << endl;
        return 0;
      } else {
        cout << ans << endl;
        return 0;
      }
    } else {
      cout << ans << endl;
      return 0;
    }
  } else {
    cout << k << endl;
    return 0;
  }
}


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

int main(){
    int n,h; cin >> n >> h;
    vector<int> hai(n),hei(n);
    for(int i = 0; i < n; i++){
        cin >> hai[i];
        hei[i] = 0;
    }
    int sum = 0;
    int a, b;
    for(int i = 0; i < h; i++){
        cin >> a >> b;
        hei[a -1] = max(hei[a-1], hai[b-1]);
        hei[b-1] = max(hei[b-1], hai[a-1]);
    }
    for(int i = 0; i< n; i++){
        if(hai[i] > hei[i]){
            sum++;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3992
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


class SegmentTree(object):

    def __init__(self, A, e, fn):  # O(N)
        """
        :param A: 区間クエリの対象となる配列
        :param e: 単位元 fn(a, e) = fn(e, a) = a
        :param fn: (a, b) -> x な関数 a, bは交換則を満たす
        """
        self.e = e
        self.fn = fn
        self.length = 2 ** (len(A) - 1).bit_length()
        self.tree = [e] * 2 * self.length
        for i in range(len(A)):
            self.tree[i + self.length - 1] = A[i]
        for i in range(self.length - 2, -1, -1):
            self.tree[i] = self.fn(self.tree[2 * i + 1], self.tree[2 * i + 2])

    # 配列のi番目をxに更新する
    def update(self, i, x):  # O(logN)
        i += self.length - 1
        self.tree[i] = x
        while i:
            i = (i - 1) // 2
            self.tree[i] = self.fn(self.tree[i * 2 + 1], self.tree[i * 2 + 2])

    # 区間[p, q)に関するクエリに答える
    def query(self, p, q):  # O(logN)
        if q <= p:
            return self.e
        p += self.length - 1
        q += self.length - 2
        res = self.e
        while q - p > 1:
            if p & 1 == 0:
                res = self.fn(res, self.tree[p])
            if q & 1 == 1:
                res = self.fn(res, self.tree[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.fn(res, self.tree[p])
        else:
            res = self.fn(self.fn(res, self.tree[p]), self.tree[q])
        return res


N = I()
S = input()
Q = [tuple(input().split()) for _ in range(I())]

A = [2 ** (ord(c) - 97) for c in S]
seg = SegmentTree(A, 0, lambda a, b: a | b)


for t, i, c in Q:
    if t == '1':
        i = int(i) - 1
        seg.update(i, 2 ** (ord(c) - 97))
    else:
        l, r = int(i) - 1, int(c)
        bit = seg.query(l, r)
        print(bin(bit).count('1'))


Measured memory_bytes: 85140
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
bool isp(ll n) {
    bool res = true;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> C(N - 1);
    vector<ll> S(N - 1);
    vector<ll> F(N - 1);
    rep(i, N - 1)cin >> C[i] >> S[i] >> F[i];
    rep(i, N) {//i からスタート
        ll ans = 0;
        for (int j = i; j < N - 1; j++) {
            if (ans < S[j])ans = S[j];
            if (ans % F[j] != 0)ans = ans + (F[j] - (ans % F[j]));
            ans += C[j];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool D[10]; int N;
int a(int x){ while(x){ if(D[x%10])return 0; x /=10; } return 1; }
int main(){ int K,d; for(cin>>N>>K;K--;){ cin>>d; D[d]=true; } while(!a(N)) N++; cout<< N<<endl; return 0; }

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
A = [int(input()) for i in range(N)]
d = defaultdict(lambda: [])
for i,a in enumerate(A):
    d[a].append(i)
B = [None for i in range(N)]
for i,k in enumerate(sorted(d.keys())):
    for j in d[k]:
        B[j] = i

bit = [0] * (N+2)
def bit_add(a,w):
    x = a
    while x <= N+1:
        bit[x] += w
        x += (x & -x)

def bit_sum(a):
    x = a
    ret = 0
    while x > 0:
        ret += bit[x]
        x -= (x & -x)
    return ret

for a in B:
    a += 2

    s = bit_sum(a)
    bit_add(a,1)
    if s and bit_sum(a-1):
        t = bit_sum(a-1)
        ok = a-1
        ng = 0
        while ok-ng > 1:
            m = (ok+ng)//2
            if bit_sum(m) == t:
                ok = m
            else:
                ng = m
        bit_add(ok,-1)

    # for i in range(N+1):
    #     print(i+1, bit_sum(i+1))

print(bit_sum(N+1))

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

#define for_(i,a,b) for(int i=a;i<b;++i)

typedef pair< int, int > pii;
typedef pair< pii, pii > ppii;

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
int n, x[20020], y[20020], visit[20020][2];
char dir[20020];
pii pos[40040], ids[40040];

int xadd(int i) { return dir[i] == 'x' ? 1 : 0; }
int yadd(int i) { return dir[i] == 'y' ? 1 : 0; }

bool rec(int i, int j, int v, vector< pii >& upd) {
	bool res = 1;
	
	if (visit[i][j] < 0) {
		visit[i][j] = v;
		visit[i][j^1] = v^1;
		upd.push_back(pii(i,j));
		upd.push_back(pii(i,j^1));
		
		int nx1 = x[i] + (j ? xadd(i) : 0), ny1 = y[i] + (j ? yadd(i) : 0);
		int nx2 = x[i] + (j ? 0 : xadd(i)), ny2 = y[i] + (j ? 0 : yadd(i));
		for_(d,0,4) {
			pii nxp1(nx1 + dx[d], ny1 + dy[d]);
			int k = lower_bound(pos, pos + 2*n, nxp1) - pos;
			if (k < 2*n && pos[k] == nxp1 && ids[k].second != i) res &= rec(ids[k].second, ids[k].first, v, upd);
			
			pii nxp2(nx2 + dx[d], ny2 + dy[d]);
			k = lower_bound(pos, pos + 2*n, nxp2) - pos;
			if (k < 2*n && pos[k] == nxp2 && ids[k].second != i) res &= rec(ids[k].second, ids[k].first, v^1, upd);
		}
	} else {
		res = (visit[i][j] == v);
	}
	
	return res;
}

int main() {
	while (scanf("%d", &n), n) {
		vector< ppii > vp;
		
		for_(i,0,n) {
			scanf("%d %d %c", &x[i], &y[i], &dir[i]);
			vp.push_back(ppii(pii(x[i], y[i]), pii(0, i)));
			vp.push_back(ppii(pii(x[i] + xadd(i), y[i] + yadd(i)), pii(1, i)));
		}
		
		sort(vp.begin(), vp.end());
		
		for_(i,0,2*n) {
			pos[i] = vp[i].first;
			ids[i] = vp[i].second;
		}
		
		memset(visit, -1, sizeof(visit));
		
		bool ok = 1;
		for_(i,0,n && ok) {
			if (visit[i][0] < 0) {
				vector< pii > upd;
				if (!rec(i, 0, 0, upd)) {
					int u_size = (int)upd.size();
					for_(j,0,u_size) visit[upd[j].first][upd[j].second] = -1;
					ok = rec(i, 0, 1, upd);
				}
			}
		}
		cout << (ok ? "Yes" : "No") << endl;
	}
	
	return 0;
}

Measured memory_bytes: 7308
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct _IO { _IO() { ios::sync_with_stdio(false); cin.tie(nullptr); } }_io;
typedef long long ll; typedef long double db;

ll exgcd(ll a, ll b, ll& x, ll& y)
{
	if (!b)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll d = exgcd(b, a % b, x, y);
	ll t = x;
	x = y;
	y = t - (a / b) * y;
	return d;
}
ll getInv(ll a, ll mod)
{
	ll x, y;
	return exgcd(a, mod, x, y) == 1 ? (x % mod + mod) % mod : -1;
}

const ll maxn = 2e5 + 5, mod = 998244353;
ll dp[maxn], sum[maxn];

int main()
{
	ll n, k;
	vector<ll> s;
	vector<pair<ll, ll>> seg;
	cin >> n >> k;
	while (k--)
	{
		ll a, b;
		cin >> a >> b;
		seg.push_back({ a,b });
	}
	sort(seg.begin(), seg.end());
	dp[1] = 1;
	sum[1] = 1;
	for (ll i = 1; i <= n; ++i)
	{
		for (pair<ll, ll>& j : seg)
		{
			if (i - j.second - 1 >= 0)
				dp[i] = (dp[i] + sum[i - j.first] - sum[i - j.second - 1] + mod) % mod;
			else if (i - j.first >= 0)
				dp[i] = (dp[i] + sum[i - j.first] - sum[0] + mod) % mod;
		}
		sum[i] = (sum[i - 1] + dp[i]) % mod;
	}
	cout << dp[n] % mod << endl;
	return 0;
}

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

int mod = (int)1e9 + 7;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int s;
  cin >> s;
  vector<int> dp(s + 1);
  for (int i = 3; i <= s; i++) {
    set<pair<int, int>> se;
    dp[i]++;
    for (int j = 3; j <= i - 3; j++) {
      if (se.find({i, j}) == se.end() && se.find({j, i}) == se.end()) {
        dp[i] = (dp[i] + dp[j]) % mod;
        se.emplace(i, j);
      }
    }
  }
  cout << dp[s] << '\n';
  return 0;
}

Measured memory_bytes: 3716
#include <stdio.h>
#define N 100

int main(){

  int a,i,v,j,k;
  int A[N];

  scanf("%d",&a);

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

  for( k = 0 ; k < a-1 ; k++ ) printf("%d ",A[k]);
  printf("%d\n",A[a-1]);

  for( i = 1 ; i < a ; i++ ){
    v = A[i];
    j = i - 1;
    while( j >= 0 && A[j] > v ){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    for( k = 0 ; k < a-1 ; k++ ){
      printf("%d ",A[k]);
    }
    printf("%d\n",A[a-1]);
  }
  return 0;
}

Measured memory_bytes: 600
#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 N, L;
    read(N, L);
    int sum = 0;
    int abs_min = abs(L);
    int abs_min_i = 1;
    for(int i = 1; i <= N; i++){
        sum += L + i - 1;
        if(abs(L + i - 1) < abs_min){
            abs_min = abs(L + i - 1);
            abs_min_i = i;
        }
    }
    int ans = sum - (L + abs_min_i - 1);
    write(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 <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int siz = s.size(),c=0;
    bool flag = true;
    for(int i=0; i<siz; i++)
    {
        if(i == 0)
        {
            if(s[i]!='A')
            {
                flag=false;
            }
        }
        if(i>0&&i<siz&&s[i]!='C')
        {
            if(!(s[i]>='a'&&s[i]<='z'))
            {
                flag = false;
            }

        }
        if(i>1&&i<siz-1 && s[i]=='C')
            ++c;
    }
    if(c!=1)
    {
        flag = false;
    }
    if(flag)
        cout<<"AC";
    else
        cout<<"WA";

}


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

#define ll long long

using namespace std;

const int max_n = 100'000;
vector<int> G[max_n];
vector<int> A(max_n, -1);

int DFS(int v) {
    if(A[v] != -1) return A[v];
    int res = 0;
    for(int i = 0; i < G[v].size(); i++)
        res = max(res, DFS(G[v][i]));
    A[v] = res + 1;
    return A[v];
}

int main() {
    std::ios::sync_with_stdio(false);
    int n, m, a, b;
    cin >> n >> m;
    while(m--) {
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
    }
    int result = 0;
    for(int i = 0; i < n; i++)
        result = max(result, DFS(i));
    cout << result - 1 << "\n";
    return 0;
}


Measured memory_bytes: 8192
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m =sc.nextInt();
		Point[] p= new Point[m];
		int ans=1;
		for(int i = 0; i<m; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			p[i]=new Point(a,b);
		}
		Arrays.sort(p, Comparator.comparing(Point::getY));
		Arrays.sort(p, Comparator.comparing(Point::getX));
		for(int i = 0; i<m; i++){
			int last=p[i].y;
			for(int j=i+1; j<m; j++){
				if(p[j].x>=last){
					i=j-1;
					ans++;
					break;
				}else{
					last=Math.min(last,p[j].y);
				}
			}
		}
		System.out.println(ans);
	}
	static class Point{
		int x;
		int y;
		public Point(int x, int y){
			this.x=x;
			this.y=y;
		}
		
		public int getX(){
			return x;
		}
		 
		public int getY(){
			return y;
		}
	}
}

Measured memory_bytes: 98952
#include <stdio.h>

int main(void) {
	int i,j,a;
	for (i = 1; i < 10; i++) {
		for (j = 1; j < 10; j++) {
			a = i*j;
			printf("%dx%d=%d\n", i, j, a);
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
using namespace std;

int main()
{
  vector<int> cards(5);
  while (~scanf("%d,%d,%d,%d,%d",
		&cards[0], &cards[1], &cards[2], &cards[3], &cards[4])) {
    sort(cards.begin(), cards.end());

    vector<int> cnt(15, 0);
    for (unsigned int i = 0; i < cards.size(); ++i)
      ++cnt[cards[i]];

    sort(cnt.begin(), cnt.end(), greater<int>());
    if (cnt[0] == 4) {
      cout << "four card" << endl;
    } else if (cnt[0] == 3 && cnt[1] == 2) {
      cout << "full house" << endl;
    } else {
      bool straight = true;
      for (unsigned int i = 1; i < cards.size(); ++i) {
	if (cards[i-1]+1 != cards[i])
	  straight = false;
      }

      if (straight ||
	  (cards[0] == 1 && cards[1] == 10 && cards[2] == 11 && cards[3] == 12 && cards[4] == 13)) {
	cout << "straight" << endl;
      } else if (cnt[0] == 3) {
	cout << "three card" << endl;
      } else if (cnt[0] == 2 && cnt[1] == 2) {
	cout << "two pair" << endl;
      } else if (cnt[0] == 2) {
	cout << "one pair" << endl;
      } else {
	cout << "null" << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	cin>>N;
	set<string>box;
	string ans;
	for(int i=0;i<s.size();i++){
		string bag;
		for(int j=i;j<s.size();j++){
			bag.push_back(s[j]);
			box.insert(bag);
			if(bag.size()==N){
				break;
			}
		}
	}
	int index=1;
	for(auto i:box){
		if(index==N){
		ans=i;
		}
		index++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<stdlib.h>
int main(){
  int i,j,v,n,*A,N;
  
  scanf("%d",&N);
  A=malloc(sizeof(int)*N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);

  for(i=0;i<N-1;i++) printf("%d ",A[i]);
  printf("%d\n",A[N-1]);
  
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    
    A[j+1]=v;
    for(n=0;n<N-1;n++){
      printf("%d ",A[n]);
    }
    printf("%d\n",A[N-1]);
  }
  free(A);
  return 0;
}

Measured memory_bytes: 600
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: u64,
        m: u64,
        k: u64,
        a: [u64; n],
        b: [u64; m],
    }
    // annotate for rust-analyzer
    let n: u64 = n;
    let m: u64 = m;
    let k: u64 = k;
    let a: Vec<u64> = a;
    let b: Vec<u64> = b;

    let mut ans = 0usize;
    let mut ma = vec![0u64];
    let mut mb = vec![0u64];

    for i in 0..n as usize {
        ma.push(ma[i] + a[i]);
    }
    for j in 0..m as usize {
        mb.push(mb[j] + b[j]);
    }

    let mut j = m as usize;
    for i in 0..=n as usize {
        if ma[i] > k {
            break;
        }
        while mb[j] > k - ma[i] {
            j -= 1;
        }
        ans = ans.max(i + j);
    }

    println!("{}", ans);
}


Measured memory_bytes: 12664
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    sc.close();

    if (A < 10 && B < 10) {
      System.out.println(A * B);
    } else {
      System.out.println("-1");
    }

  }

}

Measured memory_bytes: 23764
def resolve():
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                # divisors.append((i, n // i)) # [(1,max), (2, max-1)]
                divisors += [i,n // i]  # [1,2,3,5]
        divisors.sort()
        return divisors

    N = int(input())
    ans = 0

    # K で割り切れない時
    div1 = set(make_divisors(N-1))
    ans += len(div1) - 1

    # K で割り切れる時
    div2 = set(make_divisors(N))
    for k in div2:
        if k == 1:
            continue
        n = N
        while n % k == 0:
            n //= k
        if n % k == 1:
            ans += 1
    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    rep(i, n)
    {
        cin >> a[i];
        mp[a[i]]++;
        if (mp[a[i]] == 2)
        {

            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 10424
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

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

#define MAX_V 1000000

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

	string s;
	cin >> s;
	rep(i, 0, 4) cout << s[i];
	cout << " ";
	rep(i, 4, 12) cout << s[i];
	cout << endl;
}


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

 int main (){
     int n,k;
     int a[4][13]={0};
     cin >> n;
     string e;
     for (int i = 0;i<n;i++){
         cin >> e >> k;
         if (e=="S") {a[0][k-1] = k;
         }
         else if (e=="H"){a[1][k-1] = k;
         }
         else if (e == "C"){a[2][k-1] = k;
        }
         else if (e == "D"){a[3][k-1] = k;
         }
        }
     for(int i= 0;i<4;i++){
         for (int j =0;j<13;j++){
             
             if(a[i][j]==0){
                 if(i==0){
                        cout << "S" <<" "<<  j+1 << endl;
                 }else if (i==1){
                     
                        cout << "H" <<" "<<  j+1 << endl;
                        
                 }else if (i==2){
                     
                        cout << "C" <<" "<<  j+1 << endl;
                        
                 }else if (i==3){
                    
                        cout << "D" <<" "<< j+1 << endl;
                               
                 }
             }
         }
         
     }
 }



Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <bitset>
#include <iomanip>

using namespace std;

bool existEdge(const vector<int>& a, const vector<int>& b, int s, int e) {
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] == s && b[i] == e) {
            return true;
        }
    }
    return false;
}

int main() {
    int M, N;
    cin >> N >> M;
    vector<int> a;
    vector<int> b;
    for (int i = 0; i < M; ++i) {
        int tempa, tempb;
        cin >> tempa >> tempb;
        a.push_back(tempa);
        b.push_back(tempb);
        a.push_back(tempb);
        b.push_back(tempa);
    }

    vector<int> vertex(N, 0);
    for (int i = 0; i < N; ++i) {
        vertex[i] = i + 1;
    }

    int counter = 0;
    do {
        bool exist = true;
        for (int i = 1; i < N; ++i) {
            if (existEdge(a, b, vertex[i - 1], vertex[i])) {
                continue;
            }
            else {
                exist = false;
                break;
            }
        }
        if (exist) {
            ++counter;
        }
    } while (next_permutation(vertex.begin() + 1, vertex.end()));

    cout << counter << endl;
    //cout << setprecision(15) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int H,W,h,w;
    while(1){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0)
	break;
    for(h=1; h<=H; h++){
    	for(w=1; w<=W; w++){
		if((w+h)%2==0 )
    			putchar('#');
		else
			putchar('.');
	}
	putchar('\n');
    }
    putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 572
import sys
import math
import bisect

n,h = map(int,input().split())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n) :
  a[i],b[i] = map(int,input().split())
  
b.sort(reverse=True)

c = 0
bs = [b[0]]
am = max(a)
for i in range(1,n) :
  if b[i] < am :
    break
  bs.append(bs[i-1]+b[i])
  
if b[0] < am :
  print(math.ceil(h/am))
  sys.exit()

if bs[-1] <= h :
  print(len(bs) + math.ceil((h-bs[-1])/am))
else :
  print(bisect.bisect_left(bs,h)+1)

Measured memory_bytes: 15792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            String s = in.next();
            if (3200 > a) {
                s = "red";
            }
            out.println(s);
        }

    }
}



Measured memory_bytes: 22100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int A, B, C, i = 1;
	bool ans = false;

	cin >> A >> B >> C;

	repc(i, 1, B) {
		if ((A * i) % B == C) ans = true;
	}

	cout << (ans ? "YES" : "NO") << endl;

	return 0;
}


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

int bitdiv(int c, vector<int> x, int N){
  vector<int> d;
  while(c>0){
    d.push_back(c%2);
    c /= 2;
  }
  int m = d.size();
  reverse(d.begin(), d.end());
  for(int i=0; i<N-m+1; i++){
    int flag=0;
    for(int j=0; j<m; j++){
      if(x[i+j] > d[j]) break;
      else if(x[i+j] < d[j]){
        flag = 1; break;
      }
    }
    if(i > 0) if(x[i-1] == 1) flag = 0;
    if(flag == 0){
      int carry=0;
      for(int j=m-1; j>=0; j--){
        if(x[i+j] >= (d[j]+carry)){
          x[i+j] -= (d[j]+carry);
          carry = 0;
        }
        else{ 
          if(d[j]+carry-x[i+j] == 2) x[i+j] = 0;
          else x[i+j] = 1;
          carry = 1;
        }
      }
      //if(carry == 1) x[i-1] = 0;
    }
  }
  int ans=0;
  for(int j=N-m; j<N; j++){
    ans += x[j]*pow(2,N-j-1);
  }
  return ans;
}

int fpop(int st){
  int ans=0;
  while(st>0){
    int d=0,t;
    t = st;
    while(t>0){
      if(t%2 == 1) d++;
      t /= 2;
    }
    st = st%d;
    ans++;
  }
  return ans;
}

int main(){
  int N,c=0,er;
  cin >> N;
  string s;
  cin >> s;
  vector<int> X(N,0);
  for(int i=0; i<N; i++){
    if(s[i] == '1'){
      c++;
      X[i] = 1;
      er = i;
    }
  }
  int cp = bitdiv(c+1,X,N);
  int cn;
  if(c == 1) cn= 1;
  else cn = bitdiv(c-1,X,N);
  vector<int> retp(N),retn(N);
  int tmp = 1;
  for(int i=0; i<N; i++){
    retp[i] = tmp%(c+1);
    tmp = retp[i] * 2;
  }
  tmp = 1;
  if(c != 1){
    for(int i=0; i<N; i++){
      retn[i] = tmp%(c-1);
      tmp = retn[i] * 2;
    }
  }
  for(int i=0; i<N; i++){
    int st;
    if(X[i] == 1){
      if(c != 1){
        st = (cn - retn[N-i-1])%(c-1);
        if(st<0) st += (c-1);
      }
    }
    else{
      st = (cp + retp[N-i-1])%(c+1);
      if(st<0) st += (c+1);
    }
    
    if(c == 1 && er == i) cout << 0 << endl;
    else cout << fpop(st)+1 << endl;
  }
  return 0;
}

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

int main() {
    long n;
    cin >> n;
    string s;
    while(n)
        n--, s += char('a' + n % 26), n /= 26;
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  string s, ss;
  cin >> s >> ss;
  cout << ss << s << "\n";
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	cout<<((n&1)==0 ? n : n<<1)<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstdlib>
using namespace std;

struct T{
    char team[22];
    int score;
} ;

bool operator==(const T& left, const T& right)
{
    return left.score == right.score;
}
bool operator<(const T& left, const T& right)
{
    return left.score > right.score;
}
bool operator>(const T& left, const T& right)
{
    return left.score < right.score;
}


int main(void)
{
    int w, l, d = -1;
    
    while (1){
        int n;
        scanf("%d", &n);
        if (!n) break;
        if (d != -1) printf("\n");
        
        struct T set[n];
        
        for (int i = 0; i < n; i++){
            scanf("%s %d %d %d", set[i].team, &w, &l, &d);
            set[i].score = (w * 3) + (d * 1);
        }
        
        stable_sort(set, set + n);
        
        for (int i = 0; i < n; i++){
            printf("%s,%d\n", set[i].team, set[i].score);
        }
    }
    
    return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <set>
using namespace std;
using ll = long long;
using ld = long double;

const ll MOD = 1000000000 + 7;
const ll INF = 1e+9;
const ld PI = acos((ld)(-1));

#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define Fixed(n) std::fixed << std::setprecision(n)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define print(x) cout << x << endl;
#define next '\n'
#define sp " "
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define view(_list) foreach(e, _list){ cout << e << sp; } cout << endl
#define SIZE(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e)
#define eb(e) emplace_back(e)

int main() {
    FAST;

    ld a, b, C;
    cin >> a >> b >> C;

    ld area = a * b * sin(C * PI / 180) / 2;
    ld perimeter = a + b + sqrt(a * a + b * b - (2 * a * b * cos(C * PI / 180)));
    ld height = b * sin(C * PI / 180);

    cout << Fixed(10) <<  area << next << perimeter << next << height << endl;
}




Measured memory_bytes: 3540
from decimal import Decimal as dec
import math

def main():
    a, b, h, m = map(dec, input().split())
    hr = dec(360//12*(h%12) + dec(30*(m%60)/60))
    mr = 360//60*(m%60)
    ans = dec(math.sqrt(a**2+b**2-dec(2*a*b*dec(math.cos(dec(math.radians(abs(hr-mr))))))))
    print(ans)

if __name__ == "__main__":
    main()

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

int n,m;
int cnt[100000];

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

	cin>>n>>m;
	REP(i,m) {
		int a,b;
		cin>>a>>b;
		cnt[a-1]++,cnt[b-1]++;
	}
	REP(i,n) {
		if(cnt[i]&1) {
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;

	return 0;
}


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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LONG_LONG_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;


int main() {
    int a, b,res = 0, ans  = 0;
    bool bo = false;
    cin >> a >> b;
    rep3(i,1,999) {
        res+=i;
        if(res < a) {
            continue;
        }
        if(res >= b && ans == res - b) {
            cout << ans << endl;
            return 0;
        }
            ans = res - a;


    }
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using ull = unsigned ll;
using namespace std;

// const ll inf  = 1e9+5;

// int main (){
// 	int n,k;
// 	vector<ll> dp(n,inf);
// 	cin >> n >> k;
// 	vector<ll> h(n);
// 	for (ll& x :h){
// 		std::cin >> x;
// 	}
// 	dp[0]=0;
// 	for (ll i=0;i<n;i++){
// 		for (ll j=1;j<k+1;j++){
// 			if (0<i+j&&j+i<n){
// 				dp[j+i]=min(dp[j+i],dp[i]+abs(h[j+i]-h[i]));
// 			}
// 		}
// 	}
// 	std::cout << dp[n-1];
// 	return 0;

// }

// int main(void){
// 	ll n;
// 	vector<ll> a(n);
// 	vector<ll> b(n);
//  	vector<ll> c(n);
// 	cin >> n;
// 	for (int i=0;i<n;i++){
// 		int q,w,e;
// 		cin >> q >> w >> e;
// 		a.push_back(q);
// 		b.push_back(w);
// 		c.push_back(e);
// 	}
// 	vector<vector<ll>> dp(n+1,vector<ll>(3));
// 	dp[0][0]=0;
// 	dp[0][1]=0;
// 	dp[0][2]=0;
// 	for (int i=0;i<n;++i){
// 		dp[i+1].push_back(max(dp[i][1]+a[i],dp[i][2]+a[i]));
// 		dp[i+1].push_back(max(dp[i][0]+b[i],dp[i][2]+b[i]));
// 		dp[i+1].push_back(max(dp[i][0]+c[i],dp[i][1]+c[i]));
// 		cout << dp[i+1][0]<< " " << dp[i+1][1] << " " << dp[i+1][2] << endl;
// 	}
// 	cout << max({dp[n][0],dp[n][1],dp[n][2]});
// 	return 0;



// }
// #include "bits/stdc++.h"
// #define ALL(x) x.begin(),x.end()
// #define rep(i,n) for(int i=0;i<n;++i)
 
// using namespace std;
// typedef long long ll;
 

 

 
 
// int main(void){
//     vector<vector<ll>>dp(1e5+10);
//     ll n,a,b,c;
//     cin>>n;
//     vector<vector<ll>>h(n); //happy
//     rep(i,n){
//         cin>>a>>b>>c;
//         h[i].push_back(a);
//         h[i].push_back(b);
//         h[i].push_back(c);
//     }
//     dp[0].push_back(h[0][0]);
//     dp[0].push_back(h[0][1]);
//     dp[0].push_back(h[0][2]);
//     for(int i=1;i<n;++i){
//         dp[i].push_back(max(dp[i-1][1],dp[i-1][2])+h[i][0]);
//         dp[i].push_back(max(dp[i-1][0],dp[i-1][2])+h[i][1]);
//         dp[i].push_back(max(dp[i-1][1],dp[i-1][0])+h[i][2]);
//     }
 
//     cout<<*(max_element(ALL(dp[n-1])));
// }

// int dfs(vector<vector<int>> a,int v,int cnt){
// 	if (a[v].empty()){
// 		int ans=0;
// 		ans=max(ans,cnt);
// 		cout << ans;
// 	}	
// 	for (int next_v:a[v]){
// 		cnt+=1;
// 		dfs(a,next_v,cnt);
// 	}
// 	return 0;

	
// }


int n,m;
vector<vector<int>> g;
int dp[100100];

int dfs(int v){
	if (dp[v]!=-1){
		return dp[v];
	}

	int ans=0;
	for (auto nv:g[v]){
		ans = max(ans,dfs(nv)+1);

	}
	return dp[v]=ans;

}

int main (){
	cin >> n >> m;
	g.assign(n,vector<int>());

	for (int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		--a;
		--b;

		g[a].push_back(b);
	}

	for (int i=0;i<n;i++){
		dp[i]=-1;
	}

	int ans=0;
	for (int i=0;i<n;i++){
		ans=max(ans,dfs(i));
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;

ll euc(ll a, ll b){
	  return (a%b==0) ? b : euc(b,a%b);
}

ll lcm(ll a, ll b){
	  return a / euc(a,b) * b;
}

int main (){

	  ll n;
	  cin >> n;
	  ll a[n+1];
	  for(int i=1; i<=n; i++) cin >> a[i];

	  ll ans = 1;
	  for(int i=1; i<=n; i++)
			ans = lcm(ans,a[i]);
	  
	  cout << ans << endl;
			
	  
	  
	  
	  
	  
}

Measured memory_bytes: 1160