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

class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet() {}
        DisjointSet(int size) {
            rank.resize(size, 0);
            p.resize(size, 0);
            for(int i=0; i<size; ++i) {
                makeSet(i);
            }
        }

        void makeSet(int x) {
            p[x] = x;
            rank[x] = 0;
        }

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

        void unite(int x, int y) {
            link(findSet(x), findSet(y));
        }

        void link(int x, int y) {
            if(rank[x] > rank[y]) {
                p[y] = x;
            } else {
                p[x] = y;
                if(rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }

        int findSet(int x) {
            if(x != p[x]) {
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

int main() {
    int n, a, b, q;
    int t;

    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);

    for(int i=0; i<q; ++i) {
        cin >> t >> a >> b;
        if(t == 0) {
            ds.unite(a, b);
        } else if(t == 1) {
            if(ds.same(a, b)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++) // for簡略表記
#define DUMP(ar) for(int loop=0; loop<(int)ar.size(); loop++) cout << "[" << loop << "]:" << ar[loop] << endl // 配列一覧表示
#define DUMPL(ar) for(int loop=0; loop<(int)ar.size(); loop++) { cout << ar[loop]; if(loop<(int)ar.size()-1) cout << ' '; } cout << endl; // 配列一行一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
#define LOOPD(i) cout << "ループ[" << i << "]回目---------------" << endl // ループ回数デバグ
using namespace std;
// cout << fixed << setprecision(4) で小数点以下4桁の桁そろえ
// cout << setw(5) << ... で表示形式を5桁に設定 5桁未満なら頭に空白がつく 5桁越なら先頭から5桁まで
// cout << setw(5) << setfill('0') << ... で空白部分の埋め文字に5を使う
// getline(cin, [変数]); で空白などを含む入力の受け取り(行ごとの受け取り)
// cin >> ws; でそこまでにストリームに残されたホワイトスペースを取り除く(=以降のgetlineの有効化)

struct prf{
    int x;
    int y;
    prf(int xx=-1, int yy=-1){
        x = xx;
        y = yy;
    }
};

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

    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<prf>> p(n, vector<prf>(n));
    for(int i=0; i<n; i++){
        cin >> a[i];
        for(int k=0; k<a[i]; k++){
            cin >> p[i][k].x >> p[i][k].y;
        }
    }

    int loopn = pow(2, n);
    int ans = 0;
    for(int bit=0; bit<loopn; bit++){
        bool flag = true;
        // for(int i=0; i<n; i++){
        //     if( (1<<i) & bit ) cout << "T";
        //     else cout << "F";
        // }
        // cout << endl;

        for(int i=0; i<n; i++){
            for(int j=0; j<a[i]; j++){
                if(p[i][j].x == -1) break;
                if( (1 << (p[i][j].x-1)) & bit ){
                    if( ((1 << i) & bit) && p[i][j].y == 0 ){
                        flag = false;
                    }
                }else{
                    if( ((1 << i) & bit) && p[i][j].y == 1 ){
                        flag = false;
                    }
                }
            }
        }
        if(!flag) continue;
        // cout << "\tok" << endl;

        int tmp=0;
        for(int i=0; i<n; i++){
            if( (1<<i) & bit ) tmp++;
        }
        if(tmp > ans) ans = tmp;
    }

    COUT(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll dp[22][(1 << 21)];

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	bool a[n][n];
	rep(i, 0, n){
		rep(j, 0, n){
			cin >> a[i][j];
		}
	}
	
	memset(dp, 0, sizeof(dp));
	dp[0][(1 << n)-1] = 1;
	
	rep(i, 0, n){
		rep(bit, 0, (1 << n)){
			if(__builtin_popcount(bit) == n-i){
				rep(j, 0, n){
					if(bit&(1 << j) && a[i][j]){
						dp[i+1][bit-(1 << j)] += dp[i][bit];
						dp[i+1][bit-(1 << j)] %= MOD;
					}
				}
			}
		}	
	}
	
	print(dp[n][0])
	return 0;
}

Measured memory_bytes: 360832
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool cheak(vector<int> v){
  for(int i=0;i<v.size();i++){
    if(v[i] != i+1) return false;
  }
  return true;
}
int main(){
  int N;
  while(cin >> N && N){
    bool judge = true;
    int now = 0;
    vector<int> v(N);
    for(int i = 0; i < N ; i++ ){
      cin >> v[i];
    }

    while( !cheak(v) && now <= 10000 ){
      now++;
      for(int i = 0; i < v.size() ; i++ ) v[i]--;
      v.push_back(v.size());
      v.erase(remove(v.begin(),v.end(),0),v.end());
    }
    cout << ( now > 10000 ? -1 : now ) << endl;
  }
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    if(s.at(0) == 'S'){
        cout << "Cloudy";
    }else if(s.at(0) == 'C'){
        cout << "Rainy";
    }else{
        cout << "Sunny";
    }
}

Measured memory_bytes: 256
a=[int(input()) for i in range(4)]
#print(a)

cnt=0
for i in range(a[0]+1):
  for j in range(a[1]+1):
    for k in range(a[2]+1):
      if 500*i+100*j+50*k==a[3]:
        cnt+=1
        
print(cnt)

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

int main(){
	int dataNum,x;
	std::vector<int> number;
	
	std::cin >> dataNum;
	//input
	for(int i=0; i<dataNum; ++i){
		std::cin >> x;
		number.push_back(x);
	}
	
	std::vector<long long int> ans_num(21,0); //number of answer before now step
	
	ans_num[number[0]] = 1; //initial value
	
	for(int i=1; i<dataNum-1; ++i){
		std::vector<long long int> buf(21,0); //number of answer now step
		for(int j=0; j<21; ++j){
			if(ans_num[j] != 0){
				//plus
				if((j+number[i]) <= 20){
					buf[j+number[i]] += ans_num[j];
				}
				//minus
				if((j-number[i]) >= 0){
					buf[j-number[i]] += ans_num[j];
				}
			}
		}
		//move now step to before step
		ans_num.assign(buf.begin(), buf.end());
	}
	//output
	std::cout << ans_num[number[dataNum-1]] << std::endl;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
int n,m,k,a[100005];
int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m >> k;
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= m; j++)
			if(i * m + j * n - 2 * i * j == k) {
				cout << "Yes\n";
				return 0;
			}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int a,b,c;
    scanf("%d%d%d", &a,&b,&c);
    if(1<=a<=13 && 1<=b<=13 && 1<=c<=13){
        if((a+b+c)>=22)
            printf("bust\n");
        else
            printf("win\n");
    }
    return 0;
}

Measured memory_bytes: 128
arr = []
3.times do |i|
    a1 = gets.chomp.split(" ")
    arr << a1
end
n = gets.chomp.to_i
n.times do 
    b = gets.chomp
    arr.each do |i| 
        i.each do |o|
            if o == b
                o.replace("#")
            end         
        end
    end
    #p arr
    #p arr
       # 
    #end
end
yes = 0
(0...3).each do|i|
        count = 0
        count = arr[i].count("#")
    if count >= 3
        yes += 1
    end
end



(0...3).each do |i|
    all = 0
    o = 0
    while o <= 2
        #p arr[o][i]
        if arr[o][i] == "#"
            all += 1
        end
    o += 1
    end
    if all >= 3
        yes += 1
    end
end
count = 0
(0...3).each do|i|
    if arr[i][i] == "#"
        count += 1
    end
    if count >= 3
        yes += 1
    end
end
count = 0
(0...3).each do|i|
    #p arr[2-i][i]
    if arr[2-i][i] == "#"
        count += 1
    end
    if count >= 3
        yes += 1
    end
end
if yes >= 1
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
using namespace std;
int n, cap, w[100], v[100];
long long dp[100][100 * 1000 + 1];
long long calc(int i, int s) {
	if (i == n) return (s == 0) ? 0 : (cap + 1);
	if (dp[i][s] != -1) return dp[i][s];
	long long res = calc(i + 1, s);
	if (v[i] <= s) res = min(res, calc(i + 1, s - v[i]) + w[i]);
	return dp[i][s] = res;
}
int main() {
	scanf("%d %d", &n, &cap);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &w[i], &v[i]);
		sum += v[i];
	}
	memset(dp, -1, sizeof(dp));
	int ans;
	for (int j = sum; j >= 0; j--) {
		if (calc(0, j) <= cap) {
			ans = j;
			break;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    int ans=0;
    REP(i,3){
        if(s[i]==t[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

long long ans, n, m;

int main() {
  cin >> n >> m;
  if (n > m) swap(n, m);// n < m
  if (n == 1 && m == 1) return !puts("1");
  if (n == 1)
    return !printf("%lld\n", m - 2);
  printf("%lld\n", (n - 2) * (m - 2));
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll n,m;
  cin>>n>>m;
  if(n*m==1) {
    cout << 1 << endl;
    return 0;
  }
  if(n==1||m==1) {
    cout << n*m-2 << endl;
    return 0;
  }
  cout << (n-2)*(m-2)<<endl;
  return 0;
}


Measured memory_bytes: 256
void main()
{
    dchar[] s = rdDchar;

    dchar[] t;
    foreach_reverse (x; s)
    {
        if (x == 'b') t ~= 'd';
        if (x == 'd') t ~= 'b';
        if (x == 'p') t ~= 'q';
        if (x == 'q') t ~= 'p';
    }

    writeln(s == t ? "Yes" : "No");
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

int main() {
  int n, k;
  cin >> n >> k;
  
  vector<int> h(n);
  for(int i=0; i<n; i++) cin >> h[i];
  sort(h.begin(), h.end());
  
  int ans = 1000000000;
  for(int i=0; i<n-k+1; i++) {
    ans = min(ans, h[i+k-1]-h[i]);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3784
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
int A[100000];
int Min[100000];
int main() {
	int N, T;
	cin >> N >> T;
	rep(i, N) cin >> A[i];
	Min[0] = A[0];
	int max_d = 0;
	REP(i, 1, N) {
		max_d = max(max_d, A[i] - Min[i - 1]);
		Min[i] = min(Min[i - 1], A[i]);
	}
	int sum = 0;
	REP(i, 1, N) {
		if (A[i] - Min[i - 1] == max_d) sum++;
	}
	cout << sum << endl;
}

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

int main()
{
  long long int a,b;
  cin>>a>>b;
  if(ceil((double)(a+b)/2.0)==floor((double)(a+b)/2))
  {
    cout<<(long long int)((a+b)/2);
  }
  else cout<<"IMPOSSIBLE";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef		vector<ll>      vll;
#define		pb              push_back
string intostr(int x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}

char Uplowch(char ch){if(ch >= 'A' &&  ch <= 'Z') ch += 32; return ch;}
char Lowupch(char ch){if(ch >= 'a' &&  ch <= 'z') ch -= 32; return ch;}
bool Isalpha(char ch){if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) return true; return false;}
int Strtoint(string str){stringstream ss(str);int x = 0;ss >> x ;return x ;}
string Intostr(int x){stringstream ss; ss << x; string str = ss.str(); return str;}

#define		PB              pop_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)

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

int dx[] = {0 , 0 , -1 , 1} ; // right , left , forward , backward
int dy[] = {1 , -1 , 0 , 0} ;

//bool check(int x , int y) {
//    if(x <= n && y <= m && x >= 1 && y >= 1)
//        return 1 ;
//    return 0 ;
//}

int main()
{
     //freopen("in.txt","r",stdin);

     ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll n,m;
	cin>>n>>m;
	if(m>=n) cout<<"unsafe"<<nn;
	else cout<<"safe"<<nn;




}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define REP(i, t) for(int i = 0; i < t; i++)
#define INF (1 << 30)

int main()
{
    int N;
    cin >> N;
    int divided_count = 0;
    int ans = 0;
    for (int i = 1; i <= N; i += 2)    //1からNまで
    {
        for (int j = 1; j <= i; j += 2)
        {
            if (i % j == 0)
                divided_count++;
        }
        if (divided_count == 8)
            ans++;
        divided_count = 0;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::suspicious_arithmetic_impl)]

// using Rust(1.42.0)
// My Library Repo is at "https://github.com/Loptall/prcn_lib"
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"

/*
    AtCoder Language Update 2020204 お疲れ様でした! 有難いです(p.s. 過去問対応もありがとうございます)
*/

// from std...
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::usize::{MAX, MIN};
use std::{i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_integer::{binomial, gcd, lcm, Integer};
use permutohedron::Heap;
use petgraph::unionfind::UnionFind;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

// code...
// #[fastout]
fn main() {
    input! {
        n: usize
    }

    let mut ans = 0;

    gen(0, n, &mut ans);

    println!("{}", ans);
}

fn gen(before: usize, lim: usize, ans: &mut usize) {
    if before > lim { return; }
    else {
        let s = before.to_string();
        if s.contains('3') && s.contains('5') && s.contains('7') {
            *ans += 1;
        }
        gen(before * 10 + 3, lim, ans);
        gen(before * 10 + 5, lim, ans);
        gen(before * 10 + 7, lim, ans);
    }
}


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

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

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: usize = sc.read();
    let v: Vec<i64> = (0..n).map(|_| sc.read()).collect();
    let min = v.iter().min().unwrap();
    let max = v.iter().max().unwrap();
    let sum: i64 = v.iter().sum();
    println!("{} {} {}", min, max, sum);
}



Measured memory_bytes: 5052
#include <bits/stdc++.h>
using namespace std;
#define int long long
int inf = 10e17;
#define mod 1000000007
int findLowerBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{

    auto low = lower_bound(arr.begin(),
                           arr.end(), p);

    return low - arr.begin();
}
int findUpperBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{
    auto up = upper_bound(arr.begin(),
                          arr.end(), p);

    return up - arr.begin();
}
bool vis[200005];
vector<int> vec[100005];
int child[100005];
int div1[100005];
void dfs(int node)
{
    vis[node] = 1;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            dfs(vec[node][i]);
            child[node] += child[vec[node][i]];
        }
    }
}
void belman(int n, int m, vector<pair<int, pair<int, int>>> vec, int dis[])
{
    for (int i = 0; i <= n + m - 1; i++)
    {
        for (int j = 0; j < vec.size(); j++)
        {
            int u = vec[j].second.first;
            int v = vec[j].second.second;
            int w = vec[j].first;

            if (dis[u] + w < dis[v])
            {
                dis[v] = dis[u] + w;
            }
        }
    }
}
int fun(int a, int b)
{
    if (a > b)
        return 0;
    if (a == b)
        return 1;
    else
    {
        return fun(a + 1, b) + fun(a, b - a);
    }
}
int32_t main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    int n;
    cin >> n;
    int sum = 1;
    while (n >= sum)
    {
        sum *= 2;
    }
    cout << sum / 2 << "\n";

    return 0;
}


Measured memory_bytes: 5912
n = int(input())
s = input()
ans = 0
for i in range(10):
    for x in range(n):
        if (i==int(s[x])):
            for j in range(10):
                for y in range(x+1,n):
                    if (j==int(s[y])):
                        for k in range(10):
                            for z in range(y+1,n):
                                if (k==int(s[z])):
                                    ans += 1
                                    break
                        break
            break
        

print(ans)

Measured memory_bytes: 42716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    static int[] dp;
    static int[] input;

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


        String[] line;;

        int n = Integer.parseInt( reader.readLine());
        //int k = Integer.parseInt(line[1]);


        input = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        dp = new int[input.length];
        List<Integer> backwards;
        dp[0] = 0;

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

            backwards = new ArrayList<>();
            for (int j = i - 1, c = 0; j >= 0 && c < 2; j--, c++) {
                backwards.add(Math.abs(input[i] - input[j]) + dp[j]);
            }

            dp[i] = backwards.stream().min(Integer::compare).get();

        }

        System.out.println(dp[n - 1]);
    }




}


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

int k, s, c;
int main()
{
	int i, j;
	cin >> k >> s;
	for (i = 0; i <= k; i++) {
		for (j = 0; j <= k; j++) {
			if (s - i - j <= k && s - i - j >= 0) c++;
		}
	}
    cout << c << endl;
    return 0;
}


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

class Problem0009
{
    static void Main(string[] args)
    {
        int[] primes = Enumerable.Range(1, 999999).Where(IsPrime).ToArray();
        
        foreach (int n in GetInputLines().Select(int.Parse))
        {
            Console.WriteLine(primes.TakeWhile(p => p <= n).Count());
        }
    }

    static bool IsPrime(int n)
    {
        if (n < 2)
        {
            return false;
        }
        else
        {
            return Enumerable.Range(2, (int)Math.Sqrt(n) - 1).All(i => n % i != 0);
        }
    }

    static IEnumerable<string> GetInputLines()
    {
        string line;
        while (!string.IsNullOrEmpty(line = System.Console.ReadLine()))
        {
            yield return line;
        }
    }
}

Measured memory_bytes: 11292
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
#include<string.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	map<int, ll> mp;
	rep(i, n) {
		cin >> a[i];
		mp[a[i]]++;
	}
	ll ans = 0;
	for (auto i = mp.begin(); i != mp.end(); i++) {
		ans += ll(i->first) * ll(i->second);
	}
	int q;
	cin >> q;
	rep(iii, q) {
		ll bi, ci;
		cin >> bi >> ci;
		ans = ans - bi * mp[bi] + ci * mp[bi];
		mp[ci] += mp[bi];
		mp[bi] = 0;
      cout<<ans<<endl;
	}
}

Measured memory_bytes: 9964
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    string w;
    cin >> w;
    int n = w.size(), cnt[26] = {};
    REP(i, n) {
        cnt[w[i] - 'a']++;
    }
    REP(i, 26) {
        if (cnt[i] % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>

using namespace std;

void solve()
{
    // 入力の処理
    int N;
    cin >> N;
    // 隣接行列を作る
    vector<vector<int>> list(N);

    // 入力内容を覚えておく
    vector<pair<int, int>> inputs;

    for (int i = 0; i < N - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        list.at(a - 1).emplace_back(b - 1);
        list.at(b - 1).emplace_back(a - 1);
        inputs.emplace_back(make_pair(a - 1, b - 1));
    }

    // 1行目用の答え
    int colorSize = 0;
    for (auto elem : list)
    {
        colorSize = max(colorSize, (int)elem.size());
    }

    // 2行目以降用の答え

    // 木を1番目の頂点を根とする根付き木にしたときの、
    // 各頂点と親との間の色。
    // 根は親を持たないので0
    vector<int> colors(N, 0);
    // ある点がその親となす辺の色が決定済みである
    vector<bool> decided(N, false);

    // 色のマップ
    map<pair<int, int>, int> colorMap;

    // 幅優先探索のための処理キュー
    queue<int> que;
    que.push(0);

    // 0要素の親要素は存在しないので、それと間の辺の色は決定しているとみなす
    decided.at(0) = true;
    while (!que.empty())
    {
        int queFront = que.front();
        que.pop();

        int settingColor = 1;
        for (auto point : list.at(queFront))
        {
            // 決定済み要素はスキップ
            if (decided.at(point))
            {
                continue;
            }

            if (colors.at(queFront) == settingColor)
            {
                // 親との間の色と被っていたら、色をずらす
                settingColor++;
            }

            colors.at(point) = settingColor;

            // 回答作成用のマップを準備
            // cout << queFront << "," << point << ":" << settingColor << endl;
            colorMap[make_pair(queFront, point)] = settingColor;
            colorMap[make_pair(point, queFront)] = settingColor;

            settingColor++;
            que.push(point);

            // 色が決定
            decided.at(point) = true;
        }
    }

    cout << colorSize << endl;
    for (auto input : inputs)
    {
        cout << colorMap[make_pair(input.first, input.second)] << endl;
    }

    return;
}

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


Measured memory_bytes: 19700
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int dy[] = {-1,0,1,0};
int dx[] = {0,1,0,-1};
int height[1001][1001];
bool visited[1001][1001];

int main() {
  ll n;
  while(cin >> n, n) {
    memset(visited,0,sizeof(visited));
    int sqn = sqrt(n);
    for (int y=0; y<=sqn; ++y) {
      for (int x=0; x*x+y*y<n; ++x) {
        height[y][x] = ceil(sqrt(n-x*x-y*y));
      }
    }
    int ans = 0;
    for (int y=0; y<=sqn; ++y) {
      for (int x=0; x*x+y*y<n; ++x) {
        if (visited[y][x]) continue;
        if (height[y][x] == 0) continue;
        queue<pii> Q;
        Q.push(pii(y,x));
        int flag = 0;
        while(!Q.empty()) {
          pii p = Q.front(); Q.pop();
          int y = p.first;
          int x = p.second;
          if (visited[y][x]) continue;
          visited[y][x] = 1;
          if (y == 0) flag |= 1;
          if (x == 0) flag |= 2;
          REP(i, 4) {
            int yy = y+dy[i];
            int xx = x+dx[i];
            if (yy<0||yy>sqn||xx<0||xx>sqn) continue;
            if (height[yy][xx] != height[y][x]) continue;
            if (visited[yy][xx]) continue;
            Q.push(pii(yy,xx));
          }
        }
        if (flag == 0) ans += 24;
        else if (flag == 1 || flag == 2) ans += 12;
        else ans += 6;
      }
    }
 
    cout << ans << endl;
  }
}

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

int H, W, K;
char c[10][10];
bool visited[100][100];
int curr, curc;
int ans;

bool check() {
	int cur = 0;

	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (c[i][j] == '#') cur++;
	if (cur == K) {
        //printf("%d %d\n", curr, curc);
	}
	return cur == K;
}

int dp(int row, int col) {
	int cur = 0;
	if (row >= H && col >= W) {
		if (!visited[curr][curc] && check()) {
            visited[curr][curc] = true;
            return 1;
		}
		else return 0;
	}
	if (row < H) {
		char orig[W];
		for (int i = 0; i < W; i++) {
			orig[i] = c[row][i];
			c[row][i] = '-';
		}
		curr |= 1 << row;
		cur += dp(row + 1, col);
		for (int i = 0; i < W; i++) {
			c[row][i] = orig[i];
		}
		curr &= ~(1 << row);
		cur += dp(row + 1, col);
	}
	if (col < W) {
		char orig[H];
		for (int i = 0; i < H; i++) {
			orig[i] = c[i][col];
			c[i][col] = '-';
		}
		curc |= 1 << col;
		cur += dp(row, col + 1);
		for (int i = 0; i < H; i++) {
			c[i][col] = orig[i];
		}
		curc &= ~(1 << col);
		cur += dp(row, col + 1);
	}
	return cur;
}

int main() {
	scanf("%d%d%d", &H, &W, &K);
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) scanf(" %c", &c[i][j]);
	ans = dp(0, 0);
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

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

	if(s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}


	return 0;
}




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

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

	int a[1000],b[1000],c[1000];
	for(int i = 0;i<n;i++){
		cin >> a[i] >> b[i] >> c[i];
		if (a[i]>b[i]){int g = b[i];b[i] = a[i];a[i] = g;}
		if (b[i]>c[i]){int g = c[i];c[i] = b[i];b[i] = g;}
	}	
	for (int i=0;i<n;i++){
		if(a[i]*a[i]+b[i]*b[i]==c[i]*c[i])
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, m; cin >> n >> m;
  V<string> a(n); REP(i, n) cin >> a[i];
  V<string> b(m); REP(i, m) cin >> b[i];
  bool in_a = true;
  REP(i, n-m+1) REP(j, n-m+1) {
    in_a = true;
    REP(k, m) REP(l, m) {
      if (a[i+k][j+l] != b[k][l]) {in_a = false; break;}
    }
    if (in_a) {cout << "Yes" << endl; return 0;}
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,b) for(int i=0;i<b;i++)
#define rrep(i,a,b) for(int i=a;i<=b;i++)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;

bool f[100001];
int c[100002];
int N, L, R;

int main() {
	//篩。
	for (int i = 2; i <= 100000; i++)if (!f[i])for (int j = i + i; j <= 100000; j += i) {
		f[j] = true;
	}

	//2017likeナンバーを記録していく。
	for (int i = 3; i <= 100000; i += 2)if (!f[i] && !f[(i + 1) / 2])c[i]++;

	//累積和
	for (int i = 3; i <= 100000; i++)c[i] += c[i - 1];

	//前処理終了。クエリをさばいていく。

	cin >> N;

	while (N--) {
		cin >> L >> R;

		cout << c[R] - c[L - 1]<<endl;
	}

	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int n,x,a[105];
int main(void){
    scanf("%d%d",&n,&x);
    for(int i=0;i<n;i++)scanf("%d",a+i);
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i++){
        if(x>=a[i]){
            x-=a[i];
            ans++;
        }
    }
    if(x!=0&&ans==n)ans--;
    printf("%d\n",ans);
    
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int, int> PII;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
int mod = 1000000007;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    string s,t; cin >> s >> t;
    ll siz = s.size();
    s += s;
    map<char, vll> chs;

    // s中の各文字のindexを格納
    for(int idx = 0; idx < s.size(); ++idx) {
        chs[s[idx]].push_back((ll)idx);
    }
 
    // sに無い文字があれば-1
    for(auto ch : t) {
        if(chs.count(ch)) continue;
        cout << -1 << '\n';
        return 0;
    }

    //s+s の中で ch が出現する index に対してにぶたんしてかんがえる
    ll i = 0;  // sss...内での位置
    for(auto ch : t) {
        auto iter = lower_bound(all(chs[ch]), i%siz);
        ll plus = *iter - i%siz + 1;
        i += plus;
    }

    cout << i << endl;
}

Measured memory_bytes: 2916
// Best practice

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// #include <functional> // for less

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;
// using namespace __gnu_pbds;

// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

// #define fbo find_by_order
// #define ook order_of_key

// Code from Here -------------------------------------------------------------------------------


signed main() {
	tezz

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, k, m, p;
	cin >> n >> k;
	vector<bool> check(n + 1, false);
	for (int i = 0; i < k; i++) {
		cin >> m;
		for (int j = 0; j < m; j++) {
			cin >> p;
			check[p] = true;
		}
	}
	int c = 0;
	for (int i = 1; i <= n; i++)if (!check[i])c++;
	cout << c;

	return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)


using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

ll a[200010];
ll sum[200010];

// Description: [1,x]のクエリに対するデータ構造 
// TimeComplexity: 更新$\mathcal{O}(\log n)$ クエリ$\mathcal{O}(\log n)$
// Verifyed: ARC 033 C

struct Binary_indexed_tree{
	using T=ll;
	vector<T> data;
	int n;

	Binary_indexed_tree(int _n):n(_n){data.assign(n+1,0);}

	void update(int i,T x){
		for(i++;i<=n;i+=i&-i) data[i]+=x;
	}

	T query(int i){
		T ret=0;
		for(i++;i>0;i-=i&-i) ret+=data[i];
		return ret;
	}
};

int main(void){
	int n,k;
	cin >> n >> k;

	rep(i,1,n+1) cin >> a[i];
	rep(i,1,n+1) a[i]-=k;
	
	rep(i,1,n+1) sum[i] = sum[i-1] + a[i];
		
	using pli = pair<ll,int>;
	vector<pli> ary;
	rep(i,n+1) ary.push_back(pli(sum[i],i));
	sort(begin(ary),end(ary));


	ll ans = 0LL;
	Binary_indexed_tree bit(n+1);
	for(auto &it:ary){
		const int idx = it.second;
		ans += bit.query(idx);
		bit.update(idx,1LL);
	}

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

Measured memory_bytes: 9584
#include<stdio.h>
int main(){
int a,b,c,i,j,k,x,count=0;
scanf("%d%d%d%d",&a,&b,&c,&x);
for(i=0;i<=a;i++){
for(j=0;j<=b;j++){
for(k=0;k<=c;k++){
if(i*500+j*100+k*50==x)count++;
}}}
printf("%d",count);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main(){
  int n;
  cin >> n;
  int a,b,c,d;
  d = n%10; n /= 10;
  c = n%10; n /= 10;
  b = n%10; n /= 10;
  a = n%10;
  if(a+b+c+d==7) printf("%d%s%d%s%d%s%d%s%d",a,"+",b,"+",c,"+",d,"=",7);
  else if(a-b+c+d==7) printf("%d%s%d%s%d%s%d%s%d",a,"-",b,"+",c,"+",d,"=",7);
  else if(a+b-c+d==7) printf("%d%s%d%s%d%s%d%s%d",a,"+",b,"-",c,"+",d,"=",7);
  else if(a-b-c+d==7) printf("%d%s%d%s%d%s%d%s%d",a,"-",b,"-",c,"+",d,"=",7);
  else if(a+b+c-d==7) printf("%d%s%d%s%d%s%d%s%d",a,"+",b,"+",c,"-",d,"=",7);
  else if(a-b+c-d==7) printf("%d%s%d%s%d%s%d%s%d",a,"-",b,"+",c,"-",d,"=",7);
  else if(a+b-c-d==7) printf("%d%s%d%s%d%s%d%s%d",a,"+",b,"-",c,"-",d,"=",7);
  else if(a-b-c-d==7) printf("%d%s%d%s%d%s%d%s%d",a,"-",b,"-",c,"-",d,"=",7);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1e9 + 7;
const int MAX = 1e9;
const ll LLMAX = 1e18;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<int> A(N); rep(i, N) cin >> A[i];
    vector<int> B(M); rep(i, M) cin >> B[i];

    // a_i を作成 index: 0〜N（N + 1個）
    // 2 * 10^9 を超えるので long long
    vector<ll> a(1);
    rep(i, N) {
        a.push_back(a[i] + A[i]); // i + 1 番目の配列を作成
    }
    
    // b_i を作成 index: 0〜M（M + 1個）
    // 2 * 10^9 を超えるので long long
    vector<ll> b(1);
    rep(i, M) {
        b.push_back(b[i] + B[i]); // i + 1 番目の配列を作成
    }

    int ans = 0;
    int j = M;

    // a_i について i = 0〜N で探索
    rep(i, N + 1) {
        if (a[i] > K) break;
        
        while(b[j] > K - a[i]) {
            j -= 1;
        }
        ans = max(ans, i + j);
    }

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


Measured memory_bytes: 9564
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;
void solve()
{
	int len;
	cin>>len;
	string s;
	cin>>s;
	if(len&1)
	{
		cout<<"No\n";
		return;	
	}	
	int i = 0, j = len/2;
	while(j<len)
	{
		if(s[i]!=s[j])
		{
			cout<<"No\n";
			return;
		}
		i++, j++;
	}
	cout<<"Yes\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3620
def main():
  from collections import deque
  n,m,*t=map(int,open(0).read().split())
  i=[0]*n
  o=[[]for _ in range(n)]
  for a,b in zip(*[iter(t)]*2):
    o[a-1]+=b-1,
    i[b-1]+=1
  q=deque(v for v,f in enumerate(i)if f<1)
  r=[]
  while q:
    v=q.popleft()
    r+=v,
    for w in o[v]:
      i[w]-=1
      if i[w]==0:q+=w,
  print(-(len(r)==n))
main()


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

int main(){
    string s;
    cin >> s;
    ll sum = 0;
    for(auto x : s){
        sum += x - '0';
    }
    if(sum % 9 == 0){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3744
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n,k,a=1;
cin >> n >> k;
for(int i=1;i<n+1;i++){
   if(a<=k){
	   a = a*2;
   } 
   else{
       a = a+k;
   }
}

cout << a << endl;

////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int N;
vector<int> p(15);
vector<P> p_count;
vector<int> good_num(5);

int main()
{
    cin >> N;
    p = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
    for (auto pi : p)
    {
        p_count.push_back(P(pi, 0));
    }
    // 1~Nまでの数を素因数分解したときの素因数の数を数える
    for (int i = 1; i <= N; i++)
    {
        int a = i;
        int num = 0;
        for (auto pi : p)
        {
            while (a % pi == 0)
            {
                p_count[num].second++;
                a /= pi;
            }
            num++;
        }
    }
    // 確認用
    /*
    for (auto a : p_count)
    {
        cout << a.first << ' ' << a.second << endl;
    }
    */

    // 七五数の素因数の候補を数える
    for (auto pi : p_count)
    {
        if (pi.second >= 74)
        {
            rep(0, i, 5)
            {
                good_num[i]++;
            }
        }
        else if (pi.second >= 24)
        {
            rep(0, i, 4)
            {
                good_num[i]++;
            }
        }
        else if (pi.second >= 14)
        {
            rep(0, i, 3)
            {
                good_num[i]++;
            }
        }
        else if (pi.second >= 4)
        {
            rep(0, i, 2)
            {
                good_num[i]++;
            }
        }
        else if (pi.second >= 2)
        {
            good_num[0]++;
        }
    }

    int ans = good_num[4] + +good_num[3] * (good_num[0] - 1) + good_num[2] * (good_num[1] - 1) + good_num[1] * (good_num[1] - 1) * (good_num[0] - 2) / 2;
    if (ans > 0)
    {
        cout << ans << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 8;
int a[N][N], b[N][N];
int n, m, k;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> k;
    rep(i, 1, n) {
        string s;
        cin >> s;
        rep(j, 1, m) {
            a[i][j] = s[j - 1] == '#';
        }
    }
    int ans = 0;
    rep(mask1, 0, (1 << n) - 1) {
        rep(mask2, 0, (1 << m) - 1) {
            int cur = 0;
            rep(i, 1, n) {
                rep(j, 1, m) {
                    bool black = a[i][j] && (mask1 & (1 << (i - 1))) && (mask2 & (1 << (j - 1)));
                    cur += black;
                }
            }
            ans += cur == k;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3576