akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
const int maxM = 1e5 + 5;

vector< int> adjList [maxM];
bool visited [maxM] = { false };
int dist [maxM] = { 0 };
// int dist[maxM];
void dfs (int node) 
{
    visited[node] = true;
    for (int i = 0; i < adjList[node].size(); ++i) {
        int n2 = adjList[node][i];
        if (!visited[n2]) {
             dfs(n2);
        }
        dist[node] = max(dist[node], dist[n2] + 1);
                // cout << n2 << " " << node << " " << dist[node] << endl;
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        adjList[a].push_back(b);
    }

    for (int i = 1; i <= n; ++i) {
        if (!visited[i]) {
            dfs(i);
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans = max(ans, dist[i]);
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 12188
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, Ma, Mb, A = 0, B = 0, answer = INT_MAX;
  cin >> N >> Ma >> Mb;
  int a[N], b[N], c[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i] >> c[i];
    A += a[i];
    B += b[i];
  }
  for (int m = 1; m*Ma <= A && m*Mb <= B; m++) {
    vector<vector<vector<long long>>> dp(N+1,vector<vector<long long>>(m*Ma+1,vector<long long>(m*Mb+1,INT_MAX)));
    dp[0][0][0] = 0;
    for (int i = 1; i <= N; i++) {
      for (int j = 0; j <= m*Ma; j++) {
        for (int k = 0; k <= m*Mb; k++) {
          dp[i][j][k] = dp[i-1][j][k];
          if (j-a[i-1] >= 0 && k-b[i-1] >= 0) {
            dp[i][j][k] = min(dp[i][j][k],dp[i-1][j-a[i-1]][k-b[i-1]]+c[i-1]);
          }
        }
      }
    }
    answer = min(answer,dp[N][m*Ma][m*Mb]);
  }
  if (answer == INT_MAX) {
    cout << -1;
  }  else {
    cout << answer;
  }
}

Measured memory_bytes: 19924
t = int(input())
testcase = [list(map(int, input().split())) for _ in range(t)]

dp={}
def f(n, a, b, c, d):
    
#    print(f'n={n} a={a} b={b} c={c} d={d}')
    if n in dp:
        return dp[n]
    
    if n==0:
        dp[n]=10**20
        return dp[n]
    if n==1:
        dp[n]=d
        return dp[n]
#    elif n==2:
#        dp[n]=min(n*d, d+a)
#        return dp[n]
#    elif n==3:
#        dp[n]=min(n*d, d+b, d+a+d)
#        return dp[n]
#    elif n==5:
#        dp[n]=min(n*d, d+a+a+d, d+c, d+b+d+d, d+a+b+d)
    
    l=[d*n]
    if n%2==0:
#        print(f'f({n//2},{a},{b},{c},{d})')
        l.append(f(n//2,a,b,c,d)+a)
        #３の倍数の近い方
        x=(n+1)//3*3
        dx=abs(x-n)
#        print(f'f({x//3},{a},{b},{c},{d}+{b}+{dx}*{d})')
        l.append(f(x//3,a,b,c,d)+b+dx*d)
        #5の倍数の近い方
        x=(n+2)//5*5
        dx=abs(x-n)
        l.append(f(x//5,a,b,c,d)+c+dx*d)
    else:
        l.append(f((n-1)//2, a,b,c,d)+a+d)
        l.append(f((n+1)//2, a,b,c,d)+a+d)
        #３の倍数の近い方
        x=(n+1)//3*3
        dx=abs(x-n)
        l.append(f(x//3,a,b,c,d)+b+dx*d)
        #5の倍数の近い方
        x=(n+2)//5*5
        dx=abs(x-n)
        l.append(f(x//5,a,b,c,d)+c+dx*d)

    dp[n]=min(l)
    return dp[n]

def solve(n,a,b,c,d):
    print(f(n,a,b,c,d))
    
    

for tc in testcase:
    solve(*tc)
    dp.clear()

Measured memory_bytes: 10852
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
#include <stdio.h>
#define int long long
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}

/*ライブラリゾーン！！！！！！！！！！！！！！！*/
int n, x, a[105],ans;
signed main(){
	cin >> n >> x;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		if (a[i] <= x) {
			x -= a[i];
			ans++;
		}
		else {
			cout << ans << endl;
			goto end;
		}
	}
	if (x) {
		cout << ans - 1 << endl;
	}
	else {
		cout << ans << endl;
	}
end:;
	system("PAUSE");
	return 0;
}


Measured memory_bytes: 504
///******* In the name of Allah *******///

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

long int gcd(long int a, long int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void Ok()
{
    long long int a,b,c,d[1013],e,f,g,h,t,i,j = 0,k,l1,l2,m,n,x,y,sum,ans_1,ans_2,ans_3,cnt,Max,Min,flag,div,rcv,temp;
    long double aa,bb,cc,dd,ee,ff,gg;
    char aaa[100013],bbb[1013],ccc[1013],alpbt;

    cin>>a>>b;
    cin>>aaa;
    aaa[b-1] += 32;
    cout<<aaa<<endl;

    return;
}

int main()
{
    Ok();

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int K, S;
  cin >> K >> S;
  int count = 0;
  for(int i = 0; i <= K; i++) {
    for(int j = 0; j <= K; j++) {
      if(S - (i + j) <= K && S - (i + j) >= 0) {
        ++count;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
a, b = gets.chomp.split.map(&:to_i)

# A, B, C = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

if (a < b)
  print b.times.map { a.to_s }.join + "\n"
else
  print a.times.map { b.to_s }.join + "\n"
end

Measured memory_bytes: 1916
#include <stdio.h>


#define N 100
#define BLACK 0
#define WHITE 1
#define GRAY 2

int adj[N][N],n,time,f[N],color[N],d[N];

void dfs(void){

  int i;

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

    color[i]=WHITE;
  }

    time =0;

  for(i=0;i<n;i++){
    if (color[i]==WHITE) visit(i);
  }

  for(i=0;i<n;i++){
      printf("%d %d %d\n",i+1,d[i],f[i]);
    }
}


visit(int u){

  int v;

  color[u]=GRAY;
  d[u]=++time;

  for(v=0;v<n;v++){
    if(adj[u][v]==0) continue;
  if(color[v]==WHITE) visit(v);
  }
  color[u]=BLACK;
  f[u]=++time;

}

int main(){

  int i,j,b,c,a;

    scanf("%d",&n);

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

	adj[i][j]=0;
      }
    }

    for(i=0;i<n;i++){
      scanf("%d%d",&b,&c);
      for(j=0;j<c;j++){

      scanf("%d",&a);
      adj[b-1][a-1]=1;


    }
    }

    dfs();

    return 0;
  }

Measured memory_bytes: 636
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string str;
	cin >> str;
	if (str[0] != 'A') puts("WA"), exit(0);
	if (count(str.begin(), str.end(), 'C') != 1) puts("WA"), exit(0);
	int posc = str.find('C') + 1;
	int n = str.length();
	if (posc < 3 || posc == n) puts("WA"), exit(0);
	int cnt = 0;
	for (auto& c : str) if (isupper(c)) cnt++;
	if (cnt > 2) puts("WA");
	else puts("AC");
	return 0;
}


Measured memory_bytes: 256
package main

import (
   "fmt"
)

func solution(n int) int {
   memo := make([]int, n+1)

   for i := 1; i <= n; i++ {
        for j := 1; i*j <= n; j++ {
                memo[i*j]++
        }
   }

   out := 0
   for i := 1; i <= n; i++ {
        out += i * memo[i]
   }
   return out
}

func main() {
   var n int
   fmt.Scan(&n)
   fmt.Println(solution(n))
}

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

int main(){
    int n, x, i, j;
    cin >> n >> x;
    int l[n];
    for(i = 0; i < n; i++){
        cin >> l[i];
    }
    int d = 0, c = 1;
    for(i = 0; i < n; i++){
        d = d + l[i];
        if(d <= x) c++;
    }
    cout << c << endl;
}

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

using namespace std;

const int maxn = 310;
const ll oo = 1e18;

int n,a[maxn],s,t,trace[maxn],g[maxn][maxn];
ll f[maxn][maxn],c[maxn][maxn],maxFlow;
ll ans=0;

void add(int x,int y,ll vl) {
   // cout<<x<<" "<<y<<" "<<vl<<endl;
    f[x][y] = 0; f[y][x] = 0;
    c[x][y] = vl; c[y][x] = 0;
    g[x][y] = 1; g[y][x] = 1;
}

bool finpath(int s,int t) {
    for (int i=0;i<=n+1;i++) trace[i]=-1;
    queue<int> que;
    que.push(s);
    while (!que.empty()) {
        int u = que.front(); que.pop();
      //  cout<<u<<endl;
        for (int v=0;v<=n+1;v++)
            if ((g[u][v]==1) && (trace[v]==-1) && (f[u][v] < c[u][v])) {
                trace[v] = u;
             //   cout<<v<<" trace: "<<trace[v]<<" ";
                que.push(v);
                if (v==t) return true;
            }
       // cout<<endl;
    }
    return false;
}

void incFlow(int s,int t) {
    int v = t;
    ll x = oo;
    while (v!=s) {
        int u = trace[v];
        x = min(x,c[u][v] - f[u][v]);
        v = u;
    }
    maxFlow += x;
    v = t;
    while (v!=s) {
        int u = trace[v];
        f[u][v] += x;
        f[v][u] -= x;
        v = u;
    }

}

int main() {
   // freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    s=0; t=n+1;
  //  cout<<n<<" "<<s<<" "<<t<<endl;
    for (int i=1;i<=n;i++) {
        cin>>a[i];
        if (a[i]<=0) add(s,i,-a[i]);
        else {
            ans+=a[i];
            add(i,t,a[i]);
        }
    }
    for (int i=1;i<=n;i++)
        for (int j=i+i;j<=n;j+=i)
           add(i,j,oo);
   // cout<<f[1][7]<<" "<<c[1][7]<<endl;
    while (finpath(s,t)) incFlow(s,t);
    cout<<ans - maxFlow<<endl;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <cmath>
using namespace  std;

void fnPrimeNumber(const vector<int>& cnrvnNum, int& rnPrmCnt)
{
  for (int i = 0; i < cnrvnNum.size(); i++)
  {
    bool bPrmNo = true;
    if (cnrvnNum[i] > 2  &&  cnrvnNum[i] % 2 == 0)
      bPrmNo = false;
    else
    {
      double dSqrt = sqrt((double)cnrvnNum[i]);
      int iMaxDiv = (int)dSqrt;

      for (int nDiv = 2; nDiv <= iMaxDiv; nDiv++)
      {
        if (cnrvnNum[i] % nDiv == 0)
        {
          bPrmNo = false;
          break;
        }
      }
      if (bPrmNo) rnPrmCnt++;
    }
  }
}

int main()
{
  vector<int> vnNum;
  int nMaxSiz;
  int nPrmCnt = 0;
  
  cin >> nMaxSiz;
  for (int i = 0; i < nMaxSiz; i++)
  {
    int nNum;
    cin >> nNum;
    vnNum.push_back(nNum);
  }

  fnPrimeNumber(vnNum, nPrmCnt);
  cout << nPrmCnt << endl;

  return 0;
}

Measured memory_bytes: 3144
#include <iostream>
//#include <string>
//#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <stack>
#define mp make_pair
//#define P make_pair
#define MIN(a,b) (a>b?b:a)
//#define MAX(a,b) (a>b?a:b)
typedef long long ll;
typedef unsigned long long ull;
const int MAX=2e5+5;
const int INF=1e8+5;
using namespace std;
//const int MOD=1e9+7;
typedef pair<ll,int> pii;
const double eps=0.00000001;
int n,m;
queue<int> que[305];
int tem;
bool vi[305];
int num[305];
int cnt,an,who;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            scanf("%d",&tem);
            que[i].push(tem);
        }
    }
    for(int i=1;i<=m;i++)
    {
        memset(num,0,sizeof(num));
        cnt=0;
        who=que[1].front();
        for(int j=1;j<=n;j++)
        {
            int pre=que[j].front();
            while(vi[pre])
            {
                que[j].pop();
                pre=que[j].front();
            }
            ++num[pre];
            if(num[pre]>cnt)
            {
                 cnt=num[pre];
                 who=pre;
            }
        }
        vi[who]=true;
        if(i!=1)
            an=min(an,cnt);
        else
            an=cnt;
    }
    printf("%d\n",an);
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
///1<<3シフト演算子 とは　0001の1を三つずらして1000にする, これは8を表しておりつまりbitは0から7まで
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;

//条件式 ? 真の場合の文 : 偽の場合の文
//string S  S,at(i),S += T,S += c,S.size(),S.substr(l)l文字目から最後まで,
///S.substr(l, r)l文字目からl+r-1文字目 n文字目から0個で空列を返せる
//*min_element(all(x)) *max_element(all(x))
//vi x; x.back(),x.front(),x.push_back(),x.pop_back()
//gcd(a, b)最大公約数
//sort(all(x)),reverse(all(x)),sort(x.begin()+l,a.begin()+r)lからrまで
//stack<int> a; a.push(x),a.pop(),a.top(),a.empty()bool
//queue<int> b; b.push(x),b.pop(),b.front(),b.empty()bool,b.size() 要素が小さい順
//priority_queue<int, vector<int>, greater<int>> c,c.top()
//map<int, int> M1; 変数[key] = value; 変数.erase(key); 変数.at(key); 変数.count(key)所属判定　変数.size()
//find(all(x), key)boolソート済みのベクトル
//*lower_bound(all(x),k)以上の最小の要素,*uppper_bound(all(x),k)より大きい最小の要素
//char('0'+cnt) 数字cntからcharへの変換
//int(char-'0') charからintへの変換
//binary_search(all(p),x) bool型

int main(){

    string s;
    cin >> s;
    int len;
    for(int i = 2; i <= s.size()-2; i += 2){
        len = s.size() - i;
        bool ok = true;
        rep(j,len/2){
            if(s.at(j) != s.at(j + len/2)) ok = false;
        }
        if(ok) break;
    }
    cout << len << endl;
 
}

Measured memory_bytes: 256
import itertools


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

a.sort()
cnt = 0
for v in itertools.combinations(a, 3):
    x, y, z = v[0], v[1], v[2]
    if x + y > z and x != y and y != z and z != x:
        cnt += 1

print(cnt)

Measured memory_bytes: 9184
n = int(input())
R = [int(input()) for _ in range(n)]
ans = R[1] - R[0]
bottom = min(R[0], R[1])
for i in range(2, n):
    ans = max(ans, R[i] - bottom)
    if R[i] < bottom:
        bottom = R[i]
print(ans)

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

#ifdef DEBUG
#define debug(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
// ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//
int main() {
    int N,K;cin>>N>>K;
    int m=1+(K-1)*2;
    cout << (N>=m ? "YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int s[n+1];
    int sum=0;
    for(int i=1;i<=n;i++)
            {
                cin>>s[i];
                sum+=s[i];
            }
    if(sum%10)
    {
        cout<<sum;
    }
    else
    {
        sort(s+1,s+n+1);
        for(int i=1;i<=n;i++)
        {
            if(s[i]%10)
            {
                cout<<sum-s[i];
                return 0;
            }
        }
        cout<<0;
        return 0;
    }

} 



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(b + w < a) {
            System.out.println(a - (b + w));
        } else if(a + w < b) {
            System.out.println(b - (a + w));
        } else {
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 21716
# 2019-11-17 20:44:23(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    n, *h = [int(x) for x in sys.stdin.read().split()]
    
    step = 0
    prev_height = 0
    max_step = 0
    for i in range(n):
        if h[i] <= prev_height:
            step += 1
        else:
            max_step = max(max_step, step)
            step = 0
        prev_height = h[i]
    max_step = max(max_step, step)
    print(max_step)

if __name__ == "__main__":
    main()


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

#define ll long long
#define endl "\n"

int main(){
	ios_base::sync_with_stdio(false);

	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll ans=0;
	ll r=0;
	for(char c:s){
		if(c=='R') r++;
	}
	for(ll i=r;i<n;i++){
		if(s[i]=='R') ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3788
import java.util.Scanner;
 
public class Main {
 
    public static final int UP = 0;
    public static final int RIGHT = 1;
    public static final int INF = Integer.MAX_VALUE;
 
    public static void main(String[] args) {
        doIt();
    }
 
    public static void doIt(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
 
        for(int i = 0; i < n; i++){
            int gx = sc.nextInt();
            int gy = sc.nextInt();
            int p = sc.nextInt();
            boolean[][][] isM = new boolean[gx + 1][gy + 1][2];
           
            for(int j = 0; j < p; j++){
                int[][] point = new int[2][2];
                point[0][0] = sc.nextInt();
                point[0][1] = sc.nextInt();
                point[1][0] = sc.nextInt();
                point[1][1] = sc.nextInt();
                int from = 0,to = 0;
                if(point[0][0] < point[1][0] || point[0][1] < point[1][1]){
                    to = 1;
                }
                else{
                    from = 1;
                }
                isM[point[from][0]][point[from][1]][point[from][0] < point[to][0]? RIGHT : UP] = true;
            }
            int[][] dp = new int[gx + 1][gy + 1];
            dp[0][0] = 1;
          
            for(int j = 1; j < gy + 1; j++){
                
                if(isM[0][j - 1][UP] == false){
                    dp[0][j] = dp[0][j - 1];
                }
                else{
                    dp[0][j] = INF;
                }
            }
            for(int j = 1; j < gx + 1; j++){
                for(int k = 0; k < gy + 1; k++){
                    boolean bOK = false;
                  
                    if(0 <= j - 1 && isM[j - 1][k][RIGHT] == false && dp[j - 1][k] < INF){
                        dp[j][k] += dp[j - 1][k];
                        bOK = true;
                    }
                   
                    if(0 <= k - 1 && isM[j][k - 1][UP] == false && dp[j][k - 1] < INF){
                        dp[j][k] += dp[j][k - 1];
                        bOK = true;
                    }
                    if(bOK == false){
                        dp[j][k] = INF;
                    }
                }
            }
            //print(dp);
            if(dp[gx][gy] == INF){
                System.out.println("Miserable Hokusai!");
            }
            else{
                System.out.println(dp[gx][gy]);
            }
        }
    }
 
    public static void print(int[][] a){
        for(int[] n : a){
            for(int l : n){
                System.out.print(l + " ");
            }
            System.out.println();
        }
    }
 
}

Measured memory_bytes: 26136
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n;
	while (cin >> n && n){
		string s[1001];
		for (int i = 0; i < n; i++)
			cin >> s[i];

		for (int i = 0; i < n; i++){
			for (int j = 0; j < s[i].size() - 1; j++){
				if (s[i][j] == '.' && s[i][j + 1] != '.'){
					s[i][j] = '+'; break;
				}
			}
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < s[i].size(); j++){
				if (s[i][j] >= 'a' && s[i][j] <= 'z'){

					int t = -1;
					for (int k = i + 1; k < n; k++){
						if (j >= s[k].size())break;
						if (s[k][j] == '+'){
							t = k;
						}
						else
						if (s[k][j] == '.'){
							s[k][j] = ' ';
						}
						else break;
					}
					for (int k = t; k > i; k--){
						if (s[k][j] == ' ')
							s[k][j] = '|';
					}
					break;
				}
			}
		}
		for (int i = 0; i < n; i++){
			cout << s[i] << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 1988
def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))
    return dfs(i + 1, f + a[i + 1]) + dfs(i + 1, f + "+" + a[i + 1])


a = input()
n = len(a)

print(dfs(0, a[0]))

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
int R;
int main () {
cin >> R;
if (R<=1199){
	cout << "ABC"<< endl;
}else if (R>1199 && R<=2799){
cout << "ARC" << endl;
}else if (R>2799){
	cout << "AGC" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >>  D ;
  if (A+B>C+D){
    cout<< "Left" << endl;
  } else if(A+B == C+D){
    cout << "Balanced" << endl;
  } else{
    cout << "Right" << endl ;
  }
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main() {
  int N, p[100000], ans{};
  cin >> N;
  cin >> p[0];
  for (int i = 1; i != N; ++i) {
    cin >> p[i];
    if (p[i-1] == i) {
      swap(p[i-1],p[i]);
      ++ans;
    }
  }
  if (p[N-1] == N) ++ans;
  cout << ans << endl;
}


Measured memory_bytes: 3968
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
typedef long long int ll;
ll n, x;
ll first, second;
ll ans;
ll a[100005];


int main()
{

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

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


    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define DBG2(a) rep(_X,a.size()){rep(_Y,a[_X].size())printf("%d ",a[_X][_Y]);puts("");}
int dx[]={ 0, 0, 1, 1,-1,-1, 2,-2,-2, 2,-2, 2};
int dy[]={ 2,-2, 2,-2, 2,-2, 0, 0, 1, 1,-1,-1};

int sx[]={ 0, 1,-1, 0, 0, 1, 1,-1,-1};
int sy[]={ 0, 0, 0, 1,-1, 1,-1, 1,-1};

class NODE{
 public:
  int x;
  int y;
  int pos;
};
bool check(int x,int y){
	return (x>=0 && x<10 && y>=0 && y<10);
}

int main(){
	int x,y,n,a,b;
	NODE q,qt;
	vector<int> t;
	while(cin >> x >> y && x || y){
		bool flag = false;
		vector<int> all[10][10];
		cin >> n;
		rep(i,n){
			cin >> a >> b;
			rep(j,9){
				if(check(a+sx[j],b+sy[j]))
					all[a+sx[j]][b+sy[j]].push_back(i+1);
			}
		}
		queue<NODE> Q;
		q.x=x;q.y=y;
		q.pos=0;
		Q.push(q);
		while(Q.size()){
			q = Q.front();Q.pop();
			if(q.pos == n){
				if(n)flag = true;
			}
			rep(i,12){
				if(check(q.x+dx[i],q.y+dy[i])){
					t = all[q.x+dx[i]][q.y+dy[i]];
					if(count(t.begin(),t.end(),q.pos+1)){
						qt.x = q.x+dx[i];
						qt.y = q.y+dy[i];
						qt.pos = q.pos+1;
						Q.push(qt);
					}
				}
			}
		}
		cout << (flag?"OK":"NA") << endl;
	}
} 

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

vector<int> g[100005];

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

  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }

  vector<bool> visited(n,false);
  auto bfs = [&](int from){
    queue<int> q;
    q.push(from);
    visited[from] = true;
    int ret = 0;
    while(!q.empty()){
      int v = q.front(); q.pop();
      ret++;
      for(auto to : g[v]) if(!visited[to]){
        q.push(to);
        visited[to] = true;
      }
    }
    return ret;
  };

  long s0 = bfs(0);
  long s1 = bfs(1);
  long sx = n - s0 - s1;
// dbg(s0,s1,sx);
  long c0 = s0+sx;
  long c1 = s1+sx;

  cout << max<long>(c0*(c0-1)/2 + s1*(s1-1)/2, c1*(c1-1)/2 + s0*(s0-1)/2) - m << endl;

  return 0;
}


Measured memory_bytes: 5888
#include <cstdio>
#include <vector>
#define MAX 10001
#define LEN 2000000
typedef long long ll;

using namespace std;

int c[MAX] = {0};
int a[LEN], b[LEN];

int main() {


    ll n;
    scanf("%lld", &n);
    for (ll i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++) {
        c[a[i]]++;
    }
    for (int i = 1; i < MAX; i++) {
        c[i] += c[i-1];
    }

    for (long long  i = n-1; i >= 0; i--) {
        b[c[a[i]] - 1] = a[i];
        c[a[i]]--;
    }

    for (int i = 0; i < n; i++) {
        if (i) printf(" ");
        printf("%d", b[i]);
    }
    printf("\n");
}




Measured memory_bytes: 18364
#include <iostream>

using namespace std;

typedef long long ll;

const int MOD = 998244353; // change if needed

struct Modint {
  ll val;
  
  Modint (ll _val = 0)
    : val(_val % MOD) {}

  Modint operator+ (Modint other) const {
    return Modint(val + other.val);
  }

  void operator+= (Modint other) {
    val += other.val;
    val %= MOD;
  }

  Modint operator- () const {
    return Modint(MOD - val);
  }

  Modint operator- (Modint other) const {
    return Modint(val + MOD - other.val);
  }

  void operator-= (Modint other) {
    val += MOD - other.val;
    val %= MOD;
  }

  Modint operator* (Modint other) const {
    return Modint(val * other.val);
  }

  void operator*= (Modint other) {
    val *= other.val;
    val %= MOD;
  }

  bool operator== (Modint other) const {
    return val == other.val;
  }

  bool operator!= (Modint other) const {
    return val != other.val;
  }
};

Modint exp (Modint a, int k) {
  if (k == 0) {
    return Modint(1);
  } else if (k % 2 == 0) {
    Modint half = exp(a, k / 2);
    return half * half;
  } else {
    return a * exp(a, k - 1);
  }
}

Modint inv (Modint a) {
  return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
  out << p.val;
  return out;
}

const int MAX_N = 3e3 + 5;

Modint dp [MAX_N][MAX_N];
Modint cdp [MAX_N][MAX_N];

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

  dp[a][b] = Modint(1);
  cdp[a][b] = Modint(1);
  for (int i = a; i <= c; i++) {
    for (int j = b; j <= d; j++) {
      if (i > a && j > b) {
        dp[i][j] = Modint(j) * dp[i - 1][j] + cdp[i][j - 1];
      } else if (i > a) {
        dp[i][j] = Modint(j) * dp[i - 1][j];
      } else if (j > b) {
        dp[i][j] = Modint(i) * dp[i][j - 1];
      }
      cdp[i][j] = Modint(i) * cdp[i][j - 1] + dp[i][j] - cdp[i][j - 1];
    }
  }

  /*
  for (int i = 1; i <= c; i++) {
    for (int j = 1; j <= d; j++) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  cout << dp[c][d] << endl;
}


Measured memory_bytes: 143924
#include<stdio.h>

int main(){
 long long dp[31]={0,1,2,4};
 int i,n;

 for(i=4;i<=30;i++){
  dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
 }

 while(scanf("%d",&n),n){
  printf("%d\n",dp[n]/3650 + ((dp[n]%3650)!=0));
 }
 return 0;
}

Measured memory_bytes: 600
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

    S=0
    min_number=10**9
    minus_count=0
    for i in range(N):
        if A[i]<0:
            minus_count+=1
        a=abs(A[i])
        S+=a
        min_number=min(min_number,a)

    S=S if minus_count%2==0 else S-2*min_number
    print(S)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 14332
# coding: utf-8

import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

N = int(input())
S = input()
# N, M = map(int, input().split())
# 横
# L = [int(x) for x in input().split()]
# 縦
# AS = [int(input()) for _ in range(N)]
# 多次元
# L = [[int(x) for x in input().split()] for _ in range(N)]

print(S if N >= 3200 else "red")



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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int P = 1000000007;

int n;

int qpow(int a, int b) {
	int s = 1;
	for (; b; b >>= 1) {
		if (b & 1) {
			s = 1ll * s * a % P;
		}
		a = 1ll * a * a % P;
	}
	return s;
}

int main() {
	read(n);
	int ans = (qpow(10, n) - 2 * qpow(9, n) + qpow(8, n)) % P;
	print((ans + P) % P);
}

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

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w,m; cin >> h >> w >> m;
  int br[300000];
  int bc[300000];
  int cntr[300000] = {};
  int cntc[300000] = {};
  int maxr=0,maxc=0;
  for(int i = 0; i < m; ++i){
    cin >> br[i] >> bc[i];br[i]--;bc[i]--;
    ChangeMax(maxr,++cntr[br[i]]);
    ChangeMax(maxc,++cntc[bc[i]]);    
  }
  bitset<300000>r,c;
  int cr=0,cc=0,cntd=0;
  for(int i = max(w,h)-1; i >= 0; --i){
    cr+=r[i] = maxr == cntr[i];
    cc+=c[i] = maxc == cntc[i];
  }
  cntd = cr*cc;
  for(int i = 0; i < m; ++i)
    cntd -= c[bc[i]]&r[br[i]];
  cout << maxr + maxc - (!cntd) << '\n';
}


Measured memory_bytes: 8392
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::vec::Vec;
use std::{vec, cmp, num};


struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

// create Vec<char> from String
#[allow(dead_code)]
fn to_chars(s: String) -> vec::Vec<char> {
    let mut cs = s.chars();
    let mut res = vec::Vec::new();
    while let Some(c) = cs.next() {
        res.push(c);
    }
    res
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let mut x: String = sc.read();
    let mut y: String = sc.read();
    let f = "ABCDEF";
    let x = x.pop().expect("");
    let y = y.pop().expect("");
    if f.find(x) < f.find(y) {
        println!("<");
    } else if f.find(x) == f.find(y) {
        println!("=");
    } else {
        println!(">");
    }
}

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

int main(void) {
  string s;
  int rb = 0, rw = 0, i = 0;
  cin >> s;
  int n = s.length();
  vector<int> t(n);
  for(; i < n; i++) {
    if(i % 2 == 0) t[i] = 0;
    else t[i] = 1;
  }
  for(i = 0; i < n; i++) {
    if(s[i] - '0' == t[i]) rb++;
    else rw++;
  }
  printf("%d\n", rb < rw ? rb : rw);
  return 0;
}

Measured memory_bytes: 896
def D():
    n = int(input())
    t = [list(map(int, input().split()))[::-1] for _ in range(n)]
    t = sorted(t)
    time, result = 0, "Yes"
    for b, a in t:
        time += a
        if b < time:
            result = "No"
            break
    print(result)        
D()


Measured memory_bytes: 37992
#include<iostream>
using namespace std;
#define MAX 2000000

int H,A[MAX+1];

void maxHeapify(int i){
  int l,r,largest;
  l = 2*i;
  r = 2*i+1;

  if(l<=H && A[l] > A[i]) largest=l;
  else largest = i;
  if(r<=H && A[r] > A[largest]) largest=r;

  if(largest != i){
    swap(A[i],A[largest]);
    maxHeapify(largest);
  }
}

int main(){
  cin >> H;
  for(int i=1;i<=H;i++) cin >> A[i];

  for(int i=H/2;i>=1;i--) maxHeapify(i);

  for(int i=1;i<=H;i++){
    cout << " " << A[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 4952
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  int a, b, c;
  readf("%s %s %s\n", &a, &b, &c);
  
  int cnt;
  while (true) {
    if (a % 2 || b % 2 || c % 2) {
      cnt.writeln;
      break;
    }
    if (a == b && b == c) {
      writeln(-1);
      break;
    }
    auto ta = a / 2;
    auto tb = b / 2;
    auto tc = c / 2;
    a = tb + tc;
    b = ta + tc;
    c = ta + tb;
    cnt++;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    double ans = 0.0;
    for(ll i=1;i<=n;i++){
        double a = i;
        double den = 1.0;
        while(a < k){
            den *= 0.5;
            a *= 2.0;
        }
        ans += den;
    }
    printf("%.12f\n", ans/n);
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>


using namespace std;



int main() {
	int n;
	double x[11];
	string u[11];
	double total = 0.0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> x[i] >> u[i];
	}

	for (int i = 0; i < n; i++) {
		if (u[i] == "BTC") {
			total += x[i] * 380000.0;
		}
		else
		{
			total += x[i];
		}
	}

	cout << total;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll k,n;cin>>k>>n;
    vector<ll> a(n);rep(i,n)cin>>a[i];
    ll ans = 0;
    rep(i,n){
        ll l = (i+n-1)%n;
        ll d1 = (a[i]-a[l]+k)%k;
        ll r = (i+1)%n;
        ll d2 = (a[r]-a[i]+k)%k;
        ll d = max(d1,d2);
        ans = max(ans,d);
    }

    cout<<k-ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 998244353;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}};

vector<ll> V, C;


ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}

	else {

		return gcd(b, a % b);
	}

}


vector<ll> A;

int main() {
	ll N;

	cin >> N;
	A.resize(N);
	ll sum = 0;
	ll ans = 0;
	rep(i, N) {
		cin >> A[i];
		

		if (A[i] < 0) {
			sum += 1;
			A[i] = -A[i];
			ans += A[i];
		}
		else
			ans += A[i];
	}

	sort(A.begin(), A.end());


	if (sum % 2 == 0) {
		cout << ans << endl;

	}

	else {

		cout << ans - 2 * A[0] << endl;
	}



	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env -S JULIA_VERSION=0.5.0 julia
# contest: abc155, problem: abc155_a, alphabet: A
const YES = "Yes"
macro Y() :( println(YES); return ) end
const NO = "No"
macro N() :( println(NO); return ) end

function solve(A::Int, B::Int, C::Int)
  if length(unique([A, B, C]))==2
    @Y
  else
    @N
  end
end

function main()
  tokens = Channel{String}(32)
  Task() do
    for line in eachline(@static VERSION < v"0.6" ? STDIN : stdin)
      startswith(line, '\0') && break
      for token in split(chomp(line))
        put!(tokens, token)
      end
    end
    close(tokens)
  end |> schedule
  A = parse(Int, take!(tokens))
  B = parse(Int, take!(tokens))
  C = parse(Int, take!(tokens))
  solve(A, B, C)
end

if isempty(get(ENV, "ATCODER_LOCAL", ""))
  isempty(ARGS) && main()
else
  @eval begin
    const samples = [("5 7 5", "Yes"), ("4 4 4", "No"), ("4 9 6", "No"), ("3 3 4", "Yes")]
    function test(sampleids...)
      isempty(sampleids) && return test(collect(1:length(samples))...)
      ostdin, ostdout = @static VERSION < v"0.6" ? (STDIN, STDOUT) : (stdin, stdout)
      rd, wr = first(redirect_stdout()), last(redirect_stdin())
      try
        map(sampleids) do sampleid
          input, output = samples[sampleid]
          print(ostdout, "Testing sample #$(sampleid)..."); flush(ostdout)
          println(wr, input)
          println(wr, "\0")
          t = @elapsed main()
          println()
          result = strip(String(readavailable(rd)))
          if result == output
            println(ostdout, "OK ($t sec).")
            true
          else
            println(ostdout, "ERROR ($t sec)")
            println(ostdout, "== expected ==\n$output")
            println(ostdout, "== actual ==\n$result\n")
            false
          end
        end |> all
      finally
        redirect_stdin(ostdin)
        redirect_stdout(ostdout)
      end
    end
    submit() = test() && (prog = @__FILE__; run(`atcoder-submit $prog`))
    !isinteractive() && submit()
  end
end


Measured memory_bytes: 116396
use std::cmp::min;

struct RMQSegmentTree<T> {
    n: usize,
    dat: Vec<T>,
}

impl RMQSegmentTree<i32> {
    // 要素数nの配列に対し、セグメント木を構築する。
    pub fn new(n: usize) -> RMQSegmentTree<i32> {
        let mut n_ = 1;
        while n_ < n {
            n_ *= 2;
        }
        let n = n_;
        let dat = vec![i32::max_value(); 2 * n - 1];

        RMQSegmentTree {
            n,
            dat
        }
    }

    /// k番目の値をaに変更する
    pub fn update(&mut self, k: usize, a: i32) {
        let mut k = k + self.n - 1;
        self.dat[k] = a;

        while k > 0 {
            // k > 0 => k - 1 >= 0
            // k points index of parent
            k = (k - 1) / 2;

            self.dat[k] = min(self.dat[2 * k + 1].clone(), self.dat[2 * k + 2].clone());
        }
    }

    // 区間[a, b)の最小値を求める
    pub fn query(&self, a: usize, b: usize) -> Option<i32> {
        self._query(a, b, 0, 0, self.n)
    }

    fn _query(&self, a: usize, b: usize, k: usize, l:usize, r: usize) -> Option<i32> {
        // [a, b) と[l, r)が交差しなければ None
        if r <= a || b <= l {
            None
        } // [a, b)が[l, r)を内包するとき 
        else if a <= l && r <= b {
            Some(self.dat[k].clone())
        } else {
            let vl = self._query(a, b, k * 2 + 1, l, (l + r) / 2);
            let vr = self._query(a, b, k * 2 + 2, (l + r) / 2, r);

            match vl {
                Some(min_vl) => {
                    match vr {
                        Some(min_vr) => Some(min(min_vl, min_vr)),
                        None => Some(min_vl),
                    }
                },
                None => {
                    // match vr { Some(min_vr) => Some(min_vr), None => None,}
                    vr
                },
            }
        }
    }
}


fn main() {
    let (n, q) = read_tuple();
    let mut seq = RMQSegmentTree::new(n);

    for _ in 0..q {
        let (com, x, y) = {
            let temp = read_vec();
            (temp[0], temp[1], temp[2])
        };
        if com == 0 {
            seq.update(x, y as i32);
        } else {
            println!("{:?}", seq.query(x, y + 1).or(Some(i32::max_value())).unwrap());
        }
    }
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 5052
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define rrep(i,a) for(int i=int(a)-1; i>=0;--i)
using ll = long long;
using namespace std;
int main(){
    int h,w,k;
    cin>>h>>w>>k;
    vector<string> s(h);
    rep(i,h) cin>>s[i];
    
    //いちごの識別番号
    int cnt=0;
    vector<vector<int>> ans(h,vector<int>(w));
    rep(i,h){
        bool find = false;
        rep(j,w){
            if(s[i][j]=='#'){
                find=true;
                cnt++;
            }
            if(find){
                ans[i][j]=cnt;
            }else{
                ans[i][j]=0;
            }
        }
    }
    rep(i,h){
        bool find = false;
        for(int j=w-2; j>=0; j--){
            if(ans[i][j]==0){
                ans[i][j]=ans[i][j+1];
            }
        }
    } 

    rep(i,h){
        if(i==0) continue;
        rep(j,w){
            if(ans[i][j]==0){
                ans[i][j]=ans[i-1][j];
            }
        }
    }
    for(int i=h-2; i>=0 ; i--){
        rep(j,w){
            if(ans[i][j]==0){
                ans[i][j]=ans[i+1][j];
            }
        }
    }

    rep(i,h){
        rep(j,w){
            cout<<ans[i][j]<<" ";
        }
        cout<<endl;
    }

    
}

Measured memory_bytes: 1280