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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(2, vector<int>(n));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int up = accumulate(a[0].begin(), a[0].begin() + i + 1, 0);
    int down = accumulate(a[1].begin() + i, a[1].begin() + n, 0);
    ans = max(ans, up + down);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int ans = 1;
	char now = s[0];
	for (int ii = 1; ii < N; ++ii){
		if (now != s[ii]){
			ans++;
			now = s[ii];
		}
	}

		cout << ans << "\n";		

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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 A, B, C;
  cin >> A >> B >> C;
  cout << max(0, C - (A - B)) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true)
        {
            String s = sc.nextLine();
            int sum = 0;
            if(s.equals("0"))
                break;
            for(int i = 0 ; i < s.length() ; i++)
                sum += (s.charAt(i) - '0');
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 26620
#include<iostream>
using namespace std;
char n;
int main()
{
	cin>>n;
	if(n=='a'||n=='e'||n=='i'||n=='o'||n=='u')
	{
		cout<<"vowel"<<endl;
	}
	else
	{
		cout<<"consonant"<<endl;
	}
	return 0;
}

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

using namespace std;

void dfs(int& ans, long num, int n) {
    if (num > n) return;
    // cout << num << endl;

    bool t, f, s;
    t = false;
    f = false;
    s = false;
    long nc = num;
    while (nc) {
        int o = nc % 10;
        nc /= 10;
        if (o == 3) t = true;
        if (o == 5) f = true;
        if (o == 7) s = true;
    }
    if (t&&f&&s)
        ans++;

    dfs(ans, num*10+3, n);
    dfs(ans, num*10+5, n);
    dfs(ans, num*10+7, n);
}

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

    int ans = 0;
    dfs(ans, 0, n);
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val count = Array(n + 1) {1}
    (2..n).forEach {
        for (i in it..n step it) {
            count[i]++
        }
    }
    println(count.filterIndexed { index, x -> x == 8 && index % 2 == 1 }.count())
}

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

int main() {
	string str{};

	cin >> str;

	bool flag = true;

	for (size_t i = 0;i < str.length()/2;++i) {
		if (str[i] != str[str.length() - 1-i]) {
			flag = false;
		}
	}
	for (size_t i = 0;i < str.length() / 4;++i) {
		if (str[i] != str[str.length() /2 - 1 - i]) {
			flag = false;
		}
		if (str[str.length() / 2 + 1 + i] != str[str.length() - 1 - i]) {
			flag = false;
		}
	}

	if (flag) {
		cout << "Yes"s;
	}
	else {
		cout << "No"s;
	}


}

Measured memory_bytes: 888
h,w= map(int, input().split())
s_list = []
b_list = []
for i in range(h):
    li = input()
    aa = []
    for j in range(w):
        aa.append(li[j])
        if aa[j] == '#':
            b_list.append((i, j))
    s_list.append(aa)
ans = 0
while True:
    bb_list = []
    for p in b_list:
        pp = [(p[0]-1, p[1]), (p[0]+1, p[1]), (p[0], p[1]-1), (p[0], p[1]+1)]
        for ppp in pp:
            if (0 <= ppp[0] < h) and (0 <= ppp[1] < w):
                if s_list[ppp[0]][ppp[1]] == '.':
                    s_list[ppp[0]][ppp[1]] = '#'
                    bb_list.append((ppp[0], ppp[1]))
    # ここで複数回同じbをやらなくて済むようにしている
    b_list = bb_list
    if len(b_list) == 0:
        break
    ans += 1
    # print(x)
print(ans)


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

typedef long long ll;
typedef pair<int, pair<int, int>> piii;
//loop
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//STL
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

const int INF = 1e9;

#define deg_to_rad(deg) ((deg)*M_PI / 180.0)

bool isPrime(int num)
{
    if (num == 2)
        return true;
    if (num < 2 || num % 2 == 0)
        return false;
    int root = sqrt(num);
    for (int i = 3; i <= root; i += 2)
    {
        if (num % i == 0)
            return false;
    }
    return true;
}

void Main()
{
    int n;
    cin >> n;
    vector<int> nums(n);
    int ans = 0;
    REP(i, n)
    {
        int x;
        cin >> x;
        if (isPrime(x)) ans++;
    }
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    return 0;
}



Measured memory_bytes: 3168
use std::process;
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    let n = get!(u64);
    for i in 1..10 {
        for j in 1..10{
            if i*j == n {
                println!("Yes");
                process::exit(0);
            }
        }
    }
                println!("No"); 
}


Measured memory_bytes: 4352
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
  s = 0
  a = list(map(int,input().split()))
  for j in range(m):
    s+=a[j]*b[j]  
  if s+c>0:
    count+=1
print(count)    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vct vector<ll>
int main()
{
    ll n;
    cin>>n;
    vct ans(n);
    ll ar[n-1];
    for(ll i=0;i<n-1;i++)cin>>ar[i];
    
    ans[0]=ar[0];
    ans[1]=ans[0];

    for(ll i=1;i<n-1;i++)
    {
        ll curr=ar[i];
        if(curr>=ans[i])
        {
            ans[i+1]=curr;
        }
        else
        {
            ans[i]=curr;
            ans[i+1]=curr;
        }
    }
    ll su=0;
    for(ll i=0;i<n;i++)su+=ans[i];
    cout<<su<<endl;
}

Measured memory_bytes: 256
const input = require("fs").readFileSync("/dev/stdin", "utf8")
const lines = input.split('\n')
const [N, M] = lines[0].split(' ').map(Number)
const A = lines[1].split(' ').map(Number)

const sum = A.reduce((a, b) => a + b)

const div = sum / (M * 4)

let count = 0
A.forEach(a => {
  count += a >= div ? 1 : 0
})

console.log(count >= M ? 'Yes' : 'No')

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

const int MAXN = 2e5 + 5;
const int MOD = 1e9 + 7;

int N;
vector <int> v;
int dp[MAXN];

void load() {
	scanf("%d", &N);
	v.push_back(0);
	while (N--) {
		int x;
		scanf("%d", &x);
		if (x != v.back())
			v.push_back(x);
	}
}

inline void add(int &x, int y) {
	x += y;
	if (x >= MOD)
		x -= MOD;
}

int solve() {
	dp[0] = 1;
	N = v.size();
	for (int i = 1; i < N; i++) 
		add(dp[v[i]], dp[v[i - 1]]);
	return dp[v[N - 1]];
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;	
}

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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORD(i, m, n) for (int i = m; i >= n; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 0; i <= n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

	int x,y;
	cin>>x>>y;
	cout << x+y/2 << endl;

	return 0;
}

Measured memory_bytes: 3652
<?php

$inputCount = getStdin();

for ($i = 0; $i < $inputCount; $i++) {
    echo str_replace('Hoshino', 'Hoshina', fgets(STDIN));
}


function getStdin()
{
    return trim(fgets(STDIN));
}

function explodeStdin()
{
    return explode(' ', getStdin());
}

Measured memory_bytes: 15148
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        //string input= Console.ReadLine();
        //int input =int.Parse(Console.ReadLine());
        char[] str = Console.ReadLine().ToCharArray();
        for(int a = 0; a < str.Length; a++)
        {
            if (str[a]=='1')
            {
                str[a]='9';
            }
            else
            {
                str[a] = '1';
            }
        }
        Console.WriteLine(string.Join("",str));


        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法
 
        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();

    }
}

Measured memory_bytes: 13268
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pb push_back
# define pdd pair < db , db >
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,k;
    fi>>n>>k;
    static int s[1 << 20];
    for (int i = 1;i <= n;++i)
        fi>>s[i];
    ll ans = 0;
    for (int i = 2;i <= n;++i)
    {
        int cnt = s[i] + s[i - 1];
        int cur = min(s[i],max(0,cnt - k));
        s[i] -= cur;
        ans += cur;
        cnt -= cur;
        ans += max(0,cnt - k);
    }
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}

Measured memory_bytes: 640
# encoding: utf-8
import sys
# input = sys.stdin.readline

N = int(input())
a = list(map(int, input().split()))

cnt = [0] * N
for i, ai in enumerate(a):
    for cnti in range(128):
        if ai % (2 << cnti) > 0: break
    cnt[i] = cnti

cnt4 = 0
cnt2 = 0
cnt1 = 0
for cnti in cnt:
    if cnti < 1: cnt1 += 1
    elif cnti > 1: cnt4 += 1
    else: cnt2 += 1

# print("#", cnt)
if N < 2:
    if cnt[0] >= 2: print('Yes')
    else: print('No')
elif cnt2 == 0:
    if cnt4 == 0: print('No')
    elif cnt1 > cnt4 + 1: print('No')
    else: print('Yes')
else:
    if cnt1 > cnt4: print('No')
    else: print('Yes')

Measured memory_bytes: 14484
#include<iostream>
#include<vector>

using namespace std;
int main(){
    int N;
    cin >> N;


    int t[N+1], x[N+1], y[N+1];
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    for(int i = 1; i <= N; i++)cin >> t[i] >> x[i] >> y[i];

    for(int i = 1; i <= N; i++){
        int dist = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
        int time = t[i] - t[i-1];
        //cout << dist << " & " << time << endl;
        if(dist > time || (dist + time) % 2 == 1){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

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

ll dp[51][5100];
int N;
ll P;
vector<ll> A;
ll solve(){
  dp[0][0] = 1LL;
  for(int i=0;i<N;i++){
    for(int j=0;j<=5000;j++){
      dp[i+1][j] += dp[i][j];
      dp[i+1][j+A[i]] += dp[i][j];
    }
  }

  ll res = 0LL;
  for(int j=0;j<=5000;j++)
    if( j%2 == P ) res += dp[N][j];
  return res;
}
int main(){
  cin >> N; cin >> P;
  A.resize(N);
  for(auto &a:A) cin >> a;
  cout << solve() << endl;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long n,k;
    cin>>n>>k;
    long long a[n];
    f(i,0,n){
        cin>>a[i];
    }
    cout<<(n+k-3)/(k-1)<<endl;
    return 0;
}

Measured memory_bytes: 4380
from collections import deque
class Graph:
    edges = {}

    def append_edge(self, sv, ev, weight = 1):
        if sv in self.edges:
            self.edges[sv].append((ev, weight))
        else:
            self.edges[sv] = [(ev, weight)]

    def bfs(self, sv):
        dist = [-1]*len(self.edges.keys())
        q = deque([])   # キュー
        q.append(sv)
        dist[sv] = 0
        connect_vtxs = []
        while len(q) > 0:
            p = q.popleft()     # キュー取りだし（先頭）
            connect_vtxs.append(p)
            for (ev, w) in self.edges[p]:
                if dist[ev] != -1:
                    continue
                q.append(ev)    # キュー追加
                dist[ev] = dist[p] + 1
        return dist, connect_vtxs


N, X, Y = list(map(int, input().split()))

g = Graph()
for i in range(N - 1):
    g.append_edge(i, i + 1)
    g.append_edge(i + 1, i)
g.append_edge(X - 1, Y - 1)
g.append_edge(Y - 1, X - 1)

dist_cnt = [0]*N
for sv in range(N):
    dist, connect_vtxs = g.bfs(sv)
    for j in range(len(dist)):
        if dist[j] == -1: continue
        dist_cnt[dist[j]] += 1

for i in range(N-1):
    print(int(dist_cnt[i+1]/2))


Measured memory_bytes: 55132
def main():
    s = input()
    ans = solve(s)
    print(ans)


def solve(s):
    if not all([(c in ['R', 'U', 'D']) for c in s[::2]]):
        return 'No'
    if not all([c in ['L', 'U', 'D'] for c in s[1::2]]):
        return 'No'
    return 'Yes'


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
while True:
    I = input().split()
    a = int(I[0])
    op = I[1]
    b = int(I[2])
    if op == '?':
        break
    elif op == '+':
        print("%s"%(a + b))
    elif op == '-':
        print("%s"%(a - b))
    elif op == '/':
        print("%s"%(a // b))
    else:
        print("%s"%(a * b))
        


Measured memory_bytes: 5596
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef pair <int, int> pii;
 
// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
#define int ll
 
const int N = 2e5 + 5;
const int oo = 1e9 + 5;
 
void solve() {
	ll a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c) {
		cout << "No";
	} 
	else if ((a + b - c) * (a + b - c) > 4 * a * b) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}
 
 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt = 1;
	while (tt --) {
		solve();
	}
	return 0;
}
/*
	If you only do what you can do, 
	You will never be more than you are now!
*/

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

int main(){
  long long int s;
  int x,tmp,ans;
  
  cin >> s;
  
  for(ans=999; s>100; s/=10){
    x = s%1000; //下三桁
    tmp = abs( 753 - x );
    if( tmp < ans ) ans = tmp;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

//-------------------ここから回答する-----------------------

void solve(void)
{
    int n, k;
    cin >> n >> k;
    ll ans = 1;
    rep(i, n)
    {
        if (i == 0)
            ans *= k;
        else
            ans *= (k - 1);
    }
    cout << ans << endl;
}
int main(void)
{
    solve();
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int H,W;
    cin >> H >> W;
    
    int dist[10][10];
    for ( int i = 0; i < 10; i++ ) {
    for ( int j = 0; j < 10; j++ ) {
        cin >> dist[i][j];
    }
    }
    
    vector< vector<int> > A(H, vector<int>(W) );
    for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
        cin >> A[i][j];
    }
    }
    
    for ( int i = 0; i < 10; i++ ) {
    for ( int j = 0; j < 10; j++ ) {
    for ( int k = 0; k < 10; k++ ) {
        dist[j][k] = min( dist[j][k], dist[j][i] + dist[i][k] );
    }
    }
    }
    
    long long ans = 0;
    for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
        if ( A[i][j] != -1 ) {
            ans += dist[A[i][j]][1];
        }
    }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll solve(ll a[], ll n, ll k){
    ll dp[n+1],i,j;
    for(i=0;i<=n;i++){
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    for(i=1;i<n;i++){
        for(j=i-1;j>=max((ll)0,i-k);j--)
        dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
    }
    return dp[n-1];
}
int main(){
    ll n,k;
    cin>>n>>k;
    ll a[n],i;
    for(i=0;i<n;i++)cin>>a[i];
    cout<<solve(a,n,k);
}

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

int main(){
 int n,m;
 cin >> n >> m;
 int A[n][m],b[m];
 for(int i=0; i<n; i++){
  for(int j=0; j<m; j++){
   cin >> A[i][j];
  }
 }
 for(int i=0; i<m; i++) cin>>b[i];
 
 for(int i=0; i<n; i++){
  int vector = 0;
  for(int j=0; j<m; j++){
   vector += A[i][j]*b[j];
  }
  cout << vector << endl;
 }
}


Measured memory_bytes: 3116
#include<stdio.h>
int main(void)
{
  int n, k, m;
  scanf("%d", &n);
  scanf("%d", &k);
  
  if(n%2 == 0){
    m=n/2;
  }else{
    m=n/2+1;
  }    
  if(m >= k){
    printf("YES");
  }else{
    printf("NO");
    }
  return 0;
}

Measured memory_bytes: 128
#pragma region include
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD (int)(1e9+7)
#define INF (int)(1e9)
#define LLINF (int)(4e18)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
void input() {}
template<typename... R> void input(int& f, R&... r) { scanf("%d", &f); input(r...); }
template<typename... R> void input(double& f, R&... r) { scanf("%lf", &f); input(r...); }
template<typename... R> void input(ll& f, R&... r) { scanf("%lld", &f); input(r...); }
template<typename... R> void input(char& f, R&... r) { scanf("%c", &f); input(r...); }
template<typename... R> void input(string& f, R&... r) { cin >> f; input(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion
    
int main() {
    int H, W,N; input(H,W,N);
    vector<int> a(N); input(a);
    vector<int> c;
    vector<vector<int>> ans(H, vector<int>(W));
    REP(i, N) {
        REP(j, a[i]) {
            c.emplace_back(i);
        }
    }
    int itr = 0;
    REP(i, H) {
        if (i % 2 == 0) {
            REP(j, W) {
                ans[i][j] = c[itr++] + 1;
            }
        }
        else {
            REPR(j, W - 1) {
                ans[i][j] = c[itr++] + 1;
            }
        }
    }
    REP(i, H) {
        REP(j, W) {
            printf("%d ",ans[i][j]);
        }
        printf("\n");
    }
    getchar(); getchar();
}

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

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int m;
  m=max({a,b,c});
  cout<<m*10+a+b+c-m<<endl;



  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  int i;
  string s,f="YAKI";
  cin >> s;
  for (i=0;i<4;i++) if (s.size()<4 || s[i]!=f[i]) break;
  if (i==4) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N, sum = 0, Nsum = 0;
  cin >> N;
  vector<ll> A(N);
  for(ll i = 0; i < N; i++) {
    cin >> A.at(i);
    if(i >= 1) {
      sum += ((Nsum % 1000000007) * (A.at(i) % 1000000007)) % 1000000007;
      sum %= 1000000007;
    }
    Nsum += A.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

main() {
   string S; cin >> S;
   ll K; cin >> K;
   int cnt=1; vector<int> v;
   rep(i,S.size()-1){
      if(S[i]==S[i+1]) cnt++;
      else {v.push_back(cnt);
      cnt=1;}
   }
   v.push_back(cnt);
   if(v.size()==1){
      cout << (ll)(S.size()*K/2) << endl; 
   }
   else {
      ll sum=0;
      rep(i,v.size()){
         sum+=v[i]/2;
      }
      if(v[0]%2==1&&v[v.size()-1]%2==1&&S[0]==S[S.size()-1]){
         cout << (ll)sum*K+K-1 << endl;
      }
      else cout << (ll)sum*K << endl;
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n; cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    ll sumnum=0,ans=0;
    ll right = 0;
    for(int left = 0; left<n; left++){
        while(right<n && (sumnum+v[right])==(sumnum^v[right])){
            sumnum+=v[right];
            right++;
        }
        ans += right-left;
        if(right==left) right++;
        else{
            sumnum-=v[left];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] h = new int[n+1];
        
        for(int i = 1; i <= n; i++) h[i] = sc.nextInt();
        
        int[] dp = new int[n+1];
        
        dp[2] = Math.abs(h[1]-h[2]);
        
        for(int i = 3; i <= n; i++){
            dp[i] = Math.min(Math.abs(h[i-1] - h[i]) + dp[i-1], Math.abs(h[i-2] - h[i]) + dp[i-2]);
        }
        
        System.out.println(dp[n]);
    }
}


Measured memory_bytes: 51692
#include<bits/stdc++.h>
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair



using namespace std;
typedef unsigned long long ull;
typedef vector<int>vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef set<int> si;


const int N = 1e5+5;
int x[N],y[N],h[N];
int  H;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a,con;
	cin  >> a;
	for(int i=0;i<a;i++){
		cin >> x[i] >> y[i] >> h[i];
		if(h[i] > 0) con = i;
	}
	
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			H = h[con] + abs(x[con] - i) + abs(y[con] - j);
			bool fl = true;
				for(int k =0 ; k < a ; k ++){
					if(h[k] != max(H - abs(x[k] - i) - abs(y[k] - j), 0)){
						fl = false;
						break;
					}
			}
			if(fl){
				cout << i << ' ' << j << ' ' << H << endl;
				return 0;
			}
		}	
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  long long n,i,j,k,l,m,o,dp[111][5][5][5][5],mod=1000000007,ans=0,p;
  cin>>n;
  for(i=0;i<4;i++){
    for(j=0;j<4;j++){
      for(k=0;k<4;k++){
        for(l=0;l<4;l++){
          dp[4][i][j][k][l]=1;
          p=l+10*k+100*j+1000*i;
          if(p%1000==12||p/10==12)
            dp[4][i][j][k][l]=0;
          p=l+10*k+100*i+1000*j;
          if(p%1000==12||p/10==12)
            dp[4][i][j][k][l]=0;
          p=l+10*j+100*k+1000*i;
          if(p%1000==12||p/10==12)
            dp[4][i][j][k][l]=0;
          p=k+10*l+100*j+1000*i;
          if(p%1000==12||p/10==12)
            dp[4][i][j][k][l]=0;
          for(o=5;o<=n;o++)
            dp[o][i][j][k][l]=0;
        }
      }
    }
  }
  for(o=5;o<=n;o++){
    for(i=0;i<4;i++){
      for(j=0;j<4;j++){
        for(k=0;k<4;k++)
          for(l=0;l<4;l++){
            for(m=0;m<4;m++){
              dp[o][i][j][k][l]=(dp[o][i][j][k][l]+dp[o-1][m][i][j][k])%mod;
              p=l+10*k+100*j+1000*i;
          if(p%1000==12||p/10==12)
            dp[o][i][j][k][l]=0;
          p=l+10*k+100*i+1000*j;
          if(p%1000==12||p/10==12)
            dp[o][i][j][k][l]=0;
          p=l+10*j+100*k+1000*i;
          if(p%1000==12||p/10==12)
            dp[o][i][j][k][l]=0;
          p=k+10*l+100*j+1000*i;
          if(p%1000==12||p/10==12)
            dp[o][i][j][k][l]=0;
            }
          }
      }
    }
  }
  if(n==3)
    ans=61;
  else
    for(i=0;i<4;i++)
      for(j=0;j<4;j++)
        for(k=0;k<4;k++)
          for(l=0;l<4;l++)
            ans=(ans+dp[n][i][j][k][l])%mod;
  cout<<ans<<endl;
}


Measured memory_bytes: 768
#include<stdio.h> 
#define MAX 200000
  
int Partition(int D[],int p,int r){
 
  int i,j;
  i=p-1;
  int x = D[r];
  for(j=p;j<=r-1;j++){
    if(D[j]<=x){
      i=i+1;
      swap(&D[i],&D[j]);
    }
  }
  swap(&D[i+1],&D[r]);
  return i+1;
}
int A[MAX];
int main(){

  
  int n,temp;
  int i,x;
  int result;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  x=Partition(A,0,n-1);
  i=0;
  while(i<n){
    if(i)printf(" ");
    if(i==x)printf("[");
    result=A[i];
    printf("%d",result);
    if(i==x)printf("]");
    i=i+1;
  }
  printf("\n");
  return 0;
}
void swap(int* c,int* k){
  int temp;
  temp=*c;
  *c=*k;
  *k=temp;
}



Measured memory_bytes: 2136
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, K;
  cin >> N >> K;
  vll a(N);
  REP(i, N){
    cin >> a[i];
  }

  vvll dp(N, vll(K+1, 0));

  REP(j, a[0]+1){
    dp[0][j] = 1;
  }
  FOR(i, 1, N){
    ll tmp=0;
    REP(j, K+1){
      tmp += dp[i-1][j]%MOD;
      dp[i][j] += tmp%MOD;
      if(j>=a[i]) tmp -= dp[i-1][j-a[i]];
      while(tmp<0) tmp+=MOD;
      /*
      for(int k=0; k<a[i]+1 && j-k>=0; ++k){
        dp[i][j] += dp[i-1][j-k];
      }
      */
    }
  }

  cout << dp[N-1][K]%MOD << "\n";

  return 0;
}


Measured memory_bytes: 79488
h, w, k = map(int, input().split())
chw = [input() for _ in range(h)]
  
answer = 0
for col in range(2**h):
  for row in range(2**w):
    black = 0
    for i in range(h):
      for j in range(w):
        if ((col >> i) & 1) and ((row >> j) & 1) and (chw[i][j] == "#"):
          black = black +1

    if black == k:
      answer += 1

print(answer)

Measured memory_bytes: 9236
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int maxA = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (maxA < a[i]) {
			maxA = a[i];
		}
	}
	int lcm = 1;
	for (int p = 2; p * p <= maxA; p++) {
		int maxcnt = 0;
		for (int i = 0; i < n; i++) {
			int cnt = 0;
			while (a[i] % p == 0)
			{
				a[i] /= p;
				cnt++;
			}
			if (maxcnt < cnt)
				maxcnt = cnt;
		}
		lcm *= pow(p, maxcnt);
	}
	for (int i = 0; i < n; i++) {
		if ((a[i] > 1) && (lcm % a[i] != 0)) {
			lcm *= a[i];
		}
	}
	cout << lcm << endl;
	return 0;
}


Measured memory_bytes: 3284
h, w = map(int, input().split())
a = [input() for _ in range(h)]


for i in range(h):
  bombs = []
  for j in range(w):
    if a[i][j]=='.':
      cnt = 0
      for s in range(max(i-1, 0), min(i+2,h)):
        for t in range(max(j-1, 0), min(j+2,w)):
          if a[s][t]=='#':
            cnt += 1
      bombs.append(str(cnt))
    else:
      bombs.append('#')
    
  a[i] = ''.join(bombs)
    
for i in range(h):
  print(a[i])

Measured memory_bytes: 3064
# ABC080C - Shopping Street
import sys
input = sys.stdin.readline

from itertools import product


def main():
    N = int(input())
    F = tuple(int(input().replace(" ", ""), 2) for _ in range(N))
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    ans = []
    for i in range(1, 2 ** 10):
        cnt = sum(p[bin(i & f).count("1")] for f, p in zip(F, P))
        ans += [cnt]
    print(max(ans))


if __name__ == "__main__":
    main()

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

int     main() {
	vector<bool> PRI(100001, true);
	PRI.at(0)=false;
	for (int i=2; i<=100000; i++) {
		if (PRI.at(i)) {
			int j=i;
			j +=i;
			while (j<100001) {
				PRI.at(j)=false;
				j +=i;
			}
		}
	}
	vector<bool> PRI2(100001, false);
	for (int i=2; i<50000; i++) {
		if (PRI.at(i)) {
			int j=i+i-1;
			if (PRI.at(j))
			       PRI2.at(j)=true;	
		}
	}
	vector<int> PRIN(100001, 0);
	int N=0;
	for (int i=1; i<100001; i++) {
		if (PRI2.at(i))
			N++;
		PRIN.at(i)=N;
	}
	int Q;
	cin >>Q;
	int l, r;
	for (int i=1; i<=Q; i++) {
		cin >>l >>r;
		cout <<(PRIN.at(r)-PRIN.at(l-1)) <<endl;
	}
	return 0;
};


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map(String::toInt)
    val s = readLine()!!
    val regex = Regex("^[0-9]{$a}-[0-9]{$b}\$")
    if (regex.matches(s)) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 37864
// OURL: https://atcoder.jp/contests/abc139/tasks/abc139_a
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));  }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v);  }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", ";  } first = false; res += to_string(x);  } res += "}"; return res;  }

string to_string(string s) { return '"' + s + '"';  }
string to_string(const char* s) { return to_string((string) s);  }
string to_string(bool b) { return (b ? "true" : "false");  }
string to_string(vector<bool>::reference b) { return to_string(bool(b));  }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";  }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res; }

void debug_out() { cerr << endl;  }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...);  }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

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

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;

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

  ll n,m;
  cin >> n >> m;
  vector<ll> a(m);
  ll s=0;
  rep(i,m) {
    cin >> a[i];
    s+=a[i];
  }
  if(s<=n){
    cout << n-s << endl;
  }else{
    cout << -1 << endl;
  }
  
  return 0;
  }


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

s, t = input().split()
a, b = map(int, input().split())
u = input()
if s == u:
    print(a - 1, b)
else:
    print(a, b - 1)


Measured memory_bytes: 2940
#include <iostream>
#include <string>

using namespace std;

int main() {
	string str;
	int m, h, i;

	while (cin >> str, str != "-") {
		cin >> m;
		for (i = 0; i<m; i++) {
			cin >> h;
			str = str.substr(h, str.size() - h) + str.substr(0,h);
		}
		cout << str << endl;
	}
}

Measured memory_bytes: 1216
# include<iostream>
# include <cstdio>
# include <algorithm>

using namespace std;


int main(void)
{
    long long temp = 1;
    long long H;
    scanf("%lld",&H);
    long long ans = 0;
    while(H){
        ans+=temp;
        H>>=1;
        temp<<=1;
    }
    cout<<ans<<endl;
    return 0;
}

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

const int inf = 1012345678;

int main()
{
	vector<int> time(5);
	cin >> time[0] >> time[1] >> time[2] >> time[3] >> time[4];
	vector<int> P = {0,1,2,3,4};
	int best_time = inf;
	do
	{
		int sum_time = 0;
		for (int i = 0; i < 5; ++i)
		{
			while (sum_time % 10 != 0)
			{
				sum_time++;
			}
			sum_time += time[P[i]];
		}
		best_time = min(best_time, sum_time);

	} while (next_permutation(P.begin(), P.end()));

	cout << best_time << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  int n, m;
  cin >> n >> m;
  vector<VI> adj_list(n+1);
  forx(i,m) {
    int u, v;
    cin >> u >> v;
    adj_list[u].push_back(v);
    adj_list[v].push_back(u);
  }
  if (m & 1) {
    cout << -1 << nl;
    return 0;
  }
  VB seen(n+1);
  VI deg(n+1);
  set<pii> temp;
  function<void(int,int)> dfs = [&](int u, int p) {
    if (seen[u]) {
      pii use = minmax(p,u);
      if (!temp.count(use)) {
        deg[use.ff]++;
        temp.insert(use);
      }
      return; }
    seen[u] = true;
    for (int v : adj_list[u]) {
      if (v != p) {
        dfs(v, u);
      }
    }
  };
  dfs(1,-1);
  vector<pii> ans(temp.begin(), temp.end());
  /*
  cerr << "pre\n";
  for (pii e : ans) {
    cerr << e.ff << " " << e.ss << nl;
  }
  */
  fill(seen.begin(), seen.end(), false);
  function<void(int,int)> dfs2 = [&](int u, int p) {
    if (seen[u]) return;
    seen[u] = true;
    for (int v : adj_list[u]) {
      if (v != p)
        dfs2(v, u);
    }
    if (p != -1) {
      if (deg[u] & 1) {
        deg[u]++;
        ans.push_back({u,p});
      } else {
        deg[p]++;
        ans.push_back({p,u});
      }
    }
  };
  dfs2(1,-1);
  for (pii e : ans) {
    cout << e.ff << " " << e.ss << nl;
  }

  return 0;
}



Measured memory_bytes: 17524
#include<stdio.h>

#define S_SIZE 100001

char s[S_SIZE];

typedef struct{
  char c;
  struct Deque *prev;
  struct Deque *next;

} Deque;

int main(void) {
  int query_size;
  int reverse = 0;
  Deque *head,*tail,*tmp;
  head = (Deque *)malloc(sizeof(Deque));

  scanf("%s",s);
  scanf("%d",&query_size);

  head->c = s[0];
  head->next = NULL; head->prev = NULL;
  tail = head;

  for(int i = 1;i < strlen(s);i++) {
    tmp = (Deque *)malloc(sizeof(Deque));
    tmp->c = s[i];
    head->next = tmp;
    tmp->next = NULL;
    tmp->prev = head;
    head = tmp;
  };

  for(int i = 0;i < query_size;i++) {
    int t,f;
    char c;
    scanf("%d",&t);

    if(t==1) {
      reverse = (reverse == 0)? 1:0;
      continue;
    }
    scanf("%d %c",&f,&c);
    tmp = (Deque *)malloc(sizeof(Deque));
    tmp->c = c;
    if((f==1 && reverse == 1) || (f==2 && reverse == 0)) {
      // 末尾追加
      head->next = tmp;
      tmp->next = NULL;
      tmp->prev = head;
      head = tmp;
    } else {
      // 先頭追加
      tail->prev = tmp;
      tmp->next = tail;
      tmp->prev = NULL;
      tail = tmp;
    }
  }

  if(reverse == 0) {
    for(Deque *d = tail;d != NULL;d = d->next) {
      printf("%c",d->c);
    }
  } else {
    for(Deque *d = head;d != NULL;d = d->prev) {
      printf("%c",d->c);
    }
  }
}


Measured memory_bytes: 9984
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,x,y) for(register int i=x;i<=y;++i)
#define repd(i,x,y) for(register int i=x;i>=y;--i)
#define ll long long
using namespace std;
const int N=1e3+100;
int n,m;
int g[4][N],dp[4][N];

int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	rep(i,1,2)rep(j,1,n)cin>>g[i][j];
	rep(i,1,2)rep(j,1,n)dp[i][j]=max(dp[i-1][j]+g[i][j],dp[i][j-1]+g[i][j]);
	cout<<dp[2][n]<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        List<Integer[]> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            Integer[] array = new Integer[m + 1];
            array[0] = Integer.parseInt(sc.next());
            for (int j = 1; j <= m; j++) {
                array[j] = Integer.parseInt(sc.next());
            }
            a.add(array);
        }
        sc.close();

        // 主処理
        List<List<Integer>> combinationList = getCombinationList(n);

        int min = Integer.MAX_VALUE;
        for (List<Integer> comb : combinationList) {
            int amount = 0;
            int[] score = new int[m];
            for (int index : comb) {
                amount += a.get(index)[0];
                for (int i = 0; i < m; i++) {
                    score[i] += a.get(index)[i + 1];
                }
            }
            int size = Arrays.stream(score).filter(i -> x <= i).toArray().length;
            if (m == size) {
                min = Math.min(min, amount);
            }
        }

        int result = min == Integer.MAX_VALUE ? -1 : min;

        // 出力
        System.out.println(result);
    }

    public static List<List<Integer>> getCombinationList(int n) {
        List<List<Integer>> combinationList = new ArrayList<>();
        for (int i = 0; i < Math.pow(2, n); i++) {
            List<Integer> list = new ArrayList<>();
            for (int j = 0; j < n; j++) {
                if ((1 & i >> j) == 1) {
                    list.add(j);
                }
            }
            combinationList.add(list);
        }
        return combinationList;
    }
}


Measured memory_bytes: 42048
x, y = map(int, input().split())
if x > y and y >= 0:
    print(min(x+y+1, x-y+2))
elif x > y and x <= 0:
    print(x-y+1+(x!=0))
elif x > 0 and y < 0:
    print(abs(abs(x)-abs(y))+1)
elif x < y:
    print(min(y-x, abs(abs(y)-abs(x))+1))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		String str = sc.next();
		int zerocnt = 0, onecnt = 0;
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) == '0') {
				zerocnt++;
			} else {
				onecnt++;
			}
		}
		System.out.println(2 * Math.min(zerocnt, onecnt));
	}
}


Measured memory_bytes: 25496
#include<bits/stdc++.h>
using namespace std;
long long dp[2][100001],v[101],w[101];
int main()
{
    int n,W;
    cin>>n>>W;
    for(int i=0;i<n;i++)
        cin>>w[i]>>v[i];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=W;j++)
        {
            if(w[i]>j)
                dp[(i+1)&1][j]=dp[i&1][j];
            else
                dp[(i+1)&1][j]=max(dp[i&1][j],dp[i&1][j-w[i]]+v[i]);
        }
    }
    cout<<dp[n&1][W]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef pair<l_l,ll> lll;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
ll n,k;
bool dp[100001];
int main(){
    cin>>n>>k;
    vl a(n);rep(i,n)cin>>a[i];
    rrep(i,k){
        rep(j,n){
            if(i-a[j]>=0)dp[i]|=!dp[i-a[j]];
        }
    }
    if(dp[k])cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}

Measured memory_bytes: 3696
//Rishabh Sethi @lostground97

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

#define pb push_back
#define mp make_pair
#define ll long long
#define in insert
#define mod 1000000007
#define vpair vector< pair <ll,ll> >
#define F first
#define S second

ll modexp(ll x, ll y)
{
	ll ans = 1;
	x = x%mod;
	while(y>0)
	{
		if(y%2==1)
			ans = (ans%mod*x%mod)%mod;
		y = y/2;
		x = (x%mod*x%mod)%mod;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	vector<ll> v;
	for(int i=0; i<n; i++)
	{
	    ll x;
	    cin>>x;
	    v.pb(x);
	}
	sort(v.begin(), v.end());
	ll l = v[0], r = v[n-1];
	ll ans = (r-l);
	ll i = 1;
	ll j = n-2;
	while(i<=j)
	{
	    ll p = v[i];
	    ll q = v[j];
	    ll a1 = max(abs(l-p),abs(r-p));
	    ll a2 = max(abs(l-q),abs(r-q));
	    if(a1>=a2)
	    {
	        ans += a1;
	        if(abs(l-p)>=abs(r-p))
	        {
	            l = p;
	        }
	        else
	        {
	            r = p;
	        }
	        i++;
	    }
	    else
	    {
	        ans += a2;
	        if(abs(l-q)>=abs(r-q))
	        {
	            l = q;
	        }
	        else
	        {
	            r = q;
	        }
	        j--;
	    }
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        long long s=0,a;
       for(int i=1;i<=n;i++)
       {
           cin>>a;
           s+=a;
       }
       cout<<s-n<<endl;
    }
    return 0;
}


Measured memory_bytes: 256