akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::*;
use std::ops::*;
use std::*;

// -----------------------------------------------
// Framework
// -----------------------------------------------

#[allow(unused)]
fn rl() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused)]
fn rw<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|word| T::from_str(word).unwrap())
        .collect()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

#[allow(unused)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        {
            let entries = &[
                $((
                    &stringify!($arg).to_string() as &fmt::Debug,
                    &($arg) as &fmt::Debug,
                )),*
            ];
            eprintln!("{:?}", DebugMap(entries));
        }
    };
}

#[allow(unused)]
struct DebugMap<'a>(&'a [(&'a fmt::Debug, &'a fmt::Debug)]);

impl<'a> std::fmt::Debug for DebugMap<'a> {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        let mut m = fmt.debug_map();
        for &(key, value) in self.0.iter() {
            m.entry(key, value);
        }
        m.finish()
    }
}

// -----------------------------------------------
// Polyfill
// -----------------------------------------------

#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

#[allow(unused)]
macro_rules! eprintln {
    ($($arg:expr),*) => { _eprintln(format_args!($($arg),*)) }
}

fn _eprintln(args: fmt::Arguments) {
    let err = std::io::stderr();
    let mut err = err.lock();
    err.write_fmt(args).unwrap();
    err.write(b"\n").unwrap();
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn g(mut n: i32) -> i32 {
    let mut sum = 0;
    while n > 0 {
        sum += n % 10;
        n /= 10;
    }
    sum
}

pub fn main() {
    let n = rl().parse::<i32>().unwrap();
    let mut min_f = std::i32::MAX;
    for a in 1..n {
        let b = n - a;
        min_f = min(min_f, g(a) + g(b));
    }
    println!("{}", min_f);
    return;
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_ok() {
        assert_eq!(7, 1 + 2 * 3);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<list>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;



int main() {
   int n;
   cin >> n;
   vector<PII> a(n);
   for (int i = 0; i < n; i++)
   {
	  a[i].second = i+1;
	  cin >> a[i].first;
   }
   sort(a.begin(), a.end());
   for (int i = 0; i < n; i++)
   {
	  cout << a[i].second << endl;
   }
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m, tmp;
    map<int, int> mp;
    
    cin >> n;
    rep(n){
        cin >> tmp;
        mp[tmp]++;
    }
    cin >> m;
    rep(m){
        cin >> tmp;
        if(mp[tmp] > 0) mp[tmp]--;
        else{
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>

typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
	ld W, H, x, y, ans = 1;
	cin >> W >> H >> x >> y;
	ld curr = 0;
	ld area = W * H / 2;
	cout << area << " ";
	if (W / 2 == x && H / 2 == y) printf("1");
	else printf("0");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repf(i, j, n) for (int i = (j); i < (n); i++)
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  s.push_back(s[0]);
  vector<int> a(n + 2, 0);
  rep(i, 4) {
    a[0] = i &1, a[1] = (i>>1)&1;
    rep(j, n) { a[j + 2] = a[j] ^ a[j + 1] ^ (s[j + 1] == 'x'); }

    if (a[n] == a[0] && a[n + 1] == a[1]) {
      string t = "";
      rep(k, n) { t.push_back("SW"[a[k]]); }
      cout << t << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 1024
from operator import add
n,m,x=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]

ans=float('inf')
for i in range(2**n):
  c=0
  s=[0]*m
  for b in range(n):
    if i>>b&1:
      c+=l[b][0]
      for j in range(m):
        s[j]+=l[b][j+1]
  if all([e>=x for e in s]):
    ans=min(ans,c)
if ans==float('inf'):
  ans=-1
print(ans)

Measured memory_bytes: 69224
import java.io.*;
import java.util.*;

public class Main {

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

        new Main().go();
    }

    PrintWriter out;
    Reader in;
    BufferedReader br;

    Main() throws IOException {

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }
    }

    void go() throws IOException {

        int t = 1;
        while (t > 0) {
            solve();
            //out.println();
            t--;
        }

        out.flush();
        out.close();
    }

    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.00000001;

    int n;
    int m;

    //ArrayList<Pair>[] g = new ArrayList[2000000];

    void solve() throws IOException {

        int q = in.nextInt();
        int h = in.nextInt();
        int s = in.nextInt();
        int d = in.nextInt();

        h = Math.min(h, 2*q);
        s = Math.min(s, 2*h);
        d = Math.min(d, 2*s);

        int n = in.nextInt();

        long ans = 1l*n/2 * d;
        if (n%2 > 0)
            ans += s;

        out.println(ans);
    }

    class Pair implements Comparable<Pair>{

        int a;
        int b;

        Pair(int a, int b) {

            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair p) {

            if (a > p.a) return 1;
            if (a < p.a) return -1;
            if (b > p.b) return 1;
            if (b < p.b) return -1;
            return 0;
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }


        String nextLine() throws IOException {
            return br.readLine();
        }

    }

}

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

//Pair of Primes
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[] p = new boolean[10002];
		Arrays.fill(p, true);
		p[0] = p[1] = false;
		for(int i=2;i<=10001;i++){
			if(p[i]){
				for(int j=i*2;j<=10001;j+=i)p[j]=false;
			}
		}
		while(sc.hasNext()){
			int n = sc.nextInt();
			int c = 0;
			for(int i=1;i<=n;i++)if(p[i]&&p[n+1-i])c++;
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 13000
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define repr(i, a, n) for (ll i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;

void Main() {
  string s, t;
  cin >> s >> t;
  sort(all(s));
  sort(all(t));
  reverse(all(t));
  if (s < t)
    puts("Yes");
  else
    puts("No");
}

int main() {
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // CとC++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15);  // 小数を10進数表示
  Main();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
using namespace std;
 
int main(){
    
    double N,K,A[100000]={},B[100000]={},score,tmp=0,Am=0,deno=1,nume=0;


    cin >> N>>K;

    for(int i=1;i<=N;i++){
        score = i;
        tmp = 0;

            while(score<=(K-1)){
                score = score * 2;
                tmp += 1;
            }
        
        A[i] = tmp;
        if(Am<tmp){
            Am = tmp;
        }

    }

    for(int i=1;i<=N;i++){
        B[i] = Am - A[i];
        if(B[i]==0){
            nume +=1;
        }else{
            tmp =1;
            while(B[i]!=0){
                tmp = tmp * 2;
                B[i]-=1;
            }
            nume += tmp;
        }
    }

    deno = 1;

    for(int i=1;i<=Am;i++){
        deno = deno * 2;
    }

    deno = deno * N;

    printf("%.10f\n",nume/deno);

    return 0;

}

Measured memory_bytes: 1024
unittest
{
//	assert( [ "5 3" ].parse.expand.solve == "5\n4 3\n1 2\n3 1\n4 5\n2 3" );
	assert( [ "5 8" ].parse.expand.solve == "-1" );
}



import std.algorithm;
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[] );
	return tuple( nk[ 0 ], nk[ 1 ] );
}

auto solve( long n, long k )
{
	// 最短距離が 2 であるような頂点対の個数の上限を計算
	auto m = ( n - 1 ) * ( n - 2 ) / 2;
	if( m < k ) return "-1";
	
	// うにグラフを作成（頂点対の個数が上限になる）
	auto anss = new long[ 2 ][ n - 1 ];
	foreach( i, ref ans; anss )
	{
		ans = [ i + 1, n ];
	}
	
	// うにグラフの外側の頂点同士を辺で結ぶ（頂点対の個数が1個減る）
	for( auto f = 1L; f < n - 1 && k < m; f++ )
	{
		for( auto t = f + 1; t < n && k < m; t++ )
		{
			anss ~= [ f, t ];
			m--;
		}
	}
	
	return anss.length.to!string ~ "\n" ~ anss.map!( ( ans ) => ans.to!( string[] ).join( " " ) ).join( "\n" );
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  vec< int > x(4, 0);
  vec< int > y(4, 0);
  cin >> x[0] >> y[0] >> x[1] >> y[1];
  int dx = x[1] - x[0];
  int dy = y[1] - y[0];
  x[2] = x[1] - dy;
  y[2] = y[1] + dx;
  x[3] = x[2] - dx;
  y[3] = y[2] - dy;
  cout << x[2] << " " << y[2] << " ";
  cout << x[3] << " " << y[3] << "\n";

  // print();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    ll c[10][10]={};
    REP(i,N){
        string s=to_string(i+1);
        c[s[0]-'0'][s.back()-'0']++;
    }
    ll ans=0;
    REP(i,10) REP(j,10){
        ans+=c[i][j]*c[j][i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>
 
using namespace std;
 
 
int main(){
	int R;
	cin >> R;
    if(R<1200){
        cout << "ABC";
    }else if(R<2800){
        cout << "ARC";
    }else{
        cout << "AGC";
    }
	return 0;
}


Measured memory_bytes: 256
import sys 
S = input()
A = []
for i,s in enumerate(S):
    if s != 'x':  A.append(i)
if not A:
    print(0)
    sys.exit()
for i in range(len(A)//2):
    if S[A[i]] != S[A[-i-1]]:
        print(-1)
        sys.exit()
ans = abs((len(S)-1-A[-1])-A[0])
for i in range(len(A)//2):
    cnt = abs(A[i+1]-A[i] - (A[-1-i]-A[-2-i]))
    ans += cnt
print(ans)


Measured memory_bytes: 12620
#ABC-140-C
N = int(input())
B = list(map(int, input().split()))

max_A = [None] * N

max_A[0] = B[0]
max_A[-1] = B[-1]

for i in range(1, N-1):
    #例:max_A[1] = min(B[0], B[1])
    max_A[i] = min(B[i-1], B[i])

print(sum(max_A))

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

using namespace std;

struct Patient {
	int name;
	int d[3];
};

bool compare(Patient i, Patient j) {
	return (i.d[2] < j.d[2]);
}

int main() {
	
	int n;

	while (cin >> n && n != 0) {

		Patient *patient = new Patient[n];

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

			cin >> patient[i].name >> patient[i].d[0] >> patient[i].d[1];
			patient[i].d[2] = patient[i].d[0] + patient[i].d[1];

		}

		sort(patient, patient + n, compare);

		cout << patient[n - 1].name << " " << patient[n - 1].d[2] << "\n";
		delete patient;
		patient = NULL;
		
	}

	return 0;

}







Measured memory_bytes: 3304
/*BISMILLAH*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,i,j,k;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
        ll cnt=0;
    for(i=0;i<n-2;i++)
        for(j=i+1;j<n-1;j++)
           for(k=j+1;k<n;k++)
           if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&max(a[i],max(a[j],a[k]))<(a[i]+a[j]+a[k]-max(a[i],max(a[j],a[k]))))
           cnt++;
    cout<<cnt;
}


Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////



int main() {
	ll N, K;
	cin >> N >> K;

	if (2 * K > N + 1) { cout << -1; }
	else {


		if (N % 2 == 1) {
			ll m = N / 2;

			repn(i, m+1) {
				cout << K + i - 1 << " " << K + 3 * m + i << " " << K + 4 * m + 2 * i << endl;
			}

			repn(i, m) {
				cout << K + m + i << " " << K + 2 * m + i << " " << K + 4 * m + 2 * i + 1 << endl;
			}
		}

		else {
			ll m = N / 2;
			repn(i, m) {
				cout << K + i - 1 << " " << K + 3 * m + i - 1 << " " << K + 4 * m + 2 * i - 2 << endl;
				cout << K + m + i - 1 << " " << K + 2 * m + i - 1 << " " << K + 4 * m + 2 * i - 1 << endl;
			}
		}
	}
	
	system("PAUSE");
}


Measured memory_bytes: 2432
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		int result = (int)floor(n/1.08);
		int a = result;
		int b = result + 1;
		int c = (int)floor(a * 1.08);
		int d = (int)floor(b * 1.08);
		if(c == n){
		    result = a;
		}else if(d == n){
		    result = b;
		}else{
		    System.out.println(":(");
		    return;
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.1415926536
struct Point
{
    int x;
    int y;
};
inline double dist(Point a, Point b)
{
    return sqrt( pow(a.x - b.x , 2) + pow(a.y - b.y, 2) );
}
Point point[200005];
Point st[200005];
void getExtremePoint(int n)///at index 0
{
    int pos = 0;
    for(int i=1; i<n; i++){
        if(point[i].y < point[pos].y || (point[i].y == point[pos].y && point[i].x < point[pos].x))
            pos = i;
    }
    swap(point[0], point[pos]);
}
inline int triArea(Point p1, Point p2, Point p3)
{
    ll area = 1LL*p1.x*(p2.y - p3.y) + 1LL*p2.x*(p3.y - p1.y) + 1LL*p3.x*(p1.y - p2.y);
    if(area==0) return area;
    else return area/llabs(area);
}
inline bool comp(Point p1, Point p2)
{
    int tri = triArea(point[0],p1,p2);
    if(tri<0) return false;
    if(tri==0 && dist(point[0], p1) > dist(point[0], p2)) return false;
    return true;
}
bool comp2(Point p1, Point p2)
{
	if(p1.x==p2.x) 
		return p1.y<p2.y;
	return p1.x<p2.x;
}
int id;
void genConvexPoints(int n)
{
    getExtremePoint(n);
    sort(point+1, point+n, comp);
    id = 0;
    for(int i=0; i<3 && i<n; i++)
        st[id++] = point[i];
    for(int i = 3; i<n; i++){
        while(triArea(st[id-2], st[id-1], point[i]) <= 0 && id>=2)
            id--;
        st[id++] = point[i];
    }
}
int main()
{
    int tc,cs=1,n,d;
    tc = 1;
    while(tc--){
    	set< pair<int, int> >mp;
        scanf("%d",&n);
        int idx = 0;
        for(int i=0; i<n; i++){
            scanf("%d%d",&point[i].x,&point[i].y);
            mp.insert( make_pair(point[i].x,point[i].y));
            if(mp.size() > idx )
            	point[idx++] = point[i];
        }
        n = idx;
        genConvexPoints(n);
        int ans = 0;
        for(int i=0; i<id; i++){
        	//cout<<i<<" ->> "<<st[i].x<<" "<<st[i].y<<endl;
        	for(int j=i+1; j<id; j++){
        		ans = max(ans, abs(st[i].x-st[j].x) + abs(st[i].y - st[j].y  ));
        	}
        }
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 14780
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,m;
int a[100005];
struct SegTree{
	#define SIZE 131072
	int f[SIZE<<1]={},lazy[SIZE<<1]={};
	inline int func(int x,int y){return x<y?x:y;}
	void set(int pos,int v){
		pos+=SIZE-1;
		f[pos]=v;
		while(pos){
			pos=pos-1>>1;
			f[pos]=func(f[pos+pos+1],f[pos+pos+2]);
		}
	}
	int query(int l,int r,int l1=0,int r1=SIZE-1,int k=0){
		if(l<=l1&&r1<=r)return f[k]+lazy[k];
		if(r<l1||r1<l)return (ll)1e18;
		lazy[k+k+1]+=lazy[k];lazy[k+k+2]+=lazy[k];lazy[k]=0;
		int mid=l1+r1>>1;
		int vl=query(l,r,l1,mid,k+k+1);
		int vr=query(l,r,mid+1,r1,k+k+2);
		f[k]=func(f[k+k+1]+lazy[k+k+1],f[k+k+2]+lazy[k+k+2]);
		return func(vl,vr);
	}
	void add(int l,int r,int v,int l1=0,int r1=SIZE-1,int k=0){
		if(l<=l1&&r1<=r){
			lazy[k]+=v;
			return;
		}
		if(l1>r||r1<l)return;
		lazy[k+k+1]+=lazy[k];lazy[k+k+2]+=lazy[k];lazy[k]=0;
		int mid=l1+r1>>1;
		add(l,r,v,l1,mid,k+k+1);
		add(l,r,v,mid+1,r1,k+k+2);
		f[k]=func(f[k+k+1]+lazy[k+k+1],f[k+k+2]+lazy[k+k+2]);
		return;
	}
}dif;
ll cf[100005];
signed main(){
//	freopen("input.cpp","r",stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++)dif.set(i,0);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<n;i++){
		if(a[i+1]>a[i]){
			dif.add(a[i]+2,a[i+1],1);
			dif.add(a[i+1]+1,a[i+1]+1,-(a[i+1]-a[i]-1));
		}else{
			//a[i+1]<a[i]
			if(a[i]<m-1)dif.add(a[i]+2,m,1);
			int len=m-a[i]-1;
			if(a[i]<m-1)dif.add(0,0,len);
			dif.add(1+(a[i]==m),a[i+1],1);
			int tmp=a[i+1]+(m-a[i]);
			dif.add(a[i+1]+1,a[i+1]+1,-(tmp-1));
		}
	}
	for(int i=0;i<=m;i++){
		cf[i]=dif.query(i,i);
	}
	for(int i=1;i<=m;i++)cf[i]+=cf[i-1];
///	for(int i=1;i<=m;i++)cerr<<i<<" "<<cf[i]<<endl;
	int pos,ans=-inf;
	for(int i=1;i<=m;i++){
		if(cf[i]>ans){
			ans=cf[i];
			pos=i;
		}
	}
	int Ans=0;
	for(int i=1;i<n;i++){
		Ans+=(a[i]<a[i+1]?a[i+1]-a[i]:(m-a[i])+a[i+1]);
	}
//	cerr<<Ans<<" "<<ans<<endl;
	cout<<Ans-ans<<endl;
	return 0;
}

Measured memory_bytes: 5504
n = int(input())
AB = [list(map(int,input().split())) for _ in range(n)]
AB.sort(key=lambda x: x[1])
# print(AB)
now = 0
ok = True
for necessary, deadline in AB:
    # print(now)
    # print(necessary, deadline)
    if now + necessary > deadline:
        ok = False
        break
    now += necessary

print("Yes" if ok else "No")


Measured memory_bytes: 53716
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const ll MAX_PRIME = 1e6+100;
ll N, P;
bool prime[MAX_PRIME];

void init_prime(ll p) {
  memset(prime, true, sizeof(prime));

  for (ll i = 2; i*i <= p; ++i) {
    if (prime[i] == true) {
      for (ll j = 2; i*j*i*j <= p; ++j) {
        prime[i*j] = false;
      }
    }
  }
}

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

  cin >> N >> P;

  if (N == 1) {
    cout << P << endl;
    return 0;
  }

  init_prime(P);


  ll ans = 1;
  for (ll i = 2; i*i <= P; ++i) {
    if (prime[i] && P%i == 0) {
      ll tmp = 0;
      while (P%i == 0) {
        P /= i;
        ++tmp;
      }

      while (tmp/N > 0) {
        ans *= i;
        tmp -= N;
      }
    }
  }

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


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k=0;
	char b[16];
	string a="CODEFESTIVAL2016";
	for(int i=0;i<16;i++)
	{
		cin>>b[i];
		if(a[i]!=b[i])k++;
	}
	cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(20000000)
#input = sys.stdin.readline
s = input()
k = int(input())
ans = []
for i in range(len(s)-1):
    if s[i] == "a":
        ans.append("a")
        continue
    if ord("z")+1 - ord(s[i]) <= k:
        ans.append("a")
        k -= ord("z")+1 - ord(s[i])
    else:
        ans.append(s[i])
ans.append(chr((ord(s[-1])+k - ord("a"))%26+ord("a")))
print("".join(ans))

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

int main() {
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int c[h][w];
    int p, q;
    p = q = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < a[i]; j++) {
            c[p][q] = i + 1;
            if (p % 2 == 0) {
                if (q == w - 1) p++;
                else q++;
            } else {
                if (q == 0) p++;
                else q--;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << c[i][j];
            if (j < w - 1) cout << " ";
            else cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll x,y;
  cin >> x >> y;
  cout << x+y/2 << endl;
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 3532
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();        
        int N = r.i();
        int[] TA = r.ii();
        int T = TA[0],
            A = TA[1];
        int[] H = r.ii();
        double min = Integer.MAX_VALUE;
        int minI = 0;
        for(int i = 0; i < N; i++){
            double dH = Math.abs(T-H[i]*0.006-A);
            if(dH < min){
                min = dH;
                minI = i+1;
            }
        }
        print(minI);
    }
    static void print(Object o){
        System.out.println(o.toString());
    }
    static void print(boolean b, String s1, String s2){
        System.out.println(b ? s1 : s2);
    }
    static int max(int[] ii){
        int max = ii[0];
        for(int i : ii) if(max < i) max = i;
        return max;
    }
    static int min(int[] ii){
        int min = ii[0];
        for(int i : ii) if(i < min) min = i;
        return min;
    }
    static long max(long[] ll){
        long max = ll[0];
        for(long l : ll) if(max < l) max = l;     
        return max;
    }
    static long min(long[] ll){
        long min = ll[0];
        for(long l : ll) if(l < min) min = l;
        return min;
    }
    static double max(double[] dd){
        double max = dd[0];
        for(double d : dd) if(max < d) max = d;
        return max;
    }
    static double min(double[] dd){
        double min = dd[0];
        for(double d : dd) if(d < min) min = d;
        return min;
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return readLine().split(" ");
        }
        int i() throws IOException{
            return Integer.parseInt(readLine());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        int[] ii(int N) throws IOException{
            int[] ii = new int[N];
            for(int j = 0; j < N; j++) ii[j] = i();
            return ii;
        }
        long l() throws IOException{
            return Long.parseLong(readLine());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
        long[] ll(int N) throws IOException{
            long[] ll = new long[N];
            for(int j = 0; j < N; j++) ll[j] = i();            
            return ll;
        }
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

using ll = long long;
using namespace std;
using P = pair<int,int>;
ll mod=1e9+7;

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;
  cin>>N;
  if (N>=1000){
    cout << "ABD" << endl;
  }else{
    cout << "ABC" << endl;
  }
}


Measured memory_bytes: 256
N, K = map(int, input().split())
*A, = map(int, input().split())
for k in range(41):
    B = [0] * N
    for i, a in enumerate(A):
        l = max(0, i - a)
        r = min(N - 1, i + a)
        B[l] += 1
        if r + 1 < N: B[r + 1] -= 1
    for i in range(1, N): B[i] += B[i-1]
    A = B
    if k == K - 1: break
print(*A)

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    int N, K;
    cin >> N >> K;

    int ans = inf;
    rep(b, 1 << N) {
        int sum = 1;
        rep(i, N) {
            if ((b >> i) & 1) {
                sum += K;
            } else {
                sum *= 2;
            }
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

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

#define ff first
#define ss second
#define all(abcc) (abcc).begin(), (abcc).end()
#define endl '\n'
#define left aba
#define right abc

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N=(int)(1e5)+2;

int n;

int h[N], dp[N];

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

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

    dp[1]=abs(h[1]-h[0]);
    for(int i=2; i<n; ++i) {
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
    }

    cout<<dp[n-1]<<endl;

    //cerr<<"Time: "<<(double)clock()/CLOCKS_PER_SEC<<"s"<<'\n';
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.io.*;


public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
		String str[] = br.readLine().split(" ");
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0) {
		    System.out.println("Possible");
		}
		else {
		    System.out.println("Impossible");
		}
	}
}


Measured memory_bytes: 22484
#include<iostream>

using namespace std;
#define repeat(i,n) for(int i=0;i<(n);i++)

int main(){

  string a, b; cin>> a>> b;

  if(a.size()>b.size()) cout<< "GREATER"<< endl;
  else if(a.size()<b.size()) cout<< "LESS"<< endl;
  else{
    if(a>b) cout<< "GREATER"<< endl;
    else if(a<b) cout<< "LESS"<< endl;
    else cout<< "EQUAL"<< endl;
  }
  return 0;
}


Measured memory_bytes: 256
x,y = map(int,input().split())

a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]

if x in a:
    X = 1
elif x in b:
    X = 2

else:
    X = 3
    
if y in a:
    Y = 1
elif y in b:
    Y = 2

else:
    Y = 3

if X == Y:
    print('Yes')

else:
    print('No')

Measured memory_bytes: 3064
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define repd(i,x,y) for(int i=x; i>=y; --i)
#define mid (l+r>>1)

using namespace std;
const int N=200005,mod=1000000007;
typedef long long LL;
int n;
LL inv100,A,B,C,ans;
LL invAB,invC,invB,invA;
LL flv[N],inv[N];

LL _C(int n,int m) {return flv[n]*inv[m]%mod*inv[n-m]%mod;}

LL getmi(LL a,LL x)
{
	LL rt=1;
	while(x)
	{
		if(x&1) rt=rt*a%mod;
		a=a*a%mod,x>>=1;
	}
	return rt;
}

int main()
{
	scanf("%d%lld%lld%lld",&n,&A,&B,&C);
	inv100=getmi(100,mod-2);
	A=A*inv100%mod;
	B=B*inv100%mod;
	C=C*inv100%mod;
	if(!A) return printf("%lld\n",getmi(B,mod-2)*n%mod),0;
	if(!B) return printf("%lld\n",getmi(A,mod-2)*n%mod),0;
	A=A*getmi(1-C+mod,mod-2)%mod;
	B=B*getmi(1-C+mod,mod-2)%mod;
	invC=getmi(1-C+mod,mod-2);
	flv[0]=inv[0]=1;
	rep(i,1,2*n) flv[i]=flv[i-1]*i%mod,inv[i]=getmi(flv[i],mod-2);
	rep(i,0,n-1)
		ans=(ans+_C(n-1+i,i)*invC%mod*(n+i)%mod*getmi(A,n)%mod*getmi(B,i))%mod;
	rep(i,0,n-1)
		ans=(ans+_C(n-1+i,i)*invC%mod*(n+i)%mod*getmi(A,i)%mod*getmi(B,n))%mod;
	printf("%lld\n",(ans%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <stdio.h>
using namespace std;
main(){
  int N;
  cin>>N;
  int P[N];
  int Q[N];
  int p,q;
  for(int i=0;i<N;i++){
    cin>>p;
    P[i]=p;
  }
  for(int i=0;i<N;i++){
    cin>>p;
    Q[i]=p;
  }
  for(int i=0;i<N;i++){
    P[i]=P[i]-1;
    Q[i]=Q[i]-1;
  }
  for(int i=0;i<N;i++){
    p=P[i];
    for(int j=i+1;j<N;j++){
      if(P[j]>p)P[j]=P[j]-1;
    }
    q=Q[i];
    for(int j=i+1;j<N;j++){
      if(Q[j]>q)Q[j]=Q[j]-1;
    }
  }
  int pl=0,ql=0;
  for(int i=0;i<N-1;i++){
    pl=(pl+P[i])*(N-1-i);
    ql=(ql+Q[i])*(N-1-i);
  }
  if(pl>ql)cout<<pl-ql;
  else cout<<ql-pl;   
}

Measured memory_bytes: 384
#include <stdio.h>
 
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
 
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}
 
void skip(int k) { while (k--) gc(); }
 
void out(int n)
{
	int i;
	char ob[20];
 
	if (!n) { pc('0'); return; }
	i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
	while (i--) pc(ob[i]); 
}
 
int que[1500005]; int top, end;
 
int main()
{
	int n, i, t;
	char op;
 
	n = in(); top = 0, end = 1;
	while (n--) {
		if (gc() == 'i') {
			skip(6);
			que[end++] = in();
		} else {
			skip(5);
			op = gc();
			if (op == 'L') {
				skip(4);
				top++;
			} else if (op == 'F') {
				skip(5);
				end--;
			} else {
				que[top] = t = in();
				i = end; while (que[--i] != t);
				if (i > top) {
					if (end - i < i - top) {
						while (++i < end) que[i-1] = que[i];
						end--;
					} else {
						while (--i > top) que[i+1] = que[i];
						top++;
					}
				}
			}
		}
	}
	i = end-1; out(que[i--]);
	while (i > top) pc(' '), out(que[i--]);
	pc('\n');
	return 0;
}


Measured memory_bytes: 5416
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
using namespace std;

#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";

void sout(string* a, string* b) {
	if (*a > * b) {
		string c = *a;
		*a = *b;
		*b = c;
	}
}

int combination(int n, int k) {
	if (n > k && k > 0) {
		return (combination(n - 1, k) + combination(n - 1, k - 1));
	}
	else
		return 1;
}

int main() {
	long long int n, ans;
	cin >> n;
	ans = (n * (n + 1)) / 2;
	ans -= n;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <map>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n,m;
    cin>>n>>m;    
    map<long long int,long long int> mp;
    long long int tmp;
    REP(i,n){
        scanf("%lld", &tmp);
        mp[tmp]++;
    }
/*
    for(auto x:mp){

        cout << x.first << " " << x.second << endl;
        
    }
  
    cout << endl;
  */
    vector<pair<long long int, long long int>> v(m);
    long long int b, c;
    REP(i,m){
        scanf("%lld %lld",&v[i].second,&v[i].first);
    }
    sort(v.begin(), v.end(), greater<pair<long long int, long long int>>());
    bool f = false;
    long long int eraser;
    REP(i,m){
        eraser = -1;
        c = v[i].first;
        b = v[i].second;
        f = false;
        for(auto x:mp){

            if(x.second){
                
                if(!f){
                    if(x.first>c){
                        goto END;
                    }else{
                        f = true;
                    }
                }

                if(x.first<c){

                    if(b<=x.second){
                        mp[x.first]-=b;
                        mp[c]+=b;
                        break;
                    }else{
                        tmp=x.second;
                        mp[x.first]-=tmp;
                        mp[c]+=tmp;
                        b-=tmp;
                    }                      
                }else{
                    break;
                }
            }else{
                mp.erase(eraser);
                eraser = x.first;
            }
            
        }
    }
/*
    for(auto x:mp){

        cout << x.first << " " << x.second << endl;
        
    }
  */
END:;
    long long int result=0;
    for(auto x:mp){
        result+=x.first*x.second;
    }

    cout<<result<<endl;


    return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    ll a[n+1],b[n];
    for(int i=0;i<n+1;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ll t=min(a[i],b[i]);
        ans+=t;
        b[i]-=t;
        t=min(a[i+1],b[i]);
        ans+=t;
        a[i+1]-=t;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはメントされる
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--) //ループ変数は1ずつデクリ
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--) //ループ変数は1ずつデクリ
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) ll(x.size())      // sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000

int main() {

    ll n;
    cin >> n;
    vector<ll> A(n);
    REP(i, n) { cin >> A.at(i); }

    set<int> s;
    REP(i, n) { s.insert(A[i]); }

    cout << s.size() << endl;
}


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

#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define mod (ll)(1e9+7)

//https://atcoder.jp/contests/abc155/tasks/abc155_c


int main(){
	unordered_map <string,int> m; 
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		string s;
		cin>>s;
		m[s]++;
	}
	int freq = -1;
	auto it = m.begin();
	while(it!=m.end()){
		if(freq<it->second){
			freq = it->second;
		}
		++it;
	}
	it=m.begin();
	vector <string> res;
	while(freq!=-1 && it!=m.end()){
		if(it->second==freq){
			res.push_back(it->first);
		}
		++it;
	}
	sort(res.begin(),res.end());
	for(int i=0;i<res.size();++i){
		cout<<res[i]<<"\n";
	}
	cout<<"\n";
	return 0;
}


Measured memory_bytes: 26692
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

typedef struct {
    int a, b;
    LL cost;

} Edge;

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

    int n, m;
    cin >> n >> m;
    Edge edge[SIZE];
    for( int i = 0; i < m; ++i ) {
        cin >> edge[i].a >> edge[i].b >> edge[i].cost;
        edge[i].cost = -edge[i].cost;

    }

    LL dist[SIZE];
    for( int i = 0; i < SIZE; ++i ) dist[i] = LINF;

    dist[1] = 0;
    for( int i = 0; i < n - 1; ++i ) {
        for( int j = 0; j < m; ++j ) {
            if( dist[edge[j].a] == LINF ) {
                continue;

            }

            if( dist[edge[j].b] > dist[edge[j].a] + edge[j].cost ) {
                dist[edge[j].b] = dist[edge[j].a] + edge[j].cost;

            }
        }
    }

    LL tmp = dist[n];

    bool negative[SIZE];
    for( int i = 0; i < SIZE; ++i ) negative[i] = false;

    for( int i = 0; i < n; ++i ) {
        for( int j = 0; j < m; ++j ) {
            if( dist[edge[j].a] == LINF ) continue;
            if( dist[edge[j].b] > dist[edge[j].a] + edge[j].cost ) {
                negative[edge[j].b] = true;
                dist[edge[j].b] = dist[edge[j].a] + edge[j].cost;

            }
        }
    }

    if( negative[n] ) {
        cout << "inf";

    } else {
        cout << -dist[n];

    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int n,q,f[100005],sum[100005];
char s[100005];
int main()
{
    scanf("%d%d",&n,&q);
    scanf("%s",s+1);
    for(int i=1;i<n;i++)
        if(s[i]=='A'&&s[i+1]=='C')
            f[i]++;
    for(int i=1;i<=n;i++)
        sum[i]=f[i]+sum[i-1];
    while(q--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        printf("%d\n",sum[r-1]-sum[l-1]);
    }
}


Measured memory_bytes: 1664
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    string s;
    cin >> s;
    const ll N = s.length();
    ll X1 = 1, X2 = 1;
    string s1, s2;
    s1.push_back(s[0]);
    for (int i=1;i<N;i++) {
        s2.push_back(s[i]);
        if (s1 != s2) {
            X1++;
            s1.clear();
            s1 = s2;
            s2.clear();
        }
    }

    s1.clear(); s2.clear();
    s1.push_back(s[0]);
    s1.push_back(s[1]);
    for (int i=2;i<N;i++) {
        s2.push_back(s[i]);
        if (s1 != s2) {
            X2++;
            s1.clear();
            s1 = s2;
            s2.clear();
        }
    }

    cout << max(X1,X2) << endl;

    return 0;
}


Measured memory_bytes: 640