akhauriyash/Code-Regression huggingface dataset:
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)


ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n=nxt();
    ll ans=1;
    rep(a,0,n)
    {
        ll b=nxt();
        if(b==0)
        {
            ans=0;
        }
        if(ans>0 and b>inf/ans)
        {
            ans=-1;
        }
        if(ans!=-1)
        {
            ans*=b;
        }
    }
    cout<<ans<<endl;
	printclock;
	return 0;
}

Measured memory_bytes: 3800
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let mut v = input_vector::<usize>();
    let mut ans = 0;
    v.sort();
    ans += (v[2] - v[0]) / 2;
    ans += (v[2] - v[1]) / 2;

    if v[2] % 2 == v[0] % 2 {
        v[0] = v[2];
    } else {
        v[0] = v[2] - 1;
    }
    if v[1] % 2 == v[2] % 2 {
        v[1] = v[2];
    } else {
        v[1] = v[2] - 1;
    }

    while !(v[0] == v[1] && v[1] == v[2]) {
        v.sort();
        v[0] += 1;
        v[1] += 1;
        ans += 1;
    }
    p(ans);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

bool match(vector<string> A, int i, int j, vector<string> B) {
	int N = A.size();
	int M = B.size();
	FOR(p, 0, M) {
		FOR(q, 0, M) {
			if (B[p][q] != A[i + p][j + q]) return false;
		}
	}
	return true;
}

int main_() {
	int N, M;
	cin >> N >> M;
	vector<string> A(N), B(M);
	FOR(i, 0, N) cin >> A[i];
	FOR(i, 0, M) cin >> B[i];

	bool ok = false;
	FOR(i, 0, N-M+1) {
		FOR(j, 0, N-M+1) {
			if (match(A, i, j, B)) {
				ok = true;
				break;
			}
		}
		if (ok) break;
	}

	string ans = ok ? "Yes" : "No";
	cout << ans << endl;
	return 0;
}


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

int main(void) {
    int N,M;
    int sum = 0;
    cin >> N >> M;
    vector<int> X(M);
    vector<int> diff(M-1);
    for(int i=0;i<M;i++) {
        cin >> X[i];
    }
   
    if(N >= M){
        cout << "0\n";
        return 0;
    }

    sort(X.begin(), X.end());
    for(int i=1;i<M;i++){
        diff[i-1] = X[i]-X[i-1];
    }

    sort(diff.begin(), diff.end());
    for(int i=0;i<(M-N);i++) {
        sum += diff[i];
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n,k;
    cin >> n >> k;
    ll cnt = 0;
    for (int i = k+1; i <= n;i++){
        int tmp = n % i;
        int num = n / i;
        cnt += num * (i - k);
        cnt += max(0, tmp - max(0,(k-1)));
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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 n;cin>>n;
    int ans = 0;
    if(n<2){
        cout<<n<<endl;
        return 0;
    }
    for(int i=2;i<=n;i=i*2){
        ans = i;
        if(i>n) break;
    }
    cout<<ans<<endl;

}

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

int main(void){
    string s;
    int c = 0;
    cin >> s;
    bool flag = true;
    for (int i=0; i<s.size(); i++){
        if (i==0 && s[i]!='A'){
            flag = false;
            break;
        } else if(i>=2 && i<=s.size()-2){
            if (s[i] == 'C') c++;
            else if (s[i]>='A' && s[i]<='Z'){
                flag = false;
                break;
            }
        }
    }
    if ((s[1]>='A' && s[1]<='Z') || (s[s.size()-1]>='A' && s[s.size()-1]<='Z')) flag = false;
    if (c != 1) flag = false;
    cout << (flag ? "AC" : "WA") << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int main() {
	int x, y;	cin >> x >> y;
	int groupX = 0, groupY = 0;

	if (x == 2) {
		groupX = 3;
	}
	else if (x == 4 || x == 6 || x == 9 || x == 11) {
		groupX = 2;
	}
	else {
		groupX = 1;
	}

	if (y == 2) {
		groupY = 3;
	}
	else if (y == 4 || y == 6 || y == 9 || y == 11) {
		groupY = 2;
	}
	else {
		groupY = 1;
	}

	if (groupX == groupY) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
// Problem : D - Alter Altar
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*

WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF LLONG_MAX/2

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i = 0;
    int j = n - 1;
    int cnt = 0;
    while (i < n && j >= 0 && i < j) {
    	while (i < n && s[i] == 'R') {
    		++i;
    	}
    	while (j >= 0 && s[j] == 'W') {
    		--j;
    	}
    	if (i < n && j >= 0 && i < j) {
    		swap(s[i], s[j]);
    		cnt++;
    	}
    }
    cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 3684
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

int main() {
	ll H, W, D;

	cin >> H >> W >> D;

	map<int, pair<ll, ll> > m;

	ll a[H][W];
	rep(y, H) {
		rep(x, W) {
			cin >> a[y][x];
			m[a[y][x]] = mkp(y, x);
		}
	}


	vector<ll> imos(H * W + 1, 0);


	for(int i = D; i <= H * W; i++) {
			pair<int, int> cp = m[i - D];
			pair<int, int> np = m[i];		
			imos[i] = imos[i - D] + abs(cp.first - np.first) + abs(cp.second - np.second);	
	}

	int q;
	cin >> q;

	rep(i, q) {
		int L, R;
		cin >> L >> R;

		cout << imos[R] - imos[L] << endl;

	}

	return 0;
}

Measured memory_bytes: 9984
using System;
using System.Collections.Generic;
using System.Linq;

class MainClass
{
    static void Main(string[] args)
    {
		AnswerA();
    }
	public static void AnswerA()
    {
      int X = int.Parse(Console.ReadLine());
      int A = int.Parse(Console.ReadLine());
      int B = int.Parse(Console.ReadLine());
      X -= A;//ケーキは固定で１個購入
      int CanBuyBCnt = (int)Math.Floor((decimal)X / (decimal)B);
      X -= (CanBuyBCnt * B);
      Console.WriteLine(X.ToString());
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr i64 MOD = 1000000007;
constexpr i64 INF = 1LL << 60;

struct edge {
	int to;
	i64 cost;
	edge(int t, i64 c) : to(t), cost(c) {}
};

vector<edge> g[100000];

int main() {
	int n, a, b, q, k, x, y; cin >> n;
	i64 c;
	rep(i, 0, n - 1) {
		cin >> a >> b >> c;
		--a, --b;
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}
	cin >> q >> k;
	--k;

	queue<int> que;
	vector<i64> dist(n, INF);
	que.emplace(k);
	dist[k] = 0;
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for (edge e : g[v]) {
			if (dist[e.to] == INF) {
				que.emplace(e.to);
				dist[e.to] = e.cost + dist[v];
			}
		}
	}

	rep(i, 0, q) {
		cin >> x >> y;
		--x, --y;
		cout << dist[x] + dist[y] << '\n';
	}
	return 0;
}

Measured memory_bytes: 11600
import collections as col
cnt = col.Counter()
cnt[0] += 1


s = input()
n = len(s)

num = 0
for i,s in enumerate(s[::-1]):
    num += int(s) * pow(10, i, 2019)
    cnt[num%2019] += 1

ans = 0
for key,val in cnt.items():
    ans += val*(val-1)//2

print(ans)


Measured memory_bytes: 9612
import sys
import math
from itertools import permutations
input = sys.stdin.readline

N,M=map(int,input().split())

arr=list(map(int,input().split()))

arr.sort()
blist=[]
clist=[]
for i in range(M):
	b,c=map(int,input().split())
	blist.append(b)
	clist.append(c)

res=sorted(zip(clist,blist), reverse=True)

cur=0
ptr=0
for i in range(N):
	if cur<len(res):
		if ptr<res[cur][1]:
			arr[i]=max(arr[i],res[cur][0])
			ptr+=1
		else:
			ptr=0
			cur+=1
			if cur<len(res):
				arr[i]=max(arr[i],res[cur][0])
				ptr+=1
			else:
				break
	else:
		break

print(sum(arr))



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


int H,W;
int D[500][500];
int LIM[500][500];
int O[500][500];
int T[500][500];
int chmin(int &a,int b){
	if( a > b ) a = b;
}


int put(int i,int j){
	for(int k = -1 ; k <= 1 ; k++){
		for(int l = -1 ; l <= 1 ; l++){
			if(i+k < 0 || j+l < 0 || i+k >= H || j+l >= W ) continue;
			D[i+k][j+l]--;
		}
	}
}
int main(){
	cin >> H >> W;
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			cin >> D[i][j];
			LIM[i][j] = 1e9;
		}
	}
	
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			while( D[i][j] ){
				put(i+1,j+1);
				O[i+1][j+1] = 1;
			}
		}
	}
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			if( O[i][j] )
			for(int k = -1 ; k <= 1 ; k++){
				for(int l = -1 ; l <= 1 ; l++){
					if( k==0&&l==0||i+k < 0 || j+l < 0 || i+k >= H || j+l >= W ) continue;
					T[i+k][j+l]++;
				}
			}
		}
	}
	vector< pair<int,int> > s;
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			if( O[i][j] && T[i][j] <= 1 )
				s.push_back({i,j});
		}
	}
	if( s.size() == 1 ){
		s.push_back(s[0]);
	}
	assert(s.size()==2);
	sort(s.rbegin(),s.rend());
	cout << s[0].first << " " << s[0].second << " " << s[1].first << " " << s[1].second << endl;
}

Measured memory_bytes: 4552
#141dの応用
from collections import deque

X,Y,A,B,C = map(int, input().split())
p_list = [int(e) for e in input().split()]
q_list = [int(e) for e in input().split()]
r_list = [int(e) for e in input().split()]

p_list.sort(reverse=True)
q_list.sort(reverse=True)
r_list.sort(reverse=False)

#リストから高い方のみ取り出し
red_apples = p_list[0:min(A,X)]
green_apples = q_list[0:min(B,Y)]

colorless_apples = r_list

#print("R:",red_apples)
#print("G:",green_apples)
#print("*:",colorless_apples)
#print("########################")

#不足分をまず食べておく
if len(red_apples) < X:
    shortage = X - len(red_apples)
    red_apples += colorless_apples[0:shortage]
    del colorless_apples[0:shortage]
if len(green_apples) < Y:
    shortage = Y - len(green_apples)
    green_apples += colorless_apples[0:shortage]
    del colorless_apples[0:shortage]

#print("R:",red_apples)
#print("G:",green_apples)
#print("*:",colorless_apples)
#print("##########################")

eat_apples = red_apples + green_apples
eat_apples.sort(reverse=True)

#print("E:",eat_apples)
#print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")

lowest_apple = eat_apples.pop(-1)

replaced_deque = deque() #左高 右低

#replaced_deque | eat_apples | colorless_apples
#| 1 1 2 5 7 8 12 35 58 98 | 1 3 5 7 9
#3 | 1 2 5 7 8 12 35 58 98 | 3 5 7 9
#3 3 | 2 5 7 8 12 35 58 98 | 5 7 9
#3 3 5 | 5 7 8 12 35 58 98 | 7 9
#3 3 5 | 5 7 8 12 35 58 98 | 7 9
#3 5 7 | 5 7 8 12 35 58 98 | 9
#5 7 9 | 5 7 8 12 35 58 98 |

#リンゴを低い方から、残った無色に入れ替えた方がよければ入れ替えていく。入れ替える際はより低い方を選択する
for i in range(len(colorless_apples)):

    #print("eat_apples    :" ,eat_apples)
    #print("replaced_deque:" ,replaced_deque)
    #print("lowest        :" ,lowest_apple)
    #print("candidate     :" ,colorless_apples[i])
    #print("##########################")

    if colorless_apples[i] > lowest_apple:
        replaced_deque.appendleft(colorless_apples[i])

        if len(eat_apples) > 0:
            if replaced_deque[-1] < eat_apples[-1]:
                lowest_apple = replaced_deque.pop()
            else:
                lowest_apple = eat_apples.pop(-1)
        else:
            lowest_apple = replaced_deque.pop()

print(sum(eat_apples) + sum(replaced_deque) + lowest_apple)


Measured memory_bytes: 23480
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main{
    static int w;
    static  int n;
    static int[] we;
    static long val[];
    static long[][] memo;
    public static void main(String[] args) throws IOException {
        scanner sc = new scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        n = sc.nextInt();
        w = sc.nextInt();

        we = new int[n];
        val = new long[n];
        memo = new long[n][w+1];

        for (int i = 0; i < n; i++)
            Arrays.fill(memo[i],-1);

        for (int i = 0; i < n; i++) {
            we[i] = sc.nextInt();
            val[i] = sc.nextInt();
        }

        out.println(dp(0,w));
        out.flush();
    }

    static long dp(int i,int w){
        if (i == n || w == 0)
            return 0;

        if (memo[i][w] != -1)
            return memo[i][w];

        long take = 0;

        if (w-we[i] >= 0)
            take = dp(i+1,w-we[i]) + val[i];

        long leave = dp(i+1,w);

        return memo[i][w] = Math.max(take,leave);
    }

}
class scanner{
    StringTokenizer st;
    BufferedReader br;
    public scanner(InputStream s){
        br = new BufferedReader(new InputStreamReader(s));
    }
    public scanner (String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(s));}

    public String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public long nextLong() throws IOException {
        return  Long.parseLong(next());
    }

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

    public boolean ready() throws IOException {
        return br.ready();
    }
}

Measured memory_bytes: 126036
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 998244353
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N, S;
	cin >> N >> S;
	vl A(N);
	rep(i, N)
		cin >> A[i];
	vector<vl> DP(N + 1);
	rep(i, N + 1)
		DP[i].resize(S + 3, 0); // 0~S : 処理中で和がi, S+1 : 左端未確定, S+2 : 右端確定
	DP[0][S + 1] = 1;

	rep(i, N) {
		ll Atmp = A[i];
		rep(j, S + 1) {
			DP[i + 1][j] += DP[i][j]; // 選ばない
			DP[i + 1][j] %= mod;
			ll jnxt = j + Atmp;
			if (jnxt > S)
				continue;
			DP[i + 1][jnxt] += DP[i][j]; // 選ぶ
			DP[i + 1][jnxt] %= mod;
		}
		DP[i + 1][0] += DP[i][S + 1]; // 左端 : i, 選ばない
		DP[i + 1][0] %= mod;
		if (Atmp <= S) {
			DP[i + 1][Atmp] += DP[i][S + 1]; // 左端 : i, 選ぶ
			DP[i + 1][Atmp] %= mod;
		}
		DP[i + 1][S + 1] += DP[i][S + 1]; // 左端 : >i
		DP[i + 1][S + 1] %= mod;
		DP[i + 1][S + 2] += DP[i][S]; // 右端 : i, 選ばない
		DP[i + 1][S + 2] %= mod;
		if (S - Atmp >= 0) {
			DP[i + 1][S + 2] += DP[i][S - Atmp]; // 右端 : i, 選ぶ
			DP[i + 1][S + 2] %= mod;
		}
		if (S - Atmp == 0) {
			DP[i + 1][S + 2] += DP[i][S + 1]; // 左端,右端 : i, 選ぶ
			DP[i + 1][S + 2] %= mod;
		}
		DP[i + 1][S + 2] += DP[i][S + 2]; // 右端 : <i
		DP[i + 1][S + 2] %= mod;
	}

	ll ans = DP[N][S + 2];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <tuple>

using namespace std;

using P = pair<int, int>;
using i64 = int64_t;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;

int main(int argc, char **argv) {
    string s;
    cin >> s;
    std::vector<int> ans(s.size(), 0);

    int cnt_r{0}, cnt_l{0};
    std::size_t end_r, start_l;
    for (std::size_t i=0; i<s.size(); ++i) {
        if (s[i] == 'R') {
            ++cnt_r;
        } else {
            if (cnt_l == 0) {
                end_r = i-1;
                start_l = i;
            }
            ++cnt_l;
            if (i == s.size()-1 || s[i+1] == 'R') {
                //cout << "hey " << cnt_r << " " << cnt_l << endl;
                // gather answer
                ans[end_r] = ans[start_l] = (cnt_r+cnt_l)/2;
                if ((cnt_r+cnt_l)%2 == 1) {
                    if (cnt_r % 2 == 1) {
                        ++ans[end_r];
                    } else {
                        ++ans[start_l];
                    }
                }
                cnt_r = 0;
                cnt_l = 0;
            }
        }
    }

    for (auto i : ans) {
        cout << i << " ";
    }
    cout << endl;

    return 0;
}

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

int main()
{
    vector<int> a(3);
    
    cin >> a.at(0) >> a.at(1) >> a.at(2);
  
    sort(a.begin(),a.end());
    
    cout << a.at(0) << " " << a.at(1) << " " << a.at(2) << endl;
}


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

int main(void){
    int X, ans=0;
    std::cin >> X;
    for (int i=1; i<32; ++i){
        for (int j=2; j<10; ++j){
            int x = std::pow(i, j);
            if (x <= X && x > ans){
                ans = x;
            } else if (x > X) break;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 4028
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    vector<double> height;
    double tmp;

    while(cin >> tmp){
        height.push_back(tmp);
    }

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

    double min;
    double max;

    min = height[0];
    max = height[height.size()-1];

    cout << max - min << endl;

    return 0;
}

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

using namespace std;

int main() {
	int height[10];
	for(int i = 0; i < 10; i++)
		cin >> height[i];
	sort(height, height + 10);
	for(int i = 0; i < 3; i++)
		cout << height[9-i] << endl;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {

		int a = sc.nextInt();
		int b = sc.nextInt();
		if(b > a) {
			int temp = b;
			b = a;
			a = temp;
		}

		int c = a % b;
		while(c != 0){
			a = b;
			b = c;
			c = a % b;
		}

		System.out.println(b);

	}

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 24444
#include <iostream>
#include <cstring>
#include <climits>
int main()
{
	int n,k;
	while(std::cin>>n>>k,n|k){
		int memo[100000];
		int ans = INT_MIN;
		int cnt = 0;
		int sum = 0;
		memset(memo,0,sizeof(memo));
		
		for(int i=0; i<n; i++){
			int a; std::cin>>memo[i];
			if(cnt<k){
				sum+=memo[i]; cnt++;
			}
			else{
				sum = sum-memo[i-k]+memo[i];
				//printf("sum:%d\n",sum);
			}
			if( k==cnt && sum>ans ) ans = sum;
			//printf("sum:%d\n",sum);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
<?php
 fscanf(STDIN, '%d %d %d %d %d', $a, $b, $c, $x, $y);
 $pt1 = $a * $x + $b * $y;

 $pt2 = 2 * $c * min($x, $y);
 $pt2 += ($x > $y) ? ($x - $y) * $a : ($y - $x) * $b;

 $pt3 = 2 * $c * max($x, $y);

 echo min($pt1, $pt2, $pt3). "\n";

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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, x, res[200005], used[200005];

int main(){
	scanf("%d %d", &n, &x);
	if(x == 1 || x == (n * 2 - 1)){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	used[x] = used[x - 1] = used[x + 1] = 1;
	int p = 1;
	FI(i, 1, n * 2 - 1){
		if(abs(i - n) <= 1) printf("%d\n", x + n - i);
		else{
			while(used[p]) p++;
			printf("%d\n", p);
			used[p] = 1;
		}
	}
	return 0;
}

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

struct Node{
	int key;
	struct Node *l, *r, *p;
};

struct Node *root, *NIL;

struct Node * tMin(struct Node *v){
	while(v->l != NIL) v = v->l;
	return v;
}

struct Node *tSuc(struct Node *v){
	struct Node *y;
	if(v->r != NIL) return tMin(v->r);
	y = v->p;
	while(y != NIL && v == y->r){
		v = y;
		y = y->p;
	}
	return y;
}

void tDelete(struct Node *z){
	struct Node *y; //?????????????±?
	struct Node *x; //y??????

	// ??????????????????????±???????
	if(z->l == NIL || z->r == NIL)y=z;
	else y =tSuc(z);
	//y??????????±???????
if(y->l != NIL){
	x=y->l;
}
else {
	x = y->r;
}

	if(x != NIL){
		x->p = y->p;
	}


	if(y->p == NIL){
		root = x;
	}
	else {
		if(y==y->p->l){
			y->p->l=x;
		}
		else y->p->r = x;
	}
	if(y != z){
		z->key = y->key;
	}
	free(y);
}



struct Node * find(struct Node *u,int k){
  while(u != NIL && k != u->key){
    if(k < u->key)u=u->l;
    else u=u->r;
  }
  return u;
}

void insert(int v){
struct Node *y = NIL;
struct Node *x = root;
struct Node *z;

z = (struct Node *)malloc(sizeof(struct Node));
z->key = v;
z->l = NIL;
z->r = NIL;

while(x != NIL){
y = x;
if( z->key < x->key ){
	x = x->l;
	}
else{
x = x->r;
	}
}
z->p = y;
if(y == NIL){
	root = z;
}
else if(z->key < y->key){
	y->l =z;
}
else{
	y->r =z;
}
}

void Iorder(struct Node *u){
	if(u == NIL){
		return;
	}
	Iorder(u->l);
	printf(" %d", u->key);
	Iorder(u->r);
}
void Porder(struct Node *u){
	if(u == NIL){
		return;
	}
	printf(" %d", u->key);
	Porder(u->l);
	Porder(u->r);
}

int main(){
	int n,i,v;
  struct Node *t;
	char *sent = malloc(7);
char *s1 = "insert";
char *s2 = "print";
char *s3 = "delete";
	scanf("%d",&n);

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

		scanf("%6s",sent);
    if(sent[0] == 'f'){
      scanf("%d",&v);
      t = find(root,v);
      if(t != NIL)printf("yes\n");
      else printf("no\n");
    }
		else if(0==strcmp(sent,s1)){
			scanf("%d", &v);
			insert(v);
		}
		else if(0==strcmp(sent,s2)){
			Iorder(root);
			printf("\n");
			Porder(root);
			printf("\n");
		}
		else if(0==strcmp(sent,s3)){
			scanf("%d",&v);
			tDelete(find(root, v));
		}
	}

return 0;
}

Measured memory_bytes: 19364
while True:
  m, f, r = map(int, input().split())
 
  if m == -1 and f == -1 and r == -1:
    break
 
  if m == -1 or f == -1:
    ans = 'F'
  elif m+f >= 80:
    ans = 'A'
  elif m+f >= 65:
    ans = 'B'
  elif m+f >= 50:
    ans = 'C'
  elif m+f >= 30:
    ans = 'C' if r >= 50 else 'D'
  else:
    ans = 'F'
 
  print(ans)


Measured memory_bytes: 5596
using System;
class aoj
{
    static void Main()
    {
        int[] s = new int[50];
        int l = 0;
        while (true)
        {
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a))break;
            string[] b = a.Split(',');
            int[] c = new int[10];
            int f = 0;
            for(int i = 0;i< 10; i++)
            {
                c[i] = int.Parse(b[i]);
                f += c[i];
            }
            int d = int.Parse(b[10]);
            int e = int.Parse(b[11]);
            double g=(double)f/(double)(d+e);
            double h = g * (double)d;
            int k = 0;
            for(int i = 0; i < 10; i++)
            {
                if (c[i] > h)
                {
                    k = ++i;
                    break;
                }
                else
                {
                    h -= c[i];
                }
                if (c[i+1]==h)
                {
                    k = i+2;
                    break;
                }
            }
            s[l] = k;
            l++;
        }
        for(int i = 0; i < l; i++)
        {
            Console.WriteLine(s[i]);
        }
    }
}

Measured memory_bytes: 9248
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int s[6];
    int i;
    int tmp;
    int count=0;
    char assign;
    for(i=0;i<6;i++){
    scanf("%d",&s[i]);
    }
    while(1){
        scanf("%c",&assign);
        if(assign=='S'){
            tmp=s[0];
            s[0]=s[4];
            s[4]=s[5];
            s[5]=s[1];
            s[1]=tmp;
        }else if(assign=='E'){
            tmp=s[0];
            s[0]=s[3];
            s[3]=s[5];
            s[5]=s[2];
            s[2]=tmp;
        }else if(assign=='W'){
            tmp=s[0];
            s[0]=s[2];
            s[2]=s[5];
            s[5]=s[3];
            s[3]=tmp;
        }else if(assign=='N'){
            tmp=s[0];
            s[0]=s[1];
            s[1]=s[5];
            s[5]=s[4];
            s[4]=tmp;
        }else if(assign=='\n'){
            count++;
            if(count==2){
            break;
            }
        }


    }printf("%d\n",s[0]);
    
    
    return 0;
}

Measured memory_bytes: 1860
import numpy

n, m = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
sup_A = 10 ** 5
B = [0] * (1 << 18)
for a in A:
    B[a] += 1
C = numpy.fft.fft(B)
D = numpy.fft.ifft(C * C)

ans = 0
cnt = 0
for i in range(2 * sup_A, -1, -1):
    d = int(D[i].real + 0.5)
    if cnt + d >= m:
        ans += (m - cnt) * i
        break
    cnt += d
    ans += i * d

print(ans)

Measured memory_bytes: 48444
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
 
using namespace std;
 
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
 
const ll mod197 = 1000000007LL;
const ll INF = INT_MAX;
 
const double PI11 = 3.14159265359;
 
int main() {
 
	map<ll, bool> m;
 
	int n;
	cin >> n;
 
	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		m[a] = !m[a];
	}
 
	int ans = 0;
 
	for (auto t : m) {
		if (t.second)
			ans++;
	}
 
	cout << ans << endl;
 
	return 0;
}
 

Measured memory_bytes: 6528
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#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)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int dp[3010][3010];

int main() {
    string s, t;
    cin >> s >> t;
    rep(i,s.size()) {
        rep(j,t.size()) {
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            if (s[i]==t[j]) dp[i+1][j+1] = max(dp[i][j]+1,dp[i+1][j+1]);
            
        }
    }
    
    queue<P> que;
    que.push(P(s.size(), t.size()));
    int nowv = dp[s.size()][t.size()];
    int nowi = s.size();
    int nowj = t.size();
    string ans = "";
    while (dp[nowi][nowj]>0 and !que.empty() and nowv > 0) {
        P nowp = que.front(); que.pop();
        if (nowp.fi == 0 || nowp.se == 0) continue;

        nowi = nowp.fi;
        nowj = nowp.se;
        if (nowv != dp[nowi][nowj]) continue;

        if (s[nowi-1]==t[nowj-1]) {
            ans += s[nowi-1];
            nowi -= 1;
            nowj -= 1;
            nowv -= 1;
            queue<P> empty;
            swap(que, empty);
            que.push(P(nowi,nowj));
            if (nowi > 0 && nowv == dp[nowi-1][nowj]) que.push(P(nowi-1,nowj));
            if (nowj > 0 && nowv == dp[nowi][nowj-1]) que.push(P(nowi,nowj-1));
        }
        else {
            if (nowi > 0 && nowv == dp[nowi-1][nowj]) que.push(P(nowi-1,nowj));
            if (nowj > 0 && nowv == dp[nowi][nowj-1]) que.push(P(nowi,nowj-1));
        
        }
    }
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 35584
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int s;
  cin >> s;

  int x = sqrt(s);
  while(x*x < s) x++;

  int a = x, b = x;

  int y = x*x-s;

  if(y > (int)1e9) assert(s == -1);

  cout << 0 SP 0 SP a SP 1 SP y SP b << endl;

  //cout << a*b-y << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define IOS ios::sync_with_stdio(0);cin.tie(0);
const int INF = 1e10;
string s,t;

bool okay(string s,string t,int i,int j){
	bool flag1 = true;
	int e = 0;
	
	for(int k=i;k<s.length();k++){
		if(s[k] == t[e]){
			flag1 = true;
			e++;
		}
		else{
			flag1 = false;
			break;
		}
	}
	for(int k = 0;k<i;k++){
		if(s[k] == t[e]){
			flag1 = true;
			e++;
		}
		else{
			flag1 = false;
			break;
		}
	}
	
	return flag1;
}

int main(){
	IOS;
	string s,t;
	while(cin>>s>>t){
		char a = t[0];
		bool flag = true;
		int y=0;
		for(int i=0;i<s.length();i++){
			if(s[i] == a){
				if(okay(s,t,i,0)){
					flag = true;
					break;
				}
				else{
					flag = false;
				}
			}
		}
		if(flag){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,alt;
	cin>>n;
	int p[n];
	rep(i,n)cin>>p[i];
	int cnt=0;
	if(p[n-1]==n){
		cnt++;
		alt=p[n-1];
		p[n-1]=p[n-2];
		p[n-2]=alt;
	}
	rep(i,n){
		if(p[i]==i+1){
			cnt++;
			alt=p[i];
			p[i]=p[i+1];
			p[i+1]=alt;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

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

int main() {
    long long H, W;
    cin >> H >> W;

    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }

    long long odd = (H / 2) + (H % 2);
    long long even = (H / 2);
    long long oddNum = (W / 2) + (W % 2);
    long long evenNum = (W / 2);

    cout << (odd * oddNum) + (even * evenNum) << endl;

    return 0;
}

Measured memory_bytes: 256
<?PHP
$first_line = fgets(STDIN);
$second_line = fgets(STDIN);
$first_line_array = explode(" ", $first_line);
$steps_amount=$first_line_array[0];
//ジャンプで飛べる足場の数
$skip_power=$first_line_array[1];
$steps_heights = explode(" ", $second_line);

//足場ごとにたどり着くまでのコストの総和の最小値を入れていく配列
$dps=[];

foreach (range(0, $steps_amount-1) as $index) {

    // 最初にいた足場に辿り着くまでのコストは０
    if($index===0){
        $dps[0]=0;
        continue;
    }

//    今までのコスト
    $total_cost=$dps[$index-1];
//    今回飛ぶためのコスト
    $jump_cost=abs($steps_heights[$index]-$steps_heights[$index-1]);
    // とりあえず一つ前の踏み台から飛んだ場合の総コストで初期化して、数を比較して最小値を入れていく
    $dps[$index]= $total_cost+$jump_cost;

    foreach (range(1, $skip_power) as $i) {
        if($index>=$i){

            if ($dps[$index]> abs($dps[$index - $i] + abs($steps_heights[$index] - $steps_heights[$index - $i]))){
                $dps[$index]=abs($dps[$index - $i] + abs($steps_heights[$index] - $steps_heights[$index - $i]));
            }
        }

    }
}

echo end($dps);



Measured memory_bytes: 23028
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<bitset>
#include<deque>
#include<cstdlib>
#include<set>
#include<ctime>
#define ll long long
#define mp make_pair
#define N 1400000
using namespace std;
ll read()
{
	ll x=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return f*x;
}
int n,A,B,top,col[N],num[20],as[N],now,len[20];
bool vis[20];
void work(int l,int r,int u,int v)
{
//	cout<<l<<" "<<r<<" "<<u<<" "<<v<<'\n';
	int mid=r+l>>1;
	if(r-l+1==2)
	{
		as[l]=u,as[r]=v;
		return ;
	}
	int pos,i,gate;
	for(pos=0;pos<n;++pos)
	{
		if((u&(1<<pos))^(v&(1<<pos))) break;
	}
	vis[pos]=1;
	for(i=0;i<n;++i) if(!vis[i]) break;
	gate=(u&(~(1<<pos)))^(1<<i);
//	cout<<pos<<" "<<i<<" "<<gate<<'\n'; 
	work(l,mid,u&(~(1<<pos)),gate);work(mid+1,r,gate,v&(~(1<<pos)));
	if(u&1<<pos) for(int i=l;i<=mid;++i) as[i]|=1<<pos;
	else for(int i=mid+1;i<=r;++i)as[i]|=1<<pos; 
	vis[pos]=0;
}

int main()
{
	n=read(),A=read(),B=read();
	if(n==1)
	{
		cout<<"YES"<<'\n';
		cout<<A<<" "<<B<<'\n';
		return 0;
	}
	top=1<<n;
	for(int i=1;i<top;++i) col[i]=col[i>>1]+(i&1);
	if(col[A]%2==col[B]%2) 
	{
		cout<<"NO"<<'\n';
		return 0;
	 } 
	 cout<<"YES"<<'\n';
	 work(1,top,A,B); 
	 for(int i=1;i<=top;++i) cout<<as[i]<<' ';
	return 0;
 }
// 3 1 3  

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e8;

//---main---------------------------------------------
int main(){
    //main
    int K;
    cin >> K;
    string S(K,'a');
    cin >> S;

    if(S.size()>K){
        cout << S.substr(0,K) << "..." << endl;
    }else cout << S << endl;

    
    return 0;
}


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

int N, K;
vector<int64_t> x, y;
vector<char> c;
int64_t b[2010][2010];
int64_t w[2010][2010];

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

    x.resize(N);
    y.resize(N);
    c.resize(N);
    for(int i = 0; i < N; ++i){
        cin >> x[i] >> y[i] >> c[i];
        bool check = (c[i] == 'B');
        if((x[i] % (2*K)) >= K && (y[i] % (2*K)) < K){
            check = !check;
        }
        if((x[i] % (2*K)) < K && (y[i] % (2*K)) >= K){
            check = !check;
        }
        x[i] %= K;
        y[i] %= K;
        if(check){
            b[x[i]][y[i]] ++;
        }
        else {
            w[x[i]][y[i]] ++;
        }
    }
    for(int i = 1; i < K; ++i){
        for(int j = 0; j < K; ++j){
            b[i][j] += b[i-1][j];
            w[i][j] += w[i-1][j];
        }
    }
    for(int i = 1; i < K; ++i){
        for(int j = 0; j < K; ++j){
            b[j][i] += b[j][i-1];
            w[j][i] += w[j][i-1];
        }
    }
  
    int64_t ans = 0;
    for(int i = 0; i < K; ++i){
        for(int j = 0; j < K; ++j){
            int64_t bsum = b[K-1][K-1];
            bsum -= b[i][K-1];
            bsum -= b[K-1][j];
            bsum += b[i][j] * 2;
            int64_t wsum = w[i][K-1] + w[K-1][j];
            wsum -= w[i][j] * 2;
            ans = max(ans, bsum + wsum);
        }
    }
    for(int i = 0; i < K; ++i){
        for(int j = 0; j < K; ++j){
            int64_t wsum = w[K-1][K-1];
            wsum -= w[i][K-1];
            wsum -= w[K-1][j];
            wsum += w[i][j] * 2;
            int64_t bsum = b[i][K-1] + b[K-1][j];
            bsum -= b[i][j] * 2;
            ans = max(ans, bsum + wsum);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 36224
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>9 && a*b) {
        cout<< "-1"<<endl;
        return 0;}
    if(b>9 && a*b) {
        cout<< "-1"<<endl;
        return 0;}
    else cout<<a*b<<endl;


    return 0;
}


Measured memory_bytes: 3628
n, k = gets.chop.split.map(&:to_i)
R, S, P = gets.chop.split.map(&:to_i)
t = gets.chop.chars

scores = { r: P, s: R, p: S }
ans = 0

(0..n-1).each do |i|
  if t[i] == t[i - k] && i >= k
    t[i] = nil
  end

  unless t[i].nil?
    ans += scores[t[i].to_sym]
  end
end

puts ans


Measured memory_bytes: 8956
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    vector<string> b(m);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    for (int i = 0; i < m; i++)
    {
        cin >> b.at(i);
    }


    int va = 0;
    int c = n - m + 1;
    int l = 0;
    for (int i = 0; i < c; i++)
    {
        for (int j = 0; j < c; j++)
        {
            va = 0;
            int iii = 0;
            for (int f = 0; f < m; f++)
            {
                string x = a.at(i+f).substr(j, m);
                //cout << i+f<<" "<<j<<x << endl;
                if (x == b.at(iii))
                {
                    va++;
                }
                iii++;
            }
            if (va == m)
            {
                l++;
            }
        }
    }


    if (l > 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	ll k, n; cin >> k >> n;
	ll a[200005];
	for(ll i=0;i<n;i++){
		cin >> a[i];
	}
	ll l = 0;
	for(ll i=0;i<n-1;i++){
		l = max(l, a[i+1]-a[i]);
	}
	l = max(l, k-a[n-1]+a[0]);
	cout << k-l << endl;
	return 0;
}

Measured memory_bytes: 1792