akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

using ll =  long long;
using pint =  pair<int,int>;

#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義 #define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//lambda: [&](int x, int y){return x<y;}

signed main(void){
    ll x,y;cin>>x>>y;
    int ans=0;
    while(x<=y){
        ans++;
        x*=2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n;
	long long int kai;
	int i;
	int cnt;
	
	scanf("%d",&n);
	while(n!=0){
		kai=1;
		cnt=0;
		for(i=n;i>0;i--){
			kai=kai*i;
		//	printf("kai=%d\n",kai);
			while(kai%10==0){
				cnt++;
				kai=kai/10;
			}
			kai=kai%100000;
		}
		printf("%d\n",cnt);
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1028
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
 
class Program{
  static void Main(){
	var num = int.Parse(ReadLine());
    var list = new Dictionary<string,int>();
    var lists = new List<string>();
    var keys = "";
    var count = 0;
	
    for(var i = 0;i < num;i++){
      keys = ReadLine();
      if(list.ContainsKey(keys)){
        list[keys]++;
        count = Math.Max(count,list[keys]);
      }else{
        list[keys] = 0;
      }
    }
    foreach(var i in list){
    	if(i.Value == count){
        	lists.Add(i.Key);
        }
    }
    
    lists.Sort(StringComparer.Ordinal);
    
    foreach(var i in lists){
    
    WriteLine(i);
    }
    
 
    
  }
}

Measured memory_bytes: 41308
#include <iostream>
#include <vector>
#include <cstdio>
#include <math.h>
#include <string>
#include <map>
#include <functional>
#include <algorithm>
#include <stack> 
#include <iomanip>
#include <stdio.h>
#include <set>
#include <array>
using namespace std; 

int main()
{
	set<int> ch = { 1,2,3 };
	int a, b;
	cin >> a >> b;
	ch.erase(a);
	ch.erase(b);
	cout << *ch.begin() << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, K;
    cin >> N >> K;
    vector<int> x;
    for (int i = 0; i < N; i++)
    {
        int t;
        cin >> t;
        x.push_back(t);
    }
    x.push_back(0);
    sort(x.begin(), x.end());
    int c = 0;
    for (int i = 0; i < x.size(); i++)
    {
        if (x[i] == 0)
        {
            c = i;
        }
    }

    int ans = 1 << 30;
    for (int i = 0; i < x.size(); i++)
    {
        int t = 0;
        if (i < c)
        {
            if (c - i > K || c + K - (c - i) >= x.size())
            {
                continue;
            }
            t = abs(x[i]);
            if (c - i < K)
            {
                t += x[c + K - (c - i)] - x[i];
            }
        }
        else
        {
            if (i - c > K || c - (K - (i - c)) < 0)
            {
                continue;
            }
            t = x[i];
            if (i - c < K)
            {
                t += x[i] - x[c - (K - (i - c))];
            }
        }

        ans = min(t, ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
typedef long long i64;
int main(){
    int N,N2;
    cin >> N;
    N2 = N;
    int fx=0;
    for(int i=(int)log10(N);i>=0;i--){
        fx+=(int)(N/pow(10,i));
        N-=(int)(N/pow(10,i))*pow(10,i);
    }
    cout << (N2%fx==0 ? "Yes":"No") << endl;
}


Measured memory_bytes: 512
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;


struct ModInt {
    static const ll MOD = 1000000007;

    // constructors etc
    ModInt() :num(1ll) {}
    ModInt(ll num_) :num(((num_%MOD) + MOD) % MOD) {}
    ModInt(const ModInt& modint) :num(modint.num%MOD) {}
    ll get()const { return num; }

    // operator etc
    // operator ll() const { return num; }
    // ll operator*() { return num; }
    ModInt& operator+=(const ModInt& r) { (num += r.num) %= MOD; return *this; }
    ModInt& operator-=(const ModInt& r) { (num += -r.num + MOD) %= MOD; return *this; }
    ModInt& operator*=(const ModInt& r) { (num *= r.num) %= MOD; return *this; }
    ModInt& operator/=(const ModInt& r) { (num *= r.inv().num) %= MOD; return *this; }
    ModInt pow(const ModInt& r)const {
        ll res = 1;
        ll x = num;
        ll n = r.num;
        while (n > 0) {
            if (n & 1)res = (res*x) % MOD;
            x = (x*x) % MOD;
            n >>= 1;
        }
        return res;
    }
    ModInt inv()const { return this->pow(MOD - 2); }

    ModInt operator+(const ModInt& r)const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt& r)const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt& r)const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt& r)const { return ModInt(*this) /= r; }
    ModInt operator+(const ll& r)const { return *this + ModInt(r); }
    ModInt operator-(const ll& r)const { return *this - ModInt(r); }
    ModInt operator*(const ll& r)const { return *this * ModInt(r); }
    ModInt operator/(const ll& r)const { return *this / ModInt(r); }

private:
    ll num;
};
ostream& operator<<(ostream& stream, const ModInt& val) { stream << val.get(); return stream; }

struct Comb {
    static constexpr ll LIM = 200000;
    static vector<ModInt> fact, inv;

    static void init() {
        fact.resize(LIM, 1);
        inv.resize(LIM, 1);

        REP(i, 1, LIM)fact[i] = fact[i - 1] * i;
        inv[LIM - 1] = fact[LIM - 1].inv();
        for (ll i = LIM - 2; i > 0; i--)inv[i] = inv[i + 1] * (i + 1);
    }

    static ModInt comb(ll n, ll k) {
        if (n < k)return 0ll;
        return (fact[n] * inv[k] * inv[n - k]).get();
    }
};
vector<ModInt> Comb::fact;
vector<ModInt> Comb::inv;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N)cin >> A[i];
    sort(A.begin(), A.end());

    ModInt res(0);
    Comb::init();
    rep(i, N) {
        ll l = i, r = N - 1 - i;
        auto mn = Comb::comb(r, K - 1)*A[i];
        auto mx = Comb::comb(l, K - 1)*A[i];
        res += mx - mn;
    }
    cout << res.get() << endl;

    return 0;
}


Measured memory_bytes: 4096
#include <set>
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	int N; string S1, S2;

	cin >> N;

	set<string> dictionary;

	for (int i = 0; i < N; i++)
	{
		cin >> S1 >> S2;

		if (S1[0] == 'i')
		{
			dictionary.insert(S2);
		}
		else
		{
			if (dictionary.find(S2) != dictionary.end())
			{
				printf("yes\n");
			}
			else
			{
				printf("no\n");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 30608
n,m = map(int,input().split())
digit = ['-2']*n
for i in range(m):
    s,c = input().split()
    s = int(s)
    if digit[s-1] == '-2' or digit[s-1] == c:
        digit[s-1] = c
    else:
        digit[s-1] = '-1'
if ('-1' in digit) or (len(digit)!=1 and digit[0] == '0'):
    print(-1)
else:
    if digit[0] != '-2' or (len(digit)==1 and digit[0] == '-2'):
        print("".join(digit).replace('-2','0'))
    else:
        digit[0] = '1'
        print("".join(digit).replace('-2','0'))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

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

#define INF 1000000000
#define T_MAX 24*60*60

int main(){
  vector<int> v(T_MAX);

  while(true){
    int n;
    cin >> n;

    if(n==0) break;

    rep(i,T_MAX) v[i]=0;

    int h,m,s;
    rep(i,n){
      scanf("%d:%d:%d", &h, &m, &s);// dbg(h);dbg(m);dbg(s);
      int t1 = (h*60+m)*60+s;
      scanf("%d:%d:%d", &h, &m, &s);// dbg(h);dbg(m);dbg(s);
      int t2 = (h*60+m)*60+s;
      v[t1]++;
      v[t2]--;
    }

    int current=0, res=0;
    rep(i, T_MAX){
      current += v[i];
      res = max(res, current);
    }

    cout << res << endl;
  }
}

Measured memory_bytes: 1536
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use std::collections::VecDeque;
use std::io::stdin;
use std::str::FromStr;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let mut sc = Scanner::new();
    let s = sc.next_string();
    let s = s.chars().collect_vec();
    for i in 0..s.len(){
        print!("{}",s[i]);
        if i==3{
            print!(" ");
        }
    }
    println!();
}

pub struct Scanner {
    buf: VecDeque<String>,
}

impl Scanner {
    pub fn new() -> Self {
        Self {
            buf: VecDeque::new(),
        }
    }
    
    fn scan_line(&mut self) {
        while self.buf.is_empty() {
            let mut s = String::new();
            stdin().read_line(&mut s).unwrap();
            let mut iter = s.split_whitespace().peekable();
            if iter.peek().is_none() {
                panic!("There is no input!");
            }
            
            for si in iter {
                self.buf.push_back(si.to_string());
            }
        }
    }
    
    pub fn next<T: FromStr>(&mut self) -> T {
        self.scan_line();
        self.buf.pop_front().unwrap().parse().unwrap_or_else(|_| panic!("Couldn't parse!"))
    }
    
    pub fn next_usize(&mut self) -> usize {
        self.next()
    }
    
    pub fn next_isize(&mut self) -> isize {
        self.next()
    }
    
    pub fn next_chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect_vec()
    }
    
    pub fn next_string(&mut self) -> String {
        self.next()
    }
    
    pub fn fill_vec_line<T: FromStr>(&mut self, v: &mut Vec<T>) {
        for vi in v {
            *vi = self.next();
        }
    }
    
    pub fn fill_vec<T: FromStr>(&mut self, v: &mut Vec<Vec<T>>) {
        for vi in v {
            for vii in vi {
                *vii = self.next();
            }
        }
    }
    
    pub fn make_vec_line<T: FromStr + Default + Clone>(&mut self, i: usize) -> Vec<T> {
        let mut v = vec![Default::default(); i];
        self.fill_vec_line(&mut v);
        v
    }
    
    pub fn make_vec<T: FromStr + Default + Clone>(&mut self, i: usize, j: usize) -> Vec<Vec<T>> {
        let mut v = vec![vec![Default::default(); j]; i];
        self.fill_vec(&mut v);
        v
    }
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    ll n,k,ans,sum=0,ksum=0;cin>>n>>k;
    vector<ll> v(n);
    rep(i,n){
        cin>>v[i];
        if(k<=i && v[i]>0)sum+=v[i];
        else if(i<k)ksum+=v[i];
    }
    ans=sum+max(0ll,ksum);
    //cout<<sum<<":"<<ksum<<endl;

    repi(i,k,n){
        if(v[i]>0){
            sum-=v[i];
        }
        ksum+=v[i];

        if(v[i-k]>0)sum+=v[i-k];
        ksum-=v[i-k];

        ll res=sum+max(0ll,ksum);
        ans=max(ans,res);

        //cout<<sum<<":"<<ksum<<endl;
    }

    cout<<ans<<endl;
}





Measured memory_bytes: 1024
#include <sstream>
#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
  std::string var;

  std::cin >> var;
  std::istringstream iss(var);

  long x ;
  iss >> x;

  std::cout << (x*x*x) << std::endl;

  return 0;
}

Measured memory_bytes: 1220
N, M = map(int,input().split())
K = [list(map(int,input().split())) for i in range(M)]
P = list(map(int,input().split()))

switch_sum = 0
switch_ptn = 0
switch_ptn2 = 0

#スイッチのOnOffパターン
for i in range(2**N):
  i_2 = str(bin(i))[2:]
  i_bit = i_2.zfill(N)
  
  #各電球のスイッチパターンを確認
#  print(i_bit)
  for j in range(M):
    for k in range(1,K[j][0]+1):
      switch_sum += int(i_bit[K[j][k]-1])
    switch_sum = switch_sum%2
#    print(switch_sum,P[j])
    if switch_sum == P[j]:
      switch_ptn += 1
    switch_sum = 0
  if switch_ptn == M:
    switch_ptn2 += 1
  switch_ptn = 0
    
print(switch_ptn2)

Measured memory_bytes: 3064
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

s = sorted(Counter(list(readline().rstrip().decode())).values())
t = sorted(Counter(list(readline().rstrip().decode())).values())
if s == t:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 5260
def search(arr1,arr2,k)
  # result_arr = []
  # arr1.each do |i|
  #   arr2.each do |j|
  #     break if result_arr.size >= k && result_arr.min > i + j
  #     result_arr << i + j
  #   end
  #   result_arr = result_arr.sort.reverse[0..[k - 1,result_arr.size].min]
  # end
  # result_arr.sort.reverse[0..k - 1]
  arr1.product(arr2).map{|i,j| i + j}.sort.reverse[0..k - 1]
end

x,y,z,k = gets.chomp.split(' ').map(&:to_i)
x_arr   = gets.chomp.split(' ').map(&:to_i).sort.reverse
y_arr   = gets.chomp.split(' ').map(&:to_i).sort.reverse
z_arr   = gets.chomp.split(' ').map(&:to_i).sort.reverse

search(search(x_arr,y_arr,k), z_arr,k).each do |i|
  puts i
end

Measured memory_bytes: 287476
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 100005;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) +(ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int n, m;
struct city { int p, y, id; } t[maxn];
ll a[maxn];

bool cmp(reg city x, reg city y) { return ((x.p < y.p) || (x.p == y.p && x.y < y.y)); }

int main() {
    ios::sync_with_stdio(false);
    n = read(), m = read();
    for (reg int i = 1; i <= m; i++) t[i].p = read(), t[i].y = read(), t[i].id = i;
    sort(t + 1, t + m + 1, cmp);
    reg int now = 1;
    for (reg int i = 1; i <= m; i++) {
        if (t[i].p != t[i - 1].p) t[i].y = now = 1;
        else t[i].y = ++now;
    }
    for (reg int i = 1; i <= m; i++) a[t[i].id] = t[i].p * 1000000LL + t[i].y * 1LL;
    for (reg int i = 1; i <= m; i++) {
        reg ll tmp = a[i];
        reg int num = 0;
        while (tmp) tmp /= 10, num++;
        for (reg int j = num + 1; j <= 12; j++) cout << '0';
        cout << a[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3456
def Pow(a, n):
    if n == 0: return 1
    if n%2 == 0:
        return (Pow(a, n//2))**2%mod
    else:
        return Pow(a, n-1)*a%mod
mod = 998244353
N, M, K = map(int, input().split())
x = [1]*N
for i in range(1,N):
    x[i] = Pow(i, mod-2)
cmb = [1]*N
for i in range(N-2):
    cmb[i+1] = ((cmb[i]*(N-1-i))%mod*x[i+1])%mod
ans = 0
for i in range(K+1):
    num = Pow(M-1, N-1-i)
    ans = (ans+M*num%mod*cmb[i]%mod)%mod
print(ans)

Measured memory_bytes: 76836
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define bit(s,i) (((s)>>(i))&1LL)
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

const int N = 500001;
int BIT[26][N];
void mod(int color, int ind, int ch) {
	for(int i = ind; i <= N; i+=lowbit(i)) {
		BIT[color][i]+=ch;
	}
}
int sum(int color, int ind) {
	int ans = 0;
	for(int i = ind; i; i-=lowbit(i)) {
		ans+=BIT[color][i];
	}
	return ans;
}

signed main() {
	EmiliaMyWife

	int n, m;
	string s;
	cin >> n >> s;
	for(int i = 1; i <= s.size(); i++) BIT[s[i-1]-'a'][i]++;
	for(int i = 0; i < 26; i++) {
		for(int j = 2; j <= s.size(); j++) {
			BIT[i][j]+=BIT[i][j-1];
		}
	}
	for(int i = 0; i < 26; i++) {
		for(int j = s.size(); j; j--) {
			BIT[i][j]-=BIT[i][j-lowbit(j)];
		}
	}
	cin >> m;
	for(int i = 0, a; i < m; i++) {
		cin >> a;
		if(a==1) {
			int b;
			char c;
			cin >> b >> c;
			mod(s[b-1]-'a', b, -1);
			mod(c-'a', b, 1);
			s[b-1]=c;
		}
		else {
			int b, c;
			cin >> b >> c;
			int now = 0;
			for(int i = 0; i < 26; i++) {
				if(sum(i, c)-sum(i, b-1)) now++;
			}
			cout << now << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 51740
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){ 
    cin>>a>>b>>c;
    if(a==1){
        cout<<"YES"<<endl;
        return 0;
    }
    for(int i=1;i<=150;i++){
        if(a*i%b==c){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
import sys

#S,T = stdin.readline().rstrip().split()
#A,B = [int(x) for x in stdin.readline().rstrip().split()]
N = stdin.readline().rstrip().split()
s = list(map(int,input().split()))
dict={}
for _,i in enumerate(s):
  #print( dict.get(i))
  if dict.get(i)==None:
    dict[i]=1
  else :
    print("NO")
    sys.exit(0)
print("YES")

Measured memory_bytes: 32844
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,k,j,n,m=0,a;
	scanf("%d",&n);
	k=n;
	while(k!=0)
	{
		a=k%10;
		k/=10;
		m+=a;
	}
	if(n%m==0)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    double ans = 0;
    REP(i, n) {
        int a;
        cin >> a;
        ans += 1 / (double)a;
    }
    cout << fixed << setprecision(10) << 1 / ans << ln;
    return 0;
}


Measured memory_bytes: 3768
// atcoder/abc134/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

template<typename T>
vector<T> LIS(const T num[], const int size, const bool strict = true)
{
  const int inf = 1 << 28;
  T dp[size];
  int idx[size];
  int len = -inf;
  fill(dp, dp + size, inf);
  for (int i = 0; i < size; ++i) {
    idx[i] = (strict ? lower_bound(dp, dp + size, num[i]) : upper_bound(dp, dp + size, num[i])) - dp;
    dp[idx[i]] = num[i];
  }
  len = *max_element(idx, idx + size);
  vector<T> result(len + 1);
  for (int i = 0; i < size; ++i) {
    if (idx[size - 1 - i] == len) {
      result[len--] = num[size - 1 - i];
    }
  }
  return result;
}

const int N = 100000 + 5;
int num[N];

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    for (int i = 0; i < n; ++i) {
      cin >> num[i];
      num[i] *= -1;
    }
    cout << LIS(num, n, false).size() << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

if K == 1:
	print(0)
else:
	print(N-K)

Measured memory_bytes: 5784
#include <stdio.h>

long long unsigned digitSum(long long unsigned n)
{
    long long unsigned s=0;
    while(n != 0){
        s += n%10;
        n = n/10;
    }
    return s;
}
int main()
{
    long long unsigned n;
    scanf("%llu", &n);
    if(n%digitSum(n)==0){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {
  int x,y;
  int a,b;
  scanf("%d %d", &x,&y);
  a = 2 * x - y/2;
  b = y/2 -x;

  if(a < 0 || b < 0) {
    printf("No\n");
  } else if( x != a + b|| 2 * a + 4 *b != y) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }
  return 0;
}


Measured memory_bytes: 1648
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin>>a>>b;
    if((a+b)<0) cout<<"-1"<<endl;
    if((a+b)>0) cout<<"1"<<endl;
    if((a+b)==0) cout<<"0"<<endl;
}


Measured memory_bytes: 3100
import scala.io.StdIn.readLine
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val b = new ArrayBuffer[String]
  var l = "0 0"
  while({l= readLine.trim;l} != "0 0") {
    val size = l.split(" ").map(_.toInt)
    val matrix = (0 until size(0)).map(_=>readLine.trim.toArray)
    var (x,y,count) = (0,0,0)
    while(matrix(y)(x)!='.' && count<=size(0)*size(1)) {
      val c = matrix(y)(x)
      if(c=='>') x+=1
      else if(c=='v') y+=1
      else if(c=='^') y-=1
      else if(c=='<') x-=1
      count += 1
    }
    if(count<=size(0)*size(1))
      b += x + " " + y
    else
      b += "LOOP"
  }
  println(b.mkString("\n"))
}

Measured memory_bytes: 43684
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int a = sc.nextInt();
		int cnt = 0;
		while (h > 0) {
			h -= a;
			cnt++;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;
using pint = pair<int, int>;

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;
}

int main()
{
  int x;
  cin >> x;
  string s = x >= 30 ? "Yes" : "No";
  cout << s << endl;
  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
vector<int> E[101010];
int C[101010];
int num[101010];

void dfs(int cur,int col) {
	if(C[cur]!=-1) {
		if(C[cur]!=col) {
			cout<<1LL*N*(N-1)/2-M<<endl;
			exit(0);
		}
	}
	else if(C[cur]==-1) {
		C[cur]=col;
		num[col]++;
		FORR(e,E[cur]) dfs(e,col^1);
		
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	MINUS(C);
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	
	dfs(0,0);
	
	cout<<1LL*num[0]*num[1]-M<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

const int maxn = 52;

int H, W;
char mp[maxn][maxn];

char read_char() {
    char ch;
    while (1) {
        ch = getchar();
        if (ch == '.' || ch == '#') return ch;
    }
}

const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            mp[i][j] = read_char();
    bool done = true;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++) {
            int ok = 0;
            if (mp[i][j] != '#') continue;
            for (int k = 0; k < 4; k++) {
                int ni = i + dir[k][0], nj = j + dir[k][1];
                if (ni >= 0 && nj >= 0 && ni < H && nj < W)
                    if (mp[ni][nj] == '#') ok++;
            }
            if (ok == 0) {
                done = false;
                break;
            }
    }
    cout << ((done) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split(" "))
X = list(map(int, input().split()))

if N >= M:
    print(str("0"))
    exit(0)

diff = M - N

X_sorted = sorted(X)

distance_list = []

for i in range(len(X_sorted)-1):
    distance = abs(X_sorted[i] - X_sorted[i+1])
    distance_list.append(distance)

distance_list.sort()

ans = sum(distance_list[0:diff])

print(ans)


Measured memory_bytes: 13968
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	char S[] = br.readLine().toCharArray();
	char T[] = br.readLine().toCharArray();
	int roop = S.length - T.length + 1;
	int cnt[] = new int[roop];
	int max = 0;
	for (int i = 0; i < roop; i++) {
	    for (int j = 0; j < T.length; j++) {
		if (T[j] == S[i + j]) {
		    cnt[i]++;
		}
	    }
	}

	for (int k = 0; k < cnt.length; k++) {
	    if (max < cnt[k]) {
		max = cnt[k];
	    }
	}

	System.out.println(T.length - max);
    }
}

Measured memory_bytes: 32480
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String[] __){
		ArrayDeque<Character> deque=new ArrayDeque<>();
		for(char c:s.next().toCharArray()) {
			if(c=='B')
				deque.pollLast();
			else
				deque.add(c);
		}
		System.out.println(Arrays.toString(deque.toArray()).replaceAll("[^01]",""));
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <iomanip>
#include <string>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void abc121_b(vector<vector<int>> v) {

    int n = v[0][0];
    int m = v[0][1];
    int c = v[0][2];

    int cnt = 0;

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

        int mysum = 0;
        for (int j = 0; j < m; j++) {

            mysum += v[i][j] * v[1][j];


        }

        if (mysum +c> 0) {
            cnt += 1;
        }
    }

    cout << cnt << endl;


}

int main() {

    //    vector<vector < string>> vec_arr_result;
    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata2();

    abc121_b(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string x,k;
    cin>>x>>k;
    int counter=0;
    for(int i=0;i<x.size();i++){
    if(x.at(i)==k.at(i)){
    counter++;}
    }
    if(counter==x.size())
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
  return 0;
    }

Measured memory_bytes: 3628
parseInt(x) = parse(Int,x)

function f(N,i,b,a)
  c = 0
  sum(b[i:i:N]) % 2 == a ? c = 0 : c = 1
  return(c)
end

function main()
  N = parseInt(readline())
  a = map(parseInt,split(readline()))
  b = zeros(Int,N)
  for i = N:-1:1
    b[i] = f(N,i,b,a[i])
    if b[i] == 1 
    end
  end
  println(sum(b))
  for i in 1:N
    if b[i] == 1
      i < N ? print("$i ") : print(i)
    end
  end
end

main()

Measured memory_bytes: 171440
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()

typedef complex<int> Point;
typedef vector<Point> VP;
#define X real()
#define Y imag()

double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

string line2str(VP ps){
    string s;
    int m = ps.size();
    rep(j,m-2){
        int d = abs(ps[j+1]-ps[j]);
        bool ccw = (cross(ps[j+1]-ps[j],ps[j+2]-ps[j]) > 0);
        s += to_string(d)+(ccw?"L":"R");
    }
    s += to_string((int)abs(ps[m-1]-ps[m-2]));
    return s;
}

int main(void){
    int n;
    while(cin>>n, n){
        vector<VP> ls(n+1);
        rep(i,n+1){
            int m;
            cin>>m;
            ls[i] = VP(m);
            rep(j,m){
                int x,y;
                cin>>x>>y;
                ls[i][j] = {x,y};
            }
        }

        string key1 = line2str(ls[0]);
        reverse(all(ls[0]));
        string key2 = line2str(ls[0]);
        rep1(i,n) {
            string s = line2str(ls[i]);
            if(s==key1 || s==key2) cout<<i<<endl;
        }
        cout<<"+++++"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif
struct MinCostFlow{
	using C = ll;		// capacity
	using D = ll;		// cost (distance)
	const D inf = 1e18;	// max distance

	struct edge{
		int to;
		C cap;
		D cost;
		int rev;
		edge(int to_,C cap_, D cost_, int rev_):to(to_),cap(cap_),cost(cost_),rev(rev_){}
	};
	
	int N;
	VV<edge> G;
	V<D> h;
	V<D> dist;
	V<int> prevv,preve;
	MinCostFlow(int N_):N(N_){
		G.resize(N);
		h.resize(N);
		dist.resize(N);
		prevv.resize(N);
		preve.resize(N);
	}

	void add_edge(int from, int to, C cap, D cost){
		edge e1(to,cap,cost,(int)G[to].size());
		edge e2(from,0,-cost,(int)G[from].size());
		G[from].push_back(e1);
		G[to].push_back(e2);
	}
	D min_cost_flow(int s, int t, C f){
		D res = 0;
		h = V<D>(N);
		while(f > 0){
			using P = pair<D,int>;
			priority_queue< P,vector<P>,greater<P> > que;
			dist = V<D>(N,inf);
			dist[s] = 0;
			que.push(P(0,s));
			while(!que.empty()){
				P p = que.top();
				que.pop();
				int v = p.second;
				if(dist[v] < p.first) continue;
				for(int i=0;i<(int)G[v].size();i++){
					edge &e = G[v][i];
					if(e.cap>0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
						dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
						prevv[e.to]=v;
						preve[e.to]=i;
						que.push(P(dist[e.to],e.to));
					}
				}
			}
			if(dist[t]==inf) return -1;
			rep(v,N) h[v]+=dist[v];
			C d = f;
			for(int v=t;v!=s;v=prevv[v]){
				chmin(d,G[prevv[v]][preve[v]].cap);
			}
			f -= d;
			res += d*h[t];
			for(int v=t;v!=s;v=prevv[v]){
				edge &e=G[prevv[v]][preve[v]];
				e.cap-=d;
				G[v][e.rev].cap+=d;
			}
		}
		return res;
	}
};

int main(){
	int N;
	cin >> N;
	int V = 2*N + 6;
	MinCostFlow MCF(V);
	int S = V-2, T = V-1;
	int sum = 0;
	ll off = 2e9;
	rep(i,N){
		ll x,y,c;
		cin >> x >> y >> c;
		sum += c;
		MCF.add_edge(S,i,c,0);
		MCF.add_edge(i,N+N+0,c,off+x+y);
		MCF.add_edge(i,N+N+1,c,off+x-y);
		MCF.add_edge(i,N+N+2,c,off-x+y);
		MCF.add_edge(i,N+N+3,c,off-x-y);
	}
	rep(i,N){
		ll x,y,c;
		cin >> x >> y >> c;
		MCF.add_edge(N+i,T,c,0);
		MCF.add_edge(N+N+0,N+i,c,off-x-y);
		MCF.add_edge(N+N+1,N+i,c,off-x+y);
		MCF.add_edge(N+N+2,N+i,c,off+x-y);
		MCF.add_edge(N+N+3,N+i,c,off+x+y);
	}
	ll f = MCF.min_cost_flow(S,T,sum);
	cout << off*sum*2 - f << endl;
}


Measured memory_bytes: 1484
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
#define int long long
signed main()
{
    int n,ans=0;
    scanf("%lld",&n);
    string ss;
    cin>>ss;
    for(int i=1;i<=n;i++)
        ans+=(n-i)/2;
    int r=0,g=0,b=0;
    for(int i=0;i<n;i++)
    {
        r+=(ss[i]=='R');
        g+=(ss[i]=='G');
        b+=(ss[i]=='B');
    }
    ans+=r*(r-1)/2*(n-r)+r*(r-1)*(r-2)/6;
    ans+=g*(g-1)/2*(n-g)+g*(g-1)*(g-2)/6;
    ans+=b*(b-1)/2*(n-b)+b*(b-1)*(b-2)/6;
    for(int i=0;i<n;i++)
        for(int j=1;i+j*2<n;j++)
            if(ss[i]==ss[i+j]||ss[i+j]==ss[i+j*2]||ss[i]==ss[i+j*2])
                ans--;
    ans=n*(n-1)*(n-2)/6-ans;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3800
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <cstdio>
#include<iomanip>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  if (a>b){
    cout << "safe";
  } else {
    cout << "unsafe";
  }
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define newline printf ("\n")
#define space printf (" ")
#define cinfalse ios::sync_with_stdio(false)
#define fread(a) freopen (a".in", "r", stdin), freopen(a".out", "w", stdout)
#define rint register int
#define For(i, a, b) for (rint i = a; i <= b; i ++)
#define Low(i, a, b) for (rint i = a; i >= b; i --)
#define FFr(i, a, b, c) for (rint i = a; i <= b; i += c)
#define FLw(i, a, b, c) for (rint i = a; i >= b; i -= c)
#define min(a, b) (a)>(b)?(b):(a)
#define max(a, b) (a)>(b)?(a):(b)
using namespace std;

int main()
{
	register char ch;
	register bool f = 0;
	while (scanf ("%c", &ch) != EOF)
		if (!f) f = ch=='C';
		else if (ch == 'F') return puts("Yes"), 0;
    return puts("No"),0;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll out = -1e18;
    out = max(a * c, out);
    out = max(a * d, out);
    out = max(b * c, out);
    out = max(b * d, out);
    cout << out << endl;

    return 0;
}

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

int q;

int main()
{
	scanf("%d", &q);
	while (q--){
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		
		int res = 0;
		while (a && b && c){
			res++;
			a--;
			b--;
			c--;
		}
		
		while (a >= 2 && b){
			res++;
			a -= 2;
			b--;
		}
		
		while (a >= 3){
			res++;
			a -= 3;
		}
		
		printf("%d\n", res);
	}
	
	return 0;
}

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

typedef long long l;

int main(){
  l n;
  cin>>n;
  l result =0;
  vector<l> a(n,0);
  vector<l> b(n,0);
  vector<l> c(n-1,0);
  for(l i=0;i<n;i++){
      cin>> a[i];
  }
  for(l j=0;j<n;j++) cin>>b[j];
  for(l k=0;k<n-1;k++) cin>>c[k];
  for(l i =0;i<n;i++) {
      result += b[a[i]-1];
  }
  for(l i=0;i<n-1;i++){
      if(a[i+1]-a[i] == 1) result+=c[a[i]-1];
  }

  cout<<result;
  return 0;
 }

Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.ByteString.Char8 as B
import Data.Char
import Data.List
import Control.Monad

put :: Int -> IO ()
put s = Prelude.putStr $ show s ++ " "

solve vec n 
    | even n = do
        forM_ (Data.List.reverse [1,3..n-1]) $ \i -> VUM.read vec i >>= put
        forM_ [0,2..n-2] $ \i -> VUM.read vec i >>= put
        Prelude.putStrLn ""
    | otherwise = do
        forM_ (Data.List.reverse [0,2..n-1]) $ \i -> VUM.read vec i >>= put
        forM_ [1,3..n-2] $ \i -> VUM.read vec i >>= put
        Prelude.putStrLn ""

main = do
    n <- readLn :: IO Int
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    xs' <- VU.unsafeThaw xs
    solve xs' n

Measured memory_bytes: 16124
array = []
gets.to_i.times {
    input = gets.chomp.split.map(&:to_i)
    case input[0]
    when 0
        # push
        if input[1] == 0
            array.unshift(input[2])
        else
            array << input[2]
        end
    when 1
        # randomAccess
        puts array[input[1]]
    when 2
        # pop
        if input[1] == 0
            array.shift
        else
            array.pop
        end
    end
}



Measured memory_bytes: 11528
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#define LOCAL_DEBUG
#include <bits/stdc++.h>
using namespace	std;

typedef unsigned long long		ull;
typedef long long				ll;
typedef long double				ld; // GCC - long double, but VS - double

template<typename T> using vv	= vector<vector<T>>;
template<typename T> using pp   = pair<T, T>;

#define fr(i, n)                for(int i = 0; i < n; ++i)
#define rep(i, a, b)            for(int i = a; i <= b; ++i)
#define all(a)                  a.begin(), a.end()
#define rall(a)                 a.rbegin(), a.rend()
#define pb                      push_back
#define nl                      '\n'
#define file(name1, name2)      freopen(name1, "r", stdin); freopen(name2, "w", stdout);
#define zp_v(v)                 for(int i = 0; i < v.size(); ++i) cin >> v[i]
#define zp_vv(v)                fr(i, v.size())fr(j, v[i].size()) cin >> v[i][j];
#define print_v(v)              for (auto& u : v){ cout << u << ' '; }
#define print_vv(v)             for (auto& u : v){ for (auto& q : u) cout << q << ' '; cout << nl;}
#define int ll
struct item
{
	int w, c;

	item(int w = 0, int c = 0) : w(w), c(c) {};
};

signed main()
{
#ifdef LOCAL_DEBUG
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, w;
	cin >> n >> w;

	vector<item> v(n + 1);
	rep(i, 1, n)
	{
		item& u = v[i];
		cin >> u.w >> u.c;
	}
	vv<int> dp(n + 1, vector<int>(w + 1));

	rep(i, 1, n)
		rep(j, 1, w)
	{
		dp[i][j] = dp[i - 1][j];

		if (j - v[i].w >= 0 && dp[i - 1][j - v[i].w] + v[i].c >= dp[i][j])
			dp[i][j] = dp[i - 1][j - v[i].w] + v[i].c;
	}
	
	cout << dp[n][w];
	return 0;
}

Measured memory_bytes: 80256
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
}

int main()
{
  init_main();
  solve();
  return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// 入力ミスは考慮しない

	    // 引数で標準入力System.inを指定する
	    Scanner scanner = new Scanner(System.in);

	    // 1行目を取得(a)
	    String input_text１ = scanner.nextLine();

	    int paramA = Integer.parseInt(input_text１);

	    int b = (paramA % 1000);

	    if (b == 0) {
	    	System.out.println(0);
	    	return;
	    }

	    System.out.println(1000 -  b);

	    // Scannerクラスのインスタンスをクローズ
	    scanner.close();
	}

}

Measured memory_bytes: 27024
words = lambda t : list(map(t, input().split()))
n = int(input())
ans = 0
for i in range(1,n+1):
    k = i
    d = 0
    while k != 0:
        d += 1
        k = k // 10
    if d % 2 == 1:
        ans += 1
print(ans)


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

int main(void) {
	int numc = 0, nums = 0;
	cin >> numc;
	while (numc != 0) {
		string change;
		string str;
		string s, s1, s2;
		for (int i = 0; i < numc; i++) {
			cin >> s1 >> s2;
			change += s1 + s2;

		}
		cin >> nums;
		for (int i = 0; i < nums; i++) {
			cin >> s;
			str += s;
			for (int j = 0; j < numc; j++) {
				if (str[i] == change[j * 2]) {
					str[i] = change[j * 2 + 1];
					break;
				}
			}
		}
		cout << str << endl;
		cin >> numc;

	}
	return 0;
}

Measured memory_bytes: 3284