akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  int X;
  cin>>X;
  int a,b,c;
  int res=0;
  //500*a+100*b+50*c-X==0
  for(a=0;a<=A;a++){
    for(b=0;b<=B;b++){
      for(c=0;c<=C;c++){
        if(500*a+100*b+50*c-X==0){
          res++;
        }
      }
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>


using namespace std;
#define INF 0x3f3f3f3f3f
#define ll long long
#define pr(x) (cerr << #x << ' ' << x << ' ')
#define prln(x) (cerr << #x << ' ' << x << endl)


int main()
{
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif // LOCAL
    int n;
    scanf("%d", &n);

    if (n < 1200) {
        puts("ABC");
    }else if (n < 2800) {
        puts("ARC");
    }else {
        puts("AGC");
    }

    return 0;
}

Measured memory_bytes: 256
def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    a.sort()
    half_val = -(-a[-1] // 2)
    dist_list = [abs(half_val - an) for an in a[:-1]]
    min_index = dist_list.index(min(dist_list))
    print(f'{a[-1]} {a[min_index]}')


if __name__ == '__main__':
    main()

Measured memory_bytes: 19996
from itertools import *
N = int(input())
march = []
for _ in range(N):
  H =str(input())
  if H[0] == 'M' or H[0] == 'A' or H[0] == 'R' or H[0] == 'C' or H[0] == 'H':
    march.append(H[0])
march = ''.join(march)
m = march.count('M')
a = march.count('A')
r = march.count('R')
c = march.count('C')
h = march.count('H')
l = [m,a,r,c,h]
L = []
for i in range(len(l)):
  if l[i] > 0:
    L.append(l[i])
if len(L) < 3:
  print(0)
  exit()
else:
  ans = 0
  for l in combinations(L,3):
    a,b,c = l
    ans += (a*b*c)
    
print(ans)

Measured memory_bytes: 4016
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    k = i_input()
    num_list = i_list()

    count = 0 
    for num in num_list:
        count += min(num, k - num)

    print(count*2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 77196
N = int(input())
cnt = 0
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.pop(0)
    return divisors
N1_yakusu = make_divisors(N-1)
N_yakusu = make_divisors(N)
cnt += len(N1_yakusu)
for K in N_yakusu:
    new_N = N
    while(new_N%K==0):
        new_N = new_N//K
    if(new_N%K == 1):
        cnt += 1
print(cnt)

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

ans = "" if n!= 0 else "0"
while n != 0:
    if n % 2 == 0:
        ans = "0" + ans
    else:
        ans = "1" + ans
        n -= 1

    if n >= 0:
        n = n // 2 * (-1)
    else:
        n = abs(n) // 2

print(ans)


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
static const int HMAX = 1400;
static const int WMAX = 1400;

int main() {
  int tiles[HMAX][WMAX] = {0};
  int height, width;
  int ans = 0;
  cin >> height >> width;
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      int tmp;
      cin >> tmp;
      tiles[i][j] = !tmp;
      ans = max(ans, tiles[i][j]);
    }
  }

  for (int i = 1; i < height; i++) {
    for (int j = 1; j < width; j++) {
      if (tiles[i][j] != 0) {
        tiles[i][j] =
            min({tiles[i - 1][j], tiles[i][j - 1], tiles[i - 1][j - 1]}) + 1;
        ans = max(ans, tiles[i][j]);
      }
    }
  }
  cout << ans*ans <<endl;
}

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

int main()
{
	string s, t;

	cin >> s >> t;

	int start = -1;
	for( int i = s.size() - t.size(); i >= 0; i-- ) {
		int flag = 0;
		for( int j = 0; j < t.size(); j++ ) {
			if( s[i + j] != t[j] && s[i + j] != '?' ) {
				flag = 1;
				break;
			}
		}
		if( flag == 0 ) {
			start = i;
			break;
		}
	}
	if( start >= 0 ) {
		s.replace( s.begin() + start, s.begin() + start + t.size(), t );
		for(int i = 0; i < s.size(); i++ ) {
			if (s[i] == '?') {
				s[i] = 'a';
			}
		}
	}

	if( start >= 0 ) {
		cout << s << endl;
	}
	else {
		cout << "UNRESTORABLE" << endl;
	}

	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n, m; cin >> n >> m;
    vector<int> card(2*n);
    rep(i, 2*n) card[i] = i;
    rep(i, m) {
        int order; cin >> order;
        vector<int> tmp_card(2*n);
        rep(j, 2*n) tmp_card[j] = card[j];
        if(order == 0) {
            int t = 0;
            rep(j, n) {
                card[t++] = tmp_card[j];
                card[t++] = tmp_card[n+j];
            }
        } else {
            int t = 0;
            for(int j = order; j <= 2*n-1; j++) {
                card[t++] = tmp_card[j];
            }
            for(int j = 0; j <= order-1; j++) {
                card[t++] = tmp_card[j];
            }
        }
    }
    rep(i, 2*n) cout << card[i]+1 << '\n';
    return 0;
}


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

struct UnionFind {
    vector<ll> par,rank,cnt; // par[i]:iの親の番号,rank[r]:rを根とする木の高さ,cnt[r]:rを根とする木の要素数

    UnionFind(ll N){ //全て根として初期化
        for(ll i = 0; i < N; i++) par.push_back(i);
        rank.assign(N,0);
        cnt.assign(N,1);
    }

    ll root(ll x){ // xの根を返す
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x,ll y){ // xの木とyの木を併合
        ll rx = root(x); 
        ll ry = root(y);
        if (rx == ry) return;

        if(rank[rx] < rank[ry]){
            par[rx] = ry;
            cnt[ry] += cnt[rx]; 
        }else{
            par[ry] = rx;
            cnt[rx] += cnt[ry];
            if(rank[x] == rank[y]) rank[rx] ++;
        }
    }

    ll tsize(ll x){ //　xの木の要素数を返す
        ll rx = root(x);
        return cnt[rx];
    }

    bool same(ll x,ll y){ // xとyが同一の木に存在するかを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

struct edge{ll u,v,cost;};

bool comp(const edge& e1, const edge&e2){
    return e1.cost<e2.cost;
}

edge es[400000];
ll V,E;

ll kruskal(){
    sort(es,es+E,comp);
    UnionFind tree(V);
    ll res = 0;
    for(int i = 0;i < E;i ++){
        edge e = es[i];
        if(!tree.same(e.u,e.v)){
            tree.unite(e.u,e.v);
            res += e.cost;
        }
    }
    return res;
}

int main(){
    cin >> V;
    vector<pair<ll,ll>> vx,vy;
    for(ll i = 0;i < V;i ++){
        ll x,y;
        cin >> x >> y;
        vx.push_back(make_pair(x,i));
        vy.push_back(make_pair(y,i));
    }
    sort(vx.begin(),vx.end());
    sort(vy.begin(),vy.end());
    E = 4*(V-1);
    int cnt = 0;
    for(int i = 1;i < vx.size();i ++){
        es[cnt] = {vx[i-1].second,vx[i].second,abs(vx[i-1].first-vx[i].first)}; cnt ++;
        es[cnt] = {vx[i].second,vx[i-1].second,abs(vx[i-1].first-vx[i].first)}; cnt ++;
    }
    for(int i = 1;i < vy.size();i ++){
        es[cnt] = {vy[i-1].second,vy[i].second,abs(vy[i-1].first-vy[i].first)}; cnt ++;
        es[cnt] = {vy[i].second,vy[i-1].second,abs(vy[i-1].first-vy[i].first)}; cnt ++;
    }
    cout << kruskal() << endl;
    return 0;
}

Measured memory_bytes: 15332
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let inp = read_vec::<i32>();
    let n = inp[0];
    let m = inp[1];
    let x = inp[2];
    let an = read_vec::<i32>();
    let xn  = vec![0..m];
    let ans_n = an.iter().filter(|&a| a > &x && a < &n).count();
    let ans_0 = an.iter().filter(|&a| a < &x && a > &0).count();
    println!("{}",if ans_n > ans_0 { ans_0} else {ans_n});

    
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+6;
ll a[N];
void solve(){
	int n; 
	cin>>n; 
	ll sum = 0;
	ll ans = 0;
	for(int i=1;i<=n;i++){
		ll x; 
		cin>>x; 
		ans+=x*sum;
		ans%=mod;
		sum+=x;
		sum%=mod;
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
    long long int a,b,i,z=0,c=1,j,n,t;
    cin>>a>>b;
    if(a<10)
    {
        j=100*(10-a);
        printf("%lld\n",j+b);
    }
    else printf("%lld\n",b);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lowbit(a) ((a)&(-(a)))
using namespace std;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	}
}

int n, q, cnt = 0;

struct node {
	int t, d, x;
}c[1000000 + 5];

bool cmp(node a, node b)
{
	return a.t < b.t;
}

multiset<int>que;

int main()
{
	file(1);
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++)
	{
		int s, t, x;
		scanf("%d%d%d", &s, &t, &x);
		s -= x, t -= x;
		cnt++;
		c[cnt].t = s, c[cnt].x = x, c[cnt].d = 1;
		cnt++;
		c[cnt].t = t, c[cnt].x = x, c[cnt].d = -1;
	}
	sort(c + 1, c + 1 + cnt, cmp);
	int cc = 1;
	while (q--)
	{
		int d;
		scanf("%d", &d);
		while (c[cc].t <= d && cc <= cnt)
		{
			if (c[cc].d == 1)
				que.insert(c[cc].x);
			else
				que.erase(que.find(c[cc].x));
			cc++;
		}
		if (que.size())
			printf("%d\n", *que.begin());
		else
			printf("-1\n");
	}
	return 0;
}


Measured memory_bytes: 16768
# -*- coding utf-8 -*-
## 途中

import bisect

MOD = 10 ** 9 + 7

n = int(input())
ln = list(map(int, input().split()))
ln.sort()

ans = 0
for i in range(n):
    for j in range(i + 2, n):
        k = bisect.bisect_right(ln, ln[j] - ln[i])
        if k < i + 1:
            c = j - (i + 1)
        elif k > j - 1:
            c = 0
        else:
            c = j - k
        ans += c
print(ans)



Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>
#include <cassert>

using namespace std;

using i64 = long long int;
using u64 = std::uint_fast64_t;
using P = pair<i64, i64>;

struct edge {
    i64 from, to, cost;
    edge(i64 from, i64 to) : from(from), to(to), cost(1) {}
    edge(i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};
using Graph = vector<vector<edge>>;

constexpr i64 INF = std::numeric_limits<i64>::max();
constexpr i64 SINF = std::numeric_limits<i64>::max() / 10;
constexpr i64 MOD = 1000000007;
constexpr i64 dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const i64 dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//const i64 dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//const i64 dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    i64 n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());
    i64 ans = 0, prev = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (s[i] == s[i + 1]) {
            prev++;
            ans += prev;
        }
        else {
            prev = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
void main() {
    int n = readln.chomp.to!int;
    bool ok;
    foreach (i; 0 .. 26) {
        foreach (j; 0 .. 15) {
            if (4 * i + 7 * j == n) ok = true;
        }
    }
    writeln(ok ? "Yes" : "No");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

Measured memory_bytes: 256
N, W = map(int, input().split())
dp = [[0] * (W+1) for _ in range(N)]
weights = list() 
values = list() 
for _ in range(N):
    v, w = map(int, input().split())
    values.append(v)
    weights.append(w)

for n in range(N):
    for w in range(1, W+1):
        if n == 0 and w >= weights[n]:
            dp[n][w] = values[n]
        elif w >= weights[n]: 
            dp[n][w] = max(dp[n-1][w-weights[n]] + values[n], dp[n-1][w])
        else:
            dp[n][w] = dp[n-1][w]
print(dp[N-1][W])


Measured memory_bytes: 41628
#include<stdio.h>
int main(){
  int n,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    if(i%3==0||i%10==3||i/10%10==3||i/100%10==3||i/1000%10==3){
      printf(" %d",i);
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
fun main() {
    val (d, t, s) = readInts()
    val tt = d.toDouble()/s
    println(if (tt > t.toDouble()) "No" else "Yes")
}

// Input Reader
private fun readLn() = readLine()!!
private fun readStrings() = readLn().trim().split(" ")
private fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 36544
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	string s,t;
    int ans=0;
    cin>>s>>t;
    for (int i = 0; i < SZ(s); i++)
    {
        if(s[i]!=t[i]) ans++;
    }
    
   cout<<ans;
   return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

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

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  ll a, b;
  cin >> a >> b;


  ll ans = 0;
  --a;
  for(int i = 1; i < 64; i++){
    ll ca = (1l << (i - 1)) * ((a + 1) / (1l << i));
    ll r = (a + 1) % (1l << i);
    if(r > (1l << (i - 1))) ca += r - (1l << (i - 1));

    ll cb = (1l << (i - 1)) * ((b + 1) / (1l << i));
    r = (b + 1) % (1l << i);
    if(r > (1l << (i - 1))) cb += r - (1l << (i - 1));

    if((cb - ca) % 2 == 1) ans |= (1l << (i - 1));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n;
string s;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    cin >> s;
    int numR = 0;
    FOR(i,0,n-1) numR += s[i] == 'R';
    int res = min(numR, n - numR);
    int cnt = numR;
    FOR(i,0,numR-1)
        if (s[i] == 'R') cnt--;
    res = min(res, cnt);
    cout << res;
    return 0;
}


Measured memory_bytes: 3760
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;


int main()
{
    ll n,m;
    cin >> n >> m;
    ll ans = 1;
    if(abs(n - m) == 1){
        int a = max(n,m);
        int b = min(n,m);
        for(int i = 1; i <= a; i++){
            ans *= i;
            ans %= mod;
        }
        for(int i = 1; i <= b; i++){
            ans *= i;
            ans %= mod;
        }
    }else if(n == m){
        for(int i = 1; i <= n; i++){
            ans *= i;
            ans %= mod;
            ans *= i;
            ans %= mod;
        }
        ans *= 2;
        ans %= mod;
    }else{
        ans = 0;
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,m,u=0,p=0;
    long long ans=0;
    cin >> n >> m;
    vector<long> a(n);
    vector<pair<long,int>> b(m);
    for (int i=0;i<n;i++){
        cin >> a.at(i);
    }
    for (int i=0;i<m;i++){
        cin >> b.at(i).second >> b.at(i).first;
    }
    
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    
    while (true){
        if (p==m || a.at(n-u-1)>=b.at(p).first) {
            for (int i=0;i<n-u;i++){
                ans=ans+a.at(i);
            }
            break;
        }
        if (n-u-b.at(p).second>0){
                    if (b.at(p).first>=a.at(n-u-1-b.at(p).second)) {ans=ans+b.at(p).first*b.at(p).second;u=u+b.at(p).second;}
            else {
                 for (int i=0;i<b.at(p).second;i++){
                     if (b.at(p).first>=a.at(n-u-1)) {ans=ans+b.at(p).first;u++;}
                     else break;
                 }
                 
            }
            
            
    }
        else {
            if (b.at(p).first>=a.at(0)) {ans=ans+b.at(p).first*(n-u);break;}
            else {
                 for (int i=0;i<b.at(p).second;i++){
                     if (b.at(p).first>=a.at(n-u-1) && u<n) ans=ans+b.at(p).first;
                     else break;
                     u++;
                 }                
            }
    }
        p++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cmath>

using namespace std;

int digits(long long n){
  int i;
  for(i = 0; n >= 1; i++) n /= 10;
  return i;
}

int min(int a, int b){
  return a < b ? a : b;
}

int main(void){
  long long n;
  int ans = 10;
  int i;
  cin >> n;
  for(int i = sqrt(n); i >= 1; i--){
    if(n % i == 0) ans = min(ans, digits(n / i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*
 * 2325.cc: Mysterious Maze
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 1000;
const int MAX_W = 1000;
const int MAX_N = 1000000;

int dxs[] = {1, 0, -1, 0}, dys[] = {0, -1, 0, 1};

const int INF = 1 << 30;

/* typedef */

struct Stat {
  int d, x, y, di;
  Stat() {}
  Stat(int _d, int _x, int _y, int _di): d(_d), x(_x), y(_y), di(_di) {}
  bool operator<(const Stat &s) const { return d < s.d; }
  bool operator>(const Stat &s) const { return d > s.d; }
};

/* global variables */

bool flds[MAX_H][MAX_W];
int dirs[MAX_N + 1], nxtds[MAX_N + 1][4];
int dists[MAX_H][MAX_W][4];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int h, w, n;
    cin >> h >> w >> n;
    if (h == 0) break;

    string sop;
    cin >> sop;

    int nds[] = {INF, INF, INF, INF};
    dirs[0] = 1;
    for (int i = 0, di = 0; i < n; i++)
      dirs[i + 1] =  (dirs[i] + (sop[i] == 'L' ? 1 : 3)) % 4;
    for (int i = n; i >= 0; i--) {
      nds[dirs[i]] = i;
      for (int j = 0; j < 4; j++) nxtds[i][j] = nds[j];
      //printf("%d:", i);
      //for (int j = 0; j < 4; j++) printf(" %d", nxtds[i][j]); putchar('\n');
    }

    int sx, sy, gx, gy;
    memset(flds, true, sizeof(flds));
    
    for (int y = 0; y < h; y++) {
      string s;
      cin >> s;
      for (int x = 0; x < w; x++)
	switch (s[x]) {
	case 'S': sx = x; sy = y; break;
	case 'G': gx = x; gy = y; break;
	case '#': flds[y][x] = false; break;
	}
    }

    for (int y = 0; y < h; y++)
      for (int x = 0; x < w; x++)
	for (int di = 0; di < 4; di++) dists[y][x][di] = INF;
    dists[sy][sx][1] = 0;
    
    priority_queue<Stat,vector<Stat>,greater<Stat> > q;
    q.push(Stat(0, sx, sy, 1));
    bool ans = false;
    
    while (! q.empty()) {
      Stat u = q.top(); q.pop();
      if (dists[u.y][u.x][u.di] != u.d) continue;
      //printf("(%d,%d,%d)=%d\n", u.x, u.y, u.di, u.d);

      if (u.x == gx && u.y == gy) {
	ans = true;
	break;
      }

      for (int vdi = 0; vdi < 4; vdi++) {
	int vx = u.x + dxs[vdi], vy = u.y + dys[vdi];
	if (vx >= 0 && vx < w && vy >= 0 && vy < h && flds[vy][vx]) {
	  int vd = nxtds[u.d][vdi];
	  if (dists[vy][vx][vdi] > vd) {
	    dists[vy][vx][vdi] = vd;
	    q.push(Stat(vd, vx, vy, vdi));
	  }
	}
      }
    }

    cout << (ans ? "Yes" : "No") << endl;
  }
  
  return 0;
}

Measured memory_bytes: 22564
#include <stdio.h>

#define M (1000000007LL)

/***************************************
    繰り返し二乗法
    (a**n%m)
***************************************/
long long powm( long a, long n, long m )
{
    long long ret = 1;
    for( ; n>0; n>>=1, a=(long long)a*a%m ) {
        if( n % 2 == 1 ) {
            ret = ret * a % m;
        }
    }

    return( ret );
}

/***************************************
    aからbまでの掛け算を計算
    ((a(a+1)(a+2)…(b))%m)
***************************************/
long long multiplem( long a, long b, long m )
{
    int i;
    long long ret = 1;

    if( a > b ) {
        i = a;
        a = b;
        b = i;
    }

    for( i=a; i<=b; i++ ) {
        ret = (ret * i) %m;
    }

    return( ret );
}

/***************************************
    組み合わせ計算(nCa%m)
***************************************/
long long combinationm( long n, long a, long m )
{
    int i;
    long long ret;

    if( n-a < a ) a = n-a;

    if( a == 0 ) return( 1 );

    // 分母を計算
    ret = multiplem( n, n-a+1, m );

    // 1/(a!)を計算して嬰かける
    for( i=1; i<=a; i++ ) {
        ret = (ret * powm( i, m-2, m ) ) % m;
    }

    return( ret );
}

/***************************************
    main
***************************************/
int main( int argc, char *argv[] )
{
    long n, a, b;
    long long ret;

    scanf( "%d%d%d", &n, &a, &b );

    ret = powm( 2, n, M ) - 1;
    ret -= combinationm( n, a, M );
    ret -= combinationm( n, b, M );

    while( ret < 0 ) ret+= M;

    printf( "%lld\n", ret );
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main(){
    ll x;   cin >> x;
    ll res = !x;
    cout << res << endl;
}


Measured memory_bytes: 3600
#include<iostream>

using namespace std;
//D. Menagerie

//円環状に羊か狼が並んでいる
//羊は正直で狼が嘘つき
//各動物に対して「両隣は同じ動物？」と質問
//各動物は"o"か"x"で答える

//動物の数 N と答えの文字列 s が与えられる
//あり得る組み合わせを羊ならS、狼ならWで出力
//組み合わせができない場合は-1を出力

#define FOR(i,a,b) for(long long i =(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define debug(x) cerr << #x << " = " << x << endl;
#define maxN 100000

int candidate[4][maxN];

void printAnimanl(int num,int N){

    REP(i,N){
        if(candidate[num][i] == 0){
            cout << "W";
        }else{
            cout << "S";
        }
    }
    cout << endl;
    return;
}

int main(void){

    
    int N;
    string s;

    cin >> N;
    cin >> s;
    
    fill((int*)candidate,(int*)(candidate+4),-1);
    
    // S = 1, W = 0で円環の繋ぎ目のあり得る組み合わせ(4つ)
    candidate[0][0]   = 0; candidate[0][N-1] = 0; // W W
    candidate[1][0]   = 0; candidate[1][N-1] = 1; // W S
    candidate[2][0]   = 1; candidate[2][N-1] = 0; // S W
    candidate[3][0]   = 1; candidate[3][N-1] = 1; // S S

    
    REP(i,4){
        bool flag1 = false;
        bool flag2 = false;
        REP(k,N){
            
            int cand;
            if(k == 0){
                cand = candidate[i][N-1]^candidate[i][0];
            }else{
                cand = candidate[i][k-1]^candidate[i][k];
            }
            
            if(s[k] == 'o'){
                cand = not(cand);
            }
            //debug(cand)
            if(k != 0 && k == N-2){
                flag1 = (cand == candidate[i][k+1]);
                continue;
            }
            if(k != 0 && k == N-1){
                flag2 = (cand == candidate[i][0]);
                if(flag1 && flag2){
                    printAnimanl(i,N);
                    return 0;
                }
            }
            candidate[i][k+1] = cand;
        }
        if(i == 3) cout << -1 << endl;
    }

    return 0;
}


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

int main() {
    int a, b, c;
    int count = 0;
    scanf("%d %d %d", &a, &b, &c);
    for (a; a <= b; a++) {
        if (c % a == 0) count++;
    }
    printf("%d\n", count);
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define crap ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define int ll

using namespace std;

const int mod = 1e9+7;
const int N = 1e5+5;
string n;
int len;
int d;
vector<int> num;

int dp[N][2][105];

int digit(int idx,int tight,int sum){
  if(idx==-1){
    if(sum==0) return 1;
    else return 0;
  }
  if(dp[idx][tight][sum]!=-1)
    return dp[idx][tight][sum];
  int ans=0;
  int ch = n[idx]-'0';
  if(tight==1){
    for(int i=0;i<=ch;i++){
      if(i==ch){
        ans= (ans%mod + digit(idx-1,1,(sum+i)%d)%mod)%mod;
      }
      else{
        ans= (ans%mod + digit(idx-1,0,(sum+i)%d)%mod)%mod;
        //ans=ans%mod;
      }
    }
  }
  else{
    for(int i=0;i<=9;i++){
      ans= (ans%mod + digit(idx-1,0,(sum+i)%d)%mod)%mod;
    }
  }
  return dp[idx][tight][sum] = ans;
}


int32_t main()
{
   
    crap;
    cin>>n>>d;
    len = n.length();
    /*for(int i=0;i<len;i++){
      num.pb(n[i]-'0');
    }*/
    reverse(n.begin(),n.end());
    memset(dp,-1,sizeof(dp));
    int ans = digit(len-1,1,0);
    cout<<(ans-1+mod)%mod<<endl;
}

Measured memory_bytes: 165248
# 問題: https://atcoder.jp/contests/abc144/tasks/abc144_d

import math
a, b, x = map(int, input().strip().split())
if a * a * b / 2 < x:
    res = b
    res -= x/(a*a)
    res *= 2
    res /= a
else:
    res = a * b * b
    res /= 2 * x
res = math.atan(res)
res = math.degrees(res)
print(res)



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

vector<vector<int> > adj;
const int N=1e5+5;
bool visited[N];
vector<int> aux[2];
bool dfs(int v,int op)
{
	while(true)
	{
		int idx=0;
		int len=adj[v].size();
		while(visited[adj[v][idx]]==true&&idx<len)
		{
			idx++;
		}
		if(idx==len)
			break;
		int u=adj[v][idx];
		aux[op].push_back(u);
		visited[u]=true;
		v=u;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	adj.resize(n+5);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int a=1;
	int b=adj[1][0];
	sort(adj[b].begin(),adj[b].end());
	adj[b].erase(adj[b].begin());
	memset(visited,false,sizeof(visited));
	visited[a]=true;
	visited[b]=true;
	int x=dfs(b,0);
	x=dfs(a,1);
	vector<int> ans;
	//cout<<a<<" "<<b<<endl;
/*
 *    for(int i=0;i<aux[1].size();i++)
 *        cout<<aux[1][i]<<" ";
 *    cout<<endl;
 *    for(int i=0;i<aux[0].size();i++)
 *        cout<<aux[0][i]<<" ";
 *    cout<<endl;
 *
 */
	for(int i=aux[1].size()-1;i>=0;i--)
		ans.push_back(aux[1][i]);
	ans.push_back(a);
	ans.push_back(b);
	for(int i=0;i<aux[0].size();i++)
		ans.push_back(aux[0][i]);
	cout<<(int)(ans.size())<<endl;
	for(int i=0;i<ans.size();i++)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}


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

int nx[200010][26];
int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    s = s + s;
    fill(nx[2 * n], nx[2 * n] + 26, 2 * n);
    for (int i = s.size() - 1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) nx[i][j] = nx[i + 1][j];
        nx[i][s[i] - 'a'] = i + 1;
    }
    ll ans = 0;
    for (int i = 0; i < t.size(); i++) {
        int c = t[i] - 'a';
        int idx = ans % n;
        if(nx[idx][c] == 2 * n){
            cout << "-1" << endl;
            return 0;
        }
        ans += nx[idx][c] - idx;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 21120
#include<cstdio>
#include<algorithm>
#include<vector>


using namespace std;

int main(void){


    int n,r;
    while(scanf("%d %d", &r, &n), n){
        int p,c;
        int x[128], y[128];
        for(int i = 0; i < r; i++){
            y[i] = r-i;
        }

        for(int i = 0; i < n; i++){
            int cnt = 0;
            for(int j = 0; j < r; j++)x[j] = y[j];


            scanf("%d %d", &p, &c);

            for(int j = p-1; j < p+c-1; j++){
                y[cnt] = x[j];
                cnt++;
                x[j] = -1;
            }

            for(int j = 0; j < r; j++)if(x[j] != -1){y[cnt] = x[j];cnt++;}
//            for(int j = 0; j < r ; j++)printf("%2d:%2d\n", x[j], y[j]);
        }

        for(int j = 0; j < r; j++)x[j] = y[j];
        printf("%d\n", x[0]);
    }
    return 0;
}

Measured memory_bytes: 1028
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int b[maxn],t[maxn],ans,d;
vector <int> a1,a2,a3;

int main()
{
	int L=read()-1,base=1,cnt=0,d=L;
	while(L>0)
	{
		if(L<base) break; L-=base;
		b[++cnt]=base,t[cnt]=base*2-1; base<<=1;
	}
	ans=cnt*2; int res=b[cnt]*2;
	for(int i=1,j=cnt;i<=j;i++,j--) swap(b[i],b[j]),swap(t[i],t[j]);
	for(int i=1;i<=cnt;i++)
	{
		//cout<<L<<" "<<i<<" "<<t[i]<<endl;
		if(res+t[i]<=d)
		{
			a1.push_back(1); a2.push_back(i); a3.push_back(res);
			ans++; res+=(t[i]+1);
			//cout<<"Asjldas"<<endl;
		}
	}
	if(res<=d) a1.push_back(1),a2.push_back(cnt+1),a3.push_back(d),ans++;
	cout<<cnt+1<<" "<<ans<<endl;
	for(int i=1;i<=cnt;i++)
	{
		printf("%d %d %d\n",i,i+1,b[i]);
		printf("%d %d %d\n",i,i+1,0);
	}
	for(int i=0;i<a1.size();i++) printf("%d %d %d\n",a1[i],a2[i],a3[i]);
	return 0;
}

Measured memory_bytes: 2304
#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int red=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R') red++;
	}
	if(red>n/2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
_,m,*A=map(int,open(0).read().split());S=l=3*m;D=[0]*l
for a,b in zip(A,A[1:]):b+=m*(b<a);k=b-a;S+=k;D[a+2]+=1;D[b+1]-=k;D[b+2]+=k-1
exec("for i in range(l):D[i]+=D[i-1]\n"*2);print(S-l-max(D[a]+D[a+m]for a in A))

Measured memory_bytes: 17732
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <bitset>
#include <utility>
#include <sstream>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <complex>
#include <set>

using namespace std;

#define INF 1070000000LL
#define pb push_back
#define irep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) irep(i,0,n)

typedef long long lint;
typedef pair<int, int> pint;
struct Edge{
    int to,weight;
};
typedef vector<vector<Edge> > Graph;

int main(){
    string n;
    string a;
    cin >> n;
    rep(i,n.size()){
	if(n[i] == '9'){
	    a.pb('1');
	}
	else if(n[i] == '1'){
	    a.pb('9');
	}
    }
    cout << a << endl;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     

def iskaibun(s):
    l = 0
    r = len(s) - 1
    while l < r:
        if s[l] == s[r]:
            l += 1
            r -= 1
            continue
        else:
            return False
    return True

def main():
    s = S()
    N = len(s)
    if iskaibun(s) and iskaibun(s[:(N-1)//2]) and iskaibun(s[(N+3)//2 - 1:]):
        print('Yes')
    else:
        print('No')

main()



Measured memory_bytes: 66668
import math

a,b,h,m = map(int, input().split())

pos_x_long = a*math.sin(math.radians(30*h+0.5*m))
pos_x_short = b*math.sin(math.radians(6*m))

pos_y_long = a*math.cos(math.radians(30*h+0.5*m))
pos_y_short = b*math.cos(math.radians(6*m))

print(math.sqrt(pow(pos_x_long - pos_x_short,2) + pow(pos_y_long - pos_y_short,2)))

Measured memory_bytes: 9520
#include<stdio.h>
int main(void)
{
	int n, k, x, y, i, t, goukei = 0;
	scanf("%d%d%d%d", &n,&k, &x, &y);
	for (i = 1; i <= n; i++)
	{
		if (i <= k)
		{
			goukei += x;
		}
		else
		{
			goukei += y;
		}
	}
	printf("%d", goukei);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
 
int main(void)
{
    int n,m,i,j;
    int a[100][100]={};
    int b[100]={};
    int c[100]={};
     
    scanf("%d%d", &n, &m);
     
    for(i=0; i<n; i++) {
        for(j=0; j<m; j++)
            scanf("%d", &a[i][j]);
    }
    for(j=0; j<m; j++)
        scanf("%d", &b[j]);
     
    for(i=0; i<n; i++) {
        for(j=0; j<m; j++)
            c[i]+=a[i][j]*b[j];
        printf("%d\n", c[i]);
    }
     
    return 0;
}
 


Measured memory_bytes: 2140
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cassert>
#include<cmath>
using namespace std;
#define fi first
#define se second
#define rep(i,s,t) for(int i=(s),_t=(t);i<_t;++i)
#define per(i,s,t) for(int i=(t)-1,_s=(s);i>=_s;--i)
#define debug(x) cerr<<#x<<" == "<<(x)<<endl
#define bug(x) cerr<<#x<<" == "<<(x)<<" "
typedef long long ll;
typedef unsigned long long ull;
typedef long double db;
typedef pair<int,int> pii;
template<class T>inline void rd(T &x){
	x=0;char c;int f=1;
	while(c=getchar(),c<48)if(c=='-')f=-1;
	do x=x*10+(c&15);
	while(c=getchar(),c>47);
	x*=f;
}
template<class T>void pf(T x){
	if(x<0)putchar('-'),x=-x;
	else if(!x){
		putchar('0');
		return ;
	}
	static int stk[100],tp;
	for(tp=0;x;x/=10)stk[tp++]=x%10;
	while(tp)putchar(stk[--tp]^48);
}
template<class T>void ptn(T x){
	pf(x),putchar('\n');
}
template<class T>void ptk(T x){
	pf(x),putchar(' ');
}
template<class T>void Min(T &A,T B){
	if(A>B)A=B;
}
template<class T>void Max(T &A,T B){
	if(A<B)A=B;
}

const int N=(int)2e5+5;
int n,a[N<<1];
int main(){
	rd(n);
	int L=n,R=n;
	rep(i,1,n+1){
		int x;
		rd(x);
		if(i&1)a[--L]=x;
		else a[R++]=x;
	}
	if(n&1)rep(i,L,R)ptk(a[i]);
	else per(i,L,R)ptk(a[i]);
	return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>
int	main(void)
{
	int n,min,max,i;
	long long sum;
	int a[10000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	min=max=sum=a[0];
	for(i=1;i<n;i++){
		sum+=a[i];
		if(a[i]<min){
			min=a[i];
		}else if(a[i]>max){
			max=a[i];
		}
	}
	printf("%d %d %lld\n",min,max,sum);
	return	0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int n;
vector<int> cnt(10010);
void countingSort(vector<int> &a, vector<int> &b, int k) {
	rep(i,k+2) {
		cnt[i] = 0;
	}
	rep(j,n) {
		cnt[a[j]]++;
	}
	rep2(i,1,k+2) {
		cnt[i] += cnt[i-1];
	}
	for(int j=n-1; j>=0; --j) {
		b[cnt[a[j]]-1] = a[j];
		cnt[a[j]]--;
	}
}
int main() {
	cin >> n;
	int max = 0;
	vector<int> a(n);
	rep(i,n) {
		cin >> a[i];
		if(a[i] > max) max = a[i];
	}
	vector<int> b(n);
	countingSort(a,b,max);
	cout << b[0];
	rep2(i,1,n) {
		cout << " " << b[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 16772
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<LL>>g;
vector<edge>ed;
vector<Pll>pv;
map<string, LL>ma;
set<LL>st;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, p, q, w, h, ans, cnt,a[200000], b[200000],dp[1100][1100],sum[200000];
string str,ss;
bool f;
char c[1100][1100];
int main() {
	cin  >> h >> w>> n;
	cin >> p >> q;
	cin >> str;
	cin >> ss;
	LL cur = q;
	rep(i, n) {
		if (str[i] == 'L') {
			cur--;
		}
		if (cur == 0) {
			cout << "NO" << endl;
			return 0;
		}
		if (ss[i] == 'R') {
			if(cur+1<w)
			cur++;
		}
	}
	cur = q;
	rep(i, n) {
		if (str[i] == 'R') {
			cur++;
		}
		if (cur == w+1) {
			cout << "NO" << endl;
			return 0;
		}
		if (ss[i] == 'L') {
			if (cur - 1 > 0)
				cur--;
		}
	}
	cur = p;
	rep(i, n) {
		if (str[i] == 'U') {
			cur--;
		}
		if (cur == 0) {
			cout << "NO" << endl;
			return 0;
		}
		if (ss[i] == 'D') {
			if (cur + 1 < h+1)
				cur++;
		}
	}
	cur = p;
	rep(i, n) {
		if (str[i] == 'D') {
			cur++;
		}
		if (cur == h+1) {
			cout << "NO" << endl;
			return 0;
		}
		if (ss[i] == 'U') {
			if (cur - 1 > 0)
				cur--;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 50;
 
 
int main(void) {
	int N, M;
	cin >>  N >> M;
 
	const int NMAX = 1000;
	const int MMAX = 2000;
	int a[MMAX], b[MMAX];
	ll c[MMAX];
 
	for (int i = 0; i < M; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		c[i] = -c[i];
	}
 
	ll dist[NMAX];
 
	for (int i = 0; i < N; ++i) {
		dist[i] = INF;
	}
 
	dist[0] = 0;
 
 
	for (int loop = 0; loop < N - 1; ++ loop) {
		for (int i = 0; i < M; ++i) {
			if (dist[a[i] - 1] == INF) continue;
 
			if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
				dist[b[i] - 1] = dist[a[i] - 1] + c[i];
			}
		}
	}
 
	ll ans = dist[N - 1];
 
 
	bool negative[NMAX];
 
	for (int i = 0; i < N; ++i) {
		negative[i] = false;
	}
 
	for (int loop = 0; loop < N ; ++ loop) {
		for (int i = 0; i < M; ++i) {
			if (dist[a[i] - 1] == INF) continue;
 
			if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
				dist[b[i] - 1] = dist[a[i] - 1] + c[i];
				negative[b[i] - 1] = true;
			}
 
			if (negative[a[i] - 1] == true) {
				negative[b[i] - 1] = true;
			}
		}
	}
 
 
	if (negative[N - 1])
		cout << "inf" << endl;
	else
		cout << -ans << endl;
 
	return 0;
}

Measured memory_bytes: 384
import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		StringBuilder sb = new StringBuilder();
		
		for(int i=1; i<=n; i++){
			
			int x = i;
			
			if(x%3 == 0){
				sb.append(" "+i);
			}else{
				while(x!=0){
					if(x%10 == 3){
						sb.append(" "+ i);
						break;
					}else{
						x = x/10;
					}
				}
			}
		}
		System.out.println(sb);
	}

}

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

int main() {
    int a, b;
    cin >> a >> b;
    if(a >= 13) cout << b << '\n';
    else if(a >= 6) cout << b/2 << '\n';
    else cout << 0 << '\n';

    return 0;
}


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

/* 方針
 * 条件1(S_i != S_j ...)を満たす組の数はR,G,Bの数をr,g,bとしたときrgb通りある 
 * 条件2(j-i != k-j)を満たさないもの
 * 
 */
int main(){

    int n, i, j, k;
    long int r=0, g=0, b=0, count=0, sum=0;
    cin >> n;

    char str[n];
    cin >> str;
        //各文字のカウント
    for(i=0;i<n;i++){
        if(str[i] == 'R'){
            r++;
        }else if(str[i] == 'G'){
            g++;
        }else if(str[i] == 'B'){
            b++;
        }
    }
    //１個目の文字
    for(k=0;k<n;k++){
        //２個目の文字
        for(j=0;j<k;j++){
            if(str[2*j-k] != str[j] && str[j] != str[k] && str[k] != str[2*j-k] && 2*j-k >= 0){
                count++;
            }
        }
    }

    sum = r*g*b - count;
    cout << sum << endl;
    return 0;

}

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	if (c - a - b > 0) {
		if((c - a - b)*(c - a - b)>4 * a * b) cout << "Yes" << endl;
      else cout << "No" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class Program
{
    static List<int[]> Solve(int N)
    {
        var edges = new List<int[]>();
        for (int i = 1; i <= N; ++i)
        {
            int x = (N % 2 == 0) ? N - i + 1 : N - i;
            for (int j = i + 1; j <= N; ++j)
            {
                if (j != x)
                {
                    edges.Add(new[] { i, j });
                }
            }
        }
        return edges;
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var edges = Solve(N);
        Console.WriteLine(edges.Count);
        foreach (var edge in edges)
        {
            Console.WriteLine(string.Join(" ", edge));
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int dd[5] = {-2,-1,0,1,2};

int h, w, sx, sy, gx, gy;
string s[1010];
int cost[1010][1010];

int main(){
    cin >> h >> w;
    cin >> sy >> sx >> gy >> gx;
    sy--, sx--, gx--, gy--;
    rep(i, h) cin >> s[i];
    rep(i, h) rep(j, w) cost[i][j] = INF;

    deque<pair<int,int>> que;
    cost[sy][sx] = 0;

    que.push_front({sx, sy});

    while(!que.empty()){
        auto p = que.front(); que.pop_front();
        int x = p.first, y = p.second;
        rep(i, 4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx<0||w<=nx||ny<0||h<=ny) continue;
            if (s[ny][nx]=='#' || cost[ny][nx] <= cost[y][x]) continue;
            cost[ny][nx] = min(cost[y][x], cost[ny][nx]);
            que.push_front({nx,ny});
        }
        rep(i, 5) rep(j, 5){
            int nx = x + dd[i];
            int ny = y + dd[j];
            if (nx<0||w<=nx||ny<0||h<=ny) continue;
            if (s[ny][nx]=='#' || cost[ny][nx] <= cost[y][x]) continue;
            cost[ny][nx] = min(cost[y][x]+1, cost[ny][nx]);
            que.push_back({nx,ny});
        }
    }

    if (cost[gy][gx] == INF) cout << -1 << endl;
    else cout << cost[gy][gx] << endl;

    return 0;
}


Measured memory_bytes: 10204
#include <iostream>
using namespace std;
int main() {
    int a, b, c;
    int c1 = 0, c2 = 0;
    char d;
    while (cin >> a >> d >> b >> d >> c) {
        if (a * a + b * b == c * c) {
            c1 ++;
        }
        if (a == b) {
            c2 ++;
        }
    }
    cout << c1 << "\n";
    cout << c2 << "\n";
    return 0;
}

Measured memory_bytes: 1164
# coding: utf-8
 
a,b=list(map(int,input().split()))
 
mouse_tot = 1
mouse_cnt = 0
add_mouse = a-1
 
while mouse_tot <  b:
    mouse_tot += add_mouse
    mouse_cnt += 1
 
if b==0:
    mouse_cnt = 0
 
print(mouse_cnt)

Measured memory_bytes: 3060