akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func main() {
	ar := make([]int, 5)
	for i := range ar {
		fmt.Scan(&ar[i])
	}
	var sum, max int
	for _, v := range ar {
		m := v % 10
		if m == 0 {
			sum += v
		} else {
			sum += (v/10 + 1) * 10
			up := 10 - m
			if max < up {
				max = up
			}
		}
	}
	fmt.Println(sum - max)
}


Measured memory_bytes: 512
unittest
{
	assert( [ "4 5", "3 2 4 1" ].parse.expand.solve == 4 );
	assert( [ "6 727202214173249351", "6 5 2 5 3 2" ].parse.expand.solve == 2 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	as[] -= 1;
	return tuple( nk[ 1 ], as );
}

auto solve( long k, long[] as )
{
	auto ds = new long[ as.length ];
	ds[] = -1;
	auto p = 0L;
	for( auto i = 0L; i < k; i++ )
	{
		if( 0 <= ds[ p ] )
		{
			// ループを検知したのでシミュレーション省略
			auto l = i - ds[ p ];
			i += ( ( k - i ) / l ) * l;
		}
		if( i == k ) break;
		
		// 次に進む
		ds[ p ] = i;
		p = as[ p ];
	}
	return p + 1;
}


Measured memory_bytes: 13232
#include<bits/stdc++.h>
using namespace std;
#define INFTY 10000000000
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<ll,ll>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
#define rep(i,n) for (ll i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
    int n,k;cin>>n>>k;
    vector<int>p(n);
    rep(i,n)cin>>p[i];
    sort(p.begin(),p.end());
    int sum = 0;
    rep(i,k)sum += p[i];
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3616
S = input()
n = len(S)
p = 0
if S[0] == 'A':
    p = 1
s = []
for i in range(2,n-1):
    s.append(S[i])
q = 0
if s.count('C') == 1:
    q = 1
if 'C' in s:
    s.remove('C')
s.append(S[1])
s.append(S[n-1])
r = 1
for i in range(n-2):
    x = s[i]
    t = ord(x)-97
    if 0<= t <= 25:
        continue
    else:
        r = 0
        break
ans = 'WA'
if p*q*r == 1:
    ans = 'AC'
print(ans)

Measured memory_bytes: 3064
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")

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

#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define inf (1LL << 61)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; ++i)
#define for0(i, stop) for(ll i = 0; i < stop; ++i)
#define rep1(i, start) for(ll i = start; i >= 1; --i)
#define rep0(i, start) for(ll i = (start-1); i >= 0; --i)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define EL '\n'
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll sz = 2e5 + 10;
ll cnt[sz], pw[sz];
char s[sz];

int main()
{
    ll n, p, ans = 0;
    cin >> n >> p;
    scanf("%s", s+1);

    if(p == 2 || p == 5) {

        for(ll i = 1; i <= n && p == 2; i++) {
            if((s[i]-'0') % 2 == 0)
                ans += i;
        }

        for(ll i = 1; i <= n && p == 5; i++) {
            if(s[i] == '5' || s[i] == '0')
                ans += i;
        }

        pf("%lld\n", ans);

        return 0;
    }

    pw[0] = 1;
    for1(i, n) pw[i] = (pw[i-1] * 10) % p;

    ll sum = 0;
    for1(i, n) {
        sum = (sum * 10 + (s[i] - '0')) % p;
        if(sum == 0) ans++;

        ll now = (sum * pw[n-i]) % p;

        ans += cnt[now];
        cnt[now]++;
    }

    pf("%lld\n", ans);

    return 0;
}


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

int main() {
	string  st;
	bool flag = true;
	cin >> st;

	if (st.at(0) == st.at(1)) {
		if (st.at(0) == st.at(2)) flag = false;
		else if (st.at(0) == st.at(3)) flag = false;

		else if (!(st.at(2) == st.at(3))) flag = false;
	}

	else if (st.at(0) == st.at(2)) {
		if (st.at(0) == st.at(1)) flag = false;
		else if (st.at(0) == st.at(3)) flag = false;

		else if (!(st.at(1) == st.at(3))) flag = false;
	}

	else if (st.at(0) == st.at(3)) {
		if (st.at(0) == st.at(1)) flag = false;
		else if (st.at(0) == st.at(2)) flag = false;

		else if (!(st.at(1) == st.at(2))) flag = false;
	}

	else if(st.at(1)==st.at(2)){
		if (st.at(1) == st.at(0)) flag = false;
		else if (st.at(1) == st.at(3)) flag = false;

		else if (!(st.at(0) == st.at(3))) flag = false;
	}

	else if (st.at(1) == st.at(3)) {
		if (st.at(1) == st.at(0)) flag = false;
		else if (st.at(1) == st.at(2)) flag = false;

		else if (!(st.at(0) == st.at(2))) flag = false;
	}

	else if (st.at(2) == st.at(3)) {
		if (st.at(2) == st.at(0)) flag = false;
		else if (st.at(2) == st.at(1)) flag = false;

		else if (!(st.at(0) == st.at(1))) flag = false;
	}
  	else flag = false;
  
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder2
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = Console.ReadLine();
			var l = s.Length;
			var b = Enumerable.Repeat(1, l).ToArray();

			for (int i = 0; i < l - 2; i++)
			{
				if (s[i] == 'R' && s[i + 1] == 'R')
				{
					b[i + 2] += b[i];
					b[i] = 0;
				}
			}

			for (int i = l - 1; i > 0; i--)
			{
				if (s[i] == 'L' && s[i - 1] == 'L')
				{
					b[i - 2] += b[i];
					b[i] = 0;
				}
			}

			Console.WriteLine(String.Join(' ', b));
		}
	}
}


Measured memory_bytes: 21776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long double PI = 3.14159265358979323846;

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

    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (i % 3 == 0 || i % 5 == 0) {
            continue;
        } else {
            ans += i;
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=998244353;
int main()
{
	ll i,j,k,m,n,t,x;
	cin>>n>>x>>m;
	ll ar[100001];
	ar[0]=x;
	map<ll,ll> mp;
	mp[x]=1;
	ll ans=x,c1=1;
	for(i=1;i<n;i++)
	{
		x=ar[i-1]*ar[i-1];
		x%=m;
		if(mp[x]) break;
		mp[x]++;
		c1++;
		ar[i]=x;
		ans+=x;
	}
	n-=c1;
	ll s=0;
	for(j=0;j<c1;j++)
	if(ar[j]==x) break;
	ll ctr=0;
	ll pos=j;
	for(;j<c1;j++)
	{
		s+=ar[j];
		ctr++;
	}
	ans+=(n/ctr)*s;
	n%=ctr;
	i=pos;
	while(n--)
	{
		ans+=ar[i];
		i++;
	}
	cout<<ans;
}

Measured memory_bytes: 7064
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
Z=[list(map(int,input().split())) for i in range(M)]
ans=2*10**5
for s,t,u in Z:
  d=a[s-1]+b[t-1]-u
  ans=min(ans,d)
e=min(a)+min(b)
print(min(ans,e))

Measured memory_bytes: 38556
import java.io.*;

class Main {
	public static void main(String[] arg)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n = Integer.parseInt(br.readLine());
			if(n == 0)break;
			double m = 0,sig = 0;
			String[] div = br.readLine().split(" ");
			for(int i=0; i<n; i++){
				double s = Double.parseDouble(div[i]);
				m += s;
			}
			m = m / n;
			for(int i=0; i<n; i++){
				double s = Double.parseDouble(div[i]);
				sig +=(s-m)*(s-m);
			}
			System.out.println(Math.sqrt(sig/n));
		}
	}
}

Measured memory_bytes: 19952
#include<iostream>
#include <string>
#include <stdio.h>
using namespace std;

int main()
{
    //　数値の定義
    int N; //人数
    cin >> N;

    int num[N]; //上司番号{0,1,1,2,2}
    int buka[N]; //部下の数{2,2,0,0,0}

    for(int i=0; i < N; i++){ //部下の数をループ
        buka[i] = 0;
        if(i>0){
            cin >> num[i];
            buka[num[i]-1]++;
        }
    }

    
    
    //判定
    for(int i = 0; i < N; i++){
        cout << buka[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4728
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

int getNY(int n){
    int ret=0;
    for(int i=1;i<=n;i++){
        if(n%i==0)ret++;
    }
    return ret;
}

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

    int res=0;
    for(int i=1;i<=n;i+=2){
        if(getNY(i)==8) res++;
    }
    p(res)
} 

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int cnt = 0;
    for (int i = 1; i < N - 1; i++) {
        vector<int> B;
        B.push_back(A[i - 1]);
        B.push_back(A[i]);
        B.push_back(A[i + 1]);
        sort(all(B));
        if (A[i] == B[1]) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

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

int main() {
  int a,b;
  scanf("%d %d",&a,&b);
  if(b%a==0) printf("%d\n",a+b);
  else printf("%d\n",b-a);
  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BHoles solver = new BHoles();
        solver.solve(1, in, out);
        out.close();
    }

    static class BHoles {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();


            int[] x = new int[n];
            int[] y = new int[n];

            for (int i = 0; i < n; i++) {
                x[i] = in.nextInt();
                y[i] = in.nextInt();
            }

            for (int cur = 0; cur < n; cur++) {
                double[] angle = new double[n - 1];
                for (int j = 0, index = 0; j < n; j++) {
                    if (j == cur) {
                        continue;
                    }

                    angle[index++] = Math.atan2(y[j] - y[cur], x[j] - x[cur]) / (2 * Math.PI);
                }

                double normalized = angle[0];
                for (int i = 0; i < n - 1; i++) {
                    angle[i] -= normalized;
                    if (angle[i] < -0.5) {
                        angle[i] += 1;
                    }
                    if (angle[i] > +0.5) {
                        angle[i] -= 1;
                    }
                }

                double min = -0.25;
                double max = +0.25;

                for (double a : angle) {
                    double lower = a - 0.25;
                    double upper = a + 0.25;

                    min = Math.max(min, lower);
                    max = Math.min(max, upper);
                }

                out.println(Math.max(0, max - min));
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22996
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int vis[3000]; // Nへ到達可能

const ll INF = LLONG_MAX / 3;
vll BellmanFord(vi &from, vi &to, vi &cost, int V, int start) {
    int num = (int)to.size();
    bool update = true;
    vll dp(V, INF);
    dp[start] = 0;
    int cnt = 0;
    while (update) {
        update = false;
        for (int i = 0; i < num; ++i) {
            // ゴールできなくなる頂点へはいかない。
            if (!vis[to[i]]) {
                continue;
            }
            ll value = dp[from[i]] + cost[i];
            if (dp[from[i]] != INF && value < dp[to[i]]) {
                dp[to[i]] = value;
                update = true;
            }
        }
        if (++cnt == V + 1)
            return vll();
    }
    return dp;
}

vi rG[3000];
void dfs(int u) {
    if (vis[u]++)return;
    each(v, rG[u]) {
        if (!vis[v])dfs(v);
    }
}

void solve() {
    int N, M, P;
    cin >> N >> M >> P;

    vi from(M), to(M), coin(M), cost(M);
    rep(i, M) {
        cin >> from[i] >> to[i] >> coin[i];
        cost[i] = P - coin[i];
        --from[i];
        --to[i];
        rG[to[i]].push_back(from[i]);
    }

    dfs(N - 1);

    auto res = BellmanFord(from, to, cost, N, 0);
    if (res.empty()) {
        cout << -1 << endl;
    } else {
        cout << max(0ll, -res.back()) << endl;
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 512
class BinaryIndexedTree(object):
    def __init__(self, n: int) -> None:
        self.size = n
        self.bit = [0] * (self.size + 1)

    def add(self, i: int, v: int) -> None:
        while (i <= self.size):
            self.bit[i] += v
            i += (i & -i)  # i & -i picks the lowest 1 bit of i.

    def sum(self, i: int) -> int:
        s = 0
        while (i > 0):
            s += self.bit[i]
            i -= (i & -i)
        return s


class RangeQuery(object):
    def __init__(self, n: int) -> None:
        self.size = n
        self.bit1 = BinaryIndexedTree(n + 1)
        self.bit2 = BinaryIndexedTree(n + 1)

    def add(self, i: int, j: int, v: int) -> None:
        self.bit1.add(i, v * -i)
        self.bit1.add(j + 1, v * (j + 1))
        self.bit2.add(i, v)
        self.bit2.add(j + 1, -v)

    def sum(self, i: int, j: int) -> int:
        s = self.bit1.sum(j + 1) + (j + 1) * self.bit2.sum(j + 1)
        s -= self.bit1.sum(i) + i * self.bit2.sum(i)
        return s


if __name__ == "__main__":
    n, q = map(lambda x: int(x), input().split())
    rq = RangeQuery(n)

    for _ in range(q):
        com, *v = map(lambda x: int(x), input().split())
        if (0 == com):
            rq.add(v[0], v[1], v[2])
        else:
            print(rq.sum(v[0], v[1]))



Measured memory_bytes: 11792
#include <stdio.h>
#include <stdlib.h>

int main()
 {
     int i;
     int key;
     int final = 0;
     int n,m;
     scanf("%d", &n);
     int A[100000];
     for (i = 0; i != n; i++)
    {
        scanf("%d", &A[i]);
 }


 scanf("%d", &m);
 int left, right, mid;
 while (m--) 
 {
     scanf("%d", &key);
     left = 0;
     right = n-1;
    while (left <= right)
    {
        int mid = (left + right) / 2;
        if (A[mid] == key) {
            final++;
            break;
   }
   else if (A[mid] > key) 
   {
       right = mid - 1;
   }
   else if (A[mid] < key)
   {
       left = mid + 1;
   }
  }
  
}
  
printf("%d\n", final);

 return 0;

}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);

  int i=n-1;
  if(n%2==0){
    while(i>0){cout << a.at(i) << " "; i-=2;}
    i=0;
    while(i<n){cout << a.at(i) << " "; i+=2;}
  }else{
    while(i>=0){cout << a.at(i) << " "; i-=2;}
    i=1;
    while(i<n){cout << a.at(i) << " "; i+=2;}
  }
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int k,n,a[200005];
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>k>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int ans=inf;
	for(int i=1;i<=n-1;i++)
		ans=min(ans,k-(a[i+1]-a[i]));
	ans=min(ans,k-(a[1]+k-a[n]));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, k;
    cin >> n >> k;
    ll sum[n + 1] = {};
    rep(i, 0, n) {
        ll a;
        cin >> a;
        sum[i + 1] = sum[i] + a;
    }
    rep(i, 0, n + 1) {
        sum[i] -= i;
        sum[i] %= k;
    }
    ll ans = 0;
    map<int, int> mp;
    rep(i, 0, n + 1) {
        if (i - k >= 0) mp[sum[i - k]]--;
        ans += mp[sum[i]];
        mp[sum[i]]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
#include<stdio.h>
 
int main()
{
  int t[4][14];
  int n, i,j,c;
  char m, d;
  for(i=0; i < 4; i++){
    for(j=0; j < 14; j++){
      t[i][j]=0;
    }
  }
 scanf("%d", &c);
  for(i = 0; i < c; i++){
    scanf("%c", &d);
    scanf("%c %d", &m, &n);
    if(m == 'S'){
      t[0][n] = 1;
    }
    else if(m == 'H'){
      t[1][n] = 1;
    }
    else if(m == 'C'){
      t[2][n] = 1;
    }
    else if(m == 'D'){
      t[3][n] = 1;
    }
  }
  for(j=1; j < 14; j++){
    if(t[0][j] != 1){
      printf("S %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[1][j] != 1){
      printf("H %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[2][j] != 1){
      printf("C %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[3][j] != 1){
      printf("D %d\n", j);
    }
  }
 return 0;
}
 



Measured memory_bytes: 2100
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int m = 0;
    for (int i = 0; i < 3;i++) {
        if (s[i] == t[i]) m++;
    }
    cout << m << endl;
}


Measured memory_bytes: 256
a,b = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp
flg = 0
sarr = s.chomp.split("")
if sarr[a] == "-" && s.length == a + b + 1
  s.length.times do |i|
    if i != a
      if sarr[i] == "-" then
        flg = 1
      end
    end
  end
else
  flg = 1
end

if flg == 1 then
  print("No\n")
else
  print("Yes\n")
end


Measured memory_bytes: 1788
#include <iostream>
using namespace std;
 
int main() {
    int i;
    cin >> i;
    if(i % 2 != 0)
    {
      printf("No");
      return 0;
    }
    string s;
    cin >> s;
    int j = i/2;
    if(s.substr(0, j) == s.substr(j, j))
    {
      printf("Yes");
      return 0;
    };
    printf("No");
    return 0;
}

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

typedef long long ll;
const ll MAKSI = 1e9;
const int N = 1e5;

int n;
ll m;
ll a[N+5];

int main(){
	scanf("%d%lld",&n,&m);
	ll kpk = 1;
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		a[i]/=2;
		ll gcd = __gcd(a[i],kpk);
		kpk /=gcd;
		kpk*=a[i];
		if(kpk>MAKSI){
			printf("0\n");
			return 0;
		}
	}
	ll ans = m/kpk;
	ans = ans - (ans/2);
	for(int i=1;i<=n;i++){
		if((kpk/a[i])%2 == 0) ans = 0;
	}
	printf("%lld\n",ans);
	return 0;
}


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

inline int gcd(int a,int b){
    while(b){
        a=a%b;
        swap(a,b);
    }
    return a;
}

int n,a[1000005],u[1000005];

int main(){

    scanf("%d",&n);
    int g=0;
    for(int i=1;i<=n;i++){
        scanf("%d",a+i);
        g=gcd(g,a[i]);
        for(int j=2;j*j<=a[i];j++){
            if(a[i]%j==0){
                u[j]++;
                while(a[i]%j==0)a[i]/=j;
            }
        }
        u[a[i]]++;
    }
    if(g>1){
        cout<<"not coprime\n";
        return 0;
    }
    for(int i=2;i<=(int)1e6;i++){
        if(u[i]>1){
            cout<<"setwise coprime\n";
            return 0;
        }
    }
    cout<<"pairwise coprime\n";


    return 0;
}

Measured memory_bytes: 11460
n, m = map(int, input().split())
while n != 0 and m != 0:
    a = list(map(int, input().split()))
    dp = []
    for i in range(n):
        for j in range(n):
            if a[i]+a[j]<= m and i != j:
                dp.append(a[i]+a[j])
    if len(dp) == 0:
        print("NONE")
    else:
        print(max(dp))
    n, m = map(int, input().split())



Measured memory_bytes: 46280
l,r=map(int, input().split())
ans=((l+1)*l)%2019
if r-l>=2018:
    ans=0
l=l%2019
r=r%2019
if r<l:
    ans=0
else:
    for i in range(l,r+1):
        for j in range(l,r+1):
            if i==j: continue
            ans=min(ans, (j*i)%2019)
print(ans)

Measured memory_bytes: 40556
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	vector<pii> result;
	int n, acc;
	while(scanf("%d,%d", &n, &acc), n|acc)
		result.push_back(pii(acc, n));
	sort(result.rbegin(), result.rend());

	map<int, int> rank;
	rep(i, result.size()){
		if(!i) rank[result[i].second] = 1;
		else rank[result[i].second] = rank[result[i-1].second] + (result[i-1].first != result[i].first);
	}
	
	while(scanf("%d", &n) != EOF){
		printf("%d\n", rank[n]);
	}

	return 0;
}

Measured memory_bytes: 0
from operator import itemgetter


n, m = map(int, input().split())
a = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(m)]
a = sorted(a)
info = sorted(info, key = itemgetter(1), reverse = True)

j = 0
for i in range(n):
    if info[j][0] <= 0:
        j += 1
        if j >= m:
            break
    if a[i] < info[j][1]:
        a[i] = info[j][1]
        info[j][0] -= 1
    else:
        break
print(sum(a))

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

int N;

bool f(string s, int x){
    int n = s.size();
    if(n == N){
        cout << s << endl;
    } else {
        for (int i = 0; i <= x; i++){
            char a = 'a' + i;
            string nex = s + a;
            f(nex, x);
        }
        if(x != 25){
            char b = 'a' + x + 1;
            string nex2 = s + b;
            f(nex2, x+1);
        }
    }

    return 0;
}

int main() {
    cin >> N;

    f("a", 0);

    return 0;
}

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

int main() {
  int n,k,x,y;
  cin>>n>>k>>x>>y;
  if(n<=k) cout<<x*n<<endl;
  else cout<<x*k+y*(n-k)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(12e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()



int main() {
    int n, cnt[MAX_N]{}, ans = IINF;
    string s;
    cin >> n >> s;
    REP(i,n){
        if(s[i]=='.')cnt[i+1]++;
        cnt[i+1] += cnt[i];
    }
    REP(i,n+1){
        ans = min(ans, i-cnt[i] + cnt[n]-cnt[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5252
# -*- coding : utf-8 -*-

A = list(input())
B = list(input())
C = list(input())
X = [A,B,C]
t = 0

while True:
  if X[t] == []:
    if t == 0:
      print("A")
      break
    elif t == 1 :
      print("B")
      break
    elif t == 2:
      print("C")
      break
  else:
    if X[t][0] == "a":
      X[t].remove(X[t][0])
      t = 0
    elif X[t][0] == "b":
      X[t].remove(X[t][0])
      t = 1
    elif X[t][0] == "c":
      X[t].remove(X[t][0])
      t = 2

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            int prev = int.Parse(s[0]);
            int cont = 0;
            int ans = 0;
            for (int i = 1; i < N; i++)
            {
                int v = int.Parse(s[i]);
                if(prev >= v)
                {
                    cont++;
                }
                else
                {
                    cont = 0;
                }

                prev = v;

                ans = Math.Max(ans, cont);
            }

            Console.WriteLine(ans);
        }
    }
}




Measured memory_bytes: 24668
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
set<pair<int,int> > st;
vector<int> gr[100005];
int vis[100005],out[100005];
void dfs(int u, int p)
{
	vis[u] = 1;
	vector<int>::iterator it = gr[u].begin();
	for(;it!=gr[u].end();it++)
		if(!vis[*it] && st.count({(*it),u}) && st.count({u,(*it)}))
			dfs((*it),u);
	if(p)
	{
		vector<int>::iterator it = gr[u].begin();
		for(;it!=gr[u].end();it++)
		{
			if((*it) == p)
				continue;
			if(st.count({(*it),u}) && st.count({u,(*it)}))
			{
				st.erase({(*it),u});
				out[u]++;
			}
		}
		if(out[u]&1)
		{
			st.erase({p,u});
			out[u]++;
		}
		else
		{
			st.erase({u,p});
			out[p]++;
		}
	}
}
int main()
{
	int n,m,i,j,u,v;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>u>>v;
		gr[u].pb(v);
		gr[v].pb(u);
		st.insert({u,v});
		st.insert({v,u});
	}
	if(m&1)
		cout<<"-1"<<endl;
	else
	{
		dfs(1,0);
		set<pair<int,int> >::iterator it = st.begin();
		for(;it!=st.end();it++)
		{
			cout<<(it->f)<<" "<<(it->s)<<endl;
		}
	}
	return 0;
}	

Measured memory_bytes: 26368
#include <iostream>
#include <map>

int f(int n)
{
	return n % 2 == 0 ? n / 2 : 3 * n + 1;
}

int main()
{
	int s;
	std::cin >> s;
	
	std::map<int, int> mp;
	int i;
	for (i = 1; i <= 1000000; i++) {
		if (mp.count(s)) {
			break;
		}
		mp[s];
		s = f(s);
	}
	
	std::cout << i << std::endl;
	
	return 0;
}


Measured memory_bytes: 3220
#include<iostream>

using namespace std;

int main(void){
  long long N;
  long long ans = 1;
  long long mod = 1e9+7;
  cin >> N;
  for(long long i = 1; i <= N; i++){
    ans *= i;
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  A = [[-1]*N for _ in range(N)]
  for i in range(N):
    num = int(input())
    for _ in range(num):
      x, y = map(int, input().split())
      A[i][x-1] = y

  max_ = 0
  for bit in range(1 << N):
    for i in range(N):
      mask = (1 << i)
      # i番目の仮定についてN人の証言について検証
      for j in range(N):
        if A[j][i] == -1:
          continue
        # j番目の人が正直者と仮定してiについての証言が仮定と一致しない
        if (bit & (1 << j)) and A[j][i] != bool(bit & mask):
          # print(f'bit:{bin(bit)}, i:{i}, j:{j}, A[j][i]:{A[j][i]} != {bit & mask}')
          break
      else:
        # cnt += 1
        continue
      break
    else:
      # print(bin(bit))
      max_ = max(max_, bin(bit).count('1'))

  print(max_)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 74516
n = int(input())
s = input().split()
b =[str(i+1) for i in range(len(s))]
count=0
for i in range(len(s)):
  if s[i]!=b[i]:
    count+=1
if count==0: print("YES")
elif count==2: print("YES")
else: print("NO")

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

int main()
{
    deque<int>a;
    int q;
    cin>>q;
    REP(i,q)
    {
        int q1;
        cin>>q1;
        if(q1==0)
        {
            int d,x;
            cin>>d>>x;
            if(d==0)a.push_front(x);
            else if(d==1)a.push_back(x);
        }else if(q1==1)
        {
            int y;
            cin>>y;
            cout<<a.at(y)<<endl;
        }else if(q1==2)
        {
            int d2;
            cin>>d2;
            if(d2==0)a.pop_front();
            else if(d2==1)a.pop_back();
        }
    }
}


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

namespace ABC152_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var ans = 0;
            var cm = int.MaxValue;
            var list = new List<int>();

            for (int i = 0; i < n; i++)
            {
                if (cm >= p[i])
                {
                    ans++;
                    cm = p[i];
                }

            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 31964
#include <iostream>
#define MOD 1000000007
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}


int main(){
    int H,A;
    cin >> H >> A;
    H%A == 0 ? cout << H/A << endl : cout << H/A + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		int k = scanner.nextInt();
		int s = scanner.nextInt();
		int count = 0;
		for (int x = 0 ; x <= k ; x++) {
			for (int y = 0 ; y <= k ; y++) {
				int z = s - x- y;
				if (z >= 0 && z <=k) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
} 

Measured memory_bytes: 21844
#include <iostream>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <iomanip>
#include <deque>
#include <cmath>
#include <numeric>
using namespace std;

int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int uta, ta, tp;
	cin >> uta >> ta >> tp;
	cout << min(uta + ta + 1, tp) + ta << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    int a[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            a[i][j]=0;
        }
    }
    char s;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
           cin >> s;
           if(s=='#'){
               if(i-1>=0&&j-1>=0)a[i-1][j-1]++;
               if(i-1>=0)a[i-1][j]++;
               if(i-1>=0&&j+1<w)a[i-1][j+1]++;
               if(j-1>=0)a[i][j-1]++;
               a[i][j] = 100;
               if(j+1<w)a[i][j+1]++;
               if(i+1<h&&j-1>=0)a[i+1][j-1]++;
               if(i+1<h)a[i+1][j]++;
               if(i+1<h&&j+1<w)a[i+1][j+1]++;
           }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
           if(a[i][j]>=100){
               cout << '#';
           }else{
               cout << a[i][j];
           }
        }
        cout << endl;
    }
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
            var n = line[0];
            var m = line[1];
            var edges = new List<int[]>();
            for (var i = 0; i < m; i++)
            {
                line = ReadLine().Split(' ').Select(value => int.Parse(value) - 1).ToArray();
                edges.Add(line);
            }

            var count = 0;
            for (var i = 0; i < m; i++)
            {
                var parents = new int[n];
                for (var j = 0; j < n; j++)
                {
                    parents[j] = j;
                }

                for (var j = 0; j < m; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    var edge = edges[j];
                    Unite(parents, edge[0], edge[1]);
                }

                for(var j = 0; j < n; j++)
                {
                    GetRoot(parents, j);
                }

                if (!parents.All(value => value == parents[0]))
                {
                    count++;
                }
            }

            WriteLine(count);
        }

        private static int GetRoot(int[] parents, int node)
        {
            if (parents[node] == node)
            {
                return node;
            }
            return parents[node] = GetRoot(parents, parents[node]);
        }

        private static void Unite(int[] parents, int x, int y)
        {
            x = GetRoot(parents, x);
            y = GetRoot(parents, y);

            if (x == y)
            {
                return;
            }
            parents[x] = y;
        }
    }
}


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

using namespace std;

int main()
{
    int A,B;
    cin>>A>>B;
    if(A % 2 == 1 && B % 2== 1){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;

    }

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
#define ll long long
#define read(n) scanf("%d",&n)
#define f(i,a,b) for(int i=a;i<=b;++i)
#define N 200005
int num[N];
int main()
{
	int sum=0,n;
	cin>>n;
	f(i,1,n){
		cin>>num[i];
		sum^=num[i];
	}
	f(i,1,n) cout<<(sum^num[i])<<" ";
	return 0;
}

Measured memory_bytes: 4304
S = input()
if S == 'SSS':
   print(0)
elif S == 'RSS':
   print(1)
elif S == 'SRS':
   print(1)
elif S == 'SSR':
   print(1)
elif S == 'RSR':
   print(1)
elif S == 'RRS':
   print(2)
elif S == 'SRR':
   print(2)
else:
   print(3)

Measured memory_bytes: 9108
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll h; cin >> h;
	ll cnt = 0;
	while(h>0){
		h /= 2;
		cnt++;
	}
	cout << (1LL<<cnt)-1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main() {
	int n, m;
	string a[100], b[100];
	cin >> n >> m;
	bool score = false;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	for (int i = 0; i <= n - m; i++) {
		for (int j = 0; j <= n - m; j++) {
			bool tmpscore = true;
			for (int x = 0; x < m; x++) {
				for (int y = 0; y < m; y++) {
					if (a[i + x][j + y] == b[x][y]) {
						continue;
					}
					else tmpscore = false;
				}
			}
			if (tmpscore == true)score = true;
		}
	}
	if (score)print("Yes");
	else print("No");





	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,m,n;
int main() {
	cin>>a>>b>>c>>x;
	for(int i=0; i<=a; i++) {
		for(int j=0; j<=b; j++) {
			for(int v=0; v<=c; v++) {
				m=500*i+100*j+50*v;
				if(m==x)n++;
			}
		}
	}
	cout<<n;
	return 0;
}

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

int main(){
	int N;
	cin>>N;
	unsigned long T,A;
	cin>>T>>A;
	unsigned long tmpT,tmpA;
	unsigned long baiT,baiA;
	for(int i=1;i<N;++i){
		cin>>tmpT>>tmpA;
		if(T%tmpT==0)baiT=T/tmpT;
		else baiT=T/tmpT+1;
		if(A%tmpA==0)baiA=A/tmpA;
		else baiA=A/tmpA+1;
		T=tmpT*max(baiT,baiA);
		A=tmpA*max(baiT,baiA);
	}
	cout<<T+A<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type work struct{ time, limit int }
type works []work

func (w works) Len() int           { return len(w) }
func (w works) Swap(i, j int)      { w[i], w[j] = w[j], w[i] }
func (w works) Less(i, j int) bool { return w[i].limit < w[j].limit }

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

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var ws works = make([]work, n)
	for i := range ws {
		sc.Scan()
		ws[i].time, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		ws[i].limit, _ = strconv.Atoi(sc.Text())
	}

	sort.Sort(ws)
	sum := int64(0)
	for _, w := range ws {
		sum += int64(w.time)
		if sum > int64(w.limit) {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define y1 nibab

int n,m,dp1[2005][2005],dp2[2005][2005],dp3[2005][2005],q,x1,x2,y1,y2;

char a[2005][2005];

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n >> m >> q;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> a[i][j];
            dp1[i][j]=dp1[i-1][j]+dp1[i][j-1]-dp1[i-1][j-1]+(int)(a[i][j]=='1');
            dp2[i][j]=dp2[i-1][j]+dp2[i][j-1]-dp2[i-1][j-1]+(int)(a[i][j]=='1' && a[i][j-1]=='1');
            dp3[i][j]=dp3[i-1][j]+dp3[i][j-1]-dp3[i-1][j-1]+(int)(a[i][j]=='1' && a[i-1][j]=='1');
        }
    }
    for(int i=1;i<=q;i++){
        cin >> x1 >> y1 >> x2 >> y2;
        cout << dp1[x2][y2]-dp1[x1-1][y2]-dp1[x2][y1-1]+dp1[x1-1][y1-1]-(dp2[x2][y2]-dp2[x1-1][y2]-dp2[x2][y1]+dp2[x1-1][y1])-(dp3[x2][y2]-dp3[x1][y2]-dp3[x2][y1-1]+dp3[x1][y1-1]) << '\n';
    }
}


Measured memory_bytes: 52864
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <atcoder/all>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

using namespace atcoder;

int main(){
    string s;
    cin >> s;
    int n=s.length();
    vector<int> sa=suffix_array(s);
    vector<int> lcp=lcp_array(s,sa);
    ll ans=n-sa[0];
    rep(i,n-1){
        ans+=n-sa[i+1]-lcp[i];
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

typedef pair<ll, ll> P;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < int(s.size()); i++) cout << "x";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 const int maxn=100005;
 int n,m,u,v,res1,res2,col[maxn];
 vector<int> G[maxn];
 bool dfs(int u,int c) {
    col[u]=c;
    for (int i=0;i<(int)G[u].size();++i) {
        int v=G[u][i];
        if (!col[v]) {
            if (!dfs(v,3-c))
                return false;
        } else if (col[v]==col[u])
            return false;
    }
    return true;
 }
 int main()
 {
     scanf("%d%d",&n,&m);
     for (int i=0;i<m;++i) {
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
     }
     if (dfs(1,1)) {
        for (int i=1;i<=n;++i)
            (col[i]==1)?++res1:++res2;
        printf("%lld\n",1LL*res1*res2-m);
     } else
        printf("%lld\n",1LL*n*(n-1)/2-m);
     return 0;
 }


Measured memory_bytes: 6656
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    public static void Main()
    {
        int n = ReadInt();
        int c = 0;
        for (int i = 0; i < n; i++)
        {
            if (Read() == Read()) c++;
            else c = 0;
            if (c == 3)
            {
                Console.WriteLine("Yes");
                return;
            }
        }
        Console.WriteLine("No");
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
    public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse);
}


Measured memory_bytes: 28336
#include<cstdio>
#include<algorithm> 
using namespace std;
int q,k0,k1,n,ans;
int a[3][200010],b0[200010],b1[200010];
int cmp0(int x,int y) {
	return a[0][x]>a[0][y];
}
int cmp1(int x,int y) {
	return a[1][x]>a[1][y];
}
int main() {
	scanf("%d",&n);
	q=-2019201920;
	for (int i=1; i<=n; i++) {
		int m;
		scanf("%d",&m);
		a[i%2][m]=a[i%2][m]+1;
		if (m>q) q=m;
	}	
	for (int i=1; i<=q; i++) if (a[1][i]!=0) k1=k1+1,b1[k1]=i;
	for (int i=1; i<=q; i++) if (a[0][i]!=0) k0=k0+1,b0[k0]=i;
	sort(b0+1,b0+1+k0,cmp0);
	sort(b1+1,b1+1+k1,cmp1);
	k0=k0+1;b0[k0]=0;k1=k1+1;b1[k1]=0;ans=2019201920;
	for (int i=1; i<=k0; i++)
		for (int j=1; j<=k1; j++)
			if (b0[i]!=b1[j]) {
				ans=min(ans,n/2-a[0][b0[i]]+n/2-a[1][b1[j]]);
				break;				
			}
	for (int i=1; i<=k1; i++)
		for (int j=1; j<=k0; j++)
			if (b1[i]!=b0[j]) {
				ans=min(ans,n/2-a[1][b1[i]]+n/2-a[0][b0[j]]);
				break;				
			}
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 1280
r,c=map(int,input().split())
tbl=[[0]*c for i in range(r+1)]
for i in range(r):
    tbl[i]=list(map(int,input().split()))
for i in range(c):
    for j in range(r):
        tbl[r][i] +=tbl[j][i]
for i in range(r+1):
    m=0
    for j in range(c):
        m += tbl[i][j]
        print(tbl[i][j],end=" ")
    print(m)


Measured memory_bytes: 6220
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

LL mod = 1000000007;

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

  LL N;
  cin >> N;

  double sum = 0;

  REP(i,N){
    double x;
    string u;
    cin >> x >> u;
    if(u[0]=='J'){
      sum += x;
    }else{
      sum += x * 380000;
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 256