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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    vector<ll> l(n), r(n);
    for (int i = 0; i < n; i++)
        cin >> l[i] >> r[i];
    sort(l.rbegin(), l.rend());
    sort(r.begin(), r.end());

    ll ret = 0, sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += l[i];
        ret = max(ret, sum);
        sum -= r[i];
        ret = max(ret, sum);
    }
    sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum -= r[i];
        ret = max(ret, sum);
        sum += l[i];
        ret = max(ret, sum);
    }
    cout << ret * 2 << endl;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

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

  if(m == 1){
    if(k == 0)
      cout << 1 << " " << 1 << " " << 0 << " " << 0 << endl;
    else
      cout << -1 << endl;
    return 0;
  }

  if(k >= (1 << m)){
    cout << -1 << endl;
    return 0;
  }

  vector<int> ans(1 << (m + 1), -1);
  ans[(1 << m) - 1] = ans[(1 << (m + 1)) - 1] = k;

  for(int i=0, x=0; x < (1 << m); x++){
    if(x == k) continue;
    else{
      ans[i] = ans[(1 << (m + 1)) - 2 - i] = x;
      i++;
    }
  }

  REP(i, 1 << (m + 1)) cout << ans[i] << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 2816
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

void test_case(){
	int n;
	cin >> n;
	if(n%1000 == 0) cout << 0 << endl;
	else {
		cout << 1000 - n%1000  << endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	int t=1;
	// cin >> t;

	while(t--) test_case();
	
	return 0;
}


Measured memory_bytes: 3644
S = list(input())
T = list(input())
L = len(T)
ans = L
for i in range(len(S)-L+1):
    check = 0
    for j in range(L):
        if(S[i+j] != T[j]):
            check += 1
    if(ans > check):
        ans = check
print(ans)


Measured memory_bytes: 9048
#include<iostream>
#include<algorithm>
 
using namespace std;
typedef long long Int;
#define INF (1LL<<60)

Int N;
Int res[900];


Int solve(int x){
	res[x] = res[x-1] + res[x-2];
	x+=1;
	if (x-1==N) return res[x-1];
    else return solve(x);
}

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

	cin >> N;
	res[0]=2;
	res[1]=1;
	for (Int i=2;i<=N;i++)res[i]=res[i-1]+res[i-2];
	cout<<res[N]<<endl;
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define per(i,n) for (int i = (n)-1; i >=0; --i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    rep(i,h){
        cin>>s[i];
    }
    rep(i,h){
        cout<<s[i]<<endl;
        cout<<s[i]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
// AOJ 0539: Pizza
// 2017.9.1 bal4u@uu
// 2018.1.2

#include <stdio.h>
#include <stdlib.h>

//#define getchar_unlocked()  getchar()
#define MIN(a,b) ((a)<=(b)?(a):(b))

int N;
int d[100002];

int cmp(int *a, int *b) { return *a - *b; }

int in()
{
	int n, c;

	while ((c = getchar_unlocked()) < '0');
	n = 0;
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int bsrch(int x)
{
	int m, l = 0, r = N;
    while (l < r) {
        m = (l + r) >> 1;
		if (d[m] == x) return 0;
		if (d[m] < x) l = m + 1; else r = m;
    }
	return MIN(x-d[l-1], d[l]-x); 
}

int main()
{
	int D, M, i, ans;

	while (D = in()) {
		N = in(), M = in();

		d[0] = 0; for (i = 1; i < N; i++) d[i] = in();
		qsort(d, N, sizeof(int), cmp);
		d[N] = D;

		ans = 0; while (M--) ans += bsrch(in());
		printf("%d\n", ans);
	}
	return 0;
}



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

int main() {
	//cout << "" << endl; // prints
	string s;
	cin >> s;
	if(s[s.size() - 1] == 's'){
		string a = "es";
		string ans = s + a;
		cout << ans;
		return 0;
	}else{
		string a = "s";
		string ans = s + a;
		cout << ans;
		return 0;
	}

	//cout << s[s.size() - 1];

	return 0;
}

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

long long GCD(long long x, long long y) {
  if (y == 0) return x;
  else return GCD(y, x % y);
}

int main() {
  long long X;
  cin >> X;
  cout << 360 / GCD(X, 360) << endl;
}

Measured memory_bytes: 3612
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        (n,m,x): (usize,usize,usize),
        caas: [(usize, [usize; m]); n]
    };

    let mut cmin = std::usize::MAX;

    'outer: for i in 0..=(2usize.pow(n as u32) - 1) {
        let mut ctotal = 0;
        let mut aatotal = vec![0; m];
        for j in 0..n {
            if (i & (1 << j)) > 0 {
                let (c, aa) = caas[j].clone();
                ctotal += c;
                for k in 0..m {
                    aatotal[k] += aa[k];
                }
            }
        }

        for a in aatotal {
            if a < x {
                continue 'outer;
            }
        }

        if ctotal < cmin {
            cmin = ctotal;
        }
    }

    if cmin == std::usize::MAX {
        println!("-1");
    } else {
        println!("{}", cmin);
    }
}


Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
int findSumofDigits(int n){
  int sum=0;
  while(n>0){
    sum+=n%10;
    n/=10;
    }
    return sum;
  }
int main() {
  int N,A,B;
  cin>>N>>A>>B;
  int total=0;
  for(int i=1;i<=N;i++){
    int sum=findSumofDigits(i);
    if(sum>=A&&sum<=B){
      total+=i;
    }
  }
  cout<<total<<endl;
}


Measured memory_bytes: 508
n,q = gets.chomp.split(' ').map(&:to_i)
s = gets.chomp
arr = Array.new(n,0)
count = 0
for i in 0..(n-2)
  if s[i] == "A" && s[i+1] == "C"
    count += 1
  end
  arr[i+1] = count
end
quiz = []
q.times do
  quiz.push(gets.chomp.split(' ').map(&:to_i))
end
quiz.each do |q|
  puts arr[q[1]-1] - arr[q[0]-1]
end


Measured memory_bytes: 21684
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int x; cin >> x;
  vector<bool> expo(x+1);
  expo[1] = true;
  for (int i=2; i <= x; i++) {
    int v = i*i;
    while(v <= x) {
      expo[v] = 1;
      v *= i;
    }
  }

  for(int i=x; i>=1; i--) {
    if (expo[i]) { COUT(i); return 0; }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 2e6
double pi = acos(-1);
double _cos = cos(2 * pi / MAX_N);
double _sin = sin(2 * pi / MAX_N);
double c = 1;
double s = 0;

void next() {
    double x = c * _cos - s * _sin;
    double y = c * _sin + s * _cos;
    swap(c, x); swap(s, y);
}

int main() {
    int n; cin >> n;
    vector<double> v(n, 0);
    vector<double> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    for (int ni = 0; ni < MAX_N; ni++) {
        int best = 0; double dist = -c*a[0] - s*b[0];
        for (int i = 1; i < n; i++) {
            double d = -c*a[i]-s*b[i];
            if (dist > d) {
                best = i; dist = d;
            }
        }
        v[best]++;
        next();
    }
    for (int i = 0; i < n; i++) {
        printf("%.12f\n", v[i]/MAX_N);
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <algorithm>
#define INF 0x3f3f3f3f
#define SI(a) scanf("%d",&a)
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long ll;
const int mod = 998244353;
const int maxn = 1e5+10;
using namespace std;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
ll quick_pow(ll x,ll n,ll mod){
	ll res = 1;
	while(n > 0){
		if(n & 1)	res = res * x % mod;
		x = x * x % mod;
		n >>= 1;//相当于n=n/2.详情请参考位移运算符。
	}
	return res;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n,n5=0,n7=0;
    for(int i = 0;i < 3;i++)
    {
        cin>>n;
        if(n==5)n5++;
        else if(n==7)n7++;
    }
    if(n5==2&&n7==1)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


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

main() {
  while(1) {
    int q1, b, c1, c2, q2;
    cin >> q1;
    if(q1 == 0) break;
    cin >> b >> c1 >> c2 >> q2;
    int aizu;
    int normal;

    aizu = b / c1;
    if(aizu > q2) aizu = q2;
    bool flag = false;
    while(aizu >= 1) {
      normal = (b - aizu * c1) / c2;
      if(aizu + normal >= q1) {
        flag = true;
        break;
      }
      aizu--;
    }

    if(!flag) cout << "NA" << endl;
    else      cout << aizu << ' ' << normal << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
bool f(int a)
{
    for(int i=2;i*i<=a;i++)if(a%i<1)return 0;
    return 1;
}
main()
{
    int n;
    while(cin>>n)
    {
        int m=n-1;
        while(!f(m))m--;
        cout<<m<<" ";
        n++;
        while(!f(n))n++;
        cout<<n<<endl;
    }
}


Measured memory_bytes: 3060
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long n,a[22][22],dp[(1<<22)];
long long dfs(int x,int y)
{
	if(x==n)
	{
		return 1;
	}
	if(dp[y]!=-1)
	{
		return dp[y];
	}
	dp[y]=0;
	for(int i=0;i<n;i++)
	{
		if((y&(1<<i))==0 && a[x][i])
		{
			dp[y]=(dp[y]+dfs(x+1,y|(1<<i)))%md;
		}
	}
	return dp[y]%md;
}
int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	cout<<dfs(0,0)<<endl;
	return 0;
}

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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		public void Exec()
		{
			string w = Console.ReadLine().ToLower();

			int count = 0;
			while (true) {
				string p = Console.ReadLine();
				if (p == "END_OF_TEXT") {
					break;
				}

				string[] strs = p.ToLower().Split(' ');
				foreach (var item in strs) {
					if (w == item) {
						++count;
					}
				}
			}

			Console.WriteLine($"{count}");
			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 17800
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
op = []
for i in 0...m do
  b, c = gets.split.map(&:to_i)
  op.push([b, c])
end
op.sort! { |e, f|
  -e[1] <=> -f[1]
}
nn = 0
sum = 0
stop = false
for i in 0...m do
  for j in 1..op[i][0] do
    if nn >= n || a[nn] >= op[i][1]
      stop = true
      break
    end
    sum += op[i][1]
    nn += 1
  end
  break if stop
end
for nnn in nn...n do
  sum += a[nnn]
end
puts sum


Measured memory_bytes: 20608
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var nm=arr.shift().split(" ");
   if(nm.join(" ")=="0 0")break;
   var n=nm[0];
   var m=nm[1];
   var M=[];
   for(var i=0;i<m;i++)M.push(arr.shift()-0);
   var N=[];
   for(var i=0;i<n;i++)N.push(arr.shift()-0);
   var dp=[];
   for(var i=0;i<=n;i++){
      dp[i]=[];
      for(var j=0;j<=255;j++){
         dp[i][j]=Infinity;
      }
   }
   dp[0][128]=0;
   for(var i=1;i<=n;i++){
      for(var j=0;j<=255;j++){
         for(var k=0;k<m;k++){
            var jm=j+M[k];
            if(jm<0)jm=0;
            if(jm>255)jm=255;
            if(dp[i-1][j]!=Infinity){
               dp[i][jm]=Math.min(dp[i][jm],dp[i-1][j]+Math.pow(N[i-1]-jm,2));
            }
         }
      }
   }
   var min=Infinity;
   dp[n].forEach(function(v){
      min=Math.min(min,v);
   });
   console.log(min);
}

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

using namespace std;

string s;

int main(){
  cin>>s;
  if(s=="SUN"){
    cout<<7;
  }
  if(s=="MON"){
    cout<<6;
  }
  if(s=="TUE"){
    cout<<5;
  }
  if(s=="WED"){
    cout<<4;
  }
  if(s=="THU"){
    cout<<3;
  }
  if(s=="FRI"){
    cout<<2;
  }
  if(s=="SAT"){
    cout<<1;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadLine().Split(' ').Select(int.Parse).ToList();
            int m = input[0];
            int d = input[1];

            int cnt = 0;
            for (int i = 1; i <= m; i++)
            {
                for (int j = 1; j <= d; j++)
                {
                    int d1 = j % 10;
                    int d10 = j / 10;
                    if (d1 >= 2 && d10 >= 2)
                    {
                        if (i == d1 * d10)
                            cnt++;
                    }
                }
            }
            WriteLine(cnt);
        }
    }
}



Measured memory_bytes: 13268
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String l = null;
		while((l = r.readLine()) != null){
			String[] nums = l.split(" ");
			System.out.printf("%d\n", Integer.parseInt(nums[0]) + Integer.parseInt(nums[1]));
		}
	}
}

Measured memory_bytes: 17992
N,M = map(int,input().split())
L = [0]*N
for i in range(N):
    L[i] = list(map(int,input().split()))
for i in range(N):
    del L[i][0]
L.sort() #第一要素でソート

ans = 0
for i in range(1,M+1):
    cnt = 0
    for j in range(N):
        if i in L[j]:
            cnt += 1
    if cnt == N:
        ans += 1
    
print(ans)

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i;
  vector<int> a(n);
  for(i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  cout << a[n-1]-a[0] << "\n";
  return 0;
}

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

int main() {
    long long n, k; cin >> n >> k;
    vector<long long> w(n), d(n);
    for (int i=0; i<n; ++i) {
        cin >> w[i] >> d[i];
    }
    // f(x) = \sum_i (k-w_i) / d_i + 1
    long long l = 0, r = 2e18;
    while (r - l > 1) {
        long long mid = (l + r) / 2;
        long long cnt = 0;
        for (int i=0; i<n; ++i) if (w[i] <= mid) cnt += (mid-w[i])/d[i] + 1;
        if (cnt < k) l = mid;
        else r = mid;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long[] a1 = new long[n];
        long[] a2 = new long[n];
        for (int i = 0; i < n; i++) {
            long temp = Long.parseLong(sc.next());
            a1[i] = temp;
            a2[i] = temp;
        }
        long ans1 = 0;
        long ans2 = 0;
        long temp = 0;
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0 && temp + a1[i] >= 0) {
                ans1 += temp + a1[i] + 1;
                a1[i] -= temp + a1[i] + 1;
            }
            if (i % 2 != 0 && temp + a1[i] <= 0) {
                ans1 += Math.abs(temp + a1[i] - 1);
                a1[i] += Math.abs(temp + a1[i] - 1);
            }
            temp += a1[i];
        }
        if (Arrays.stream(a1).sum() == 0) {
            ans1++;
        }
        temp = 0;
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0 && temp + a2[i] <= 0) {
                ans2 += Math.abs(temp + a2[i] - 1);
                a2[i] += Math.abs(temp + a2[i] - 1);
            }
            if (i % 2 != 0 && temp + a2[i] >= 0) {
                ans2 += temp + a2[i] + 1;
                a2[i] -= temp + a2[i] + 1;
            }
            temp += a2[i];
        }
        if (Arrays.stream(a2).sum() == 0) {
            ans2++;
        }
        System.out.println(Math.min(ans1, ans2));
    }
}

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

int main(){

	long long int n, mi=2, ma=3;
	vector<int> v;
  
	cin>> n;
	v.resize(n);
	for(int i=0;i<n;i++) cin>> v[i];
  	reverse(v.begin(), v.end());
  
  	if(v[0]!=2){
      	cout<< "-1" <<endl;
      	return 0;
    }
  
  	for(int i=1;i<n;i++){
        mi=(mi+v[i]-1)/v[i]*v[i];
        ma=ma/v[i]*v[i]+v[i]-1;
      
      	if(ma<mi){
          	cout<< "-1" <<endl;
          	return 0;
        }
    }
  
  	cout<< mi << " " << ma <<endl;
  
  	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int a = sc.nextInt(), b = sc.nextInt();
        String s = sc.next();

        try {
            Integer.parseInt(s.substring(0, a));
            Integer.parseInt(s.substring(a + 1));
            if (!s.substring(a, a+1).equals("-") || s.length() != a + b + 1) {
                throw new Exception();
            }
        } catch (Exception e) {
            System.out.println("No");
            return;
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
using R = double;
using P = complex<R>;
#define x real()
#define y imag()
const R eps = 1e-9,PI = acos(-1);

bool equal(R a,R b){return abs(b-a)<eps;}
bool equal0(R a){return equal(a,0.0);}

P operator*(const P& p,const R& d){
    return P(p.x*d,p.y*d);
}

istream &operator>>(istream& is,P& p){
    R a,b;
    is >> a >> b;
    p = P(a,b);
    return is;
}

ostream &operator<<(ostream& os,P& p){
    os << fixed << setprecision(10) << p.real() << " " << p.imag();
}
//内積
double dot(P a,P b) {return (conj(a)*b).real();}
//外積
double cross(P a,P b) {return (conj(a)*b).imag();}

struct L{
    P a,b;
    L(P a,P b):a(a),b(b){}
    L(R A,R B,R C){
        if(equal(A,0)) a = P(0,C/B),b = P(1,C/B);
        else if(equal(B,0)) b = P(C/A,0),b = P(C/A,1);
        else a = P(0,C/B),b = P(C/A,0);
    }
};

//pをbに射影
P projection(P p,P b) {return b*dot(p,b)/norm(b);}

//pとp1 to p2 に射影
P projection(L l,P p){
    p -= l.a; l.b -= l.a;
    P proj = projection(p,l.b);
    return l.a+proj;
}

struct S:L{
    S(P a,P b):L(a,b){}
};

//点の回転方向を判定
int ccw(P& p0,P p1,P p2){
    p1 -= p0,p2 -= p0;
    if(cross(p1,p2)>eps) return 1; //"COUNTER_CLOCKWISE"
    if(cross(p1,p2)<-eps) return -1; //"CLOCKWISE"
    if(dot(p1,p2)<0) return 2; //"ONLINE_BACK"
    if(norm(p1)<norm(p2)) return -2; //"ONLINE_FRONT"
    return 0; //"ON_SEGMENT"
}

bool is_parallel(L l1,L l2){
    return equal0(cross(l1.b-l1.a,l2.b-l2.a));
}

bool is_orthogonal(L l1,L l2){
    return equal0(dot(l1.b-l1.a,l2.b-l2.a));
}

//pをlに関して対称移動
P reflection(L l,P p){
    P pj = projection(l,p);
    return 2.0*pj-p;
}

//pがl上にあるか
bool is_online(L& l,P& p){
    return abs(ccw(l.a,l.b,p))!=1;
}

bool is_onsegment(S& s,P& p){
    return ccw(s.a,s.b,p)==0;
}

int main(){
    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        P p1,p2,p3,p4;
        cin >> p1 >> p2 >> p3 >> p4;
        if(is_parallel(L(p1,p2),L(p3,p4))) cout << 2 << endl;
        else if(is_orthogonal(L(p1,p2),L(p3,p4))) cout << 1 << endl;
        else cout << 0 << endl;
    }
}


Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
int main()
{
	constexpr int n = 1001;
	int v, d;
	while (std::cin >> v >> d) {
		std::vector<bool> exist(n, false);
		int prev = 1, current = 1;
		for (auto i = 0; i < v; ++i) {
			current = (current + prev) % n;
			prev = (current - prev + n) % n;
			exist[current] = true;
		}
		std::queue<int> queue;
		int count = 0;
		for (auto i = 0; i < n; ++i) if (exist[i]) {
			while (!queue.empty() && i - queue.front() >= d) queue.pop();
			if (queue.empty()) ++count;
			queue.push(i);
		}
		std::cout << count << '\n';
	}
}


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

const int MOD = (int)1e9 + 7;

int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif


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

        int N = n + m + 5;
        vector<int> fct(N), ofct(N);
        fct[0] = 1;
        for (int i = 1; i < N; i++) fct[i] = 1LL * fct[i - 1] * i % MOD;

        if (n < m) swap(n, m);
        int ans = 1;
        if (n > m + 1) ans = 0;
        if (n == m + 1) ans = 1LL * fct[n] * fct[m] % MOD;
        if (n == m) ans = 2LL * fct[n] * fct[m] % MOD;

        cout << ans << endl;
    }


#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 1792
n = str(input())

n = list(n)

N = [int(s) for s in n]


if N[-1] ==2 or N[-1] == 5 or N[-1] ==4 or N[-1] == 7 or N[-1] ==9:
    print("hon")
elif N[-1] == 0 or N[-1] == 1 or N[-1] == 6 or N[-1] ==8:
    print("pon")
else:
    print("bon")

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

bool isPalindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}

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

    int n = s.size();

    string left = s.substr(0, (n - 1) / 2);
    string right = s.substr((n + 1) / 2);

    if(isPalindrome(s) && isPalindrome(left) && isPalindrome(right))
        cout << "Yes" << "\n";
    else cout << "No" << "\n";
    
    return 0;
}

Measured memory_bytes: 3532
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		TreeMap<String,TreeMap<Integer,Integer>> map = new TreeMap<String,TreeMap<Integer,Integer>>();
		String sa[] = new String[101];
		for(int i = 0; i < 101; i++){
			sa[i] = "";
		}
		int scou = 0;
		for(int i = 0; i < n; i++){
			String s = sc.next();
			int p = sc.nextInt();
			if(!map.containsKey(s)){
				map.put(s,new TreeMap<Integer,Integer>());
				map.get(s).put(p,i);
				sa[scou] = s;
				scou++;
			}else{
				map.get(s).put(p,i);
			}
		}
		Arrays.sort(sa);
		for(int i = 100-scou+1; i < 101; i++){
			TreeMap<Integer,Integer> map2 = map.get(sa[i]);
			for(int j = 100; j >= 0; j--){
				if(map2.containsKey(j)){
					System.out.println(map2.get(j)+1);
				}
			}
		}
	}
}


Measured memory_bytes: 22100
import bisect
LI=lambda:map(int,input().split())
A=0
n,m=LI()
a=sorted(LI())
R=a[::-1]
def Q(x,M):
    w=0
    for i in range(n):
        y=x-R[i]
        c=bisect.bisect(a,y-1)
        w+=n-c
        if w>=M:return True
    return False
N=a[-1]*3
O=-1
while N-O>1:
    f=(O+N)//2
    if Q(f,m):
        O=f
    else:
        N=f
P=0
for i in range(n):
    e=n-bisect.bisect(a,O-a[i]-1)
    P+=e
    A+=e*a[i]*2
print(A-O*(P-m))


Measured memory_bytes: 54824
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for l in range(m)]
b=[int(-1) for _ in range(n)]
for x in a:
    if b[x[0]-1]==-1:b[x[0]-1]=x[1]
    elif x[1]!=b[x[0]-1]:
        print(-1)
        exit(0)
if len(b)==1 and (b[0]==-1 or b[0]==0):
    print(0)
    exit(0)
if b[0]==0:
    print(-1)
    exit(0)
if b[0]==-1:b[0]=1
for i in range(1,n):
    if b[i]==-1:b[i]=0
print("".join(map(str,b)))

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

template <class T>
vector<T> sumup(const vector<T>& a) {
  int N = a.size();
  vector<T> res(N + 1);
  for (int i = 0; i < N; i++) res[i + 1] = res[i] + a[i];
  return res;
}

template <class T>
ll invs(vector<T>& A) {
  ll res = 0;
  int N = A.size();
  if (N > 1) {
    vector<T> L(A.begin(), A.begin() + N / 2);
    vector<T> R(A.begin() + N / 2, A.end());
    res += invs(L);
    res += invs(R);
    for (int i = 0, j = 0; i < L.size(); i++) {
      while (j < R.size() && R[j] < L[i]) ++j;
      res += j;
    }
    merge(L.begin(), L.end(), R.begin(), R.end(), A.begin());
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  ll K;
  while (cin >> N >> K) {
    vector<ll> A(N);
    for (ll& x : A) cin >> x;
    auto S = sumup(A);
    for (int i = 0; i < S.size(); i++) S[i] -= i * K;
    ll res = 1ll * N * (N + 1) / 2 - invs(S);
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <string>

using namespace std;
int main()
{
	int wn, hn;
	cin >> hn >> wn;

	vector<string> h(hn);

	for (int i = 0; i < hn; i++) {
		cin >> h.at(i);
	}
	

	string a = "";
	for (int i = 0; i<hn+2; i++){
		if ((i == 0) || (i == hn+1)) {
			for (int j = 0; j < wn + 2; j++) {
				a += '#';
			}
		}
		else {
			if ((i - 1) <= hn) {
				a = '#' + h.at(i - 1) + "#";
			}
		}
		cout << a << endl;
		a = "";
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

LL dp[10005][105];
LL n,k,ans = 0;
string s;

int main(){
	cin >> s; n = s.length();
	cin >> k; s = ' ' + s;
	dp[0][0] = 1;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 0;j <= 9;j ++){
			for(LL l = 0;l <= k;l ++){
				dp[i][(j + l) % k] += dp[i - 1][l];
				dp[i][(j + l) % k] %= N;
			}
		}
	}
	LL sdg = 0;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 0;j < s[i] - '0';j ++){
			ans += dp[n - i][(k - (sdg + j) % k) % k];
			ans %= N;
		}
		sdg += (s[i] - '0');
		sdg %= k;
	}
	if(sdg == 0) ans ++;
	ans --; ans = (ans + N) % N;
	printf("%lld\n",ans);
	return 0;
}
//

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

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

vector<int> g[5];

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

    for(int i=0;i<3;i++){
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    bool flag = false;

    vector<int> dig;

    for(int i=1;i<=4;i++){
        dig.push_back(g[i].size());
    }
    sort(dig.begin(), dig.end());

    if(dig[0] == 1 && dig[1] == 1 && dig[2] == 2 && dig[3] == 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N, l, r, x;
  cin >> N;

  x = 0;

  for (int i = 0; i < N; ++i)
  {
    cin >> l >> r;

    x += r - l;
  }
  cout << x + N << endl;
}

Measured memory_bytes: 3632
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

H,W = two_int()

maps = [list(input()) for i in range(H)]

import copy 
temp_maps = copy.deepcopy(maps)

#start調査
def solve(W,H,maps):
    start_X=0
    start_Y=0
    for x in range(W):
        for y in range(H):
            count=0

            if maps[y][x]=="#":
                count += 1

                if x+1 < W:
                    if maps[y][x+1]=="#":
                        count += 1     

                if y+1 < H:
                    if maps[y+1][x]=="#":
                        count += 1     

                if x-1 >= 0:
                    if maps[y][x-1]=="#":
                        count += 1     


                if y-1 >= 0:
                    if maps[y-1][x]=="#":
                        count += 1     

                if count==1:
                    return "No"
    return "Yes"

ans = solve(W,H,maps)
print(ans)

Measured memory_bytes: 42460
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

dic = {}
for num in A:
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

prev_sum = 0

for key, value in dic.items():
    prev_sum += key * value

for _ in range(Q):
    B, C = map(int, input().split())
    if B in dic and C in dic:
        dic[C] += dic[B]
        dif = (C - B) * dic[B]
        prev_sum += dif
        del dic[B]
    elif B in dic and C not in dic:
        dic[C] = dic[B]
        dif = (C - B) * dic[B]
        prev_sum += dif
        del dic[B]
    print(prev_sum)


Measured memory_bytes: 20960
import itertools
n = int(input())
l = list(map(int, input().split()))    
count = 0
ind_list = list(itertools.combinations(range(0,n), 3))

for ind in ind_list:
    if (l[ind[0]]+l[ind[1]])>l[ind[2]] and (l[ind[1]]+l[ind[2]])>l[ind[0]] and (l[ind[2]]+l[ind[0]])>l[ind[1]]:
        if l[ind[0]]!=l[ind[1]] and l[ind[0]]!=l[ind[2]] and l[ind[1]]!=l[ind[2]]:
            count += 1

print(count)

Measured memory_bytes: 20596
import sys
input = sys.stdin.readline

N = int(input())
X = list(map(int, input().split()))

tmpans = 0
ans = float('inf')

for P in range(min(X), max(X) + 1):
    for x in X:
        tmpans += (x-P)**2

    if tmpans < ans:
        ans = tmpans
    tmpans = 0
print(ans)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B_Some_Sums
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var n = int.Parse(input[0]);
            var a = int.Parse(input[1]);
            var b = int.Parse(input[2]);
            var result = 0;
            for (int i = 1; i <= n; i++)
            {
                var temp = getKetaSum(i);
                if(a <= temp && temp <= b)
                {
                    result+=i;
                }
            }
            Console.WriteLine(result);
        }
        static int getKetaSum(int n)
        {
            int result = 0;

            while (n > 0)
            {
                result += n % 10;
                n /= 10;
            }

            return result;
        }
    }
}


Measured memory_bytes: 11092
N = int(input())
H = [int(h) for h in input().split(" ")]

if N <= 1:
  print("Yes")
  exit()
H[0] -= 1
i = 1
while i<N:
  if H[i]>H[i-1]:
    H[i]-=1
  if H[i] < H[i-1]:
    print("No")
    exit()
  i+=1
print("Yes")

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

int main()
{
	double n=3.14159265358979323846264338327950288;
	int c;
	cin>>c;
	int d=c*2;
	cout<<setiosflags(ios::fixed)<<setprecision(20)<<d*n<<endl;
	return 0;
}

Measured memory_bytes: 3764
def koch(n, a, b)
  return true if n == 0
  th = Math::PI * 60.0 / 180.0
  s = {
    x: (2.0 * a[:x].to_f + 1.0 * b[:x].to_f) / 3.0,
    y: (2.0 * a[:y].to_f + 1.0 * b[:y].to_f) / 3.0
  }
  t = {
    x: (1.0 * a[:x].to_f + 2.0 * b[:x].to_f) / 3.0,
    y: (1.0 * a[:y].to_f + 2.0 * b[:y].to_f) / 3.0
  }
  u = {
    x: (t[:x] - s[:x]) * Math::cos(th) - (t[:y] - s[:y]) * Math::sin(th) + s[:x],
    y: (t[:x] - s[:x]) * Math::sin(th) + (t[:y] - s[:y]) * Math::cos(th) + s[:y]
  }

  koch(n-1, a, s)
  puts format('%.8f %.8f', s[:x].to_f, s[:y].to_f)
  koch(n-1, s, u)
  puts format('%.8f %.8f', u[:x].to_f, u[:y].to_f)
  koch(n-1, u, t)
  puts format('%.8f %.8f', t[:x].to_f, t[:y].to_f)
  koch(n-1, t, b)
end

n = gets.to_i
a = {x: 0.0, y: 0.0}
b = {x: 100.0, y: 0.0}
puts format('%.8f %.8f', a[:x].to_f, a[:y].to_f)
koch(n, a, b)
puts format('%.8f %.8f', b[:x].to_f, b[:y].to_f)

Measured memory_bytes: 9456
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc162
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var input = Enumerable.Range(1, n).ToArray();

            long ans = 0;
            foreach (var item in input)
            {
                if (item % 3 != 0 && item % 5 != 0 && item % 15 != 0)
                {
                    ans += item;
                }
            }
            Console.WriteLine(ans);
         /*   var k = int.Parse(Console.ReadLine());

            var a = Enumerable.Range(1,k).ToArray();
            var b = Enumerable.Range(1, k).ToArray();
            var c = Enumerable.Range(1, k).ToArray();
            if()
            */
        }
    }
}


Measured memory_bytes: 31964
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var S = input[1].split("");
  var K = parseInt(input[2]);
  for(var i=0;i<N;i++){
    if(S[i]!=S[K-1]){
      S[i]="*";
    }
  }
  var ans=S.join("");

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

ll solve() {
    ll N, K, a;
    cin >> N >> K;
    vector<ll> A(N);
    const int M = 1e5+1;
    bitset<M> ab;
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        ab.set(a);
    }
    bitset<M> dp;
    for ( int i = 0; i < K; i++ ) {
        if ( !dp.test(i) ) {
            dp |= ab << i;
        }
    }
    return dp.test(K);
}

int main() {
    string ans = solve() ? "First" : "Second";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
// Aizu Vol-1 0188: Search
// 2017.8.3

#include <stdio.h>
#include <stdlib.h>

char *gets(char *);
char buf[100];
int a[120];

int main()
{
	int i, j, k, n, g;
	int cnt;

	while (1) {
		gets(buf);
		if (!(n = atoi(buf))) break;
		for (i = 0; i < n; i++) gets(buf), a[i] = atoi(buf);
		gets(buf), g = atoi(buf);
		for (cnt = 0, i = 0, j = n - 1; i <= j; ) {
			cnt++;
			k = (j + i) >> 1;
			if (g == a[k]) break;
			if (g < a[k]) j = k - 1;
			else i = k + 1;
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 524
N, T = map(int, input().split())
c = [0 for _ in range(N)]
t = [0 for _ in range(N)]
ans = 1001

for i in range(N):
    c[i], t[i] = map(int, input().split())
    if t[i] <= T:
        if c[i] <= ans:
            ans = c[i]

if ans == 1001:
    print('TLE')
else:
    print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int m[9][9];
int vis[9];
int sum,n;
void dfs(int cot,int num){
    if(num==n){
        sum++;
        return;
    }
    for(int i=2;i<10;i++){
        if(m[cot][i]==1&&vis[i]==0){
            vis[i]=1;
            dfs(i,num+1);
            vis[i]=0;
        }
    }
}
int main(){
    int mm,a,b;
    cin>>n>>mm;
    for(int i = 0;i<mm;i++){
        cin>>a>>b;
        m[a][b]=1;
        m[b][a]=1;
    }
    sum = 0;
    vis[1]=1;
    dfs(1,1);
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

#define INF 100000

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int>x(N), y(M);
    for (int i = 0; i < N; i++)cin >> x[i];
    for (int i = 0; i < M; i++)cin >> y[i];

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    cout << ((x.back() < y.front() && X <= x.back() && y.front() <= Y) ? "No War" : "War") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;


int main()
{
    int N;
    cin >> N;
    double x;
    string u;
    double res = 0;
    REP(_, N)
    {
        cin >> x >> u;
        res += x * (u == "JPY" ? 1 : 380000);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
/* https://drken1215.hatenablog.com/entry/2020/01/26/234000 */
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    ll n, d, a;
    cin >> n >> d >> a;

    vector<int> zahyo(n), kaisu(n);

    REP(i, n) {
        cin >> zahyo[i] >> kaisu[i];
        kaisu[i] = (kaisu[i] + (a-1)) / a;
    }

    vector<int> idx_(n);
    REP(i, n) idx_[i] = i;
    
    sort(ALL(idx_), [&](int i, int j) {
        return zahyo[i] < zahyo[j];});
    
    ll ans = 0;
    queue<P> que;
    ll num = 0;
    for(auto i: idx_) {
        while(!que.empty() && que.front().first < zahyo[i]) {
            num -= que.front().second;
            que.pop();
        }
        kaisu[i] -= num;
        if(kaisu[i] > 0) {
            ans += kaisu[i];
            que.push({zahyo[i] + 2 * d, kaisu[i]});
            num += kaisu[i];
        }
    }
    cout << ans << endl;
    
    
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int gcd(int x, int y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

int main(){
    int n;cin>>n;
    vector<int> a(n,0);

    REP(i,n){
        cin>>a[i];
    }
    vector<int> l(n,0),r(n,0);
    for (int i = 0; i < n-1; i++)
    {
        /* code */
        l[i+1]=gcd(l[i],a[i]);
    }
    for(int i=n-1;i>=1;--i){
        r[i-1]=gcd(r[i],a[i]);

    }
    int ans=1;
    REP(i,n){
        ans=max(gcd(r[i],l[i]),ans);
    }
    cout<<ans<<endl;
    }

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

#define pb push_back
#define ri(x) scanf("%d",&x)
#define rii(x,y) ri(x),ri(y)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define ms2(obj,val,sz) memset(obj,val,sizeof(obj[0])*sz)
#define FOR(i,f,t) for(int i=f;i<(int)t;i++)
#define FORR(i,f,t) for(int i=f;i>(int)t;i--)

typedef long long ll;
typedef vector<int> vi;

const int MAXN=3001;

int a1,a2;
double best=0;
int a,b,c,d,e,f;
bool g1[MAXN],g2[MAXN];

int main() {
	rii(a,b);
	rii(c,d);
	rii(e,f);
	g1[0] = true;
	g2[0] = true;
	FOR(i,1,MAXN) if((0 <= i-100*a && g1[i-100*a]) || (0 <= i-100*b && g1[i-100*b])) g1[i] = true;
	FOR(i,1,MAXN) if((0 <= i-c && g2[i-c]) || (0 <= i-d && g2[i-d])) g2[i] = true;
	FOR(i,0,MAXN) FOR(j,0,MAXN) {
		if(i + j > f || i + j <= 0) continue;
		if(i / 100.0 * e < j) continue;
		if(!g1[i] || !g2[j]) continue;
		if(best <= (100.0*j) / (i+j)) {
			a1 = i+j;
			a2 = j;
			best = (100.0*j) / (i+j);
		}
	}
	printf("%d %d\n",a1,a2);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
  int N;
  cin>>N;
  int A[N+2];
  int i,k;
  A[0]=0;
  A[N+1]=0;
  int sum=0;
  for(i=1;i<=N;i++)
  {
    cin>>A[i];
  }
  int ans[N+2];
  for(i=0;i<=N;i++)
  {
  sum=sum+abs(A[i]-A[i+1]);
  }


  for(i=1;i<=N;i++)
  {
    cout<<sum+abs(A[i-1]-A[i+1])-(abs(A[i-1]-A[i])+abs(A[i]-A[i+1]))<<endl;
  }
  return 0;
}


Measured memory_bytes: 1792
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val w = readLine()!!.split(' ').map(String::toInt)
    var i = 0
    var j = n - 1
    var s1 = 0
    var s2 = 0
    while (i <= j) {
        if (s1 < s2) {
            s1 += w[i++]
        } else {
            s2 += w[j--]
        }
    }
    println(Math.abs(s1 - s2))
}


Measured memory_bytes: 38304
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        Arrays.sort(h);
        int min = Integer.MAX_VALUE;
        for (int i = 0; i <= n - k; i++) {
            if (min > h[i + k - 1] - h[i])
                min = h[i + k - 1] - h[i];
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 51904
m = [[0, 1], [0, 0]]
n = gets.to_i
arr = gets.chomp.gsub("T","0").gsub("F", "1").split.map(&:to_i)
answer = m[arr[0]][arr[1]]
2.upto(n - 1){|i| answer = m[answer][arr[i]]}
puts (answer == 0 ? "T" : "F")


Measured memory_bytes: 12404
#include <bits/stdc++.h>
using namespace std;
int dif[(int) 2e5+2];
    int n,m;

long long solve(int n)
{
    if (2 > n) return 0;
    if (2 == 0) return 1;

    int result = n;
    for( int i = 2; i <= 2; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}

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

    cout<<solve(n)+solve(m)<<endl;

    return 0;
}


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

int keta(int N){
  if(N == 0) return 1;
 int a =  log10(N);
  return a+1;
}


int main() {
int N,K;
 cin >>N>>K;
 int ans =0;
  for(int i=0;i<N;i++){
   int x;
    cin >>x;
    int a = K-x;
    ans += min(a,x) *2;
  }
  printf("%d\n",ans);
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

// 深さ優先探索
vector<bool> seen;
vll score;
void dfs(const Graph &G, int v) {
  seen[v] = true; // v を訪問済にする

  // v から行ける各頂点 next_v について
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue; // next_v が探索済だったらスルー
    score[next_v] += score[v];
    dfs(G, next_v); // 再帰的に探索
  }
}

int main()
{
  int N,Q;
  cin >> N >> Q;
  
  Graph G(N);
  score.assign(N, 0);
  REP(i,N-1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  REP(i,Q){
    int p,x;
    cin >> p >> x;
    p--;
    score[p] += x;
  }
  seen.assign(N,false);
  REP(i,N){
    if(seen[i])continue;
    dfs(G,i);
  }
  for(auto s :score){
    cout << s << " ";
  }
  cout << endl;
}

Measured memory_bytes: 25064