akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    int A[n][m];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> A[i][j];
        }
    }
    int B[m][l];
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> B[i][j];
        }
    }

    int C[n][l];
    for (int i = 0; i < n; i++) {
        long long xs[l];
        for (int j = 0; j < l; j++) {
            long long sum = 0;
            for (int k = 0; k < m; k++) {
                sum += A[i][k] * B[k][j];
            }
            xs[j] = sum;
        }
        for (int i = 0; i < l - 1; i++) cout << xs[i] << ' ';
        cout << xs[l - 1] << endl;
    }
}

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

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

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

int main(){
    ll a,b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;
    return 0;
}

Measured memory_bytes: 3612
import std.algorithm, std.range, std.string;
void main()
{
    import std.stdio;
    auto masked = readln.chomp;
    auto sub = readln.chomp;
    string[] candidate;
    foreach (substringPosition; 0..masked.length-sub.length+1)
    {
        bool match = true;
        foreach (i, c; sub)
        {
            if (masked[substringPosition+i] == '?')
                continue;
            if (masked[substringPosition+i] == c)
                continue;
            stderr.writefln("sp=%d, i=%d, %c!=%c", substringPosition, i, masked[substringPosition+i], c);
            match = false;
        }
        if (match)
        {
            candidate ~= retrieveKey(masked, sub, substringPosition);
        }
    }
    candidate.sort();
    if (candidate.empty)
        "UNRESTORABLE".writeln;
    else
        candidate.front.writeln;
}
string retrieveKey(string masked, string sub, size_t substringPosition)
{
    string toFillWithA = masked[0..substringPosition] ~ sub ~ masked[substringPosition+sub.length..$];
    return toFillWithA.replace("?", "a");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N,C,K;cin>> N >> C >> K;
    vector<int> T(N);
    rep(i,N)cin >> T[i];
    sort(All(T));
    int left=T[0],cnt=0,res=1;
    for(int i=0;i<N;i++){
        if(T[i]-left<=K&&cnt<C)cnt++;
        else{
            left=T[i];
            cnt=1;
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
S = input()


def isp(s):
    for i in range(len(s) // 2):
        if s[i] != s[len(s) - i - 1]:
            return False
    return True


if isp(S) and isp(S[: (len(S) - 1) // 2]) and isp(S[(len(S) + 3) // 2 - 1 :]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ps push_back
#define LL long long
using namespace std;
const int maxn=2e5+5;
int a[maxn],b[maxn];
LL prea[maxn],preb[maxn];

int main(){
    LL N,M,K;
    cin>>N>>M>>K;
    for(int i=0;i<N;i++){
        cin >> a[i];
        if(i)prea[i] = prea[i-1] + a[i];
        else prea[i] = a[i];
    }
    for(int j=0;j<M;j++){
        cin >> b[j];
        if(j)preb[j] =preb[j-1] + b[j];
        else preb[j] = b[j];
    }
    int na,nb;
    LL remain = 0;
    int res=0,tmpres=0;
    // cout << "runnning" << endl;
    for(int i=-1;i<N;i++){
        if(i==-1){
            remain = K;
            na = 0;
            nb = 0;
        }
        else{
            remain = K - prea[i];
            nb = 0;
            if(remain>=0){
                na = i+1;
            }
            else{
                break;
            }
        }
        int head = 0,tail = M-1;
        int middle = (head + tail)  / 2;
        // cout << "read a:" << na << endl;
        // cout << "remain:" << remain << endl;
        while(head<=tail){
            // cout << head << " " << tail << endl;
            if(remain>=preb[middle]){
                nb = middle + 1;
                head = middle + 1;
            }
            else{
                tail = middle - 1;
            }
            middle = (head + tail) / 2;
        }
        tmpres = na + nb;
        // cout << "thus read a:" << na << " read b:" << nb << endl;
        res = max(res,tmpres);
    }

    cout << res;


    return 0;

}

/*

3 4 122
120 1 1
80 150 80 150

*/

Measured memory_bytes: 8292
#include <stdio.h>
int main(void){
    int H,W;
    int A;
    int i, j, k;
    int c[10][10];
    int MP = 0;
    
    scanf("%d %d", &H, &W);
    for(i = 0; i < 10; i++)
    {
        for(j = 0; j < 10; j++)
        {
            scanf("%d", &c[i][j]);
        }
    }
    
    for(k = 0; k < 10; k++)
    {
        for(i = 0; i < 10; i++)
        {
            for(j = 0; j < 10; j++)
            {
                if(c[i][j] > c[i][k] + c[k][j])
                {
                    c[i][j] = c[i][k] + c[k][j];
                }
            }
        }
    }
    
    for(i = 0; i < (H * W); i++)
    {
        scanf("%d", &A);
        if(A >= 0)
        {
            MP += c[A][1];
        }
    }
    
    printf("%d\n", MP);
    
    return 0;
}


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

int main() {
	int n; cin >> n;
	int a[200000];
	rep(i,n) cin >> a[i];
	lint ans = 9999999999999999;
	lint l,r;
	l = r = 0;
	rep(i,n) r += a[i];
	rep(i,n) {
		l += a[i];
		r -= a[i];
		ans = min(ans, abs(r-l));
	}
	cout << ans << endl;
}

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

vvt<int> edge;

void dfs(int v, int c, vt<int> &dist) {
  if(dist[v] != -1) return;

  dist[v] = c;
  for(auto &nxt : edge[v]) {
    dfs(nxt, c + 1, dist);
  }
}

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

  int n;
  cin >> n;
  edge = vvt<int>(n);
  rep(i, 0, n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  vt<int> dist1(n, -1), dist2(n, -1);
  dfs(0, 0, dist1);
  dfs(n - 1, 0, dist2);

  int f = 0, s = 0;
  rep(i, 0, n) {
    if(dist1[i] <= dist2[i]) f++;
    else s++;
  }

  if(f > s) cout << "Fennec\n";
  else cout << "Snuke\n";
}

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

const int MAX = 100100;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i=2; i<MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int n, m, tem, i, j;
    cin >> n >> m;
    map<int, ll> mp;
    ll res = 1;
    i = 2;
    while(m != 1){
        while(m % i == 0){
            m /= i;
            mp[i]++;
        }
        i++;
    }
    COMinit();
    for(auto j = mp.begin(); j!=mp.end(); j++){
        res *= COM(j->second + n -1, j->second);
        res %= MOD;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,d,i,cnt=0,z;
    double ans;
    cin>>n>>d;
    for(i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        z=(x*x)+(y*y);
        ans=sqrt(z);
        if(ans<=d)cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	int a;
	int b;
	int c;
	int d;
	int e;
	std::cin >> a >> b;
	cout << a * b - 1 * a - 1 * b + 1 << "\n";
	
	std::cin >> e;
}

Measured memory_bytes: 256
using System;
using System.Linq;
public class Program {
  public static void Main() {
    int count = int.Parse(Console.ReadLine());
    for (int i = 0; i < count; i++) {
      var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      int a = input[0], b = input[1], c = input[2];
      if (a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b) {
        Console.WriteLine("YES");
      } else {
        Console.WriteLine("NO");
      }
    }
  }
}

Measured memory_bytes: 9356
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cstdlib>
#include <random>
#include <map>
#include <string>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cassert>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 1e5 + 1;
const int EPS = 1e-9;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 10;
const ld PI = acosl(-1);
const int N = 1e6 + 2;

string s[N];
int x[N];

void solve() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i] >> x[i];
	}
	string xx;
	cin >> xx;
	int i = find(s, s + n, xx) - s;
	cout << accumulate(x + i + 1, x + n, 0) << endl;
}

int main() {
	//auto trash = freopen("a.in", "r", stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
}

Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;
int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}

ll f[2000001];



ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}

bool prime[100005];
void seive()
{  memset(prime,true,sizeof(prime));
    for(int i=2;i*i<=100005;i++)
    {
         if(prime[i]==true) {
        for(int j=2*i;j<=(100005);j+=i)
           { prime[j]=false;}
           }

    }
}

bool isit[205]={false};
void test()
{
    for(int i=1;i<=200;i++)
    {
    }
}
int main()
{   //f[0] = 1;
	//for(int i = 1 ; i <= 2000000 ; i++)
	//	f[i] = (f[i-1]*i)%MOD;
    // cout<<powmod(2,1000000,MOD);
    ll n,m;
    cin>>n>>m;
    string s3,s4;
    cin>>s3>>s4;
    ll p = ((n)/(__gcd(n,m)))*m;
  //  string ss(p,'?');
    //cout<<ss<<endl;
    ll a = max(n,m);
   // if(a==n) { s3=s1 ;} else s3=s2;
    ll b = min(n,m);
    //if(b==n) { s4=s1 ;} else s4=s2;
    //cout<<p;
    if(a==1||b==1)
    {

        if(a==1&&b==1) {
            if(s3[0]==s4[0]) cout<<1<<endl;
            else cout<<-1<<endl;
        }
        else if(a!=1) cout<<a<<endl;
        else if(b!=1) cout<<b<<endl;
        return 0;
    }
    if(b==n)
    {
        string s1;
        s1=s3;
        s3=s4;
        s4=s1;

    }
    //cout<<p<<" "<<1ll*n*m<<endl;
    //cout<<a<<" "<<b<<" "<<s3<<" "<<s4;
    //if(p==1ll*n*m) { cout<<p<<endl; return 0;}

    ll aa = p/a;
    ll bb = p/b;
    ll j=0;
     bool f =false;
    for(int i=0;i<a;i+=bb)
        { if(s3[i]!=s4[j]) {f=true; break;}
          else j+=aa;
        }
//cout<<ss<<endl;

        if(f) cout<<-1<<endl;
else
    cout<<p<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(){
int N,D,u;
scanf("%d %d",&N,&D);
if((D>=1&&D<=20)&&(N>=1&&N<=20))
u=2*D+1;
if(N%u != 0)
printf("%d",N/u +1);
else
printf("%d",N/u);
}

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

asc = [0] * N
dec = [0] * N

asc[0] = A[0]
dec[-1] = A[-1]

for i in range(1, N):
  asc[i] = asc[i-1] + A[i]
  dec[-i-1] = dec[-i] + A[-i-1]

ans = float("inf")
for i in range(N-1):
  ans = min(ans, abs(asc[i] - dec[i+1]))
print(ans)

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int x;
    cin >> x;
    FOR(i, -1000, 1000) {
        FOR(j, -1000, 1000) {
            if(pow(i, 5) - pow(j, 5) == x) {
                cout << i << " " << j << en;
                return;
            }
        }
    }
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


Measured memory_bytes: 4080
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
c = Counter(s)
ans = []
max_values = max(c.values())

for k in c.keys():
    if c[k] == max_values:
        ans.append(k)

ans = sorted(ans)
for item in ans:
    print(item)

Measured memory_bytes: 101968
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  };
  ($e:expr => $i:expr; $t:ty) => {
    (0..$i).map(|_| $e.get::<$t>()).collect::<Vec<$t>>()
  };
  ($e:expr => $row:expr, $col:expr; $t:ty) => {
    (0..$i).map(|_| scan!($e => $col; $t)).collect::<Vec<$t>>()
  }
}

struct Scanner<R: Read> {
  reader: R
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader }
  }
  fn safe_get<T: FromStr>(&mut self) -> Option<T> {
    let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
      .skip_while(|c| c.is_whitespace())
      .take_while(|c| !c.is_whitespace())
      .collect::<String>();
    if token.is_empty() { None } else { token.parse().ok() }
  }
  fn get<T: FromStr>(&mut self) -> T {
    if let Some(v) = self.safe_get() { v } else {
      writeln!(stderr(), "Terminated with EOF").unwrap();
      std::process::exit(0);
    }
  }
}

trait Writable {
  fn write(&self, sep: &'static str) -> String;
}

impl<T: ToString> Writable for Vec<T> {
  fn write(&self, sep: &'static str) -> String {
    self.iter().map(|e| e.to_string()).collect::<Vec<String>>().join(sep)
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let s = scan!(sc; String);
  let mut nums: Vec<i32> = Vec::with_capacity(s.len());
  for i in 0..(s.len() - 2) {
    nums.push(abs(753 - (&s[i..(i + 3)]).parse::<i32>().unwrap()));
  }
  nums.sort();
  println!("{}", nums[0]);
}

fn abs(a: i32) -> i32 {
  if a >= 0 { a } else { -a }
}


Measured memory_bytes: 4352
import sys
sa=list(str(input()))
sb=list(str(input()))
sc=list(str(input()))

tmp="a"

while True:
    if tmp=="a":
        if len(sa)==0:
            print("A")
            sys.exit()
        else:
            tmp=sa[0]
            sa.pop(0)
    elif tmp=="b":
        if len(sb)==0:
            print("B")
            sys.exit()
        else:
            tmp=sb[0]
            sb.pop(0)
    elif tmp=="c":      
        if len(sc)==0:
            print("C")
            sys.exit()
        else:
            tmp=sc[0]
            sc.pop(0)

Measured memory_bytes: 3064
/*
এইসব বৃত্ত থাকুক। থাকুক আমার কড়া পাহারা। তারপরও অসাবধানে ঢুকে পড়ুক কিছু মানুষ। 
তারপর চলে যাইতে চাইলে চলে যাক। বলব, ভালো থাকবেন। আবার দেখা হবে।
*/

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

#define EPS (1e-9)
#define ll long long int
#define ull unsigned long long
#define pi (acos(-1.0))
#define endl "\n"
#define all(v) v.begin(),v.end()
#define printa(a,L,R) for(int i=L;i<R;i++) cout<<a[i]<<(i==R-1?'\n':' ')
#define precise(n) cout << fixed << setprecision(n)
#define show(a) cout << (#a) << " is " << (a) << endl;
#define pcase cout<<"Case "<<++cs<<": "
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int mod=1e9+7;
const int mx=1e5+10;
ll binpow(ll base, ll exp){ll res = 1;while(1){ if(exp&1) res*=base;exp>>=1;if(!exp)break;base*=base;}return res;}

int main(int argc, char const *argv[])
{
	FAST
	int n,k;
	cin >> n;
	ll arr[n+10],dp[n+10]={0};
    for (int i = 1; i <= n; ++i )
    {
    		cin >> arr[i];
    }
   
    dp[1]=0;
    dp[2]=abs(arr[2]-arr[1]);
    for (int i = 3; i <= n; ++i )
    {
    	dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    		
    }
    //printa(dp,0,n+1);
    cout << dp[n] << endl;

	
	

	return 0;
}

Measured memory_bytes: 1792
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
dictCompare :: [a -> a -> Ordering] -> a -> a -> Ordering
dictCompare [] _ _ = EQ
dictCompare (f:fs) x y = let c = f x y in if c==EQ then dictCompare fs x y else c
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
count :: (a -> Bool) -> [a] -> Int
count = (length .) . filter
-- end of templete




main = do
    n <- getInt
    when (n/=0) $ map (\[p,h,w] -> (abs(10000*w%(h^2)-22),p)) <$> replicateM n getInts >>= print . snd . minimum >> main



Measured memory_bytes: 5592
"use strict";

new Promise(resolve => {
  resolve(require("fs").readFileSync("/dev/stdin", "utf8").split(/\s/));
}).then(input => {
  const [A, B] = input.map(x => Number(x));
  const N = [A + B, A - B, A * B];
  const temp = Math.max(...N);
  const ans = temp === -0 ? 0 : temp;
  console.log(ans);
});

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

using namespace std;

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

int main()
{
    int t, n;
    
    while (scanf("%d %d", &t, &n) && t){
        bool done[256][256] = {0};
        
        for (int i = 0; i < n; i++){
            int y, x;
            scanf("%d %d", &x, &y);
            done[y + 128][x + 128] = 1;
        }
        
        int x, y;
        
        queue<pair<int, pair<int, int> > > q;
        
        scanf("%d %d", &x, &y);
        
        int ct = 1;
        done[y + 128][x + 128] = true;
        for (q.push(make_pair(t, make_pair(y + 128, x + 128))); q.size(); q.pop()){
            pair<int, pair<int, int> > stat = q.front();
            
            int l = stat.first;
            int ny = stat.second.first, nx = stat.second.second;
            
            if (l == 0) continue;
            
            for (int i = 0; i < 6; i++){
                int ty = ny + dy[i], tx = nx + dx[i];
                if (!done[ty][tx]){
                    done[ty][tx] = 1;
                    ct++;
                    q.push(make_pair(l - 1, make_pair(ty, tx)));
                }
            }
        }
        
        printf("%d\n", ct);
    }
    
    return (0);
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,K;cin>>A>>B>>C>>K;
  vector<int>v{1,2,4,8,16,32,64,128};
  bool J=false;
  for(int X=0;X<=K;X++){
    for(int Y=0;Y<=K;Y++){
      if(A<B*v[X]&&B*v[X]<C*v[Y]&&X+Y<=K){
        J=true;
      }
    }
  }
  if(J==true){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

int main() {
  int N, L;
  cin >> N >> L;

  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }

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

  for (int i = 0; i < N; i++) {
    cout << s.at(i);
  }
  cout << endl;
  return 0;
}

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

using namespace std;

int main  ()
{

 int A;
 int B;
 int C;
 int D;

 cin >> A;
 cin >> B;
 cin >> C;
 cin >> D;

 int L;
 int R;

 L=A+B;
 R=C+D;

 if(L>R)
 {
  cout<< "Left" <<endl;
 }

 else if(L==R)
 {
  cout<< "Balanced" <<endl;
 }

 else
 {
  cout<< "Right" <<endl;
 }

return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
int f[5][5],i,j,a,y,x,p;
int main()
{
	for(;i<9;++i){
		char s[6];
		scanf("%s",s);
		for(j=0;j<4+i%2;++j){
			a=s[j]-48;
			f[i/2][j]|=a<<(1+i%2);
			f[i/2+i%2][j+!(i%2)]|=a<<3-i%2*3;
		}
	}
	do{
		do
			p=(p+1)%4;
		while(!((f[y][x]>>p)&1));
		putchar("URDL"[p]);
		x+=p?2-p:0;
		y+=p==3?0:p-1;
		p=(p+2)%4;
	}while(y!=0||x!=0||f[0][0]==6&&p==3);
	puts("");
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 
#include <cctype>
#include <set>

using namespace std;

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

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    set<int> B;
    for (int i = 0; i < N; i++) {
        if (B.count(A.at(i))) {
            B.erase(A.at(i));
        } else {
            B.insert(A.at(i));
        }
    }
    cout << B.size() << endl;
    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    int total = 0, now = 1;
    int ans = 0;
    while(n > 0)
    {
        while((total + now - 1) / now > k) now++;
        if(n - now < 0) break;
        total += now;
        n -= now;
        ans++;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int x, n;
    cin >> x >> n;
    set<int> p;
    rep(i,n) {
        int pi;
        cin >> pi;
        p.insert(pi);
    }
    // cout << p << endl;
    int ans = 0, dis = x;
    repSE(i, 1, 102) {
        if (p.find(i) == p.end()) {
            int ndis = abs(i - x);
            if (ndis < dis) {
                ans = i;
                dis = ndis;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3576
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll N, K, Q, A[100001]={0}, a;
    scanf("%lld %lld %lld", &N, &K, &Q);
    rep(i, Q){
        scanf("%lld", &a);
        A[a-1]++;
    }
    rep(i, N) printf((A[i]>Q-K)?"Yes\n":"No\n");
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char s[200010];
int main(){
	scanf("%s",s);
	ll n=strlen(s);
	ll ans=0;
	rep(i,0,n){
		int t=i;
		while(s[i]==s[i+1])i++;
		ll c=i-t+1;
		ans+=c/3*2+!!(c%3);
		if(c%3==2&&i+1<n)i++,ans++;
	}
	printf("%lld",ans);
}

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


//#define int long long 

const int N = 1e6 + 7;

int c[N], x[N];

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for(int i = 1; i < N; i++) {
		for(int j = i; j < N; j += i) {
			c[j]++;
		}
	}
	
	int n; cin >> n;
	long long ans = 0;
	for(int i = 1; i < n; i++) {
		ans += c[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 7568
#include <stdio.h>
#include <string.h>
int main()
{
    int n,i,t;
    char c[10000];

    scanf("%d",&n);
    scanf("%s",c);

    for(i=0;i<strlen(c);i++)
    {
        t= c[i]+n;
        if(t>90)
        {
            c[i]=64+(t-90);
        }
        else c[i]=c[i]+n;
    }
    printf("%s\n",c);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1000

int num[MAX];
int top;

int isEmpty(); /*スタックが空なら1を、そうでないなら0を返す関数*/
int isFull();/*スタックが要素で満されているなら1を、そうでないなら0を返す関数*/
void push(int);/*要素を挿入する関数*/
int pop();/*要素を取り出す関数*/

int main(){
    int n;
    char s[100];
    int a,b;

    top=0;

    while(scanf(" %s",s) != EOF){
        if(s[0] == '+'){
            
            a = pop();
            b = pop();
            push(a+b);

        }else if(s[0] == '-'){
            
            a = pop();
            b = pop();
            push(b-a);


        }else if(s[0] == '*'){
            
            a = pop();
            b = pop();
            push(a*b);

        }else{
            n = atoi(s);
            push(n);
        }

    }

    printf("%d\n",pop());

    return 0;
}

int isEmpty(){
    if(top == 0) return 1;
    return 0; 
}

int isFull(){
    if(top >= MAX-1) return 1;
    return 0;
}

void push(int n){
    if(isFull()){
        printf("Error,stack is full\n");
        exit(2);
    }
    num[++top] = n;
}

int pop(){
    if(isEmpty()){
        printf("Error,stack is empty\n");
        exit(3);
    }
    top--;
    return num[top+1];
}



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

const int MOD = 1000000007;

int main()
{
  int a, b;
  cin >> a >> b;
  string ans1, ans2;
  for (int i = 0; i < a; i++)
  {
    char c = '0' + b;
    ans1 += c;
  }
  for (int i = 0; i < b; i++)
  {
    char c = '0' + a;
    ans2 += c;
  }
  if (ans1 <= ans2)
    cout << ans1 << endl;
  else
    cout << ans2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstdio>
using namespace std;
#define PI acos(-1,0)
#define eps 1e-10
#define ll long long
#define mst(ss,b) memset((ss),(b),sizeof(ss))
using namespace std;
int main()
{
    cin.tie(0);
    int flag=0;
    string s;
    cin>>s;
    for(int i=0;i<s.length()-1;i++)
    {
        if(s[i]==s[i+1])
        {
            cout<<i+1<<" "<<i+2<<endl;
            flag=1;
            break;
        }
        else if(i<s.length()-2&&s[i]==s[i+2])
        {
            cout<<i+1<<" "<<i+3<<endl;
            flag=1;
            break;
        }
    }
    if(flag!=1)
    cout<<-1<<" "<<-1<<endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();
	int y = sc.nextInt();
	int z = sc.nextInt();
	if(x>y){
	    if(z>x){
                System.out.printf("%d %d %d\n",y,x,z);
	    }	else if (y>z) {
                System.out.printf("%d %d %d\n",z, y, x );
	    }else System.out.printf("%d %d %d\n",y ,z ,x);
	}else if(z>y){
	    System.out.printf("%d %d %d\n",x, y, z);
	}else if(x>z){
	    System.out.printf("%d %d %d\n",z, x, y);
	}else System.out.printf("%d %d %d\n",x ,z, y);
    }
}  



Measured memory_bytes: 26432
n = int(input())
inf = 10**9
dp = [inf] * (n + 1)
dp[0] = 0

for i in range(1, n + 1):
    dp[i] = dp[i - 1] + 1
    mlp6 = 6
    while i - mlp6 >= 0:
        dp[i] = min(dp[i], dp[i - mlp6] + 1)
        mlp6 *= 6
    mlp9 = 9
    while i - mlp9 >= 0:
        dp[i] = min(dp[i], dp[i - mlp9] + 1)
        mlp9 *= 9
print(dp[-1])


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> a,q;
    int b;
    for(int i=0;i<3;i++){
        cin >> b;
        a.push_back(b);
    }
    for(int i=0;i<2;i++){
        cin >> b;
        q.push_back(b);
    }
    sort(a.begin(),a.end());
    sort(q.begin(),q.end());
    int ans=0;
    ans+=a[0];
    ans+=q[0];
    cout << ans-50 << endl;

    return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

#define MAX_V 301

ll a[MAX_V][MAX_V];

vector<pair<ll, ll>> G[MAX_V];

// ダイクストラ法
vector<ll> dijkstra(ll start) {
	vector<ll> dist(MAX_V, inf);
	dist[start] = 0; // dist[i] := start->iまでの最短距離
	priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que;
	que.push({ 0, start });
	while (!que.empty()) {
		ll cost, u; // 今までにかかった時間　現在の頂点
		cost = que.top().first, u = que.top().second;
		que.pop();
		if (dist[u] < cost) continue;
		for (auto tmp : G[u]) {
			ll v = tmp.first, time = tmp.second; // 隣接する頂点、その頂点まで行く時間
			if (dist[v] > dist[u] + time) {
				dist[v] = dist[u] + time;
				que.push({ dist[v], v });
			}
		}
	}
	return dist;
}

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

	int n;
	cin >> n;

	rep(i, n) {
		rep(j, n) {
			cin >> a[i][j];
		}
	}

	vector<vector<bool>> used (n, vector<bool>(n, true));

	// 直接着くより、迂回して辿り着く方が良い
	rep(k, n) {
		rep(i, n) {
			rep(j, n) {
				if (a[i][j] > a[i][k] + a[k][j]) {
					cout << -1 << endl;
					return 0;
				}

				if (a[i][j] == a[i][k] + a[k][j] && a[i][k] != 0 && a[k][j] != 0) {
					used[i][j] = false;
				}
			}
		}
	}

	ll ans = 0;

	rep(i, n) {
		rep(j, i) {
			if (used[i][j]) {
				ans += a[i][j];
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/#define lli long long int
#define uli unsigned long long int
#define INF 999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  random_device rnd;     
    mt19937 mt(rnd());     
    uniform_int_distribution<> rand100(1,26);
  rep(i,0,365){
    Out(rand100(mt));
  }
}

Measured memory_bytes: 3664
import itertools

N = int(input())
seq = list(range(1,N + 1))

all = itertools.permutations(seq)
all = list(all)
Ps =  list(map(int,input().split(" ")))
Ps = tuple(Ps)
Qs =  list(map(int,input().split(" ")))
Qs = tuple(Qs)
for i,li in  enumerate(all):
    if li == Ps:
        a = i
        break


for i,li in  enumerate(all):
    if li == Qs:
        b = i
        break
print(abs(a-b))

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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> P(N), r(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> P[i];
        P[i]--;
    }
    for ( int i = 0; i < N; i++ ) {
        r[P[i]] = i;
    }
    ll m = 0, c = 1;
    for ( int i = 0; i < N-1; i++ ) {
        if ( r[i] > r[i+1] ) {
            m = max(m,c);
            c = 1;
        } else {
            c++;
        }
    }
    m = max(m,c);
    ll ans = N - m;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<int, ll> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 102;

int n, a[MAXN], b[MAXN], c[MAXN];
/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();

    cin >> n;

    int sum = 0;
    REP (i, n) {
        cin >> a[i];
    }
    REP (i, n) {
        cin >> b[i];
        sum += b[i];
    }
    REP1 (i, n-1) {
        cin >> c[i];
    }

    REP (i, n-1) {
        if (a[i+1] - a[i] == 1) {
            sum += c[a[i]];
        }
    }

    cout << sum << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[~] [" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
  cerr << ' ' << head << ',';
  debug_cerr(tail...);
}
void chmax(lint &a, lint b) { if (a < b) a = b; }
void chmin(lint &a, lint b) { if (a > b) a = b; }
struct IoSetup{
    IoSetup(){
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
      cout << fixed << setprecision(20);
      cerr << fixed << setprecision(20);
    }
} iosetup;
const lint INF = 1000000000000000000LL;

int main() {
  int n;
  cin >> n;
  vector<lint> a(n);
  vector<lint> b(n);
  lint ans = 0, cnt = 0, tnc = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ans += abs(abs(a[i]));
    debug(ans);
    if (a[i] == 0) cnt++;
    if (a[i] < 0) tnc++;
  }
  if (tnc%2==1 && cnt==0) {
    lint x = INF;
    for (int i = 0; i < n; ++i) {
      x = min(x, abs(a[i]));
    }
    ans = ans - 2 * x;
  }
  
  cout << ans << '\n';
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
using namespace std;
int main() {
	int n, m;
	int a;
	bool a1[100010];
	cin >> n >> m;
	for (int b = 0; b < n+1; b++) {
		a1[b] = true;
	}
	for (int i = 0; i < m; i++) {
		cin >> a;
		a1[a] = false;
	}
	long long dp[100000] = { 0 };
	dp[0] = 1;
	dp[1] = 1;
	for (int j = 2; j < n+1; j++) {
		if (a1[j - 1] == true) {
			dp[j] += dp[j - 1] % 1000000007;
		}
		if (a1[j - 2] == true) {
			dp[j] += dp[j - 2] % 1000000007;
		}
	}
	cout << dp[n]%1000000007 << endl;
	return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N, K;
    cin >> N >> K;
    vi p(N);
    REP(i, N) cin >> p[i];

    sort(ALL(p));

    int ans = 0;
    REP(i, K) ans += p[i] ;

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;

    if(t*v-t*w>=abs(a-b))cout<<"YES\n";
    else cout<<"NO\n";

    return 0;

}

Measured memory_bytes: 3636
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>
#include<boost/multiprecision/cpp_int.hpp>


using namespace std;
using namespace boost::multiprecision;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
template<typename A, typename B>
void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>
void maxs(A& a, const B& b) { a = max(a, (A)b); };


ll N, L, K;
struct node {
	int state[2];
	vector<int> link[2];
};

vector<node> nod;
unordered_map<ull, int> num;

void paint(int ind, int s, int k) {
	nod[ind].state[k] = s;
	for (int c : nod[ind].link[k]) {
		if (nod[c].state[k] == -1) paint(c, s, k);
	}
}

ull key(uint a, uint b) {
	return ((ull)a << 32) | b;
}

int main() {
	cin >> N >> K >> L;
	nod.resize(N);
	REP(i, 0, N) REP(k, 0, 2)nod[i].state[k] = -1;
	REP(i, 0, K) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		nod[a].link[0].push_back(b);
		nod[b].link[0].push_back(a);
	}
	REP(i, 0, L) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		nod[a].link[1].push_back(b);
		nod[b].link[1].push_back(a);
	}
	int c[2] = { -1,-1 };
	REP(i, 0, N) REP(k, 0, 2) if (nod[i].state[k] == -1) paint(i, ++c[k], k);
	REP(i, 0, N) {
		ull ky = key(nod[i].state[0], nod[i].state[1]);
		if (num.count(ky) == 0) num[ky] = 1;
		else ++num[ky];
	}
	REP(i, 0, N) PRI(num[key(nod[i].state[0], nod[i].state[1])]);
	return 0;
}


Measured memory_bytes: 26884