akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Maybe
import Data.Ord
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  [n,m] <- getInts
  q <- getInt
  as <- getInts
  let goal = dropLastIncr $ lru m as
  -- print goal
  let g = S.fromList goal
  let rs = reverse $ filter (`S.member` g) as
  let result = (iterate (>>= dropGreedy goal) (Just rs)) !! n
  -- mapM_ print . take n $ iterate (>>= dropGreedy goal) (Just rs)
  putStrLn . yesNo $ isJust result

dropGreedy :: (Eq a) => [a] -> [a] -> Maybe [a]
dropGreedy [] xs = Just xs
dropGreedy _ [] = Nothing
dropGreedy (x:xs) (y:ys)
  | x == y  = dropGreedy xs ys
  | otherwise = (y :) <$> dropGreedy (x:xs) ys

lru m as = let
  lasts = accumArray min 1 (1,m) $ zip as [0,-1..]
  in  map snd . sort . map swap $ assocs lasts

dropLastIncr = reverse . foo . reverse  where
  foo xs = map snd . dropWhile (uncurry (>)) $ zip xs (tail xs)
 
type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "Yes"
yesNo False = "No"

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . unwords . map show

readLnList :: (Read a) => IO [a]
readLnList = map read . words <$> getLine


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 52092
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define REPEACH(i,k) for(auto& i:k)
#define FOR(a, b) for (ll i = a; i < b + 1; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template<class T>
inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
signed main(){
    int n;
    cin >> n;
    map<int,int> m1;
    map<int,int> m2;
    REP(i,n/2){
        int a,b;
        cin >> a >> b;
        m1[a]++;
        m2[b]++;
    }
    int amax=0;
    int amax_a;
    int asecond=0;
    int asecond_a;
    REPEACH(i,m1){
        if(i.second>amax){
            asecond=amax;
            asecond_a=amax_a;
            amax = i.second;
            amax_a = i.first;
        }
        else
        {
            if (i.second > asecond)
            {
                asecond = i.second;
                asecond_a = i.first;
            }
        }
    }
    int bmax = 0;
    int bmax_b;
    int bsecond = 0;
    int bsecond_b;
    REPEACH(i, m2)
    {
        if (i.second > bmax)
        {
            bsecond = bmax;
            bsecond_b = bmax_b;
            bmax = i.second;
            bmax_b = i.first;
        }
        else{
            if(i.second>bsecond){
                bsecond = i.second;
                bsecond_b = i.first;
            }
        }
    }
    int ans=0;
    if(amax_a==bmax_b){
        if(asecond+bmax>bsecond+amax){
            ans = asecond + bmax;
        }
        else{
            ans = amax + bsecond;
        }
    }
    else{
        ans = amax + bmax;
    }
    cout << n-ans << endl;
}

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

using namespace std;

vector<int> x;
vector<int> y;
bool dpx[8000][20000];
bool dpy[8000][20000];

int main() {
  string s;
  int X,Y;
  int xn = 0;
  int yn = 0;
  cin >> s;
  cin >> X >> Y;

  int i = 0;
  bool xy = true;
  while(i < s.size()) {
    int d = 0;
    while(i < s.size() && s[i] != 'T') {
      d++;
      i++;
    }
 
    if(xy) {
      // cout << "iji"<<d<<endl;
      x.push_back(d);
      xy = false;
      xn++;
    }
    else {
      // cout << d << endl;
      y.push_back(d);
      xy = true;
      yn++;
    }
    i++;
  }
  
  
  dpx[1][10000+x[0]] = true;

  for(int i = 1; i < x.size(); i++) {
    for(int j = 0; j < 20000; j++) {
      if(!dpx[i][j])continue;
      // cout <<"i = "<<i<<"   j = "<<j<<endl;
      dpx[i+1][j+x[i]] = dpx[i][j];
      dpx[i+1][j-x[i]] = dpx[i][j];
    }
  }

  dpy[0][10000] = true;

  for(int i = 0; i < y.size(); i++) {
    for(int j = 0; j < 20000; j++) {
      if(!dpy[i][j]) continue;
      dpy[i+1][j+y[i]] = dpy[i][j];
      dpy[i+1][j-y[i]] = dpy[i][j];
    }
  }

  if(dpx[xn][X+10000] && dpy[yn][Y+10000]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  int p[n];
  for (int i = 0; i < n; i++) cin >> p[i];
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    a[i] = (i + 1) * (n + 10);
    b[i] = (n - i) * (n + 10);
  }
  for (int i = 0; i < n; i++) {
    a[p[i] - 1] += i;
  }
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  cout << "\n";
  for (int i = 0; i < n; i++) cout << b[i] << " ";
  cout << "\n";
  return 0;
}

Measured memory_bytes: 896
package main

import "fmt"

func main() {
	// Code for B - Lucas Number
	var N int
	fmt.Scanf("%d", &N)
	L := make([]int, N+1)

	L[0] = 2
	L[1] = 1
	for i := 2; i <= N; i++ {
		L[i] = L[i-1] + L[i-2]

	}

	fmt.Println(L[N])

}


Measured memory_bytes: 1840
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){return (a%mod * b%mod)%mod;}
inline int power(int a,int b,int MOD){int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
     SPEED;
     int n;
     cin>>n;
     vi v(n+1);
     in1(v,n);
     int x1=0;
     FOR(i,1,n)
     {
     	  if(i&1)
     	  	x1+=v[i];
     	  else
     	  	x1-=v[i];
     }
     vi ans(n+1);
     ans[1]=x1;
     int previous=x1/2;
     FOR(i,1,n-1)
     {
            ans[i+1]=2*(v[i]-previous);
            previous=v[i]-previous;
     }
     FOR(i,1,n)
      cout<<ans[i]<<" ";
      cout<<endl;
     time();
     return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first;
#define se second;
#define print(x,y) (cout << (x) << (y))
#define inf INT_MAX
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
const int MOD = 1e9 + 7; //998244353;
bool isPal(string s){
    string rev = s;
    reverse(all(s));
    return s == rev;
}
int main(){
    boost;
    ld x;
    cin >> x;
   cout << fixed <<pow(x/3 , 3);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll p1=a*c,p2=b*c,p3=a*d,p4=b*d;
	ll res = max(p1,max(p2,max(p3,p4)));
	cout<<res<<"\n";
	
}

Measured memory_bytes: 3636
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
      xys: [(usize1,usize1 ); m],
    }
    let mut red = vec![false; n];
    red[0] = true;
    let mut balls = vec![1; n];

    for (x, y) in xys {
        balls[x] -= 1;
        balls[y] += 1;

        if red[x] {
            red[y] = true;
        }
        if balls[x] == 0 {
            red[x] = false;
        }
    }

    let mut ans = 0;
    for i in 0..n {
        if red[i] {
            ans += 1;
        }
    }
    puts!("{}\n", ans);
}


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

using namespace std;
using L = vector<long long>;
using A = vector<vector<long long>>;
#define sorted(vector) sort(vector.begin(),vector.end())
#define vmin(vector) *min_element(vector.begin(),vector.end())
#define vmax(vector) *max_element(vector.begin(),vector.end())
#define vsum(vector) accumulate(vector.begin(),vector.end(),0)
#define append(a) push_back(a)
#define int(a) stoi(a)
#define str(a) to_string(a)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())



int main(void) {
    int n;
    cin>>n;
    A a = vector<vector<long long>>(n,vector<long long>(2,0));
    for(int i=0  ;i<n  ;i++){
        cin>>a[i][0];
        a[i][1]=i;
    }
    sorted(a);
    for(int i=0  ;i<n  ;i++){
        cout<<a[i][1]+1<<" ";
    }

}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    while(1){
        cin >> n;
        if(n == 0) break;
        vector<int> a(n);
        rep(i, 0, n) cin >> a[i];
        sort(all(a));
        int ans = 0;
        rep(i, 0, n){
            ans += a[i] * (n - 1 - i);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3188
def gcm(a,b):
    if a < b:
        a,b = b,a
    while True:
        if a % b == 0:
            return b
        else:
            a,b = b,a % b

def lcm(a,b):
    g = gcm(a,b)
    return a*b//g;

N = int(input())
Data = []
for _ in range(N):
    Data.append(int(input()))
ans = Data[0]
for i in range(1,N):
    ans = lcm(ans,Data[i])
print(ans)


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

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

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main (String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    
    while ((A > 0) && (C > 0)){
      C -= B;
      if(C <= 0){
        break;
      }
      A -= D; 
    }
    
    if (C<=0){
      System.out.println("Yes");
    } else if (A<=0){
      System.out.println("No");
    }
  }
}
    
    

Measured memory_bytes: 35804
fun main(args: Array<String>) {
    var tmp = readLine()!!.split(" ").map { it.toInt() }
    var a = tmp[0]
    var b = tmp[1]
    var c = 1
    var count = 0
    while (c < b){
        c = c - 1 + a
        count++
    }
    println(count)
}


Measured memory_bytes: 37884
n = input()
l = len(n)
n = int(n)
ans = 0

if l%2 == 0:
    for i in range(l//2):
        ans = ans + 9*(10**(i*2))
else:
    ans = n - (10**(l - 1)) + 1
    for i in range(l//2):
        ans = ans + 9*(10**(i*2))

print(ans)

Measured memory_bytes: 3064
mod = 998244353
n,k = map(int,input().split())
c = [0 for _ in range(n+1)]
cs = [0 for _ in range(n+1)]
c[1] = 1
cs[1] = 1
csi = 1
lr = [(0,0) for _ in range(k)]
for i in range(k):
  li,ri = map(int,input().split())
  lr[i] = (li,ri)
for i in range(2,n+1):
  for lri in lr:
    l,r = lri
    if i-l > 0:
      c[i] = (c[i]+cs[i-l]-cs[max(0,i-r-1)])%mod
  csi = (c[i]+csi)%mod
  cs[i] = csi
print(c[n])

Measured memory_bytes: 94452
palindrome [] = True
palindrome [x] = True
palindrome (x:xs) = (x == last xs) && palindrome (init xs)

main = do
  s <- getLine
  let n = length s
  let s1 = (take ((n-1)`div`2) s)
      s2 = (drop ((n+3)`div`2-1) s)
  putStrLn $ if (palindrome s && palindrome s1 && palindrome s2) then "Yes" else "No"

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

public class Main {
    public static int distance(int x, int y){
    	return Math.abs(x-y);
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] spot = new int[N+2];
        
        spot[0]=0;
        spot[N+1]=0;
        for(int n=1;n<=N;n++) spot[n]=sc.nextInt();
        
        int normalCost = 0;
        for(int n=0;n<=N;n++) normalCost+=distance(spot[n],spot[n+1]);
        
        
        for(int i=1;i<=N;i++) System.out.println(normalCost-distance(spot[i-1],spot[i])-distance(spot[i],spot[i+1])+distance(spot[i-1],spot[i+1]));
    }
}

Measured memory_bytes: 64152
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
#ifdef DAIJOBU
#include "/home/v-o_o-v/deb.h"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif 

using namespace std;

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef long long lint;
typedef double ld;

const int maxn = 5e5 + 100;
vector<vector<int>> tree(maxn, vector<int>(26, 0));

void add(int in, int id, int del){
    while(in < maxn){
        // deb("inf loop");
        tree[in][id] += del;
        in += (in & -in);
    }
}

vi sum(int in){
    vi ret(26, 0);
    while(in){
        forn(i, 26)ret[i] += tree[in][i];
        in -= (in & -in);
    }
    return ret;
}

int rsum(int l, int r){
    vi R = sum(r);
    vi L = sum(l - 1);
    forn(i, 26)R[i] -= L[i];
    int ans = 0;
    forn(i, 26)if(R[i])ans++;
    return ans;
}

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    for1(i, s.size()){
        add(i, s[i - 1] - 'a', 1);
    }
    int q;
    cin >> q;
    while(q--){
        int op;
        cin >> op;
        if(op == 1){
            int pos;char c;
            cin >> pos >> c;
            // pos--;
            add(pos, s[pos - 1] - 'a', -1);
            add(pos, c - 'a', 1);
            s[pos - 1] = c;
        }else{
            int l, r;
            cin >> l >> r;
            cout << rsum(l, r) << '\n';
        }
    }
    return 0;
}
// Write Here


Measured memory_bytes: 67604
#include <math.h>

#include <cmath>
#include <iostream>
using namespace std;
int main() {
    int n, m;
    cin >> n;
    m = n / 10 * 10;
    m = n - m;
    if (m == 3) {
        cout << "bon" << endl;
    } else if (m == 0 || m == 1 || m == 6 || m == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
    return 0;
}

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

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

  int cnt = 0;

  for(int i = 1; i <= n; i++){
    string s = to_string(i);
    if(s.length() % 2 == 1){
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;

}


Measured memory_bytes: 256
N = int(input())
A = []
B = []
diff = []
tasu = []
tmp = []
for i in range(N):
    a,b = map(int,input().split())
    tmp.append((a+b, a, b))
    # A.append(a)
    # B.append(b)
    # diff.append(a-b)
    # tasu.append(a+b)

tmp = sorted(tmp, reverse=True)

Ta = 0
Ao = 0
for i in range(N):
    a = tmp[i][1]
    b = tmp[i][2]
    if i%2 == 0:
        Ta += a
    else:
        Ao += b
ans = Ta - Ao
print(ans)


Measured memory_bytes: 62516
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	static int INF=1000000007;
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//int a[]=new int[N];for(int i=0;i<N;i++) {}
		//Ae2+Be2=Ce2
		//StringBuffer str = new StringBuffer(hoge1);
		//for(int i=0;i<N;i++) {}
		
		
		StringBuffer S = new StringBuffer(sc.next());
		
		
		int A=Integer.parseInt(S.subSequence(0, 2).toString());
		int B=Integer.parseInt(S.subSequence(2,4).toString());
	
		if((A==0&&B==0)||(A>12&&B>12)||(A==0&&B>12)||(B==0&&A>12)) {
			p("NA");
		}else if(A>12||A==0) {
			p("YYMM");
		}else if(B>12||B==0) {
			p("MMYY");
		}
		else  if(A<=12&&B<=12) {
			p("AMBIGUOUS");
		}
	
	}
	
		
	
	
		
	
	public static long modPow(long g,long N) {
		long T=1;
		for(int i=0;i<N;i++) {
			T*=g;
			T%=mod;
		}
		return T;
	}
	
	public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
	}
	
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


Measured memory_bytes: 21844
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, vv[111111], ans;

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n; int i;
	for(i=1 ; i<=n ; i++) cin>>vv[i];
	for(i=0 ; i<=n ; i++) ans+=abs(vv[i]-vv[i+1]);
	for(i=1 ; i<=n ; i++) cout<<ans+abs(vv[i-1]-vv[i+1])-abs(vv[i-1]-vv[i])-abs(vv[i]-vv[i+1])<<"\n";
	return 0;
}

// it may be easier than you think
// it may be harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
using namespace std;

int main(){
  int n,ans=0;
  cin>>n;
  int p[n];
  for(int i=0;i<n;i++){
    cin>>p[i];
    ans+=p[i];
  }
  sort(p,p+n);
  if(ans%10==0){
    for(int i=0;i<n;i++){
      if(p[i]%10!=0){
        ans-=p[i];
        break;
      }
    }
  }
  if(ans%10==0)
  cout<<0<<endl;
  else
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
int n;
ll x;
ll b[200000],l[200000],u[200000];
P s[200000];
int id[200000];
ll sum=0;

bool C(ll t){
	ll m=t/x;
	if(m>=n)return true;
	ll S=0;
	rep(i,m)S+=s[i].first;
	ll r=t%x;
	ll Max=0;
	rep(i,n){
		ll d=(id[i]<m?S-s[id[i]].first+s[m].first:S);
		if(r<=b[i])d+=r*l[i];
		else d+=b[i]*l[i]+(r-b[i])*u[i];
		Max=max(Max,d);
	}
	return sum+Max>=0;
}

int main(){
	cin>>n>>x;
	rep(i,n){
		scanf("%lld%lld%lld",&b[i],&l[i],&u[i]);
		sum-=b[i]*l[i];
		s[i]=P(b[i]*l[i]+(x-b[i])*u[i],i);
		//cout<<s[i].first<<" "<<s[i].second<<endl;
	}
	sort(s,s+n);reverse(s,s+n);
		//rep(i,n){ cout<<s[i].first<<" "<<s[i].second<<endl;}
	rep(i,n)id[s[i].second]=i;
	ll ok=n*x,ng=-1;
	while(ok>ng+1){
		ll md=(ok+ng)/2;
		if(C(md))ok=md;
		else ng=md;
	}
	cout<<ok<<endl;
}

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

const int N = 105, W = 100005, INF = 1000000009;

int n, w;
ll dp[N][W];

int main(){
    cin >> n >> w;
    for(int i = 1; i <= n; i++){
        int a, c;
        cin >> a >> c;
        for(int j = 0; j < a; j++)
            dp[i][j] = dp[i-1][j];
        for(int j = a; j <= w; j++)
            dp[i][j] = max(dp[i-1][j-a]+c, dp[i-1][j]);
    }
    ll ans = 0;
    for(int i = 0; i <= w; i++)  ans = max(ans, dp[n][i]);
    cout << ans << "\n";
}

Measured memory_bytes: 79360
package main

import (
  "fmt"
)

var A, B, C, K int

func main() {
  fmt.Scan(&A, &B, &C, &K)
  if K == (A+B+C) {
    fmt.Println(A + C*-1)
  }else {
    if A >= K {
      fmt.Println(K)
    }else if (A+B) >= K {
      fmt.Println(A)
    }else {
      // Cの個数
      K -= (A+B)
      fmt.Println(A + (K * -1))
    }
  }
}



Measured memory_bytes: 1756
output = []
while True:
    number = int(input())
    if number == 0:
        break
    table = list(map(int, input().split()))

    tmp_sum = 0
    for i in range(len(table)):
        tmp_sum += table[i]
    average = tmp_sum / len(table)

    squared_sum = 0
    for i in range(len(table)):
        squared_sum += (table[i] - average) ** 2
    standard_deviation = (squared_sum / len(table)) ** 0.5
    output.append(standard_deviation)
for i in output:
    print('{:.10f}'.format(i))



Measured memory_bytes: 5680
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,total=1,count=0;
    cin>>a>>b;
    while(total<b)
    {
        total-=1;
        total+=a;
        count++;
    }
    cout<<count<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main(){
  int n;
  std::cin >> n;
  std::vector<long long> a(n+1);
  std::vector<long long> b(n);
  for (long long i = 0; i <= n; i++) {
    std::cin >> a[i];
  }
  for (long long i = 0; i < n; i++) {
    std::cin >> b[i];
  }
  long long ans=0;
  long long stock=0;
  for (long long i = 0; i <= n; i++) {

    //ストックを利用できる
    if(stock!=0){
      //ストックを全て利用出来る
      if(a[i]-stock>0){
        ans+=stock;
        a[i]-=stock;
        stock=0;
      }//ストックの方が多い
      else{
        ans+=a[i];
        a[i]=0;
        stock=b[i];
      }
    }

    //モンスターが存在
    if(a[i]!=0 && i!=n){
      //今いる勇者が倒せない
      if(a[i]-b[i]>0){
        ans+=b[i];
        stock=0;
      }//今いる勇者で討伐可能
      else{
        ans+=a[i];
        stock=b[i]-a[i];
      }
    }

  }

  std::cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


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

    int w[n];
    rep(i,n){
        cin>>w[i];
        if(i>0){
            w[i] += w[i-1];
        }
    }

    int ans = 99999999;

    rep(i,n-1){
        ans = min(ans,abs(w[i]*2-w[n-1]));
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
 
int main()
{
  double R;
  cin >> R;
  
  cout << 2 * R * M_PI << endl;
 
  return 0;
}

Measured memory_bytes: 3756
import bisect
A, B, Q = map(int, input().split())
INF  = 10 ** 18
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]

for _ in range(Q):
    x = int(input())
    s1 = bisect.bisect_left(S, x) -1 #自分の左側のindex
    s2 = s1 + 1 #自分の右側のindex
    t1 = bisect.bisect_left(T, x) -1 #自分の左側のindex
    t2 = t1 + 1 #自分の右側のindex
    res = 10 ** 18
    for s in [S[s1], S[s2]]:
        for t in [T[t1], T[t2]]:
            d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)
            res = min(res, d1, d2)
    print (res)

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

int main() {
    int N, M;
    cin >> N >> M;
    if (N == M) cout << "Yes" << endl;
    else cout << "No" << endl;   
}

Measured memory_bytes: 256
S=list(input())
S=[int(i) for i in S]
n=len(S)
ans=0
if n!=1:
    for k in range(1,n+1):#上からk桁目
        for j in range(n-k):#10のj乗（n-k桁まで)
            ans+=S[k-1]*(10**j)*(2**(n-2-j))
        ans+=S[k-1]*(10**(n-k))*(2**(k-1))#n-k+1桁
    print(int(ans))
else:print(S[0])



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cfenv>
#include <cmath>
using namespace std;

vector<long long> A(6);


int main(void){
    // Your code here!
    for(int i = 0; i < 6; i++){
        cin >> A[i];
    }
    
    double min = A[1];
    for(int i = 1; i <= 5; i++) {
        if(min > A[i]) min = double(A[i]);
    }
    
    long long divide = ceil(A[0] / min);
    cout << divide + 4<< endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    long long x, y;
    cin >> x >> y;

    int cnt = 0;
    while(1){
        if(x <= y){
            cnt++;
            x *= 2;
        }else break;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  bool minus = false;
  bool plus = false;
  rep(i, n) {
    cin >> a[i];
    if(a[i] < 0) minus = true;
    if(a[i] > 0) plus = true;
  }
  vector<P> ans;
  if(minus && plus) {
    P maxv = P(a[0], 0);
    P minv = P(a[0], 0);
    rep(i, n) {
      if (maxv.first < a[i]) {
        maxv.first = a[i];
        maxv.second = i;
      }
      if (minv.first > a[i]) {
        minv.first = a[i];
        minv.second = i;
      }
    }

    auto add = [&] (int val, int idx) {
      rep(i, n) {
        ans.push_back(P(idx, i));
      }
    };

    if(abs(maxv.first) > abs(minv.first)) {
      minus = false;
      add(maxv.first, maxv.second);
    } else {
      plus = false;
      add(minv.first, minv.second);
    }
  }
  //処理を書く

  if(minus) {
    for(int i = n - 2; i >= 0; --i) {
      ans.push_back(P(i + 1, i));
    }
  } else if (plus) {
    for(int i = 1; i < n; ++i) {
      ans.push_back(P(i - 1, i));
    }
  }

  cout << ans.size() << endl;
  rep(i, ans.size()) {
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
  }
  
}

Measured memory_bytes: 256
/*
* Welcome to my code!
*---------------------------------------------*
* author : lynmisakura(twitter : @andoreiji11)
*/

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size()) 
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using pl = pair<ll,ll>;
using vpl = vector<pl>;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){ int sz = a.size();
for(int i=0;i<a.size();i++)cout << a[i] << (i < sz-1 ? ' ' : '\n'); }
void ioboost(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}
///////////////////////////////////////////////////////////

int main(int argc, char const *argv[])
{
	int n;cin >> n;
	vector<ll> v(3);
	cin >> v[0] >> v[1] >> v[2];

	vector<string> com(n);
	rep(i,n)cin >> com[i];

	vector<char> ans;

	rep(i,n){
		int x = com[i][0] - 'A';
		int y = com[i][1] - 'A';

		if(!v[x] and !v[y]){
			cout << "No" << '\n';
			return 0;
		}

		if(i < n-1){
			int nx = com[i+1][0] - 'A';
			int ny = com[i+1][1] - 'A';

			if(!v[nx] and !v[ny]){
				if(!v[x]){
					v[x]++;
					v[y]--;
					ans.pb('A' + x);
				}else{
					v[y]++;
					v[x]--;
					ans.pb('A' + y);
				}
			}else{

				if(v[x] == v[y]){
					if(x == nx or x == ny){
						v[x]++;
						v[y]--;
						ans.pb('A'+x);
					}else{
						v[y]++;
						v[x]--;
						ans.pb('A'+y);
					}
					continue;
				}

				if(v[x] > v[y]){
					v[x]--;
					v[y]++;
					ans.pb('A'+y);
				}else{
					v[y]--;
					v[x]++;
					ans.pb('A'+x);
				}
			}
		}
		else{
			if(v[x] > v[y]){
				v[x]--;
				v[y]++;
				ans.pb('A'+y);
			}else{
				v[y]--;
				v[x]++;
				ans.pb('A'+x);
			}
		}

	}	
	cout << "Yes" << '\n';
	rep(i,n)cout << ans[i] << '\n';
	return 0;
}

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

class Node
{
    internal int d, f;
    internal List<int> Adj;
    public Node() {
        this.Adj = new List<int>();
    }
}

class B
{
    static int time=0;
    static int n;
    public static void Main() {
        n = int.Parse(Console.ReadLine());
        Node[] nodes = new Node[n + 1];
        for(int i = 0; i < n; i++) {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            nodes[input[0]] = new Node();
            for(int j = 0; j < input[1]; j++) {
                nodes[input[0]].Adj.Add(input[j + 2]);
            }
        }
        DFSvisit(nodes);
    }

    public static void DFS(Node[] nodes, Node v) {
        v.d = ++time;
        for (int i=0;i<v.Adj.Count;i++) {
            if (nodes[v.Adj[i]].d == 0) {
                DFS(nodes, nodes[v.Adj[i]]);
            }
        }
        v.f = ++time;
    }

    public static void DFSvisit(Node[] nodes) {
        for (int i = 1; i < n; i++) {
            if (nodes[i].d == 0) {
                DFS(nodes, nodes[i]);
            }
        }
        StringBuilder output = new StringBuilder();
        for (int i = 1; i <= n; i++) {
            output.AppendLine(i + " " + nodes[i].d + " " + nodes[i].f);
        }
        Console.Write(output);
    }
}


Measured memory_bytes: 15992
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt();
        int [] prices = new int [N];

        int min=Integer.MAX_VALUE;
        int maxDiff = 0;
        int cnt = 0;
        for(int i =0;i<N;i++){
            prices[i] = sc.nextInt();
            if(prices[i]<min){
                min = prices[i];
            }
            else{
                int diff = prices[i]-min;
                if(diff==maxDiff){
                    cnt++;
                }
                else if(diff>maxDiff){
                    maxDiff = diff;
                    cnt =1;
                }
            }
        }

        System.out.println(cnt);

        sc.close();

    }

}


Measured memory_bytes: 34100
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAX
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define sz size()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define ar array
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

void init() {
  int n;
  cin >> n;
  const int mod = 1e9 + 7;
  vi a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vi pref(n);
  pref[0] = a[0];
  for (int i = 1; i < n; i++)
    pref[i] = (pref[i - 1] + a[i]) % mod;
  int ans = 0;
  // for(auto x:pref) cout<<x<<" ";
  for (int i = 1; i < n; i++) {
    ans = (ans % mod + (pref[i - 1] * a[i]) % mod) % mod;
  }
  cout << ans << endl;
}
int32_t main() {
  IOS;
  init();
  return 0;
}


Measured memory_bytes: 6372
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();


        System.out.println((n - h+ 1) * (n - w + 1));
    }

}


Measured memory_bytes: 24276
while True:
    h,w=map(int,input().split())
    if (h,w)==(0,0):
        break
    roop=[[False for i in range(w)]for j in range(h)]
    s=[input() for _ in range(h)]
    x,y=0,0
    jud=True
    while s[y][x]!='.':
        if roop[y][x]:
            print("LOOP")
            jud=False
            break
        roop[y][x]=True
        if s[y][x]=='>':
            x+=1
        elif s[y][x]=='<':
            x-=1
        elif s[y][x]=='v':
            y+=1
        else:
            y-=1
    if jud:
        print(x,y)


Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){
    ll s;cin>>s;
    ll l=0;
    ll r=pow(10,10);
    ll mid;
    while(r-l>1){
        mid=(r+l)/2;
        if(s<=mid*mid){
            r=mid;
        }else{
            l=mid;
        }
    }
    if(r*(r-1)<s){
        ll x=r*r-s;
        cout<<0<<' '<<0<<' '<<r<<' '<<x<<' '<<1<<' '<<r<<endl;
    }else{
        ll x=r*(r-1)-s;
        cout<<0<<' '<<0<<' '<<r<<' '<<x<<' '<<1<<' '<<r-1<<endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var k, a, b int
	fmt.Scanf("%d %d %d\n", &k, &a, &b)
	fusoku := (a - 1)
	jikkou := (k - fusoku) / 2
	amari := (k - fusoku) % 2
	x := (b-a)*jikkou + amari + a
	if x > (k + 1) {
		fmt.Println(x)
	} else {
		fmt.Println(k + 1)
	}
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );

		String[] list = str.split(" ");

		System.out.print("A");
		System.out.print(list[1].substring(0, 1));
		System.out.println("C");

	}

}


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

using namespace std;
const int MAXN = 100 + 10;

int n;
char a[MAXN], b[MAXN], c[MAXN];

int main(){
    scanf("%d", &n);
    scanf("%s%s%s", a + 1, b + 1, c + 1);
    
    int ans = 0;
    
    for(register int i=1; i<=n; i++){
        if(a[i] != b[i] && b[i] != c[i] && c[i] != a[i]){
            ans += 2;
        }else if(a[i] == b[i] && b[i] == c[i]){
            ans += 0;
        }else{
            ans += 1;
        }
    }
    
    printf("%d", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 100001
#define MAX_M 100001

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int par[MAX_N];
int myrank[MAX_N];

void init(int n)
{
  for (int i = 0; i < n; i++) {
    par[i] = i;
    myrank[i] = 0;
  }
}

int find(int x)
{
  if (par[x] == x) return x;
  return par[x] = find(par[x]);
}

void unite(int x, int y)
{
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (myrank[x] < myrank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if(myrank[x] == myrank[y]) myrank[x]++;
  }
}

bool same(int x, int y)
{
  return find(x) == find(y);
}

int main() {
  int N, M;
  int p[MAX_N];
  int x[MAX_M]; int y[MAX_N];
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> p[i]; p[i]--;
  }
  for (int i = 0; i < M; i++) {
    cin >> x[i] >> y[i]; x[i]--; y[i]--;
  }

  init(N);
  for (int i = 0; i < M; i++) {
    unite(x[i], y[i]);
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (same(i, p[i])) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;
int main() {
  string s1, s2;
  cin >> s1 >> s2;

  bool isMatch = true;
  for (size_t i = 0; i < 3; i++) {
    if (s1[i] != s2[2 - i]) isMatch = false;
  }
  cout << (isMatch ? "YES" : "NO") << endl;

  return 0;
}

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

int main(){

int a,b,c,d,e;
cin >> a >> b >> c >> d >> e;
int r = 0;
if(a < b){
r = a;
a = b;
b = r;
}
if(a < c){
r = a;
a = c;
c = r;
}
if(a < d){
r = a;
a = d;
d = r;
}
if(a < e){
r = a;
a = e;
e = r;
}

if(b < c){
r = b;
b = c;
c = r;
}
if(b < d){
r = b;
b = d;
d = r;
}
if(b < e){
r = b;
b = e;
e = r;
}
if(c < d){
r = c;
c = d;
d = r;
}
if(c < e){
r = c;
c = e;
e = r;
}
if(d < e){
r = d;
d = e;
e = r;
} 
cout << a << " "<< b <<" "<< c << " " << d << " " << e << endl;
    return 0;
}

Measured memory_bytes: 1164
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		long ans=0;
		Array.Sort(a);
		for(int i = 0;i<n-2;i++) {
			for(int j = i+1;j<n;j++) {
				ans+=a.Bs(a[i]+a[j],true)-j;
			}
		}
		Console.WriteLine("{0}",ans);
	}
}
static class Ex1{
	public static int Bs(this int[] a,int x,bool b){return Bs2(a,x,b,a.Length);}
	public static int Bs(this int[] a,int x,bool b,int ub){return Bs2(a,x,b,ub+1);}
	private static int Bs2(int[] a,int x,bool b,int ub){
		int lb=-1,mid=0;
		while(ub-lb>1){
			mid=(ub+lb)/2;
			if(a[mid]>=x){ub=mid;}
			else{lb=mid;}
		}
		return b?lb:ub;
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13304