akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc085/tasks/abc085_c

"""
import sys
from sys import stdin
input = stdin.readline


def calc_yukichi(n, total):
    # 五千円札と一万円札をn枚使用して、ちょうどtotal円にするときの諭吉の枚数を返す
    if total % 5000 != 0:
        return -1

    gap = total - (5000 * n)
    if gap < 0:
        return -1
    yukichi = gap // 5000
    ichiyou = n - yukichi
    if ichiyou >= 0:
        return yukichi
    else:
        return -1


def solve(N, Y):
    # N枚の紙幣で、ちょうどY円になるような組み合わせを探す
    for hideyo in range(N+1):
        nokori = Y - hideyo * 1000
        yukichi = calc_yukichi(N-hideyo, nokori)
        if yukichi >= 0:
            ichiyou = N - yukichi - hideyo
            return yukichi, ichiyou, hideyo
    return -1, -1, -1


def main(args):
    N, Y = map(int, input().split())
    # N, Y = 2000, 20000000
    ans = solve(N, Y)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
import java.util.Scanner;
    public class Main{
    	public static void main(String[] args) {
    		// TODO 自動生成されたメソッド・スタブ
    		Scanner sc = new Scanner(System.in);
    		int N = sc.nextInt();
    		int c = 0;
    		while(N  >  c) {
    			c = c + 1000;
    		}
    			c= c-N;
    		System.out.println(c);
    	}
     
    }

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

using namespace std;
using lli = long long int;
using ll = long long;

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

    if (N % 2 == 0) {
        cout << 0.5 << endl;
        return 0;
    }

    int harf = N / 2;

    cout << double((harf + 1.0) / N) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long t;
t N,K,i,num,p,tmp;
vector<pair<t,t> >td;
bool used[1<<17];
priority_queue<t,vector<t>,greater<t>>d;
int main(){
  cin>>N>>K;
  td.resize(N);
  for(i=0;i<N;i++)cin>>td[i].second>>td[i].first;
  sort(td.rbegin(),td.rend());
  for(i=0;i<K;i++){
    tmp+=td[i].first;
    if(used[td[i].second])d.push(td[i].first);
    else used[td[i].second]=true,num++;
  }
  p=tmp+num*num;
  for(i=K;i<N;i++){
    if(!used[td[i].second]){
      if(!d.size())break;
      used[td[i].second]=true;
      tmp+=td[i].first;
      tmp-=d.top();d.pop();
      p=max(p,tmp+(++num)*num);
    }
  }
  cout<<p<<endl;
  return 0;
}


Measured memory_bytes: 2556
N, K, *A = map(int, open(0).read().split())

MOD = 10 ** 9 + 7
s = []  # v >= 0
t = []  # v < 0
for i in range(N):
    if A[i] < 0:
        t.append(A[i])
    else:
        s.append(A[i])
        
ok = False  # ans > 0
if len(s) > 0:
    if N == K:
        ok = len(t) % 2 == 0
    else:
        ok = True
else:
    ok = K % 2 == 0

ans = 1
if not ok:
    x = sorted(A, key=lambda x: abs(x))
    for i in range(K):
        ans = ans * x[i] % MOD
else:
    s.sort()
    t.sort(key=lambda x: abs(x))
    if K % 2 == 1:
        ans = ans * s.pop() % MOD
        
    p = []
    while len(s) >= 2:
        x = s.pop() * s.pop()
        p.append(x)
    
    while len(t) >= 2:
        x = t.pop() * t.pop()
        p.append(x)

    p.sort(reverse=True)
    for i in range(K // 2):
        ans = ans * p[i] % MOD
    
print(ans)



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

int main(){
  int N;
  double x;
  string u;
  double ans = 0;
  cin >> N;
  for(int i = 0; i < N ; i++){
    cin >> x >> u;
    if (u == "JPY"){
      ans += x;
    }
    if (u == "BTC"){
      ans += x * 380000.0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
const lines=readlines()
input()=shift!(lines)
int(x)=parse(Int,x)
function intLine()
    s=input()|>split
    int(s[1]),int(s[2])
end
function makeE(n,m)
    e=Array{Int,1}[[]for i=1:n]
    for i=1:m
        u,v=intLine()
        push!(e[u],v)
    end
    e
end
function bfs(n,e,s,t)
    f=ones(Int,(n,3))*-3
    f[s,1]=0
    q=Array{Pair{Int,Int}}([s=>1])
    while !isempty(q)
        v,m=shift!(q)
        if v==t&&m==1;break;end
        u=m>2?1:m+1
        for w=e[v]
            if f[w,u]<0
                f[w,u]=f[v,m]+1
                push!(q,w=>u)
            end
        end
    end
    f[t,1]÷3
end
function main()
    n,m=intLine()
    e=makeE(n,m)
    s,t=intLine()
    show(bfs(n,e,s,t))
end
main()

Measured memory_bytes: 167080
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  string S; cin >> S;
  map<char, int> a;
  rep(i, S.length()) a[S[i]]++;
  string result = "yes";
  for (auto x: a) if (x.second >= 2) result = "no";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
import math

N = int(input())
ab = []
cd = []

for i in range(N):
    ab.append(list(map(int,input().split())))

for i in range(N):
    cd.append(list(map(int,input().split())))

res = 0

cd.sort()

for i in range(len(cd)):
    c,d = cd[i]
    max_b = -1
    index = -1
    tmp_list = 0
    for j in range(len(ab)):
        a,b = ab[j]
        if a > c or b > d:
            continue
        
        tmp_b = b

        if max_b < b:
            max_b = tmp_b
            index = j

    if index > -1:
        ab.pop(index)
        res += 1

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }
    vi sum(n + 1);
    for (int i = 0; i < n; i++) {
        sum[i + 1] = sum[i] + as[i];
    }

    vvi dp(n, vi(n, 1e18));
    for (int i = n - 1; i >= 0; i--) {
        for (int j = i; j < n; j++) {
            if (i == j) {
                dp[i][i] = as[i];
                continue;
            }
            for (int k = i; k < j; k++) {
                assert(dp[i][k] != 1e18);
                assert(dp[k + 1][j] != 1e18);
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum[j + 1] - sum[i]);
            }
        }
    }
    cout << dp[0][n - 1] - sum.back() << endl;
}

Measured memory_bytes: 1536
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
////@formatter:on
//endregion

int fpow(int a, int b){
    int res = 1;
    while(b != 0){
        if (b & 1){
            res = res * a % M7;
        }
        a = a * a % M7;
        b /= 2;
    }
    return res;
}

int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);

    vector<int> p, d(1'000'000 + 1);
    for(int i = 2; i < d.size(); ++i){
        if (d[i] == 0){
            d[i] = i;
            p.push_back(i);
        }
        for(int j = 0; j < p.size() && p[j] * i < d.size() && p[j] <= d[i]; ++j){
            d[p[j] * i] = p[j];
        }
    }

    make(int, n);
    makev(a, n);
    VI st(d.size());
    for(int num : a){
        while(num > 1){
            int dv = d[num], cnt = 0;
            while(d[num] == dv){
                cnt++;
                num /= dv;
            }
            st[dv] = max(st[dv], cnt);
        }
    }

    int lcm = 1;
    for(int i = 2; i < st.size(); ++i){
        while(st[i] != 0){
            lcm = lcm * i % M7;
            st[i]--;
        }
    }
    int ans = 0;
    for(auto& num : a){
        int q = fpow(num, M7 - 2);
        ans = (ans + lcm * q) % M7;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 16628
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define NL << endl

using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;


signed main() {
	string s;
	cin >> s;
	if (s.size() == 2) {
		cout << s NL;
	} else {
		cout << s[2] << s[1] << s[0] NL;
	}


	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;


int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll a,p;
    cin >> a >> p;
   	p += a*3;
   	cout << p/2 << endl;
   	cin >> a;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;
const int MAXN = 305;
struct Edge {
    int v, w;
};
vector<Edge> adj[MAXN];
int n;
struct Item {
    int val;
    int u, v;
};
bool cmp(const Item &a, const Item &b) {
    return a.val < b.val;
}
int dis[MAXN];
bool inque[MAXN];
void spfa(int s) {
    queue<int> que;
    dis[s] = 0;
    inque[s] = true;
    que.push(s);
    while(!que.empty()) {
        int u = que.front(); que.pop();
        inque[u] = false;
        for(int i = 0; i < adj[u].size(); i++) {
            if(dis[adj[u][i].v] > dis[u] + adj[u][i].w) {
                dis[adj[u][i].v] = dis[u] + adj[u][i].w;
                if(!inque[adj[u][i].v]) {
                    inque[adj[u][i].v] = true;
                    que.push(adj[u][i].v);
                }
            }
        }
    }
}
Item item[MAXN * MAXN];
int cnt_item;
int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) {
            int val; scanf("%d", &val);
            if(i < j) {
                item[cnt_item++] = (Item){val, i, j};
            }
        }
    sort(item, item + cnt_item, cmp);
    long long ans = 0;
    for(int i = 0; i < cnt_item; i++) {
        memset(dis, 0x3f, sizeof(dis));
        spfa(item[i].u);
        if(dis[item[i].v] < item[i].val) {
            printf("-1\n");
            return 0;
        }
        else if(dis[item[i].v] > item[i].val) {
            adj[item[i].u].push_back({item[i].v, item[i].val});
            adj[item[i].v].push_back({item[i].u, item[i].val});
            ans += item[i].val;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 768
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

int n,m;
ll s;
vector<pair<int,pair<ll,ll>>> g[55];
ll c[55],d[55];
ll res[55];
ll mi[55][2501];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> m >> s;
	for(int i=0;i<m;i++){
		int w,x,y,z; cin >> w >> x >> y >> z;
		w--; x--;
		g[w].push_back(make_pair(x,make_pair(y,z)));
		g[x].push_back(make_pair(w,make_pair(y,z)));
	}
	for(int i=0;i<n;i++){
		cin >> c[i] >> d[i];
	}
	for(int i=1;i<n;i++){
		res[i]=1e18;
	}
	for(int i=0;i<55;i++){
		for(int j=0;j<2501;j++){
			mi[i][j]=1e18;
		}
	}
	s=min(s,2500LL);
	priority_queue<pair<ll,pair<int,int>>> q;
	q.push(make_pair(0,make_pair(0,s)));
	mi[0][s]=0;
	while(q.size()){
		auto p=q.top();
		q.pop();
		int ss=p.second.second;
		int ii=p.second.first;
		ll ti=-p.first;
		if(mi[ii][min(ss+c[ii],2500LL)]>ti+d[ii]){
			mi[ii][min(ss+c[ii],2500LL)]=ti+d[ii];
			q.push(make_pair(-mi[ii][min(ss+c[ii],2500LL)],make_pair(ii,min(ss+c[ii],2500LL))));
		}
		for(auto t:g[ii]){
			if(ss<t.second.first)continue;
			else{
				if(mi[t.first][ss-t.second.first]>ti+t.second.second){
					mi[t.first][ss-t.second.first]=ti+t.second.second;
					res[t.first]=min(res[t.first],ti+t.second.second);
					q.push(make_pair(-mi[t.first][ss-t.second.first],make_pair(t.first,ss-t.second.first)));
				}
			}
		}
	}
	for(int i=1;i<n;i++){
		printf("%lld\n",res[i]);
	}
}

Measured memory_bytes: 6224
/*
======================
[     ___T_          ]
[    | 6=6 | =>HI :-)]
[    |__o__|         ]
[ >===]__o[===<      ]
[     [o__]          ]
[      .".           ]
[      |_|           ]
[                    ]
======================
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    for(int t = 1; t <= T; t++){
        int n,m;
        cin >> n >> m;
        vector<int> nums;
        for(int i = 1; i <= n; i++){
            nums.push_back(2 * i);
        }
        int x = 1;
        for(int i = 1; i <= m; i++){
            nums.push_back(x);
            x += 2;
        }
        int count = 0;
        n = (int) nums.size();
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                if((nums[i] + nums[j]) % 2 == 0){
                    count += 1;
                }
            }
        }
        cout << count << "\n";
    }
}


Measured memory_bytes: 3608
// ConsoleApplication3.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

//#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
	int a, b;
	b = 1;
	while (1) {
		cin >> a;
		if (a == 0) {
			break;
		}
		else {
			cout << "Case " << b << ": " << a << endl;
			b++;
		}
	}
	return 0;
}




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

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int main()
{
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    vector<int> L;
    vector<int> R;
    int idx = 0;
    while (L.size() < k) {
        if (s[idx] == 'o') {
            L.push_back(idx);
            idx += c + 1;
        } else {
            idx++;
        }
    }
    idx = n - 1;
    while (R.size() < k) {
        if (s[idx] == 'o') {
            R.push_back(idx);
            idx -= c + 1;
        } else {
            idx--;
        }
    }
    REP(i, k)
    {
        if (L[i] == R[k - 1 - i])
            cout << L[i]+1 << endl;
    }
}

Measured memory_bytes: 5692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()

const ll mod=1000000007;

int countBits(int in){
  int res=0;
  for(int i=0;i<10;i++){
    int msk=1<<i;
    if((in&msk)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  ll a,b,n;cin>>a>>b>>n;
  ll ans=0;
  ll x=min(n,b-1);
  ans=(a*x)/b-a*(x/b);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
const int MAXN=100001;
int n,nowt=0,nowx=0,nowy=0,tot,tox,toy;
bool flag=true;
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	n=read();
	while(n--)
	{
		tot=read();tox=read();toy=read();
		int dist=abs(tox-nowx)+abs(toy-nowy);
		int Time=tot-nowt;
		if(Time<dist) {flag=false;break;}
		Time-=dist;
		if(Time&1) {flag=false;break;}
	}
	if(flag) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
function main(input){
  const args = input.split('\n');
  const N = parseInt(args[0],10);
  const nums = args.slice(1,N+1);

  //everyを使ってすべての地点が到達可能であるかをチェックしなければならない
  const isValid = nums.every((n) => {
    var ns = n.split(" ");
    var t = parseInt(ns[0],10);
    var x = parseInt(ns[1],10);
    var y = parseInt(ns[2],10);
    var sum = x + y;
    //tとsumの偶奇が等しいという条件も必要
    return ((t >= sum) && ((t % 2) === (sum % 2)));
  });

  if(isValid){
    console.log('Yes');
  }else{
    console.log('No');
  }
}
main(require("fs").readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 30316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> pr;
struct item{
	ll wt;
	ll val;
	item(){
		wt = 0;
		val = 0;
	}
	item(ll w,ll value){
		wt = w;
		val = value;
	}
};
const ll inf = 1e12L;
int main(int argc,char const* argv[]){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n,w;
	cin>>n>>w;
	vector<item> arr(n);
	ll sum_of_val = 0;
	for(int i=0;i<n;i++){
		cin>>arr[i].wt>>arr[i].val;
		sum_of_val+=arr[i].val;
	}
	vector<vector<ll>> dp(n+1,vector<ll>(sum_of_val+1,inf));
	for(int i=0;i<=n;i++){
		dp[i][0] = 0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=sum_of_val;j++){
			if(arr[i-1].val<=j){
				dp[i][j] = min(dp[i-1][j],dp[i-1][j-arr[i-1].val] + arr[i-1].wt);
			}else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	ll ans = 0;
	for(int j=sum_of_val;j>=0;j--){
		if(dp[n][j] <= w){
			ans = j;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

typedef long long int ll;

typedef struct{
    ll w;
    ll v;
}obj;

int main(){
    ll n,w;
    cin>>n>>w;
    obj arr[n];
    for(ll i = 0;i< n;i++){
        cin>>arr[i].w>>arr[i].v;
    }
    ll markArr[n+1][w+1];
    memset(markArr, 0, sizeof(markArr));
    for(ll i = 0;i< n+1;i++){
        for(ll j= 0;j< w+1;j++){
            if(i == 0 || j == 0){
                markArr[i][j]= 0;
                continue;
            }
            else if(j >= arr[i-1].w){
                // cout<<"HERE j>= arr[i-1].w j= "<<j<<" i= "<<i<<endl;
                // cout<<"markArr[i-1][j]= "<<markArr[i-1][j]<<endl;
                // cout<<"markArr[i-1][j- arr[i-1].w]= "<<markArr[i-1][j -arr[i-1].w]<<endl;
                // cout<<"arr[i-1].v= "<<arr[i-1].v<<endl;
                markArr[i][j] = std::max(markArr[i-1][j], arr[i-1].v +markArr[i-1][j - arr[i-1].w]);
                // cout<<"markArr[i][j]= "<<markArr[i][j]<<endl; 
            }
            else if(j< arr[i-1].w){
                markArr[i][j] = markArr[i-1][j];
                // cout<<"HERE"<<endl;
            }
        }
    }
    // for(ll i = 1;i< n+1;i++){
    //     for(ll j= 1;j< w+1;j++){
    //             cout<<markArr[i][j]<<' ';
    //         }
    //     cout<<endl;
    // }
    cout<<markArr[n][w]<<endl;
}

Measured memory_bytes: 79104
n=int(input())
a=list(map(int,input().split()))
s=[]
if n%2==0:
  for i in range(n,0,-2):
    s.append(a[i-1])
  for j in range(1,n,2):
    s.append(a[j-1])
else:
  for i in range(n,0,-2):
    s.append(a[i-1])
  for j in range(2,n,2):
    s.append(a[j-1])
print(*s)

Measured memory_bytes: 26020
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

const UINT mod = 1000000007;

UINT PowMod(UINT x, UINT y)
{
	if (y == 0)
	{
		return 1;
	}
	else if (y == 1)
	{
		return x % mod;
	}
	else if (y % 2 == 0)
	{
		auto tmp = PowMod(x, y / 2);
		return tmp * tmp % mod;
	}
	else
	{
		auto tmp = PowMod(x, y / 2);
		return (tmp * tmp % mod) * x % mod;
	}
}

UINT getModInv(UINT N)
{
	return PowMod(N, mod - 2);
}

struct uf
{
	vector<INT> p;

	uf(INT n) : p(n)
	{
		for (size_t i = 0; i < n; i++)
		{
			p[i] = i;
		}
	}

	INT rt(INT n)
	{
		return p[n] == n ? n : p[n] = rt(p[n]);
	}

	void un(INT n, INT m)
	{
		p[rt(n)] = p[rt(m)];
	}

	bool eq(INT n, INT m)
	{
		return rt(n) == rt(m);
	}
};

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

	INT n = s.length();
	vector<INT> re(n, 0), ro(n, 0), le(n, 0), lo(n, 0);
	
	for (INT i = 0; i < n; i++)
	{
		if (s[i] == 'R')
		{
			ro[i + 1] += 1 + re[i];
			re[i + 1] += ro[i];
			if (s[i + 1] == 'R')
			{
				re[i] = 0;
				ro[i] = 0;
			}
			else
			{
				ro[i] = re[i + 1];
				re[i] = ro[i + 1];
			}
		}
	}
	for (INT i = n - 1; i >= 0; i--)
	{
		if (s[i] == 'L')
		{
			lo[i - 1] += 1 + le[i];
			le[i - 1] += lo[i];
			if (s[i - 1] == 'L')
			{
				le[i] = 0;
				lo[i] = 0;
			}
			else
			{
				lo[i] = le[i - 1];
				le[i] = lo[i - 1];
			}
		}
	}
	for (size_t i = 0; i < n; i++)
	{
		cout << re[i] + le[i];
		if (i < n - 1)
		{
			cout << ' ';
		}
	}
	return 0;
}


Measured memory_bytes: 3840
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    int q;cin>>q;
    deque<ll>a;
    for(ll i=0;i<q;i++){
        int x;cin>>x;
        if(x==0){
            bool d;cin>>d;
            if(d==0){
                ll b;cin>>b;
                a.push_front(b);
            }
            else{
                ll b;cin>>b;
                a.push_back(b);
            }
        }
        else if(x==1){
            int i;cin>>i;
            cout<<a[i]<<endl;
        }
        else{
            bool d;cin>>d;
            if(d==0){
                a.pop_front();
            }
            else a.pop_back();
        }
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------













































Measured memory_bytes: 6256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

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

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % mod;
        inv_fact[i] = exp(fact[i], mod-2, mod);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 2e5 + 5;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	ll n, d; cin>>n>>d;
	ll cnt = 0;
	while(n--){
		ll x, y; cin>>x>>y;
		cnt += x*x + y*y <= d*d;
	}
	cout<<cnt;
}

Measured memory_bytes: 3656
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

const int MAX = 1000000;

vector<bool> sieve(int n = MAX) {
	vector<bool> prime(n, true);
	prime[0] = prime[1] = false;
	for(int i = 2; i < n; ++i)
	if(prime[i])
		for(int j = i * 2; j < n; j += i)
			prime[j] = false;

	return prime;
}

int main() {
	vector<bool> prime = sieve();
	vector<int> num(MAX, 0);

	for(int i = 0; i < MAX - 1; ++i)
		num[i + 1] = num[i] + prime[i + 1];

	for(int n; scanf("%d", &n) == 1;)
		printf("%d\n", num[n]);

	return EXIT_SUCCESS;
}

Measured memory_bytes: 4900
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


H1,M1,H2,M2,K = MI()
print(max(0,60*H2+M2-60*H1-M1-K))


Measured memory_bytes: 61896
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000




int main(){
	
	int N;
	cin>>N;
	
	int a = (N+1)/2;
	
	double ans = 0.0;
	ans = (double)a / (double)N;
	
	cout<<fixed<<setprecision(15)<<ans<<endl;
		
	
	return 0;
}



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

int main(void){
  int h, w;
  while(cin >> h >> w, h | w){
    int init_taitai = h*h + w*w;
    int taitai = h*h + w*w;
    int ansh = 0, answ = 0;
    while(1){
      for(int nh = 1; nh <= sqrt(taitai)+1; nh++){
        for(int nw = sqrt(taitai)+1; nw > nh; nw--){
          int ntaitai = nw*nw + nh*nh;
          if(taitai == ntaitai){
            if(taitai == init_taitai && h < nh){
              ansh = nh; answ = nw;
            }else if(taitai == init_taitai){
              continue;
            }else{
              ansh = nh; answ = nw;
            }
          }
          if(ansh != 0 && answ != 0) break;
        }
        if(ansh != 0 && answ != 0) break;
      }
      if(ansh != 0 && answ != 0) break;
      taitai++;
    }
    cout << ansh << " "<< answ << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>

using namespace std;

int main(){
	string s;
	int L;
	while(cin >> s >> L, s != "0", L){
		string zero;
		for(int i = 0; i < L - s.size(); i++) zero += "0";
		s = zero + s;
		int n = atoi(s.c_str());
		vector<int> slist;
		int i = 0;
		do{
			slist.push_back(n);
			string smax, smin;
			sort(s.begin(), s.end());
			smin = s;	
			sort(s.begin(), s.end(), greater<char>());
			smax = s;
			int imax = atoi(smax.c_str()), imin = atoi(smin.c_str());
			n = imax - imin;
			ostringstream os;
			os << n;
			s = os.str();
			zero = "\0";
			for(int i = 0; i < L - s.size(); i++) zero += "0";
			s = zero + s;
		}while(find(slist.begin(), slist.end(), n) == slist.end());
		int I;
		for(int i = 0; i < slist.size(); i++) if(slist[i] == n) I = i;
		cout << I << " " <<  atoi(s.c_str()) << " " << slist.size() - I << endl;
	}

	return 0;
}

Measured memory_bytes: 1260
object Main extends scala.App {
    import java.util
    import scala.collection._
    import scala.collection.mutable
    import scala.math._

    val sc = new java.util.Scanner(System.in)
    val S = sc.next()

    val (pre, suf) = if (S.length % 2 == 0) {
        val n = S.length / 2
        (S.substring(0, n), S.substring(n).reverse)
    } else {
        val n = S.length / 2
        (S.substring(0, n), S.substring(n + 1).reverse)
    }

    val ans = (pre zip suf)
            .filter(p => p._1 != p._2)
            .foldLeft(0)((cnt, ch) => cnt + 1)
    println(ans)
}

Measured memory_bytes: 25556
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
using namespace std;

int main() {

    int n, m;
    cin >> n >> m;

    const int NMMAW = 50;
    vector<int> a(NMMAW), b(NMMAW);

    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
    }

    vector<int> road(NMMAW, 0);
    
    for (int i = 0; i < m; i++) {
        road[a[i] - 1] ++;
        road[b[i] - 1] ++;
    }

    for (int i = 0; i < n; i++) {
        cout << road[i] << endl;
    }
    
    return 0;   

}


Measured memory_bytes: 256
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long MOD = 1000000007;

int main() {
	//	--- I/O 高速化 ---
	cin.tie(0);
	ios::sync_with_stdio(false);
	// --- ここまで ---

	int N, A, B, n;
	long total, ans = 0;
	cin >> N >> A >> B;

	for (int i = 1; i <= N; i++)
	{
		n = i;
		total = 0;

		while(n != 0)
		{
			total += n % 10;

			if (total > B) break;

        	n /= 10;
        	
		}

		if (total > B) continue;

		if (total < A) continue;

		ans += i;

    }

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<iostream>
#include<iomanip>
#include<set>
#include<string>
#include<math.h>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;

//--------------
//#define DEBUG
//--------------

#ifdef DEBUG
	#define debugprint(x) cout<<x<<" "
	#define debugendl cout<<endl
	#define debug(x) x
#else
	#define debugprint(x)
	#define debugendl
	#define debug(x)
#endif

class zahyo{
	public:
	int x;
	int y;
	zahyo(){
		x=0;
		y=0;
	}
	zahyo(int x_,int y_){
		x=x_;
		y=y_;
	}
	void print(){
		cout<<x<<" "<<y;
	}
	zahyo operator+(zahyo add){
		add.x=this->x+add.x;
		add.y=this->y+add.y;
		return add;
	}
	zahyo operator-(zahyo add){
		add.x=this->x-add.x;
		add.y=this->y-add.y;
		return add;
	}
	zahyo operator*(int t){
		zahyo temp;
		temp.x=this->x*t;
		temp.y=this->y*t;
		return temp;
	}
	zahyo operator%(int t){
		zahyo temp(this->x%t,this->y%t);
		return temp;
	}
	zahyo operator/(int t){
		zahyo temp(this->x/t,this->y/t);
		return temp;
	}
	bool operator==(const zahyo add) const{
		if(add.x==this->x and add.y==this->y){return true;}
		else{return false;}
	}
	bool operator!=(const zahyo add) const{
		if(add.x==this->x or add.y==this->y){return false;}
		else{return true;}
	}
	bool operator<(const zahyo add) const{
		if(this->x<add.x){return true;}
		else if(this->x==add.x and this->y<add.y){return true;}
		else{return false;}
	}
	bool operator>(const zahyo add) const{
		if(this->x>add.x){return true;}
		else if(this->x==add.x and this->y>add.y){return true;}
		else{return false;}
	}
	void input(){
		cin>>x>>y;
	}
};

bool IsInBoard(int x,int maxx, int y,int maxy){
	if(x>=0 and x<maxx and y>=0 and y<maxy){
		return true;
	}
	else{
		return false;
	}
}

int main(){
	int n,m;
	cin>>n>>m;
	int coin[20];
	for(int i=0;i<m;i++){
		cin>>coin[i];
	}
	int maisu[50001];
	for(int i=0;i<50000;i++){
		maisu[i]=100000;
	}
	maisu[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<m;j++){
			if(i>=coin[j]){
				maisu[i]=min(maisu[i],maisu[i-coin[j]]+1);
			}
		}
	}
	cout<<maisu[n]<<endl;
	return 0;
}



Measured memory_bytes: 3296
L, R = map(int, input().split())
MOD = 2019
INF = 10**5
ans = INF


if 2019 <= R-L:
    print(0)
else:
    x = L % MOD
    y = R % MOD
    if x < y:
        for i in range(x, y):
            for j in range(i+1, y+1):
                ans = min(ans, (i*j) % MOD)
        else:
            print(ans)
    else:
        print(0)

Measured memory_bytes: 3064
from fractions import gcd


def main():
    n = int(input())
    As = list(map(int, input().split()))
    ans = gcd(As[0], As[1])
    for i in range(2, n):
        ans = gcd(ans, As[i])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16280
n, m = map(int, input().split())

penalty = [0] * n
isAC = [False] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == "WA":
        if not isAC[p]:
            penalty[p] += 1
    else:
        isAC[p] = True
for i in range(n):
    if not isAC[i]:
        penalty[i] = 0
print(sum(isAC), sum(penalty))

Measured memory_bytes: 47320
#include <bits/stdc++.h>
using namespace std;
int main(){
    double A,B, H ,M;
    cin >> A >> B>> H >> M;
    double a = 2 * M_PI* H/ 12, b = 2 * M_PI*M / 60;
    a += 2 * M_PI / 12 * M / 60; 
    double ans = A*A + B*B - 2* A* B * cos(a - b);
    printf("%.10lf\n", sqrt(ans));
}

Measured memory_bytes: 4216
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAX = 3000000;
const ll MOD = 1000000007;
string s;
//ll k;

int main() {
    cin >> s;
    ll n = s.length();
    ll tmp = 0;
    ll count = 0;
    bool checked[n];
    for(ll i=0;i<n;i++){
        checked[i] = false;
    }
    for(ll i=0;i<n;i++){
        if(checked[i] != true){  
            ll smallCount = 0;
            for(ll j=i;j<n;j++){
                tmp = tmp*10+(s[j]-48);
                tmp = tmp%2019;
                if(tmp==0){
                    smallCount++;
                    // cout << i << " " << j << " " << smallCount << endl;
                    count = count + smallCount;
                    checked[j+1] = true;
                }
            }
        }
        tmp = 0;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int count = 0;
  int a, b;
  cin >> a >> b;
  for(int i = 1; i <= a; i++) { 
    for(int j = 1; j <= 31; j++) { 
      if (i == j) count++;
      if (i == a && j == b) {
        cout << count << endl;
        return 0;
      }
    }
  }
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

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

signed main() {
  int n;
  cin >> n;
  if (n == 3 || n == 5 || n == 7) {
    puts("YES");
  } else {
    puts("NO");
  }

  return 0;
}

Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::cmp::*;
//use std::num;

fn main() {
    input! {
        n:usize,
        q:usize,
        s:Chars,
        lr:[(usize,usize);q]
    }
    let mut sum = vec![0; n + 1];
    for i in 0..n - 1 {
        if s[i] == 'A' && s[i + 1] == 'C' {
            sum[i + 2] = sum[i + 1] + 1;
        } else {
            sum[i + 2] = sum[i + 1];
        }
    }
    //println!("{:?}", sum);
    for &(l, r) in lr.iter() {
        let ans = sum[r] - sum[l];
        println!("{}", ans);
    }
}


Measured memory_bytes: 5768
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int a,b,N;
  cin>>a>>b>>N;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int s,f;
    cin>>s>>f;
    if ((s==a&&f==b) || (s<a&&a<f) || (s<b&&b<f) || (a<s&&s<b)) {
      ans=1;
      break;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	int ma=0;
	rep(i,n){
		cin >> a.at(i);
		ma=max(ma,a.at(i));
	}
	int x=ma,y=0,d=1000000000;
	ma=ma/2;
	rep(i,n){
		if(a.at(i)>ma){
			if(a.at(i)==x) continue;
			if(a.at(i)-(ma+1)<d){
				d=a.at(i)-(ma+1);
				y=a.at(i);
			}
		}
		else if(a.at(i)<ma){
			if(ma-a.at(i)<d){
				d=ma-a.at(i);
				y=a.at(i);
			}
		}
		else{
			d=0;
			y=a.at(i);
			break;
		}
	}
	cout << x << " " << y << endl;
}

Measured memory_bytes: 640
def lcm(a, b):
    c = max(a, b)
    d = min(a, b)
    while d != 0:
        r = c % d
        c, d = d, r

    return a * b // c


n = int(input())
t = [int(input()) for i in range(n)]

if len(t) == 1:
    ans = t[0]
else:
    ans = lcm(t[0], t[1])
    for i in range(2, len(t)):
        ans = lcm(t[i], ans)


print(ans)


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

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, m;; cin >> n >> m;
	vector<ll> mod(n + 1);
	mod[0] = 0;
	rep(i, 1, n)
	{
		ll a; cin >> a;
		mod[i] = (mod[i - 1] + a) % m;
	}
	map<ll, ll> mp;
	rep(i, 0, n)
	{
		++mp[mod[i]];
	}
	ll ans = 0;
	for (pair<ll, ll> p : mp)
	{
		ans += p.second*(p.second - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

vector<pair<pair<int,int>,int>> G;
ll dist[SIZE];

int main() {
  int N, M, P;

  scanf("%d%d%d", &N, &M, &P);

  for (int i=0; i<M; i++) {
    int A, B, C;
    scanf("%d%d%d", &A, &B, &C);
    A--; B--;
    C = P - C;
    G.push_back({{A, B}, C});
  }


  for (int i=0; i<N; i++)
    dist[i] = LLINF;


  bool valid[SIZE] = {};

  int lastUpdated = 0;

  dist[0] = 0;
  valid[N-1] = true;

  for (int i=0; i<=N*2; i++) {
    for (auto e : G) {
      int a = e.first.first;
      int b = e.first.second;
      int c = e.second;

      if (dist[a] == LLINF) continue;

      valid[a] |= valid[b];

      if (dist[b] > dist[a] + c) {
        dist[b] = dist[a] + c;
        if (valid[b]) lastUpdated = i;
      }
    }
  }

  if (lastUpdated >= N) {
    puts("-1");
  } else {
    printf("%lld\n", max(0LL, -dist[N-1]));
  }

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

#define INF 1e9
#define MAX_V 102

// ????????????????????£?¨?
int prim(int adjmatrix[MAX_V][MAX_V], int v);

// ?????????
int main(void){
  while(true){
    // ???????????°??¨???????????°???????????????
    int n, m;
    cin >> n;
    if(n == 0){ break; }
    cin >> m;
    
    // ??£??\???????????£?¨???¨?????????
    int adjmatrix[MAX_V][MAX_V];
    for(int i = 0; i < MAX_V; i++)
      for(int j = 0; j < MAX_V; j++)
        adjmatrix[i][j] = INF;

    // ???????????±????????????????????£??\???????????????
    for(int i = 0; i < m; i++){
      int a, b, d;
      scanf("%d,%d,%d", &a, &b, &d);
      adjmatrix[a][b] = d;
      adjmatrix[b][a] = d;
    }
  
    // ????°???¨?????¨????????????????±??????????????????????
    int length = prim(adjmatrix, n);
    cout << length / 100 - n + 1 << endl;
  }

  return 0;
}


// ????????????
// ?????°: ??£??\??????, ????????°
// ?????????: ??¨????????????
int prim(int adjmatrix[MAX_V][MAX_V], int v){
  vector<int> mincost(v, INF); // ?????§???????????????????????¨?????§???????°??????????
  vector<bool> used(v, false); // ??????i?????¨????????????????????????
  int length = 0; // ??¨????????¶???

  // ???????????????
  mincost[0] = 0;
  while(true){
    // ??¨????±??????????????????????????????¨?????§?????????????????????????°?????????????????????¢???
    // newmember???????¬??????¨????????????????£??????????(-1??§?????????)
    int newmember = -1;
    for(int u = 0; u < v; u++){
      // if(???u???????????¨???????±?????????????????????? && ?????¶???????£??????????u?????¨?????????){ u???????£??????????; }
      if(!used[u] && (newmember == -1 || mincost[u] < mincost[newmember])){ newmember = u; }
    }

    // ????????????????????£??????newmember???-1??¨???????????¨???
    // ???????????????????????¨???????±???????????????¨???????????¨????????§?????¢?´¢??????
    if(newmember == -1){ break; }
    
    // ???newmember?????¨?????????
    used[newmember] = true;
    length += mincost[newmember];

    // ??¨?????§???????°??????????????¨?????????´???
    // ??°?????????newmember?????¨???????±????????????¨????????£????????§???????????§???????°???¨???newmember?????§??????????????¢???????????????????????°??????
    for(int u = 0; u < v; u++){
      mincost[u] = min(mincost[u], adjmatrix[newmember][u]);
    }
  }
  
  return length;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int ans = 0;
    int v[50] = {};
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++)
    {
        int n = 0;
        cin >> n;
        if (v[i] - n > 0)
        {
            ans += v[i] - n;
        }
    }
    cout << ans << endl;
}


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

int gc[205][205];

signed main() {
	int n;
	cin >> n;
	long long a = 0;
	for (register int i = 1; i <= n; i++)
		for (register int j = 1; j <= n; j++)
			gc[i][j] = __gcd(i, j);
	for (register int i = 1; i <= n; i++)
		for (register int j = 1; j <= n; j++)
			for (register int k = 1; k <= n; k++)
				a += gc[i][gc[j][k]];
	cout<<a<<endl;
}

Measured memory_bytes: 3796