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

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

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

	ll n;
	cin>>n;

	ll x=n , sz=0 , t=0 , res=0;

	while (x>0)
    {
        if (x/10==0)
        {
            t=x;
        }

        sz++;
        res+=(x%10);
        x/=10;
    }

    cout<<max(res , t-1+(sz-1)*9);
}


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>

using namespace std;
int M, N, B[500], R[500], P[500];
bool C[500][500], V[500];

bool match(int i) {
	if (i < 0) return true;
	for (int j = 0; j < N; j++) {
		if (!C[i][j] || V[j]) continue;
		V[j] = true;
		if (match(P[j])) {
			P[j] = i;
			return true;

		}

	}
	return false;

}int main() {
	while (cin >> M >> N && M) {
		for (int i = 0; i < M; i++)
			cin >> B[i];
		for (int j = 0; j < N; j++)
			cin >> R[j];
		fill(P, P + N, -1);
		for (int i = 0; i < M; i++)
			for (int j = 0; j < N; j++)
				C[i][j] = (__gcd(B[i], R[j]) >= 2);
		int count = 0;
		for (int i = 0; i < M; i++) {
			fill(V, V + N, false);
			if (match(i)) ++count;
		}
		cout << count << endl;

	}

}

Measured memory_bytes: 3344
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define F .first
#define S .second 
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[110000];
main(){
  ll n,ans=0;
  cin>>n;
  rep(i,0,n){cin>>a[i];ans+=a[i]-1;}
  cout<<ans;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = float('inf')
for i in range(n - k + 1):
  ans = min(ans, abs(x[i]) + abs(x[i + k - 1] - x[i]))
  ans = min(ans,  abs(x[i + k - 1]) + abs(x[i + k - 1] - x[i]))
print(ans)

Measured memory_bytes: 14252
<?php

while (true) {
    fscanf(STDIN, '%d %d', $H, $W);
    if (isNoneBoth($H, $W)) { break; }

    $rect    = chunk_split(str_repeat('#', $H * $W), $W, PHP_EOL);
    $rects[] = $rect;
}

echo implode(PHP_EOL, $rects), PHP_EOL;

function isNoneBoth($H, $W)
{
    return !($H || $W);
}

Measured memory_bytes: 6776
#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first    
#define se second 
void solve()
{   
    ll n;
    cin>>n;
    ll ans = 0,i;
    for(i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
            ans+=i;
    }
    cout<<ans;
}
int main(){ 
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // # ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif  
    // clock_t tStart = clock();
    // ll t;
    // cin>>t;
    // while(t--)
        solve();
    //printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 3620
import java.util.*;
import java.util.stream.*;
import java.io.*;

public class Main {

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] in = br.readLine().split(" ");
    int n = Integer.parseInt(in[0]);

    int[] a = new int[n], b = new int[n];
    long[] c = new long[n];
    long ans = 0;

    for(int i = 0; i < n; i++){
      in = br.readLine().split(" ");
      a[i] = Integer.parseInt(in[0]);
      b[i] = Integer.parseInt(in[1]);
      c[i] = a[i] + b[i];
      ans -= b[i];
    }

    br.close();

    Arrays.sort(c);

    for(int i = n - 1; i >= 0; i -= 2){
      ans += c[i];
    }

    System.out.println(ans);
  }
}

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

typedef long long int64;
const int MAX = 3e5 + 5;
int n;
int64 k, a[MAX];

typedef long double ld;

int64 parte_entera(ld x, ld y) {
	return (int64) floorl(x / y);
}

int64 parte_superior(ld x, ld y) {
	return (int64) ceill(x / y);
}

int64 cnt(int64 x) {

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

		else if(a[i] > 0LL) {
			int64 param = parte_entera(x, a[i]);
			int p = upper_bound(a + 1, a + n + 1, param) - a - 1;
			tot += p;

			// printf("<= %lld, cnt = %d\n", param, p);

			if(p >= i)
				tot--;
		}

		else {
			int64 param = parte_superior(x, a[i]);
			int p = lower_bound(a + 1, a + n + 1, param) - a;
			tot += n - p + 1;

			// printf(">= %lld, cnt = %d\n", param, n - p + 1);

			if(i >= p)
				tot--;
		}
	}

	assert(tot % 2 == 0);
	return tot / 2;
}

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

	for(int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);

	sort(a + 1, a + n + 1);

	// printf("%lld\n", cnt(0));

	int64 st = -1e18, nd = 1e18, ans = 2e18;

	while(st <= nd) {
		int64 mid = (st + nd) / 2LL;

		if(cnt(mid) >= k) {
			ans = min(ans, mid);
			nd = mid - 1;
		}

		else st = mid + 1;
	}

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<vector>
#define ll long long int
using namespace std;
int main(void) {
  int n;
  cin>>n;
  vector<int> v(n);
  vector<int> ans(n);
  for(int i=0; i<n; i++) {
    cin>>v[i];
  }
  for(int i=1; i<=n; i++) {
    if(i%2==1) {
      ans[i-1-(i/2)]=v[n-i];
    } else {
      ans[n-i+(i/2)]=v[n-i];
    }
  }
  for(int i=0; i<n; i++) {
    cout<<ans[i]<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3712
import sys
from io import StringIO
import unittest

def resolve():
    n, m=list(map(int,input().strip().split()))

    res=[-1 for i in range(n)]

    for i in range(m):
        s,c = list(map(int,input().strip().split()))
        s-=1
        if res[s] == -1:
            res[s]=c
        elif res[s] != c:
            print("-1")
            return

    if n==1 and res[0]==-1:
            print("0")
            return
    if n==1 and res[0]==0:
            print("0")
            return

    h=0
    for i in range(n):
        if res[i]==-1:
            if h==0:
                res[i]=1
                h=1
            else:
                res[i]=0
        else:
            h=1
    if res[0]==0:
            print("-1")
            return

    r=""
    for i in range(n):
        r+=str(res[i])
    print(r)
    return

resolve()

Measured memory_bytes: 5592
// aribon3-2-7_c
// AGC 026 C - String Coloring　
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;


#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    string S;
    cin >> S;

    using P = pair<string, string>;
    map<P, ll> mp;

    REP(i, 1 << N){
        string a, b;
        REP(n, N){
            if (i >> n & 1){
                a += S[n];
            } else {
                b += S[n];
            }
        }
        mp[P(a,b)]++;
    }

    ll ans = 0;
    REP(i, 1 << N){
        string a, b;
        REP(n, N){
            if (i >> n & 1){
                a += S[2*N-1-n];
            } else {
                b += S[2*N-1-n];
            }
        }
        ans += mp[P(a,b)];
    }

    print(ans);



    return 0;
}


Measured memory_bytes: 91904
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())

counter = Counter(a)
sum_res = sum(a)

for _ in range(q):
  b, c = map(int, input().split())

  sum_res += (c - b) * counter[b]

  counter[c] += counter[b]
  counter[b] =0

  print(sum_res)

Measured memory_bytes: 24092
def InsertionSort(A, N):
    ans = ' '.join(map(str, A)) + '\n'
    i = 1
    while i < N:
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        ans += ' '.join(map(str, A)) + '\n'
        i += 1
    return ans[:-1]

n = int(input())
A = list(map(int, input().split(' ')))
ans = InsertionSort(A, n)
print(ans)


Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
char s[60][60];
signed main()
{
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> s[i][j];
        }
    }

    bool flag = false;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++) 
        {
            if(s[i][j]=='#'){
                if (s[i + 1][j] != '#' && s[i][j+1] != '#' && s[i - 1][j] != '#' && s[i][j-1] != '#'){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
        
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B && B != C){
        cout << "Yes" << endl;
    }
    else if (A != B && B == C){
        cout << "Yes" << endl;
    }
    else if (A == C && B != C){
        cout << "Yes" << endl;
    }
    else if (A == B && B == C){
        cout << "No" << endl;
    }
    else if (A != B && B!= C){
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String w = sc.next();
        String t;
        int cnt = 0;
        while(true){
            t = sc.next();
            if(t.equals("END_OF_TEXT")) break;
            if(t.equalsIgnoreCase(w)) cnt++;
        }
        System.out.println(cnt);
    }
}



Measured memory_bytes: 26232
#include <stdio.h>

int main(void){
  char s[200001];
  int i, n, a, b, c, d, flag1 = 1, flag2 = 1;
  scanf("%d %d %d %d %d %s", &n, &a, &b, &c, &d, s);
  if(c > d){
    flag1=0;
  	for(i = b-2; i < d-1; i++){
    	if(s[i] == '.' && s[i+1] == '.' && s[i+2] == '.') flag1 = 1;
    }
  }
  for(i = a-1; i < c-1; i++){
    if(s[i] == '#' && s[i+1] == '#') flag2 = 0;
  }
  for(i = b-1; i < d-1; i++){
    if(s[i] == '#' && s[i+1] == '#') flag2 = 0;
  }
  if(flag1 == 1 && flag2 == 1){printf("Yes\n");}
  else{ printf("No\n");}
  return 0;
}

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

int n, arr[100000];

int solve(int n) {
	arr[0]=arr[1]=1;
	for (int i = 2; i <= n; i++) arr[i] = arr[i-2]+arr[i-1];
	return arr[n];
}

int main() {
	cin >> n ;
	cout << solve(n) << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
 

int main(){
    string s; cin >> s;
    if(s[2]==s[3] && s[4]==s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
return 0;
}


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

class Program
{
    public static int Main()
    {
        bool exist = false;
        string S = Console.ReadLine();

        if (S.Length < 3)
        {
            if (S[0] == S[1])
            {
                Console.WriteLine("1 2");
                exist = true;
            }
        }
        for (int i = 2; i < S.Length; ++i)
        {
            if (S[i - 2] == S[i - 1] || S[i - 1] == S[i] || S[i] == S[i - 2])
            {
                Console.WriteLine((i - 1) + " " + (i + 1));
                exist = true;
                break;
            }
        }
        if (!exist)
        {
            Console.WriteLine("-1 -1");
        }
        return 0;
    }
}


Measured memory_bytes: 3032
# https://atcoder.jp/contests/abc110/tasks/abc110_b

N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.sort()
y.sort()

if x[-1] < y[0]:
    for i in range(x[-1]+1, y[0]+1):
        if X < i <= Y:
            # print("X({}) < i({}) <= Y({})".format(X, i, Y))
            print("No War")
            exit()

print("War")


Measured memory_bytes: 3060
N, A, B, C = map(int, input().split())
Ss = [input() for _ in range(N)]

ans = []
arr = {}
arr['A'] = A
arr['B'] = B
arr['C'] = C
for i, s in enumerate(Ss):
    v1 = s[0]
    v2 = s[1]
    if arr[v1] == arr[v2] == 0:
        print('No')
        exit()
    if i < N-1 and arr[v1] == arr[v2] == 1:
        if s == Ss[i+1]:
            ans.append(v1)
            arr[v1] += 1
            arr[v2] -= 1
        elif v1 in Ss[i+1]:
            ans.append(v1)
            arr[v1] += 1
            arr[v2] -= 1
        else:
            ans.append(v2)
            arr[v1] -= 1
            arr[v2] += 1
    elif arr[v1] < arr[v2]:
        ans.append(v1)
        arr[v1] += 1
        arr[v2] -= 1
    else:
        ans.append(v2)
        arr[v1] -= 1
        arr[v2] += 1
print('Yes')
for a in ans:
    print(a)



Measured memory_bytes: 16872
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 #include<memory>
 
 using namespace std;
 
 int main()
 {
   int n,m,k;
   while(cin>>n>>m>>k)
   {
     int result=0;
     for(int i=0;i<=n;i++)
     {
       for(int j=0;j<=m;j++)
       {
         if(j*n+(m-j)*i-i*j==k)
         {
           result=1;
           //cout<<i<<" "<<j<<endl;
           break;                  
         }        
       }        
     }           
     if(result) cout<<"Yes"<<endl;
     else cout<<"No"<<endl;        
   } 
   return 0;
 }
 

Measured memory_bytes: 256
L, R = list(map(int, input().split()))

ans = 2019
if R-L>2019:
    print(0)
else:
    for l in range(L, R):
        for r in range(l + 1, R+1):
            tmp = (l * r) % 2019
            # tmp = ((l%2019) * (r%2019)) % 2019
            ans = min(ans, tmp)
            if ans == 0:
                break
    print(ans)


Measured memory_bytes: 2940
def slove():
    import sys
    input = sys.stdin.readline
    x = int(input().rstrip('\n'))
    mt = 0
    for i in range(1, 1001):
        for j in range(2, 1001):
            if i ** j > x:
                break
            else:
                mt = max(mt, i ** j)
    print(mt)


if __name__ == '__main__':
    slove()


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

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

    int res = 0, g_cnt = 0, p_cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'g') {
            if (p_cnt < g_cnt) {
                res++;
                p_cnt++;
            } else {
                g_cnt++;
            }
        } else {
            if (p_cnt < g_cnt) {
                p_cnt++;
            } else {
                res--;
                g_cnt++;
            }
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string S,T;
    cin >> S >> T;

    cout << T << S << endl;
}

Measured memory_bytes: 3580
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


#define INF (1e+9)
int main(void) {
    int num, cap, limit;
    cin >> num >> cap >> limit;
    vector<pii> ranges(num);
    for(int i = 0; i < num; i++) {
        int time;
        cin >> time;
        ranges[i] = make_pair(time, time+limit+1);
    }
    auto comp = [](pii a, pii b) {
        return a.second < b.second;
    };
    sort(ranges.begin(), ranges.end(), comp);

    int ans = 0;
    int time = 0;
    int ps = 0;
    for(int i = 0; i < num; i++) {
        pii r = ranges[i];
        debug("[time: %d] r: %d, %d, ps: %d\n", time, r.first, r.second, ps);
        if(ps == cap) {
            time = 0;
        }
        // in time
        if(r.first < time) {
            ps++;
        } else {
            ans++;
            time = r.second;
            ps = 1;
        }
        debug("%d\n", ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4036
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility>
using ll=long long;
using namespace std;

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    double a;
    for(int i=0;i<N;i++){
        cin>>a;
        a*=1000000000;
        a+=0.5;
        A[i]=a;
    }

    ll ans=0;

    //map<pair<int,int>,int> m;
    map<pair<int,int>,int> mm;
    for(int i=N-1;i>=0;i--){
        int cnta=0;
        int cntb=0;
        while(1){
            if(A[i]%2==0){
                A[i]/=2;
                cnta++;
                if(cnta==18){
                    break;
                }
            }else{
                break;
            }
        }
        while(1){
            if(A[i]%5==0){
                A[i]/=5;
                cntb++;
                if(cntb==18){
                    break;
                }
            }else{
                break;
            } 
        }
        //m[{cnta,cntb}]++;
        //cout<<cnta<<" "<<cntb<<endl;
        ans+=mm[{18-cnta,18-cntb}];
        for(int i=0;i<=cnta;i++){
            for(int j=0;j<=cntb;j++){
                mm[{i,j}]++;
            }
        }
    }
    cout<<ans<<endl;


    return 0;
}

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

struct Money{
    double bit;
    string str;
};

int main(){
    int N;
    cin>>N;
    double sum=0;
    for(int i=0;i<N;++i){
        Money kane;
        cin>>kane.bit>>kane.str;
        if(kane.str=="JPY"){
            sum+=kane.bit;
        }else{
            sum+=kane.bit*380000.0;
        };
    }
cout<<sum<<endl;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()

typedef pair< int, int > pii;

int N, m;

int main() {
	cin >> N >> m;
	vector< pii > vp;
	
	for_(i,0,m) {
		int c, d; cin >> c >> d;
		vp.push_back(pii(c,d));
	}
	
	sort(allof(vp));
	
	vector< pii > vvp;
	int ans = 0, s = 0, a = 0, b = 0;
	for_(i,0,m) {
		if (a <= vp[i].first && vp[i].first <= b) {
			a = min(a, vp[i].first);
			b = max(b, vp[i].second);
		} else {
			ans += (b - s) + 2 * (b - a);
			s = b;
			a = vp[i].first;
			b = vp[i].second;
		}
	}
	
	ans += (b - s) + 2 * (b - a) + N + 1 - b;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1212
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

a, b, c = MAP()
d = gcd(a, b)
if c % d == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 59628
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){
      lint n;
      string s;
      cin>>n>>s;
      lint count1=0;
      lint count2=0;
      rep(i,n){
          if(s[i]=='W')count1++;
          else count2++;
      }
      lint ans=min(count1,count2);
      lint x=0,y=0;
      rep(i,count2){
          if(s[i]=='W')x++;
      }
      ans=min(x,ans);
      for(int i=(n-1);i>n-1-count1;i--){
          if(s[i]=='R')y++;
      }
      ans=min(ans,y);
      cout<<ans<<endl;
  }

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

int main(){
  int n, k;
  cin >> n >> k;
  long long x[n+1];
  for ( int i = 1; i <= n; i++){
    cin >> x[i];
  }
  long long ans = 1000000000;
  for ( int i = 1; i <= n+1-k; i++){
    ans = min(ans, min(abs(x[i]), abs(x[i+k-1])) + x[i+k-1] - x[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  string S;
  cin >> S;
  int w;
  cin >> w;

  REP(i, S.length()){
    if(i%w==0) cout << S[i];
  }

  return 0;
}


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

int f(int x,int p) {
	return p * (100 + x) / 100;
}

int main() {
	int x1,x2,s;

	while(cin >> x1 >> x2 >> s && !(x1 == 0 && x2 == 0 && s == 0)) {
		int max = 0,res;
		for(int i = 1;i <= s - 1;i++) {
			for(int j = 1;j <= s - 1;j++) {
				res = f(x2,i) + f(x2,j);
				if((f(x1,i) + f(x1,j) == s) && res > max) {
					max = res;
				}
			}
		}
		cout << max << endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    vector <pair<int,int> > v(n);
    for(int i=0;i<n;i++)
    {
        int x=nxt();
        v[i]={x,i+1};
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
        cout<<v[i].second<<" ";
    cout<<endl;
    
    
    return 0;   
}


 
 


Measured memory_bytes: 1664
n, k = map(int, input().split())
s = input()
result = ''
for i, c in enumerate(s):
    if i == k-1:
        if c == 'A':
            result += 'a'
        elif c == 'B':
            result += 'b'
        elif c == 'C':
            result += 'c'
    else:
        result += c
print(result)


Measured memory_bytes: 2940
#include <stdio.h>
#include <algorithm>
#include <iostream>

using namespace std;

int main(){

	int N,r,t,point[4];
	bool FLG;

	scanf("%d",&N);

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

		t = min(t,360-t);

		if(r%100 == 0 && t%30 == 0){

			point[0] = 5*(t/30)+(r/100);
			printf("%d\n",point[0]);

		}else if(r%100 == 0){

			for(int k = 0; k <= 150; k += 30){
				if(t > k && t < k + 30){
					point[0] = 5*(k/30)+(r/100);
					point[1] = 5*((k+30)/30)+(r/100);
					break;
				}
			}
			printf("%d %d\n",point[0],point[1]);

		}else if(t%30 == 0){
			for(int k = 100; k <= 400; k += 100){
				if(r > k && r < k + 100){
					point[0] = 5*(t/30)+(r/100);
					point[1] = 5*(t/30)+((r+100)/100);
					break;
				}
			}
			printf("%d %d\n",point[0],point[1]);
		}else{
			FLG = false;
			for(int k = 0; k <= 150; k += 30){
				for(int p = 100; p <= 400; p += 100){
					if(t > k && t < k + 30 && r > p && r < p + 100){
						point[0] = 5*(k/30)+(p/100);
						point[1] = 5*(k/30)+((p+100)/100);
						point[2] = 5*((k+30)/30)+(p/100);
						point[3] = 5*((k+30)/30)+((p+100)/100);
						FLG = true;
						break;
					}
				}
				if(FLG)break;
			}
			printf("%d %d %d %d\n",point[0],point[1],point[2],point[3]);
		}
	}


}

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

int main(){
	int n;
	int i , j;
	while(cin >> n, n!=0) {
	int arr[10][10]={0,0};
	int ansW[11]={0};
	int ansH[11]={0};
		for(i=0 ; i<n ; i++){
			for(j=0 ; j <n ; j++){
				cin >>arr[i][j];
			}
		}
		for(i=0 ; i<n ; i++){
			for(j=0 ; j<n ; j++){
				ansH[i]+=arr[i][j];
			}
		}
		for(i=0 ; i<n ; i++){
			for(j=0 ; j<n ; j++){
				ansW[i]+=arr[j][i];
			}
		}
		for(i=0 ; i<n ; i++){
			for(j=0 ; j<n ; j++){
				cout.fill(' ');
				cout << setw(5) <<right <<arr[i][j];
			}
			cout << setw(5) <<right <<ansH[i] << endl;
		}
		for(i=0; i<n ; i++){
				ansW[n]+=ansW[i];
		}
		for(i=0 ; i<n+1 ; i++){
			cout << setw(5) <<right << ansW[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
long long int arr[1000000]={0};
long long int ch[1000000]={0};
map<int,vector<int> > v;
map<pair<int,int>,int> m;
int rec(int node)
{   //cout<<" "<<node<<endl;
    ch[node]=1;
    vector<int> e = v[node];

    for(int i=0;i<e.size();i++)
    {
        if(ch[e[i]]==0)
        {
            int node1 = e[i];
            if(m[make_pair(node,node1)]%2==0)
            {
                arr[node1]=arr[node];

            }
            else
            {

                arr[node1] = (arr[node]+1)%2;
            }
            rec(e[i]);
        }
    }

}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int u1,v1,w1;
        cin>>u1>>v1>>w1;
        v[u1-1].push_back(v1-1);
        v[v1-1].push_back(u1-1);
        m[make_pair(u1-1,v1-1)]=w1;
        m[make_pair(v1-1,u1-1)]=w1;




    }
    rec(0);

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

        cout<<arr[i]<<endl;
    }

}


Measured memory_bytes: 34048
import Data.List
main=interact$f.map read.words
f(n:p)=unlines$map(unwords.map show)[a,reverse b]where
  q=map snd.sort$zip p[1..n]
  [a,b]=map g[q,reverse q]
g p=zipWith(+)[1..].scanl(\t v->t+max v 0)0.zipWith(-)(tail p)$p

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

bool compareX(const P& lp, const P& rp){
    return lp.first < rp.first;
}

bool compareY(const P& lp, const P& rp){
    return lp.second < rp.second;
}

int distance(const P& lp, const P& rp){
    int dx = lp.first - rp.first,
        dy = lp.second - rp.second;

    return dx * dx + dy * dy;
}

int bruteForce(std::vector<P>& ps, int begin, int n){
    int res = INF;

    REP(i, n){
        FOR(j, i+1, n){
            res = std::min(res, distance(ps[begin+i], ps[begin+j]));
        }
    }

    return res;
}

int stripClosest(std::vector<P>& strip, int d){
    int res = d;

    std::sort(strip.begin(), strip.end(), compareY);

    REP(i, strip.size()){
        for(int j=i+1;j<strip.size()&&(strip[j].second-strip[i].second)<res;j++){
            res = std::min(res, distance(strip[i], strip[j]));
        }
    }

    return res;
}

int closestUtil(std::vector<P>& ps, int begin, int n){
    if(n <= 3){ // bruteForce
        return bruteForce(ps, begin, n);
    }

    int mid = n / 2;
    P& mid_p = ps[mid];

    int dl = closestUtil(ps, begin, mid),
        dr = closestUtil(ps, begin + mid, n - mid),
        d = std::min(dl, dr);

    std::vector<P> strip;
    REP(i, n){
        if(std::abs(ps[begin+i].first - mid_p.first) < d){
            strip.push_back(ps[begin+i]);
        }
    }

    return std::min(d, stripClosest(strip, d));
}

int closest(std::vector<P> ps){
    std::sort(ps.begin(), ps.end(), compareX);

    return closestUtil(ps, 0, ps.size());
}

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

    std::vector<P> ps;
    REP(i, N){
        int x, y;
        std::cin >> x >> y;

        ps.push_back(mp(x, y));
    }

    std::cout << closest(ps) << std::endl;
}

Measured memory_bytes: 9412
from itertools import accumulate

N, K = map(int, input().split())
S = input() + "2"
T = []
i = 0
for j in range(1, len(S)):
    if S[i] != S[j]:
        T.append(j - i)
        i = j
U = [0] + list(accumulate(T))
ans = 0
for i in range(len(T)):
    if (i + int(S[0])) % 2 == 0:
        j = i + 2 * (K - 1) + 1
    else:
        j = i + 2 * K
    j = min(j, len(T) - 1)
    ans = max(ans, U[j + 1] - U[i])
print(ans)


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

int H[45][20];
vector<pair<int, int>> v;

void solve() {
  int n; cin >> n;
  for (int i = 0; i < n; ++i) {
    string s; cin >> s;
    long long num = 0;
    int t = 0, f = 0;
    bool start = false;
    for (int j = 0; j < (int)s.size(); ++j) {
      if (s[j] == '.') {
	start = true;
	continue;
      }
      num *= 10;
      num += s[j]-'0';
      if (start) t = --f;
    }
    while (num%2==0) {
      ++t;
      num /= 2;
    }
    while (num%5==0) {
      ++f;
      num /= 5;
    }
    v.emplace_back(f, t);
    debug(f);
    debug(t);
  }
  long long ans = 0;
  sort(v.begin(), v.end());
  for (int i = 0; i < (int)v.size(); ++i) {
    const auto &e = v[i];
    for (int f = -e.first; f < 20; ++f) {
      ans += upper_bound(v.begin()+i+1, v.end(), make_pair(f+1, -45))-lower_bound(v.begin()+i+1, v.end(), make_pair(f, -e.second));
    }
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 5316
N, M = map(int, input().split())
A,B = [],[]

for i in range(N):
    A.append(input())
for i in range(M):
    B.append(input())

ans_list = list()
for i in range(N-M+1):
    #print(A[i])
    if B[0] in A[i]:
        ans = "T"
        y = A[i].find(B[0])
        #print("{}行目の{}文字目".format(i+1, y+1))
        for j in range(1,M):
    
            if A[i+j][y:y+M] == B[j]:
                ans += "T"
            else:
                ans += "F"
            #print(i, j, ans)
        ans_list.append(ans)

flag = False
for ans in ans_list:
    if "T" * M in ans:
        flag = True
    if flag:
        print("Yes")
        break
if not flag:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;



int n, a[200005], ans, cnt = 1;

int main() {

	cin >> n;
	rep(i, n)cin >> a[i];

	rep(i, n) {
		if (a[i] == cnt) {
			cnt++;
		}
		else {
			ans++;
		}
	}

	if (cnt == 1)ans = -1;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(){
int a;
int b;
int c;
int d;
int e;
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;
if(a>b){a=b;}
if(a>c){a=c;}
if(d>e){d=e;}
cout << a+d-50<<endl;}

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

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

	int N;
	int min=1000000;
	int i,j;
	int tmp;
	int answer;
	int counter=0;
	double ave;
	vector<int> given;

	cin >> N;

	for(i=0;i<N;i++){
		cin >> tmp;
		given.push_back(tmp);
	}

	for(i=0;i<N;i++){
		if(given[i]<=min){
			counter++;
		}

		if(given[i]<min){
			min=given[i];
		}
	}
	
	answer=counter;
	cout << answer << endl;

	return 0;
}



Measured memory_bytes: 1400
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.geom.Point2D;
import java.util.*;
 
public class Main {
    Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
    	new Main(); 
    }
 
    public Main() {
    	new aoj0179().doIt();
    }
    class aoj0179{
    	String check(String s){
    		if(s.equals("rb") || s.equals("br"))return "gg";
    		else if(s.equals("rg") || s.equals("gr"))return "bb";
    		return "rr";
    	}
    	int ans(String str,int length){
    		TreeSet<String> ts = new TreeSet<String>();
    		ArrayList<String> array = new ArrayList<String>();
    		ArrayList<Integer> array2 = new ArrayList<Integer>();
    		ts.add(str);array.add(str);array2.add(0);
    		int num = 0;
    		while(array.size() > 0){
    			boolean out = true;
    			str = array.remove(0);
    			num = array2.remove(0);
//    			System.out.println(str+" "+num);
				for(int j=0;j<length-1;j++)if(str.charAt(j)!=str.charAt(j+1))out = false;
				if(out)return num;
				for(int j = 0;j < length-1;j++)if(str.charAt(j)!=str.charAt(j+1)){
					String str2 = str.substring(0,j)+check(str.substring(j,j+2))+str.substring(j+2,length);
//					System.out.println(cnt+" "+str+" "+str2+" "+ts.size());
					if(ts.add(str2)){
						array.add(str2);
						array2.add(num+1);
					}
				}
			}
    		return -1;
    	}
    	void doIt(){
    		while(true){
    			String str = sc.next();	
    			if(str.equals("0"))break;
    			int a = ans(str,str.length());
    			System.out.println(a == -1 ? "NA":a);
    		}
    	}
    }
}

Measured memory_bytes: 92848
import Data.Char

getInts :: IO [Int]
getInts = map read . words <$> getLine

infixl 1 |>
x |> f = f x

between :: Int -> Int -> Int -> Bool
between a b x = a <= y && y <= b
    where y = x |> show |> map digitToInt |> sum

main = do
  n:a:b:_ <- getInts
  [1..n] |> filter (between a b) |> sum |> print


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
vector<long long> v;
struct hugeint{
	int len;
	long long num[200];
}a;
hugeint operator +(hugeint a,long long b){
	a.num[1]+=b;
	int i=1;
	while(a.num[i]>=10)
	{
		a.num[i+1]+=a.num[i]/10;
		a.num[i]%=10;
		i++;
	}
	a.len=max(a.len,i);
	return a;
}
void divi(long long n){
	for(long long i=1;i*i<=n;i++){
		if(n%i==0){
			v.push_back(i);
			v.push_back(n/i);
		}
	}
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	long long n;
	cin>>n;
	divi(n);
	a.len=0;
	for(int i=0;i<v.size();i++){
		long long m=n/v[i] -1;
		if(v[i]<m)
			a=a+m;
	}
	if(a.len==0)
		cout<<0<<endl;
	else{
		for(int i=a.len;i>=1;i--)
			cout<<a.num[i];
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std; 
int main()
{
	string nn;
	int n;
	cin>>n;
	stringstream x;
	x<<n;
	x>>nn;
	if(nn.size()==6)
	{
		cout<<90909<<endl;
		return 0;
	}	
	if(nn.size()==4)
	{
		cout<<909<<endl;
		return 0;
	}
	if(nn.size()==2)
	{
		cout<<9<<endl;
		return 0;
	}
	if(nn.size()==1)
	{
		cout<<n<<endl;
		return 0;
	}
	if(nn.size()==3)
	{
		cout<<n-90<<endl;
		return 0;
	}
	if(nn.size()==5)
	{
		cout<<n-90-9000<<endl;
		return 0;
	}	
}

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

ll factorial[4000];
int mod =1e9+7;

ll binaryExp(ll a, ll b){
	ll result =1;
	while(b){
		if(b%2){
			result = (result*a)%mod;
		}
		a = (a*a)%mod;
		b/=2;
	}
	return result;
}

ll ncr(ll n, ll r){
	ll result = (factorial[n+r-1]*binaryExp((factorial[n]*factorial[r-1])%mod,mod-2))%mod;
	return result;
}


int main(){
	factorial[0]=1;
	for(int i=1;i<4000;++i){
		factorial[i]=(i*factorial[i-1])%mod;
	}
	int s;
	cin>>s;
	ll ans=0;
	for(int i=1;i*3<=s;++i){
		ans = (ans + ncr(s-3*i,i))%mod;
	}
	cout<<ans;
}



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

int main(){
    vector<vector<int>> a(3,vector<int>(3));
    vector<vector<bool>> b(3,vector<bool>(3,false));
    
    rep(i,3){
        rep(j,3)
            cin>>a[i][j];
    }
    
    int n;
    cin>>n;
    
    
    rep(h,n){
        int r;
        cin>>r;
        rep(i,3){
            rep(j,3){
                if(a[i][j]==r){
                    b[i][j]=true;
                }
            }
        }
    }
   
    bool ans=false;
    rep(i,3){
        if(b[i][0]&&b[i][1]&&b[i][2]) ans=true;
        if(b[0][i]&&b[1][i]&&b[2][i]) ans=true;
    }
    if(b[0][0]&&b[1][1]&&b[2][2]) ans=true;
    if(b[0][2]&&b[1][1]&&b[2][0]) ans=true;
    
    if(ans) cout<<"Yes"<<endl;
    else    cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int a, b, k[105], ans = 0;
	cin >> a >> b;
	for (int i = 0; i < a; ++i) {
		cin >> k[i];
	}
	for (int i = 0; i < a; ++i) {
		ans += min(k[i], b - k[i]);
	}
	cout << ans*2 << endl;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
from collections import Counter
l=[]
for _ in range(h):
    l+=list(input())
c=Counter(l)

if h==1 and w==1:
    print("Yes")
elif h==1:
    two=w//2
    for k,v in c.items():
        c[k]-=2*(v//2)
        two-=v//2
    if two==0:
        print("Yes")
    else:
        print("No")
elif w==1:
    two=h//2
    for k,v in c.items():
        c[k]-=2*(v//2)
        two-=v//2
    if two==0:
        print("Yes")
    else:
        print("No")
else:
    four=((w//2)*(h//2))
    two=0
    if w%2==1 and h%2==1:
        two=(h+w-2)//2
    elif w%2==1:
        two=h//2
    elif h%2==1:
        two=w//2
    for k,v in c.items():
        four-=v//4
        c[k]-=4*(v//4)
        two-=c[k]//2
        c[k]-=2*(c[k]//2)

    if four==0 and two==0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3444
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<complex>
#include<bitset>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, A, B, C, D;

signed main() {
    cin >> N >> A >> B >> C >> D;
    if (A > B)swap(A, B);
    B -= A;
    A = 0;
    rep(k, N) {
        //k回下げる、残りは上げる
        int kl = -k * D;
        int kg = -k * C;
        int bl = B - D * (N - 1 - k);
        int bg = B - C * (N - 1 - k);
        if (kg < bl || bg < kl)continue;
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,y;
	scanf("%d%d",&n,&y);
	y /= 1000;
	for(int i=0; i<=n; i++)if(i*10 <= y)
		for(int j=0; i+j<=n; j++)if(i*10+j*5+(n-i-j)==y){
			printf("%d %d %d\n",i,j,n-i-j);
			return 0;
		}
	puts("-1 -1 -1");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 200006
using namespace std;
int L[M],R[M],tot,sum[M];
vector<int>son[M];
void dfs(int x){
	L[x]=++tot;
	for(int i=0;i<son[x].size();i++){
		int y=son[x][i];
		dfs(y);
	}
	R[x]=tot;
}
int main(){
	int n,m,u,v;
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)scanf("%d%d",&u,&v),son[u].push_back(v);
	dfs(1);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		sum[L[u]]+=v;
		sum[R[u]+1]-=v;
	}
	for(int i=1;i<=n;i++)sum[i]+=sum[i-1];
	for(int i=1;i<=n;i++)printf("%d ",sum[L[i]]);
	return 0;
}

Measured memory_bytes: 25088
#include <bits/stdc++.h>
#define ff(i, x, y) for(int i = x; i <= y; i++)
#define fs(i, x, y) for(int i = x; i >= y; i--)
#define maxn 1;
using namespace std;
typedef long long ll;
ll ans, n, k;
map<int, ll>mp;
int main() {
    scanf("%lld%lld", &n, &k);
    ff(i, 1, n) {
        ll re = i % k;
        mp[re]++;
    }
    ll re;
    ff(i, 0, k - 1) {
        if(i == 0 || i * 2 == k);
        else continue;
        if(!mp.count(i))
            continue;
        re = (k - i) % k;
        if(!mp.count(re))
            continue;
        ans += mp[i] * mp[i] * mp[re];
        //printf("   %d\n", i);
    }
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

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

    vector <int> min_notes(amount + 1, 0);

    for(int i = 1; i <= amount; i++)
    {
        min_notes[i] = 1 + min_notes[i - 1];

        for(int power = 6; power <= i; power *= 6)
            min_notes[i] = min(min_notes[i], 1 + min_notes[i - power]);

        for(int power = 9; power <= i; power *= 9)
            min_notes[i] = min(min_notes[i], 1 + min_notes[i - power]);
    }

    printf("%d\n", min_notes[amount]);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
 
int main(){
 
  char W[3];
  int ans=0;

  for(int i=0 ; i<3; i++){
   cin >> W[i];
 
    if(W[i]=='R')ans++;
  }
  
  if(ans==2 && W[1]=='S') ans=1;
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 3632
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
R = max(D)
MOD = 998244353

cntD = Counter(D)
ans = 1
for i in range(1, R + 1):
    ans *= pow(cntD[i - 1], cntD[i], MOD)
    ans %= MOD

if D[0] == 0 and cntD[0] == 1 and all(cntD[i] >= 1 for i in range(R + 1)):
    print(ans)
else:
    print(0)

Measured memory_bytes: 19936
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, a, b;
  cin >> x >> a >> b;
  if(abs(x-a)>abs(x-b)) cout << "B" << endl;
  else cout << "A" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define _USE_MATH_DEFINES
#include<cmath>
#include<iomanip>

using namespace std;

int main(){

double A,B,C;
cin>>A>>B>>C;
 double ans=sqrt(A*A+B*B-2*A*B*cos(C*M_PI/180.0000)); 

cout<<fixed<<setprecision(10);
cout<<B*(A*sin(C*M_PI/180.0000))/2<<endl;
cout<<ans+A+B<<endl;
cout<<B*sin(C*M_PI/180.0000)<<endl;

    return 0;
}


Measured memory_bytes: 3456